Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUDA: Make arg optional for Stream.add_callback() #8542

Merged
merged 1 commit into from Oct 26, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions numba/cuda/cudadrv/driver.py
Expand Up @@ -2238,7 +2238,7 @@ def auto_synchronize(self):
yield self
self.synchronize()

def add_callback(self, callback, arg):
def add_callback(self, callback, arg=None):
"""
Add a callback to a compute stream.
The user provided function is called from a driver thread once all
Expand All @@ -2256,7 +2256,7 @@ def add_callback(self, callback, arg):
eventual deprecation and may be replaced in a future CUDA release.

:param callback: Callback function with arguments (stream, status, arg).
:param arg: User data to be passed to the callback function.
:param arg: Optional user data to be passed to the callback function.
"""
data = (self, callback, arg)
_py_incref(data)
Expand Down
11 changes: 11 additions & 0 deletions numba/cuda/tests/cudadrv/test_streams.py
Expand Up @@ -29,6 +29,17 @@ def callback(stream, status, event):
stream.add_callback(callback, callback_event)
self.assertTrue(callback_event.wait(1.0))

def test_add_callback_with_default_arg(self):
callback_event = threading.Event()

def callback(stream, status, arg):
self.assertIsNone(arg)
callback_event.set()

stream = cuda.stream()
stream.add_callback(callback)
self.assertTrue(callback_event.wait(1.0))

@with_asyncio_loop
async def test_async_done(self):
stream = cuda.stream()
Expand Down