Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions numba/cuda/cudadrv/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1920,7 +1920,7 @@ def _stream_callback(handle, status, data):
def async_done(self) -> asyncio.futures.Future:
"""
Return an awaitable that resolves once all preceding stream operations
are complete.
are complete. The result of the awaitable is the current stream.
"""
loop = asyncio.get_running_loop() if utils.PYVERSION >= (3, 7) \
else asyncio.get_event_loop()
Expand All @@ -1930,7 +1930,7 @@ def resolver(future, status):
if future.done():
return
elif status == 0:
future.set_result(None)
future.set_result(self)
Comment thread
stuartarchibald marked this conversation as resolved.
else:
future.set_exception(Exception(f"Stream error {status}"))

Expand Down
16 changes: 14 additions & 2 deletions numba/cuda/tests/cudadrv/test_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ async def async_cuda_fn(value_in: float) -> float:
h_src[:] = value_in
d_ary = cuda.to_device(h_src, stream=stream)
d_ary.copy_to_host(h_dst, stream=stream)
await stream.async_done()
done_result = await stream.async_done()
self.assertEqual(done_result, stream)
return h_dst.mean()

values_in = [1, 2, 3, 4]
Expand All @@ -59,7 +60,18 @@ async def async_cuda_fn(value_in: float) -> float:
async def test_multiple_async_done(self):
stream = cuda.stream()
done_aws = [stream.async_done() for _ in range(4)]
await asyncio.gather(*done_aws)
done = await asyncio.gather(*done_aws)
for d in done:
self.assertEqual(d, stream)

@with_asyncio_loop
async def test_multiple_async_done_multiple_streams(self):
streams = [cuda.stream() for _ in range(4)]
done_aws = [stream.async_done() for stream in streams]
done = await asyncio.gather(*done_aws)

# Ensure we got the four original streams in done
self.assertSetEqual(set(done), set(streams))

@with_asyncio_loop
async def test_cancelled_future(self):
Expand Down