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 Jul 21, 2023
1 parent 9d610b8 commit 5db9f25
Showing 1 changed file with 66 additions and 20 deletions.
86 changes: 66 additions & 20 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -1384,36 +1384,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 @@ -1658,7 +1677,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 @@ -2296,6 +2315,8 @@ def alloc2(size):
# }}}


# {{{ test_logical_and_or

def test_logical_and_or(ctx_factory):
# NOTE: Copied over from pycuda/test/test_gpuarray.py
rng = np.random.default_rng(seed=0)
Expand Down Expand Up @@ -2349,6 +2370,31 @@ def test_logical_not(ctx_factory):
cl_array.logical_not((cl_array.zeros(cq, 10, np.float64) + 1)).get(),
np.logical_not(np.ones(10)))

# }}}


# {{{ 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:
Expand Down

0 comments on commit 5db9f25

Please sign in to comment.