Skip to content

Commit a8e1ae3

Browse files
committed
use read/write_events in tests
1 parent 9d610b8 commit a8e1ae3

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

13861386
x = clrand(queue, (5, 10), dtype=np.float32)
1387-
assert len(x.events) == 1, len(x.events)
1387+
assert len(x.write_events) == 1, x.write_events
1388+
assert len(x.read_events) == 0, x.read_events
13881389

13891390
x.finish()
13901391

1391-
assert len(x.events) == 0
1392-
1393-
y = x+x
1394-
assert len(y.events) == 1
1395-
y = x*x
1396-
assert len(y.events) == 1
1397-
y = 2*x
1398-
assert len(y.events) == 1
1399-
y = 2/x
1400-
assert len(y.events) == 1
1401-
y = x/2
1402-
assert len(y.events) == 1
1403-
y = x**2
1404-
assert len(y.events) == 1
1405-
y = 2**x
1406-
assert len(y.events) == 1
1392+
assert len(x.write_events) == 0
1393+
assert len(x.read_events) == 0
1394+
1395+
y = x + 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) == 2
1398+
1399+
y = x * x
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) == 4
1402+
1403+
y = 2 * x
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) == 5
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) == 6
1410+
1411+
y = x / 2
1412+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1413+
assert len(x.write_events) == 0 and len(x.read_events) == 7
1414+
1415+
y = x ** 2
1416+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1417+
assert len(x.write_events) == 0 and len(x.read_events) == 8
1418+
1419+
y = 2 ** x
1420+
assert len(y.write_events) == 1 and len(y.read_events) == 0
1421+
assert len(x.write_events) == 0 and len(x.read_events) == 9
1422+
1423+
x.finish()
14071424

14081425
for _i in range(10):
14091426
x.fill(0)
14101427

1411-
assert len(x.events) == 10
1428+
assert len(x.write_events) == 10
1429+
assert len(x.read_events) == 0
14121430

14131431
for _i in range(1000):
14141432
x.fill(0)
14151433

1416-
assert len(x.events) < 100
1434+
assert len(x.write_events) < 100
1435+
assert len(x.read_events) == 0
14171436

14181437
# }}}
14191438

@@ -1658,7 +1677,7 @@ def test_get_async(ctx_factory):
16581677
assert np.abs(b1 - b).mean() < 1e-5
16591678

16601679
wait_event = cl.UserEvent(context)
1661-
b_gpu.add_event(wait_event)
1680+
b_gpu.add_write_event(wait_event)
16621681
b, evt = b_gpu.get_async() # testing that this doesn't hang
16631682
wait_event.set_status(cl.command_execution_status.COMPLETE)
16641683
evt.wait()
@@ -2296,6 +2315,8 @@ def alloc2(size):
22962315
# }}}
22972316

22982317

2318+
# {{{ test_logical_and_or
2319+
22992320
def test_logical_and_or(ctx_factory):
23002321
# NOTE: Copied over from pycuda/test/test_gpuarray.py
23012322
rng = np.random.default_rng(seed=0)
@@ -2349,6 +2370,31 @@ def test_logical_not(ctx_factory):
23492370
cl_array.logical_not((cl_array.zeros(cq, 10, np.float64) + 1)).get(),
23502371
np.logical_not(np.ones(10)))
23512372

2373+
# }}}
2374+
2375+
2376+
# {{{ test multiple queues
2377+
2378+
def test_multiple_queues(ctx_factory):
2379+
ctx = ctx_factory()
2380+
2381+
a = [None] * 3
2382+
for i in range(len(a)):
2383+
queue = cl.CommandQueue(ctx)
2384+
a[i] = cl_array.arange(queue, 1000, dtype=np.float32)
2385+
2386+
b = a[i] + a[i]
2387+
b = a[i] ** 2
2388+
b = a[i] + 4000
2389+
assert len(b.write_events) == 1
2390+
assert len(a[i].read_events) == 4
2391+
2392+
a[i] = a[i].with_queue(None)
2393+
2394+
b = a[0].with_queue(queue) + a[1].with_queue(queue)
2395+
2396+
# }}}
2397+
23522398

23532399
if __name__ == "__main__":
23542400
if len(sys.argv) > 1:

0 commit comments

Comments
 (0)