diff --git a/pyopencl/capture_call.py b/pyopencl/capture_call.py index c0648b21ea3f89fb68114c1315d8075cb7ef6775..11535f5849618f79e1e587d8e79709286b745089 100644 --- a/pyopencl/capture_call.py +++ b/pyopencl/capture_call.py @@ -146,7 +146,7 @@ def capture_kernel_call(kernel, output_file, queue, g_size, l_size, *args, **kwa for name, val in arg_data: cg("%s = (" % name) with Indentation(cg): - val = str(b64encode(compress(memoryview(val)))) + val = b64encode(compress(memoryview(val))).decode() i = 0 while i < len(val): cg(repr(val[i:i+line_len])) diff --git a/test/test_wrapper.py b/test/test_wrapper.py index 22f27f74cbc4d35f5d5dcc4cf279aecce22772b1..0ec3e1343a324d36bc2f14dd31963970a1c7e498 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -1266,6 +1266,39 @@ def test_command_queue_context_manager(ctx_factory): q.flush() +def test_capture_call(ctx_factory): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + + a_np = np.random.rand(500).astype(np.float32) + b_np = np.random.rand(500).astype(np.float32) + + ctx = cl.create_some_context() + queue = cl.CommandQueue(ctx) + + mf = cl.mem_flags + a_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a_np) + b_g = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=b_np) + + prg = cl.Program(ctx, """ + __kernel void sum( + __global const float *a_g, __global const float *b_g, __global float *res_g) + { + int gid = get_global_id(0); + res_g[gid] = a_g[gid] + b_g[gid]; + } + """).build() + + res_g = cl.Buffer(ctx, mf.WRITE_ONLY, a_np.nbytes) + from io import StringIO + sio = StringIO() + prg.sum.capture_call(sio, queue, a_np.shape, None, a_g, b_g, res_g) + + compile_dict = {} + exec(compile(sio.getvalue(), "captured.py", "exec"), compile_dict) + compile_dict["main"]() + + if __name__ == "__main__": # make sure that import failures get reported, instead of skipping the tests. import pyopencl # noqa