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 8, 2022
1 parent ec4d7f0 commit 27f78a4
Showing 1 changed file with 62 additions and 20 deletions.
82 changes: 62 additions & 20 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1351,36 +1351,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 @@ -1624,7 +1643,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 Expand Up @@ -2262,6 +2281,29 @@ def alloc2(size):
# }}}


# {{{ test multiple queues

def test_multiple_queues(ctx_factory):
ctx = ctx_factory()

a = [None] * 3
for i in range(len(a)):
queue = cl.CommandQueue(ctx)
a[i] = cl_array.arange(queue, 1000, dtype=np.float32)

b = a[i] + a[i]
b = a[i] ** 2
b = a[i] + 4000
assert len(b.write_events) == 1
assert len(a[i].read_events) == 3

a[i] = a[i].with_queue(None)

b = a[0].with_queue(queue) + a[1].with_queue(queue)

# }}}


if __name__ == "__main__":
if len(sys.argv) > 1:
exec(sys.argv[1])
Expand Down

0 comments on commit 27f78a4

Please sign in to comment.