mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-10-30 16:10:36 +00:00
cuda-bindings loads libcuda and libnvidia-ml by absolute path from the NixOS driver link. Unlike libraries that carry the driver link in their RUNPATH, that ignores LD_LIBRARY_PATH, so on non-NixOS hosts where the driver is exposed that way (nixglhost, container runtimes) every cuda.bindings driver and NVML call fails. Packages that probe the GPU through cuda.bindings then silently fall back: CUTLASS DSL, for one, compiles for its default sm_100a and the kernels fail to launch with cudaErrorNoKernelImageForDevice. Try the soname first and fall back to the configured path, matching the dynamic linker's order for RUNPATH-linked libraries. On NixOS the soname lookup finds nothing and the driver link is used as before. This affects NVML in the 12.9 and 13.1 through 13.4 patches, and libcuda in the 13.4 patch only; earlier versions load libcuda by soname, which the patches leave alone. 13.0 has no NVML module. Assisted-by: Claude Code (Claude Opus 5.5, claude-opus-5-5)
167 lines
6.6 KiB
Diff
167 lines
6.6 KiB
Diff
diff --git a/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx b/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx
|
|
index 78ea77b283..0b875a6cd3 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/cufile_linux.pyx
|
|
@@ -9,7 +9,7 @@ import threading
|
|
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
import cython
|
|
|
|
@@ -95,7 +95,7 @@ cdef void* __cuFileSetParameterString = NULL
|
|
|
|
|
|
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/cuda/bindings/_internal/nvfatbin_linux.pyx b/cuda_bindings/cuda/bindings/_internal/nvfatbin_linux.pyx
|
|
index f5a9bbd218..8271f7aa20 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/nvfatbin_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/nvfatbin_linux.pyx
|
|
@@ -9,7 +9,7 @@ from libc.stdint cimport intptr_t, uintptr_t
|
|
import threading
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
|
|
###############################################################################
|
|
@@ -73,7 +73,7 @@ cdef void* __nvFatbinAddTileIR = NULL
|
|
|
|
|
|
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/cuda/bindings/_internal/nvjitlink_linux.pyx b/cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx
|
|
index d676aac372..ed3c000566 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx
|
|
@@ -9,7 +9,7 @@ from libc.stdint cimport intptr_t, uintptr_t
|
|
import threading
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
|
|
###############################################################################
|
|
@@ -76,7 +76,7 @@ cdef void* __nvJitLinkVersion = NULL
|
|
|
|
|
|
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/cuda/bindings/_internal/nvml_linux.pyx b/cuda_bindings/cuda/bindings/_internal/nvml_linux.pyx
|
|
index 51f6e8205b..1dd64a6d5e 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/nvml_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/nvml_linux.pyx
|
|
@@ -10,7 +10,7 @@ import threading
|
|
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
|
|
###############################################################################
|
|
@@ -414,7 +414,13 @@ cdef void* __nvmlGpuInstanceSetVgpuSchedulerState_v2 = NULL
|
|
|
|
|
|
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/cuda/bindings/_internal/nvrtc_linux.pyx b/cuda_bindings/cuda/bindings/_internal/nvrtc_linux.pyx
|
|
index d3eb62be13..6d5d093c1b 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/nvrtc_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/nvrtc_linux.pyx
|
|
@@ -9,7 +9,7 @@ from libc.stdint cimport intptr_t, uintptr_t
|
|
import threading
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
###############################################################################
|
|
# Extern
|
|
@@ -82,7 +82,7 @@ cdef void* __nvrtcGetPCHHeapSizeRequired = NULL
|
|
cdef void* __nvrtcSetFlowCallback = NULL
|
|
|
|
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
|
|
|
|
cdef int _init_nvrtc() except -1 nogil:
|
|
diff --git a/cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx b/cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
|
|
index 03ade4f939..0385da3087 100644
|
|
--- a/cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
|
|
+++ b/cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
|
|
@@ -9,7 +9,7 @@ from libc.stdint cimport intptr_t, uintptr_t
|
|
import threading
|
|
from .utils import FunctionNotFoundError, NotSupportedError
|
|
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
|
|
|
|
###############################################################################
|
|
@@ -76,7 +76,7 @@ cdef void* __nvvmLLVMVersion = NULL
|
|
|
|
|
|
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/cuda/bindings/cyruntime.pyx.in b/cuda_bindings/cuda/bindings/cyruntime.pyx.in
|
|
index 5cd65fbd96..fbbcffbbb7 100644
|
|
--- a/cuda_bindings/cuda/bindings/cyruntime.pyx.in
|
|
+++ b/cuda_bindings/cuda/bindings/cyruntime.pyx.in
|
|
@@ -1874,7 +1874,7 @@ cdef cudaError_t cudaGraphicsVDPAURegisterOutputSurface(cudaGraphicsResource** r
|
|
{{if True}}
|
|
|
|
from libc.stdint cimport uintptr_t
|
|
-from cuda.pathfinder import load_nvidia_dynamic_lib
|
|
+from ctypes import CDLL
|
|
{{if 'Windows' == platform.system()}}
|
|
cimport cuda.bindings._lib.windll as windll
|
|
{{else}}
|
|
@@ -1884,11 +1884,11 @@ cimport cuda.bindings._lib.dlfcn as dlfcn
|
|
cdef cudaError_t getLocalRuntimeVersion(int* runtimeVersion) except ?cudaErrorCallRequiresNewerDriver nogil:
|
|
# Load
|
|
with gil:
|
|
- loaded_dl = load_nvidia_dynamic_lib("cudart")
|
|
+ loaded_dl = CDLL("@libcudart@/lib/libcudart.so")
|
|
{{if 'Windows' == platform.system()}}
|
|
- handle = <uintptr_t>loaded_dl._handle_uint
|
|
+ handle = <uintptr_t>loaded_dl._handle
|
|
{{else}}
|
|
- handle = <void *><uintptr_t>loaded_dl._handle_uint
|
|
+ handle = <void *><uintptr_t>loaded_dl._handle
|
|
{{endif}}
|
|
|
|
{{if 'Windows' == platform.system()}}
|