fix: Make CUDA shared memory stream cache thread-safe in Python client - #915
Draft
jpbhdrey wants to merge 1 commit into
Draft
fix: Make CUDA shared memory stream cache thread-safe in Python client#915jpbhdrey wants to merge 1 commit into
jpbhdrey wants to merge 1 commit into
Conversation
jpbhdrey
marked this pull request as draft
August 9, 2026 20:32
Greptile SummaryThis PR makes creation and lookup of the process-global CUDA stream cache thread-safe.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or non-blocking defects identified in the changed code. The lock covers the complete cache lookup-and-create critical section, releases correctly on construction errors, and introduces no supported re-entrancy, lifetime, or lock-order failure. Important Files Changed
Reviews (1): Last reviewed commit: "fix: Make CUDA shared memory stream cach..." | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I opened this draft to discuss possible solutions to issue #914.
The simplest possible solution is just adding a lock inside the
_get_or_create_global_cuda_stream. With this lock, just one thread enters the global cuda stream creation clause at a time. And, of course, operations in a cuda stream are guaranteed to be serialized, so no problem in two python threads "owning" it.I also considered changing the return to an actual
CudaStreaminstance, but then it would change the intention of a unique cuda stream per device, as it is written right now, and I would need to change the callers as well.I opened this as a draft because there are comments in the
__del__methods in the wrappers of some cuda resources atcuda_shared_memory._utilsandCudaSharedMemoryRegioncould also suffer from the same problem.If you run the same reproducing script in the respective issue, it will run without errors. I don't know if this could be implemented as a test because it need GPUs.