From d26147212eaba35ec5839a8238e4099884d0223c Mon Sep 17 00:00:00 2001 From: Alexandru Fikl Date: Mon, 3 Oct 2022 22:13:36 +0300 Subject: [PATCH] use read/write_events in tests --- test/test_array.py | 82 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 20 deletions(-) diff --git a/test/test_array.py b/test/test_array.py index bde3bb0e5..679732d0b 100644 --- a/test/test_array.py +++ b/test/test_array.py @@ -1351,36 +1351,55 @@ def test_event_management(ctx_factory): from pyopencl.clrandom import rand as clrand x = clrand(queue, (5, 10), dtype=np.float32) - assert len(x.events) == 1, len(x.events) + assert len(x.write_events) == 1, x.write_events + assert len(x.read_events) == 0, x.read_events x.finish() - assert len(x.events) == 0 - - y = x+x - assert len(y.events) == 1 - y = x*x - assert len(y.events) == 1 - y = 2*x - assert len(y.events) == 1 - y = 2/x - assert len(y.events) == 1 - y = x/2 - assert len(y.events) == 1 - y = x**2 - assert len(y.events) == 1 - y = 2**x - assert len(y.events) == 1 + assert len(x.write_events) == 0 + assert len(x.read_events) == 0 + + y = x + x + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 1 + + y = x * x + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 2 + + y = 2 * x + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 3 + + y = 2 / x + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 4 + + y = x / 2 + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 5 + + y = x ** 2 + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 6 + + y = 2 ** x + assert len(y.write_events) == 1 and len(y.read_events) == 0 + assert len(x.write_events) == 0 and len(x.read_events) == 7 + + x.finish() for _i in range(10): x.fill(0) - assert len(x.events) == 10 + assert len(x.write_events) == 10 + assert len(x.read_events) == 0 for _i in range(1000): x.fill(0) - assert len(x.events) < 100 + assert len(x.write_events) < 100 + assert len(x.read_events) == 0 # }}} @@ -1624,7 +1643,7 @@ def test_get_async(ctx_factory): assert np.abs(b1 - b).mean() < 1e-5 wait_event = cl.UserEvent(context) - b_gpu.add_event(wait_event) + b_gpu.add_write_event(wait_event) b, evt = b_gpu.get_async() # testing that this doesn't hang wait_event.set_status(cl.command_execution_status.COMPLETE) evt.wait() @@ -2262,6 +2281,29 @@ def alloc2(size): # }}} +# {{{ test multiple queues + +def test_multiple_queues(ctx_factory): + ctx = ctx_factory() + + a = [None] * 3 + for i in range(len(a)): + queue = cl.CommandQueue(ctx) + a[i] = cl_array.arange(queue, 1000, dtype=np.float32) + + b = a[i] + a[i] + b = a[i] ** 2 + b = a[i] + 4000 + assert len(b.write_events) == 1 + assert len(a[i].read_events) == 3 + + a[i] = a[i].with_queue(None) + + b = a[0].with_queue(queue) + a[1].with_queue(queue) + +# }}} + + if __name__ == "__main__": if len(sys.argv) > 1: exec(sys.argv[1])