Skip to content

Commit fd6a059

Browse files
authored
Merge pull request #7453 from gmarkall/async_done_stream
CUDA: Provide stream in async_done result
2 parents a39594f + b7793a9 commit fd6a059

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

‎numba/cuda/cudadrv/driver.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1920,7 +1920,7 @@ def _stream_callback(handle, status, data):
19201920
def async_done(self) -> asyncio.futures.Future:
19211921
"""
19221922
Return an awaitable that resolves once all preceding stream operations
1923-
are complete.
1923+
are complete. The result of the awaitable is the current stream.
19241924
"""
19251925
loop = asyncio.get_running_loop() if utils.PYVERSION >= (3, 7) \
19261926
else asyncio.get_event_loop()
@@ -1930,7 +1930,7 @@ def resolver(future, status):
19301930
if future.done():
19311931
return
19321932
elif status == 0:
1933-
future.set_result(None)
1933+
future.set_result(self)
19341934
else:
19351935
future.set_exception(Exception(f"Stream error {status}"))
19361936

‎numba/cuda/tests/cudadrv/test_streams.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ async def async_cuda_fn(value_in: float) -> float:
4747
h_src[:] = value_in
4848
d_ary = cuda.to_device(h_src, stream=stream)
4949
d_ary.copy_to_host(h_dst, stream=stream)
50-
await stream.async_done()
50+
done_result = await stream.async_done()
51+
self.assertEqual(done_result, stream)
5152
return h_dst.mean()
5253

5354
values_in = [1, 2, 3, 4]
@@ -59,7 +60,18 @@ async def async_cuda_fn(value_in: float) -> float:
5960
async def test_multiple_async_done(self):
6061
stream = cuda.stream()
6162
done_aws = [stream.async_done() for _ in range(4)]
62-
await asyncio.gather(*done_aws)
63+
done = await asyncio.gather(*done_aws)
64+
for d in done:
65+
self.assertEqual(d, stream)
66+
67+
@with_asyncio_loop
68+
async def test_multiple_async_done_multiple_streams(self):
69+
streams = [cuda.stream() for _ in range(4)]
70+
done_aws = [stream.async_done() for stream in streams]
71+
done = await asyncio.gather(*done_aws)
72+
73+
# Ensure we got the four original streams in done
74+
self.assertSetEqual(set(done), set(streams))
6375

6476
@with_asyncio_loop
6577
async def test_cancelled_future(self):

0 commit comments

Comments
 (0)