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
make cuPythonInit reentrant + ensure GIL is released when calling und…
…erlying C APIs
  • Loading branch information
leofang committed Aug 15, 2025
commit cd45744b985057f745b8997cc5ed3f3609a31fa6
1,134 changes: 570 additions & 564 deletions cuda_bindings/cuda/bindings/_bindings/cydriver.pyx.in

Large diffs are not rendered by default.

7 changes: 3 additions & 4 deletions cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ 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 Expand Up @@ -237,7 +236,7 @@ cdef int cuPythonInit() except -1 nogil:
{{endif}}

{{else}}
handle = <void*><uintptr_t>load_nvidia_dynamic_lib("nvrtc")._handle_uint
handle = <void*><uintptr_t>(load_nvidia_dynamic_lib("nvrtc")._handle_uint)

# Load function
{{if 'nvrtcGetErrorString' in found_functions}}
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,12 +79,13 @@ 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 void* handle = NULL
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,12 +61,13 @@ 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 void* handle = NULL
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
6 changes: 3 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +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,12 +60,13 @@ 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 void* handle = NULL
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
6 changes: 3 additions & 3 deletions cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +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