Files
nixpkgs/pkgs/development/python-modules/cuda-bindings/patch-nvidia-libs-paths_13_5.patch
2026-11-07 14:57:26 +00:00

232 lines
9.6 KiB
Diff

diff --git a/cuda_bindings_13/cuda/bindings/_internal/cudla_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/cudla_linux.pyx
index 461464febfd..9504b5edb2a 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/cudla_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/cudla_linux.pyx
@@ -61,7 +61,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -248,7 +248,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("cudla")._handle_uint
+ cdef uintptr_t handle = CDLL("@libcudla@")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/cufile_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/cufile_linux.pyx
index 6f5f8835407..d757fbd566c 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/cufile_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/cufile_linux.pyx
@@ -59,7 +59,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -599,7 +599,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("cufile")._handle_uint
+ cdef uintptr_t handle = CDLL("@libcufile@/lib/libcufile.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx
index a1a4472fe91..965d1bae5da 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/driver_linux.pyx
@@ -59,7 +59,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -3799,7 +3799,13 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("cuda")._handle_uint
+ # Search like the dynamic linker would for a library with the driver link in its RUNPATH: LD_LIBRARY_PATH
+ # first (e.g. a host driver exposed by nixglhost or a container runtime), then the configured path.
+ cdef uintptr_t handle
+ try:
+ handle = CDLL("libcuda.so.1")._handle
+ except OSError:
+ handle = CDLL("@libcuda@/libcuda.so.1")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/nvfatbin_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/nvfatbin_linux.pyx
index b8bfa45c994..e2f3855689b 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/nvfatbin_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/nvfatbin_linux.pyx
@@ -57,7 +57,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -233,7 +233,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("nvfatbin")._handle_uint
+ cdef uintptr_t handle = CDLL("@libnvfatbin@/lib/libnvfatbin.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/nvjitlink_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/nvjitlink_linux.pyx
index e111a388264..a0cf60ec055 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/nvjitlink_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/nvjitlink_linux.pyx
@@ -60,7 +60,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -280,7 +280,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("nvJitLink")._handle_uint
+ cdef uintptr_t handle = CDLL("@libnvjitlink@/lib/libnvJitLink.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/nvml_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/nvml_linux.pyx
index 2bf77971953..0c9d2d98d99 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/nvml_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/nvml_linux.pyx
@@ -57,7 +57,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -4259,7 +4259,13 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("nvml")._handle_uint
+ # Search like the dynamic linker would for a library with the driver link in its RUNPATH: LD_LIBRARY_PATH
+ # first (e.g. a host driver exposed by nixglhost or a container runtime), then the configured path.
+ cdef uintptr_t handle
+ try:
+ handle = CDLL("libnvidia-ml.so.1")._handle
+ except OSError:
+ handle = CDLL("@libnvml@/lib/libnvidia-ml.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/nvrtc_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/nvrtc_linux.pyx
index 76605168771..76acdb48eb0 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/nvrtc_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/nvrtc_linux.pyx
@@ -57,7 +57,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -420,7 +420,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("nvrtc")._handle_uint
+ cdef uintptr_t handle = CDLL("@libnvrtc@/lib/libnvrtc.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/nvvm_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/nvvm_linux.pyx
index 0e410e0618d..3773a20308f 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/nvvm_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/nvvm_linux.pyx
@@ -57,7 +57,7 @@ cdef object _cyb_symbol_lock = _cyb_threading.Lock()
from libc.stdint cimport uintptr_t
from .utils import FunctionNotFoundError, NotSupportedError
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
###############################################################################
@@ -255,7 +255,7 @@ cpdef _inspect_function_pointer(str name):
cdef void* load_library() except* with gil:
- cdef uintptr_t handle = load_nvidia_dynamic_lib("nvvm")._handle_uint
+ cdef uintptr_t handle = CDLL("@libnvvm@/lib/libnvvm.so")._handle
return <void*>handle
diff --git a/cuda_bindings_13/cuda/bindings/_internal/runtime_linux.pyx b/cuda_bindings_13/cuda/bindings/_internal/runtime_linux.pyx
index 0cbc3454ba2..6be8b7961e9 100644
--- a/cuda_bindings_13/cuda/bindings/_internal/runtime_linux.pyx
+++ b/cuda_bindings_13/cuda/bindings/_internal/runtime_linux.pyx
@@ -9,11 +9,19 @@ import os
from libc.stdint cimport uintptr_t
-from cuda.pathfinder import load_nvidia_dynamic_lib
+from ctypes import CDLL
cimport cuda.bindings._lib.dlfcn as dlfcn
cimport cuda.bindings._internal.runtime_ptds as ptds
cimport cython
+try:
+ CDLL("libcuda.so.1")
+except OSError:
+ try:
+ CDLL("@libcuda@/libcuda.so.1")
+ except OSError:
+ pass
+
###############################################################################
# Per-thread default stream dispatch
@@ -50,14 +58,14 @@ include "../_lib/cyruntime/cyruntime.pxi"
cdef cudaError_t _getLocalRuntimeVersion(int* runtimeVersion) except ?cudaErrorCallRequiresNewerDriver nogil:
# Load cudart dynamically to read its embedded version number.
with gil:
- loaded_dl = load_nvidia_dynamic_lib("cudart")
- handle = <void *><uintptr_t>loaded_dl._handle_uint
+ loaded_dl = CDLL("@libcudart@/lib/libcudart.so")
+ handle = <void *><uintptr_t>loaded_dl._handle
cdef void* __cudaRuntimeGetVersion = dlfcn.dlsym(handle, 'cudaRuntimeGetVersion')
if __cudaRuntimeGetVersion == NULL:
with gil:
- raise RuntimeError(f'Function "cudaRuntimeGetVersion" not found in {loaded_dl.abs_path}')
+ raise RuntimeError(f'Function "cudaRuntimeGetVersion" not found in {loaded_dl._name}')
# We explicitly do *NOT* cleanup the library handle here, acknowledging
# that, yes, the handle leaks. The reason is that there's a