Skip to content

Commit 3b061dd

Browse files
committed
use read/write_events in tests
1 parent 98303de commit 3b061dd

File tree

1 file changed

+66
-20
lines changed

1 file changed

+66
-20
lines changed

test/test_array.py

Lines changed: 66 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,36 +1374,55 @@ def test_event_management(ctx_factory: cl.CtxFactory):
13741374
from pyopencl.clrandom import rand as clrand
13751375

13761376
x = clrand(queue, (5, 10), dtype=np.float32)
1377-
assert len(x.events) == 1, len(x.events)
1377+
assert len(x.write_events) == 1, x.write_events
1378+
assert len(x.read_events) == 0, x.read_events
13781379

13791380
x.finish()
13801381

1381-
assert len(x.events) == 0
1382-
1383-
y = x+x
1384-
assert len(y.events) == 1
1385-
y = x*x
1386-
assert len(y.events) == 1
1387-
y = 2*x
1388-
assert len(y.events) == 1
1389-
y = 2/x
1390-
assert len(y.events) == 1
1391-
y = x/2
1392-
assert len(y.events) == 1
1393-
y = x**2
1394-
assert len(y.events) == 1
1395-
y = 2**x
1396-
assert len(y.events) == 1
1382+
assert len(x.write_events) == 0
1383+
assert len(x.read_events) == 0
1384+
1385+
y = x + x
1386+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1387+
assert len(x.write_events) == 0 and len(x.read_events) == 2
1388+
1389+
y = x * x
1390+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1391+
assert len(x.write_events) == 0 and len(x.read_events) == 4
1392+
1393+
y = 2 * x
1394+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1395+
assert len(x.write_events) == 0 and len(x.read_events) == 5
1396+
1397+
y = 2 / x
1398+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1399+
assert len(x.write_events) == 0 and len(x.read_events) == 6
1400+
1401+
y = x / 2
1402+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1403+
assert len(x.write_events) == 0 and len(x.read_events) == 7
1404+
1405+
y = x ** 2
1406+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1407+
assert len(x.write_events) == 0 and len(x.read_events) == 8
1408+
1409+
y = 2 ** x
1410+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1411+
assert len(x.write_events) == 0 and len(x.read_events) == 9
1412+
1413+
x.finish()
13971414

13981415
for _i in range(10):
13991416
x.fill(0)
14001417

1401-
assert len(x.events) == 10
1418+
assert len(x.write_events) == 10
1419+
assert len(x.read_events) == 0
14021420

14031421
for _i in range(1000):
14041422
x.fill(0)
14051423

1406-
assert len(x.events) < 100
1424+
assert len(x.write_events) < 100
1425+
assert len(x.read_events) == 0
14071426

14081427
# }}}
14091428

@@ -1643,7 +1662,7 @@ def test_get_async(ctx_factory: cl.CtxFactory):
16431662
assert np.abs(b1 - b).mean() < 1e-5
16441663

16451664
wait_event = cl.UserEvent(context)
1646-
b_gpu.add_event(wait_event)
1665+
b_gpu.add_write_event(wait_event)
16471666
b, evt = b_gpu.get_async() # testing that this doesn't hang
16481667
wait_event.set_status(cl.command_execution_status.COMPLETE)
16491668
evt.wait()
@@ -2283,6 +2302,8 @@ def alloc2(size):
22832302
# }}}
22842303

22852304

2305+
# {{{ test_logical_and_or
2306+
22862307
def test_logical_and_or(ctx_factory: cl.CtxFactory):
22872308
# NOTE: Copied over from pycuda/test/test_gpuarray.py
22882309
rng = np.random.default_rng(seed=0)
@@ -2336,6 +2357,31 @@ def test_logical_not(ctx_factory: cl.CtxFactory):
23362357
cl_array.logical_not(cl_array.zeros(cq, 10, np.float64) + 1).get(),
23372358
np.logical_not(np.ones(10)))
23382359

2360+
# }}}
2361+
2362+
2363+
# {{{ test multiple queues
2364+
2365+
def test_multiple_queues(ctx_factory):
2366+
ctx = ctx_factory()
2367+
2368+
a = [None] * 3
2369+
for i in range(len(a)):
2370+
queue = cl.CommandQueue(ctx)
2371+
a[i] = cl_array.arange(queue, 1000, dtype=np.float32)
2372+
2373+
b = a[i] + a[i]
2374+
b = a[i] ** 2
2375+
b = a[i] + 4000
2376+
assert len(b.write_events) == 1
2377+
assert len(a[i].read_events) == 4
2378+
2379+
a[i] = a[i].with_queue(None)
2380+
2381+
b = a[0].with_queue(queue) + a[1].with_queue(queue)
2382+
2383+
# }}}
2384+
23392385

23402386
# {{{ test XDG_CACHE_HOME handling
23412387

0 commit comments

Comments
 (0)