Skip to content
Merged
Show file tree
Hide file tree
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
move init check inside of lock
  • Loading branch information
kkraus14 committed Aug 14, 2025
commit 58b7074cc905cd48cccbff05456489506f603023
9 changes: 5 additions & 4 deletions cuda_bindings/cuda/bindings/_bindings/cydriver.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -492,13 +492,14 @@ cdef bint __cuPythonInit = False

cdef int cuPythonInit() except -1 nogil:
global __cuPythonInit
if __cuPythonInit:
return 0
__cuPythonInit = True

cdef bint usePTDS
cdef char libPath[260]

with gil, __symbol_lock:
if __cuPythonInit:
return 0
__cuPythonInit = True

usePTDS = os.getenv('CUDA_PYTHON_CUDA_PER_THREAD_DEFAULT_STREAM', default=0)

# Load library
Expand Down
5 changes: 3 additions & 2 deletions cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ cdef bint __cuPythonInit = False

cdef int cuPythonInit() except -1 nogil:
global __cuPythonInit
if __cuPythonInit:
return 0

# Load library
with gil, __symbol_lock:
if __cuPythonInit:
return 0

{{if 'Windows' == platform.system()}}
handle = load_nvidia_dynamic_lib("nvrtc")._handle_uint

Expand Down
7 changes: 4 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ cdef void* load_library(const int driver_ver) except* with gil:

cdef int _check_or_init_cufile() except -1 nogil:
global __py_cufile_init
if __py_cufile_init:
return 0

cdef int err, driver_ver = 0

with gil, __symbol_lock:
if __py_cufile_init:
return 0

# Load driver to check version
handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL)
if handle == NULL:
Expand Down
7 changes: 4 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ cdef void* load_library(int driver_ver) except* with gil:

cdef int _check_or_init_nvjitlink() except -1 nogil:
global __py_nvjitlink_init
if __py_nvjitlink_init:
return 0

cdef int err, driver_ver = 0

with gil, __symbol_lock:
if __py_nvjitlink_init:
return 0

# Load driver to check version
handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL)
if handle == NULL:
Expand Down
7 changes: 4 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ cdef void* __nvJitLinkVersion = NULL

cdef int _check_or_init_nvjitlink() except -1 nogil:
global __py_nvjitlink_init
if __py_nvjitlink_init:
return 0

cdef int err, driver_ver = 0

with gil, __symbol_lock:
if __py_nvjitlink_init:
return 0

# Load driver to check version
try:
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
Expand Down
7 changes: 4 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,12 @@ cdef void* load_library(const int driver_ver) except* with gil:

cdef int _check_or_init_nvvm() except -1 nogil:
global __py_nvvm_init
if __py_nvvm_init:
return 0

cdef int err, driver_ver = 0

with gil, __symbol_lock:
if __py_nvvm_init:
return 0

# Load driver to check version
handle = dlopen('libcuda.so.1', RTLD_NOW | RTLD_GLOBAL)
if handle == NULL:
Expand Down
7 changes: 4 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ cdef void* __nvvmGetProgramLog = NULL

cdef int _check_or_init_nvvm() except -1 nogil:
global __py_nvvm_init
if __py_nvvm_init:
return 0

cdef int err, driver_ver = 0

with gil, __symbol_lock:
if __py_nvvm_init:
return 0

# Load driver to check version
try:
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
Expand Down