Skip to content

Commit

Permalink
use read/write_events in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfikl committed Oct 3, 2022
1 parent 957efa6 commit e2819b6
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1345,36 +1345,55 @@ def test_event_management(ctx_factory):
from pyopencl.clrandom import rand as clrand

x = clrand(queue, (5, 10), dtype=np.float32)
assert len(x.events) == 1, len(x.events)
assert len(x.write_events) == 1, x.write_events
assert len(x.read_events) == 0, x.read_events

x.finish()

assert len(x.events) == 0

y = x+x
assert len(y.events) == 1
y = x*x
assert len(y.events) == 1
y = 2*x
assert len(y.events) == 1
y = 2/x
assert len(y.events) == 1
y = x/2
assert len(y.events) == 1
y = x**2
assert len(y.events) == 1
y = 2**x
assert len(y.events) == 1
assert len(x.write_events) == 0
assert len(x.read_events) == 0

y = x + x
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 1

y = x * x
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 2

y = 2 * x
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 3

y = 2 / x
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 4

y = x / 2
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 5

y = x ** 2
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 6

y = 2 ** x
assert len(y.write_events) == 1 and len(y.read_events) == 0
assert len(x.write_events) == 0 and len(x.read_events) == 7

x.finish()

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

assert len(x.events) == 10
assert len(x.write_events) == 10
assert len(x.read_events) == 0

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

assert len(x.events) < 100
assert len(x.write_events) < 100
assert len(x.read_events) == 0

# }}}

Expand Down Expand Up @@ -1618,7 +1637,7 @@ def test_get_async(ctx_factory):
assert np.abs(b1 - b).mean() < 1e-5

wait_event = cl.UserEvent(context)
b_gpu.add_event(wait_event)
b_gpu.add_write_event(wait_event)
b, evt = b_gpu.get_async() # testing that this doesn't hang
wait_event.set_status(cl.command_execution_status.COMPLETE)
evt.wait()
Expand Down

0 comments on commit e2819b6

Please sign in to comment.