Skip to content

Commit c54df4b

Browse files
committed
use read/write_events in tests
1 parent f79583b commit c54df4b

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
@@ -1371,36 +1371,55 @@ def test_event_management(ctx_factory):
13711371
from pyopencl.clrandom import rand as clrand
13721372

13731373
x = clrand(queue, (5, 10), dtype=np.float32)
1374-
assert len(x.events) == 1, len(x.events)
1374+
assert len(x.write_events) == 1, x.write_events
1375+
assert len(x.read_events) == 0, x.read_events
13751376

13761377
x.finish()
13771378

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

13951412
for _i in range(10):
13961413
x.fill(0)
13971414

1398-
assert len(x.events) == 10
1415+
assert len(x.write_events) == 10
1416+
assert len(x.read_events) == 0
13991417

14001418
for _i in range(1000):
14011419
x.fill(0)
14021420

1403-
assert len(x.events) < 100
1421+
assert len(x.write_events) < 100
1422+
assert len(x.read_events) == 0
14041423

14051424
# }}}
14061425

@@ -1646,7 +1665,7 @@ def test_get_async(ctx_factory):
16461665
assert np.abs(b1 - b).mean() < 1e-5
16471666

16481667
wait_event = cl.UserEvent(context)
1649-
b_gpu.add_event(wait_event)
1668+
b_gpu.add_write_event(wait_event)
16501669
b, evt = b_gpu.get_async() # testing that this doesn't hang
16511670
wait_event.set_status(cl.command_execution_status.COMPLETE)
16521671
evt.wait()
@@ -2284,6 +2303,8 @@ def alloc2(size):
22842303
# }}}
22852304

22862305

2306+
# {{{ test_logical_and_or
2307+
22872308
def test_logical_and_or(ctx_factory):
22882309
# NOTE: Copied over from pycuda/test/test_gpuarray.py
22892310
rng = np.random.default_rng(seed=0)
@@ -2337,6 +2358,31 @@ def test_logical_not(ctx_factory):
23372358
cl_array.logical_not(cl_array.zeros(cq, 10, np.float64) + 1).get(),
23382359
np.logical_not(np.ones(10)))
23392360

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

23412387
# {{{ test XDG_CACHE_HOME handling
23422388

0 commit comments

Comments
 (0)