Skip to content

Commit 2b6609f

Browse files
Update NVML bindings to use cuda_pathfinder (#1661) (#1721)
* Update NVML bindings to use cuda_pathfinder * Fix Windows build (cherry picked from commit 3e4af8f) Co-authored-by: Michael Droettboom <[email protected]>
1 parent c7d444c commit 2b6609f

File tree

2 files changed

+5
-31
lines changed

2 files changed

+5
-31
lines changed

cuda_bindings/cuda/bindings/_internal/_nvml_linux.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ cdef void* __nvmlDeviceSetRusdSettings_v1 = NULL
406406

407407

408408
cdef void* load_library() except* with gil:
409-
return dlopen("libnvidia-ml.so.1", RTLD_NOW | RTLD_GLOBAL)
409+
cdef uintptr_t handle = load_nvidia_dynamic_lib("nvml")._handle_uint
410+
return <void*>handle
410411

411412

412413
cdef int _init_nvml() except -1 nogil:

cuda_bindings/cuda/bindings/_internal/_nvml_windows.pyx

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ from libc.stdint cimport intptr_t
99
import os
1010
import threading
1111

12+
from cuda.pathfinder import load_nvidia_dynamic_lib
13+
1214
from .utils import FunctionNotFoundError, NotSupportedError
1315

1416
from libc.stddef cimport wchar_t
@@ -422,43 +424,14 @@ cdef void* __nvmlDeviceReadPRMCounters_v1 = NULL
422424
cdef void* __nvmlDeviceSetRusdSettings_v1 = NULL
423425

424426

425-
cdef uintptr_t load_library() except* with gil:
426-
def do_load(path):
427-
return LoadLibraryExW(
428-
path,
429-
<void *>0,
430-
LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
431-
)
432-
433-
handle = do_load(
434-
os.path.join(
435-
os.getenv("WINDIR", "C:/Windows"),
436-
"System32/nvml.dll"
437-
)
438-
)
439-
if handle:
440-
return handle
441-
442-
handle = do_load(
443-
os.path.join(
444-
os.getenv("ProgramFiles", "C:/Program Files"),
445-
"NVIDIA Corporation/NVSMI/nvml.dll"
446-
)
447-
)
448-
if handle:
449-
return handle
450-
451-
return 0
452-
453-
454427
cdef int _init_nvml() except -1 nogil:
455428
global __py_nvml_init
456429

457430
cdef int err, driver_ver = 0
458431
cdef uintptr_t handle
459432

460433
with gil, __symbol_lock:
461-
handle = load_library()
434+
handle = load_nvidia_dynamic_lib("nvml")._handle_uint
462435

463436
# Load function
464437
global __nvmlInit_v2

0 commit comments

Comments
 (0)