Skip to content

Instantly share code, notes, and snippets.

@gmarkall
Created October 1, 2021 15:37
Show Gist options
  • Save gmarkall/a5579a813f2d16ec36e8d7cb9c6b3d02 to your computer and use it in GitHub Desktop.
Save gmarkall/a5579a813f2d16ec36e8d7cb9c6b3d02 to your computer and use it in GitHub Desktop.
Iterating
Stream <CUDA stream 93950825260944 on <CUDA context c_void_p(93950819544272) of device 0>> done
Stream <CUDA stream 93950825975488 on <CUDA context c_void_p(93950819544272) of device 0>> done
Iterating
Stream <CUDA stream 94405088815088 on <CUDA context c_void_p(94405082385552) of device 0>> done
Iterating
Stream <CUDA stream 94405088101008 on <CUDA context c_void_p(94405082385552) of device 0>> done
from numba import cuda
import asyncio
async def f():
s1 = cuda.stream()
s2 = cuda.stream()
f1 = s1.async_done()
f2 = s2.async_done()
f_to_s = {f1: s1, f2: s2}
futures_pending = True
pending = set((f1, f2))
while futures_pending:
print("Iterating")
done, pending = await asyncio.wait(pending,
return_when=asyncio.FIRST_COMPLETED)
for d in done:
print(f"Stream {f_to_s[d]} done")
futures_pending = bool(pending)
loop = asyncio.get_event_loop()
loop.run_until_complete(f())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment