Skip to content

Commit 43184d7

Browse files
authored
Add deadlock warnings to Stream.add_callback and Stream.async_done docstrings (#321)
* Add deadlock warnings to Stream.add_callback and Stream.async_done docstrings - Add warning about potential deadlock when using libraries that call CUDA functions without releasing the GIL - This can occur when callback functions attempt to acquire the GIL while another thread is holding it and making CUDA calls - Recommends using libraries that properly release the GIL around CUDA operations * Update docstring warnings to clarify lock ordering issue - Clarify that deadlock is due to lock ordering issue between GIL and CUDA driver lock - Remove reference to 'another thread attempting to make CUDA calls' as this is not required - Focus on the core issue: callback acquiring GIL while CUDA driver lock is held
1 parent 3129f55 commit 43184d7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

numba_cuda/numba/cuda/cudadrv/driver.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,6 +2391,16 @@ def add_callback(self, callback, arg=None):
23912391
callback will block later work in the stream and may block other
23922392
callbacks from being executed.
23932393
2394+
.. warning::
2395+
There is a potential for deadlock due to a lock ordering issue
2396+
between the GIL and the CUDA driver lock when using libraries
2397+
that call CUDA functions without releasing the GIL. This can
2398+
occur when the callback function, which holds the CUDA driver lock,
2399+
attempts to acquire the GIL while another thread that holds the GIL
2400+
is waiting for the CUDA driver lock. Consider using libraries that
2401+
properly release the GIL around CUDA operations or restructure
2402+
your code to avoid this situation.
2403+
23942404
Note: The driver function underlying this method is marked for
23952405
eventual deprecation and may be replaced in a future CUDA release.
23962406
@@ -2425,6 +2435,16 @@ def async_done(self) -> asyncio.futures.Future:
24252435
"""
24262436
Return an awaitable that resolves once all preceding stream operations
24272437
are complete. The result of the awaitable is the current stream.
2438+
2439+
.. warning::
2440+
There is a potential for deadlock due to a lock ordering issue
2441+
between the GIL and the CUDA driver lock when using libraries
2442+
that call CUDA functions without releasing the GIL. This can
2443+
occur when the callback function (internally used by this method),
2444+
which holds the CUDA driver lock, attempts to acquire the GIL
2445+
while another thread that holds the GIL is waiting for the CUDA driver lock.
2446+
Consider using libraries that properly release the GIL around
2447+
CUDA operations or restructure your code to avoid this situation.
24282448
"""
24292449
loop = asyncio.get_running_loop()
24302450
future = loop.create_future()

0 commit comments

Comments
 (0)