Skip to content

Commit cc6ea10

Browse files
committed
use read/write_events in tests
1 parent 9f45645 commit cc6ea10

File tree

1 file changed

+62
-20
lines changed

1 file changed

+62
-20
lines changed

test/test_array.py

Lines changed: 62 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) == 1
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) == 2
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) == 3
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) == 4
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) == 5
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) == 6
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) == 7
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,29 @@ def alloc2(size):
22962315
# }}}
22972316

22982317

2318+
# {{{ test multiple queues
2319+
2320+
def test_multiple_queues(ctx_factory):
2321+
ctx = ctx_factory()
2322+
2323+
a = [None] * 3
2324+
for i in range(len(a)):
2325+
queue = cl.CommandQueue(ctx)
2326+
a[i] = cl_array.arange(queue, 1000, dtype=np.float32)
2327+
2328+
b = a[i] + a[i]
2329+
b = a[i] ** 2
2330+
b = a[i] + 4000
2331+
assert len(b.write_events) == 1
2332+
assert len(a[i].read_events) == 3
2333+
2334+
a[i] = a[i].with_queue(None)
2335+
2336+
b = a[0].with_queue(queue) + a[1].with_queue(queue)
2337+
2338+
# }}}
2339+
2340+
22992341
if __name__ == "__main__":
23002342
if len(sys.argv) > 1:
23012343
exec(sys.argv[1])

0 commit comments

Comments
 (0)