Skip to content

Commit 93a66b0

Browse files
committed
Use win32api.LoadLibrary() instead of ctypes.windll.kernel32.LoadLibraryW(), to be more similar to original (and working) cython code.
Hoping to resolve this kind of error: ``` _ ERROR at setup of test_c_or_v_program_fail_bad_option[txt-compile_program] __ request = <SubRequest 'minimal_nvvmir' for <Function test_c_or_v_program_fail_bad_option[txt-compile_program]>> @pytest.fixture(params=MINIMAL_NVVMIR_FIXTURE_PARAMS) def minimal_nvvmir(request): for pass_counter in range(2): nvvmir = MINIMAL_NVVMIR_CACHE.get(request.param, -1) if nvvmir != -1: if nvvmir is None: pytest.skip(f"UNAVAILABLE: {request.param}") return nvvmir if pass_counter: raise AssertionError("This code path is meant to be unreachable.") # Build cache entries, then try again (above). > major, minor, debug_major, debug_minor = nvvm.ir_version() tests\test_nvvm.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ cuda\bindings\nvvm.pyx:95: in cuda.bindings.nvvm.ir_version cpdef tuple ir_version(): cuda\bindings\nvvm.pyx:113: in cuda.bindings.nvvm.ir_version status = nvvmIRVersion(&major_ir, &minor_ir, &major_dbg, &minor_dbg) cuda\bindings\cynvvm.pyx:19: in cuda.bindings.cynvvm.nvvmIRVersion return _nvvm._nvvmIRVersion(majorIR, minorIR, majorDbg, minorDbg) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E cuda.bindings._internal.utils.FunctionNotFoundError: function nvvmIRVersion is not found ```
1 parent 19c50f8 commit 93a66b0

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,35 @@
1-
import ctypes
21
import functools
3-
import os
42
import sys
53

4+
if sys.platform == "win32":
5+
import pywintypes
6+
import win32api
7+
else:
8+
import ctypes
9+
import os
10+
611
from .find_nvidia_dynamic_library import find_nvidia_dynamic_library
712

813

914
@functools.cache
1015
def load_nvidia_dynamic_library(name: str) -> int:
16+
print(f"\nLOOOK load_nvidia_dynamic_library({name}) ENTRY", flush=True)
1117
dl_path = find_nvidia_dynamic_library(name)
1218
if sys.platform == "win32":
1319
try:
14-
handle = ctypes.windll.kernel32.LoadLibraryW(dl_path)
15-
if not handle:
16-
raise ctypes.WinError(ctypes.get_last_error())
17-
except Exception as e:
20+
handle = win32api.LoadLibrary(dl_path)
21+
except pywintypes.error as e:
1822
raise RuntimeError(f"Failed to load DLL at {dl_path}: {e}") from e
23+
print(f"\nLOOOK load_nvidia_dynamic_library({name}) RETURN {type(handle)=} {handle=}", flush=True)
1924
# Use `cdef void* ptr = <void*><intptr_t>` in cython to convert back to void*
2025
return handle # C signed int, matches win32api.GetProcAddress
2126
else:
2227
try:
2328
handle = ctypes.CDLL(dl_path, mode=os.RTLD_NOW | os.RTLD_GLOBAL)
2429
except OSError as e:
2530
raise RuntimeError(f"Failed to dlopen {dl_path}: {e}") from e
31+
print(
32+
f"\nLOOOK load_nvidia_dynamic_library({name}) RETURN {type(handle._handle)=} {handle._handle=}", flush=True
33+
)
2634
# Use `cdef void* ptr = <void*><uintptr_t>` in cython to convert back to void*
2735
return handle._handle # C unsigned int

0 commit comments

Comments
 (0)