Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
relocate setting __cuPythonInit to avoid deadlock since we use cuGetP…
…rocAddress in the init function...
  • Loading branch information
kkraus14 committed Aug 14, 2025
commit 47c1c525eaab5780af41882818aa8701c7c0197c
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_bindings/cydriver.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ cdef int cuPythonInit() except -1 nogil:
global __cuPythonInit
if __cuPythonInit:
return 0
Comment on lines +495 to +496

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this outside of the lock if you have a bunch of threads trying to run this initially at the same time, you can end up in the situation where they all don't hit this early exit and all wait for the symbol lock and the reinitialize all of the symbols. I had done a quick and dirty local benchmark with a single thread acquiring a lock and doing nothing to understand the overhead in the early exit case and it was ~50ns.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I thought about this too. Good to know it's only ~50 ns. We should fix the codegen so that we check if symbol is null to avoid re-initialization, but it can be done later.

__cuPythonInit = True
Comment thread
leofang marked this conversation as resolved.
Resolved

cdef bint usePTDS
cdef char libPath[260]
Expand Down Expand Up @@ -8873,7 +8874,6 @@ cdef int cuPythonInit() except -1 nogil:
{{endif}}
{{endif}}

__cuPythonInit = True
return 0
Comment thread
leofang marked this conversation as resolved.
Resolved

{{if 'cuGetErrorString' in found_functions}}
Expand Down