diff --git a/pyopencl/tools.py b/pyopencl/tools.py index 2a2d0f9d061d6f74c38dc07a4341fbf8081d463d..633854e07a523b2cac694b111fabb4b7422ad73c 100644 --- a/pyopencl/tools.py +++ b/pyopencl/tools.py @@ -249,11 +249,18 @@ def pytest_generate_tests_for_pyopencl(metafunc): (self.device.name.strip(), self.device.platform.name.strip())) + class QueueFactory: + def __init__(self, ctx_factory): + self.ctx_factory = ctx_factory + + def __call__(self): + return cl.CommandQueue(self.ctx_factory()) + test_plat_and_dev = get_test_platforms_and_devices() arg_names = [] - for arg in ("platform", "device", "ctx_factory", "ctx_getter"): + for arg in ("platform", "device", "ctx_factory", "cl_queue", "ctx_getter"): if arg not in metafunc.fixturenames: continue @@ -277,6 +284,7 @@ def pytest_generate_tests_for_pyopencl(metafunc): for device in plat_devs: arg_dict["device"] = device arg_dict["ctx_factory"] = ContextFactory(device) + arg_dict["cl_queue"] = QueueFactory(ContextFactory(device)) arg_dict["ctx_getter"] = ContextFactory(device) arg_values.append(tuple(arg_dict[name] for name in arg_names)) diff --git a/test/test_wrapper.py b/test/test_wrapper.py index 75b39b495feab12b18f89b99d3e85bd53ea08849..74376b35fefedd5d6a795c6436347a843180e81b 100644 --- a/test/test_wrapper.py +++ b/test/test_wrapper.py @@ -531,6 +531,24 @@ def test_copy_buffer(ctx_factory): assert la.norm(a - b) == 0 +def test_copy_buffer_using_cl_queue(ctx_factory, cl_queue): + context = ctx_factory() + + queue = cl_queue() + mf = cl.mem_flags + + a = np.random.rand(50000).astype(np.float32) + b = np.empty_like(a) + + buf1 = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=a) + buf2 = cl.Buffer(context, mf.WRITE_ONLY, b.nbytes) + + cl.enqueue_copy(queue, buf2, buf1).wait() + cl.enqueue_copy(queue, b, buf2).wait() + + assert la.norm(a - b) == 0 + + def test_mempool(ctx_factory): from pyopencl.tools import MemoryPool, ImmediateAllocator