Repository navigation
Conversation
Under free-threaded Python, concurrent register/unregister of callbacks (cuLogs*, *AsyncNotification) corrupts the shared m_global._allocated std::map. Guard it with a cython.pymutex. driver.pyx and runtime.pyx are regenerated from cybind, not hand-edited. Closes NVIDIA#3282
Findings
|
| Layer / File(s) | Summary |
|---|---|
Locked allocation-map helpers cuda_bindings_13/cuda/bindings/driver.pyx, cuda_bindings_13/cuda/bindings/runtime.pyx |
Both global objects add a mutex and locked _insert and _take helpers for allocation-map access. |
Callback API integration cuda_bindings_13/cuda/bindings/driver.pyx, cuda_bindings_13/cuda/bindings/runtime.pyx |
Async-notification and log callback registration use _insert. Successful unregistration uses _take to remove callback data and then frees it. Generated-file content hashes also change. |
Concurrent regression test cuda_bindings_13/tests/test_callback_threads.py |
The test starts 16 workers together. Each performs 500 callback registration and unregistration cycles and checks for operation failures and worker exceptions. |
Assessment against linked issues
| Objective | Addressed | Explanation |
|---|---|---|
Synchronize callback bookkeeping shared by callback APIs [#3282] |
✅ | |
Add concurrent regression coverage for callback registration and unregistration [#3282] |
✅ |
Possibly related PRs
- NVIDIA/cuda-python#3081: It implements CUDA error-log helpers through the same
cuLogsRegisterCallbackandcuLogsUnregisterCallbackAPIs.
Suggested labels: bug, cuda.bindings
Suggested reviewers: rwgk, mdboom
Fixed issue severity: <fixed_issue_severity>Medium</fixed_issue_severity>
Change: Bug fix
Merge Risk: 
Low · up to 1ceee
-
The change adds locking around the callback bookkeeping maps so concurrent registration and unregistration should no longer corrupt them. The new regression test registers a null callback, so it could crash the test run if CUDA emits a log during it. Register a valid no-op callback in the test before merging.
Finishing Touches: 💡 1
-
🛠️ Fix failing CI checks: 💡
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
There was a problem hiding this comment.
Actionable comments posted: 1

Review info
-
Run configuration-
- Source mode: Auto
- Repository: NVIDIA/cuda-python
- Branch: main
- File: .coderabbit.yaml
- Commit: 71e837a
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Enterprise
- Run ID:
d8fed3c3-1408-42b1-aa7e-90d4dccf54b8
Files selected for processing: 3-
cuda_bindings_13/cuda/bindings/driver.pyxcuda_bindings_13/cuda/bindings/runtime.pyxcuda_bindings_13/tests/test_callback_threads.py
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
-
| try: | ||
| barrier.wait() | ||
| for _ in range(NUM_ITERATIONS): | ||
| err, handle = driver.cuLogsRegisterCallback(0, None) |
There was a problem hiding this comment.
important: Register a valid callback. If CUDA emits a log while a callback is registered, driver.pyx Line 51114–51117 calls this null pointer and crashes the pytest process. (raw.githubusercontent.com)
Register a no-op callback with the correct calling convention and keep it alive until the workers exit.
Description
closes #3282
reference cybind MR number: 609
cuLogsRegisterCallback/cuLogsUnregisterCallbackand the*DeviceRegisterAsyncNotification/*DeviceUnregisterAsyncNotificationpairs incuda.bindings.driverandcuda.bindings.runtimekeep their callback data in a globalstd::map. Concurrent register/unregister calls modified it without synchronization, which aborts the process under free-threaded Python.This PR adds a lock around that map.
driver.pyxandruntime.pyxare regenerated from cybind (companion MR: ), not edited by hand.A new test,
test_callback_threads.py, registers and unregisters callbacks from many threads at once. It crashes onmain(5/5 runs) and passes with this change.Checklist