Skip to content

Commit 260821f

Browse files
committed
use read/write_events in tests
1 parent 9cea994 commit 260821f

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

13741374
x = clrand(queue, (5, 10), dtype=np.float32)
1375-
assert len(x.events) == 1, len(x.events)
1375+
assert len(x.write_events) == 1, x.write_events
1376+
assert len(x.read_events) == 0, x.read_events
13761377

13771378
x.finish()
13781379

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

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

1399-
assert len(x.events) == 10
1416+
assert len(x.write_events) == 10
1417+
assert len(x.read_events) == 0
14001418

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

1404-
assert len(x.events) < 100
1422+
assert len(x.write_events) < 100
1423+
assert len(x.read_events) == 0
14051424

14061425
# }}}
14071426

@@ -1647,7 +1666,7 @@ def test_get_async(ctx_factory):
16471666
assert np.abs(b1 - b).mean() < 1e-5
16481667

16491668
wait_event = cl.UserEvent(context)
1650-
b_gpu.add_event(wait_event)
1669+
b_gpu.add_write_event(wait_event)
16511670
b, evt = b_gpu.get_async() # testing that this doesn't hang
16521671
wait_event.set_status(cl.command_execution_status.COMPLETE)
16531672
evt.wait()
@@ -2285,6 +2304,8 @@ def alloc2(size):
22852304
# }}}
22862305

22872306

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

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

23422388
# {{{ test XDG_CACHE_HOME handling
23432389

0 commit comments

Comments
 (0)