From 12b3f8465a9c43fed9d3ff169de3a195d66f24a3 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 13:12:30 -0700 Subject: [PATCH 01/10] Revert "Restore cuda/bindings/_bindings/cynvrtc.pyx.in as-is on main" This reverts commit ba093f5700a99153b5c26b224a21aaceb69ae72b. --- .../cuda/bindings/_bindings/cynvrtc.pyx.in | 63 +++---------------- 1 file changed, 9 insertions(+), 54 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in b/cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in index a0f8a27a0..2b0f3dc23 100644 --- a/cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in +++ b/cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in @@ -9,13 +9,12 @@ # This code was automatically generated with version 12.8.0. Do not modify it directly. {{if 'Windows' == platform.system()}} import os -import site -import struct import win32api -from pywintypes import error {{else}} cimport cuda.bindings._lib.dlfcn as dlfcn +from libc.stdint cimport uintptr_t {{endif}} +from cuda.bindings import path_finder cdef bint __cuPythonInit = False {{if 'nvrtcGetErrorString' in found_functions}}cdef void *__nvrtcGetErrorString = NULL{{endif}} @@ -46,64 +45,18 @@ cdef bint __cuPythonInit = False {{if 'nvrtcSetFlowCallback' in found_functions}}cdef void *__nvrtcSetFlowCallback = NULL{{endif}} cdef int cuPythonInit() except -1 nogil: + {{if 'Windows' != platform.system()}} + cdef void* handle = NULL + {{endif}} + global __cuPythonInit if __cuPythonInit: return 0 __cuPythonInit = True - # Load library - {{if 'Windows' == platform.system()}} - with gil: - # First check if the DLL has been loaded by 3rd parties - try: - handle = win32api.GetModuleHandle("nvrtc64_120_0.dll") - except: - handle = None - - # Else try default search - if not handle: - LOAD_LIBRARY_SAFE_CURRENT_DIRS = 0x00002000 - try: - handle = win32api.LoadLibraryEx("nvrtc64_120_0.dll", 0, LOAD_LIBRARY_SAFE_CURRENT_DIRS) - except: - pass - - # Final check if DLLs can be found within pip installations - if not handle: - site_packages = [site.getusersitepackages()] + site.getsitepackages() - for sp in site_packages: - mod_path = os.path.join(sp, "nvidia", "cuda_nvrtc", "bin") - if not os.path.isdir(mod_path): - continue - os.add_dll_directory(mod_path) - LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000 - LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100 - try: - handle = win32api.LoadLibraryEx( - # Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path... - os.path.join(mod_path, "nvrtc64_120_0.dll"), - 0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR) - - # Note: nvrtc64_120_0.dll calls into nvrtc-builtins64_*.dll which is - # located in the same mod_path. - # Update PATH environ so that the two dlls can find each other - os.environ["PATH"] = os.pathsep.join((os.environ.get("PATH", ""), mod_path)) - except: - pass - - if not handle: - raise RuntimeError('Failed to LoadLibraryEx nvrtc64_120_0.dll') - {{else}} - handle = dlfcn.dlopen('libnvrtc.so.12', dlfcn.RTLD_NOW) - if handle == NULL: - with gil: - raise RuntimeError('Failed to dlopen libnvrtc.so.12') - {{endif}} - - - # Load function {{if 'Windows' == platform.system()}} with gil: + handle = path_finder.load_nvidia_dynamic_library("nvrtc") {{if 'nvrtcGetErrorString' in found_functions}} try: global __nvrtcGetErrorString @@ -288,6 +241,8 @@ cdef int cuPythonInit() except -1 nogil: {{endif}} {{else}} + with gil: + handle = path_finder.load_nvidia_dynamic_library("nvrtc") {{if 'nvrtcGetErrorString' in found_functions}} global __nvrtcGetErrorString __nvrtcGetErrorString = dlfcn.dlsym(handle, 'nvrtcGetErrorString') From b002ff676c681c18f82fb9ebda875ddfec668fc9 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 13:13:20 -0700 Subject: [PATCH 02/10] Revert "Reapply "Revert debug changes under .github/workflows"" This reverts commit 8f69f832af51c393601b09c2fe29d874e9abb057. --- .github/workflows/build-and-test.yml | 10 ---------- .github/workflows/test-wheel-linux.yml | 8 ++++---- .github/workflows/test-wheel-windows.yml | 4 ++-- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 288a5624b..b33bbcf65 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -21,14 +21,9 @@ jobs: matrix: host-platform: - linux-64 - - linux-aarch64 - win-64 python-version: - - "3.13" - "3.12" - - "3.11" - - "3.10" - - "3.9" cuda-version: # Note: this is for build-time only. - "12.8.0" @@ -211,13 +206,8 @@ jobs: matrix: host-platform: - linux-64 - - linux-aarch64 python-version: - - "3.13" - "3.12" - - "3.11" - - "3.10" - - "3.9" cuda-version: # Note: this is for test-time only. - "12.8.0" diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index 322f859e3..19c78c8cc 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -194,7 +194,7 @@ jobs: pushd ./cuda_bindings pip install -r requirements.txt - pytest -rxXs -v tests/ + pytest -ra -s -v tests/ # It is a bit convoluted to run the Cython tests against CTK wheels, # so let's just skip them. @@ -205,7 +205,7 @@ jobs: # TODO: enable this once win-64 runners are up exit 1 fi - pytest -rxXs -v tests/cython + pytest -ra -s -v tests/cython fi popd @@ -229,7 +229,7 @@ jobs: pushd ./cuda_core pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt" - pytest -rxXs -v tests/ + pytest -ra -s -v tests/ # It is a bit convoluted to run the Cython tests against CTK wheels, # so let's just skip them. Also, currently our CI always installs the @@ -243,7 +243,7 @@ jobs: # TODO: enable this once win-64 runners are up exit 1 fi - pytest -rxXs -v tests/cython + pytest -ra -s -v tests/cython fi popd diff --git a/.github/workflows/test-wheel-windows.yml b/.github/workflows/test-wheel-windows.yml index 948d2fae6..5bfa9bdf0 100644 --- a/.github/workflows/test-wheel-windows.yml +++ b/.github/workflows/test-wheel-windows.yml @@ -179,7 +179,7 @@ jobs: Push-Location ./cuda_bindings pip install -r requirements.txt - pytest -rxXs -v tests/ + pytest -ra -s -v tests/ # skip Cython tests for now (NVIDIA/cuda-python#466) Pop-Location @@ -203,7 +203,7 @@ jobs: Push-Location ./cuda_core pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt" - pytest -rxXs -v tests/ + pytest -ra -s -v tests/ Pop-Location - name: Ensure cuda-python installable From 9d1653170d606e2b9923dc33da92add8afceaa19 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 13:33:26 -0700 Subject: [PATCH 03/10] Also load nvrtc from cuda_bindings/tests/path_finder.py --- cuda_bindings/tests/path_finder.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cuda_bindings/tests/path_finder.py b/cuda_bindings/tests/path_finder.py index e9245a5be..9b7dd23a3 100644 --- a/cuda_bindings/tests/path_finder.py +++ b/cuda_bindings/tests/path_finder.py @@ -4,6 +4,15 @@ for k, v in paths.items(): print(f"{k}: {v}", flush=True) +print() -print(path_finder.find_nvidia_dynamic_library("nvvm")) -print(path_finder.find_nvidia_dynamic_library("nvJitLink")) +libnames = ("nvJitLink", "nvrtc", "nvvm") + +for libname in libnames: + print(path_finder.find_nvidia_dynamic_library(libname)) + print() + +for libname in libnames: + print(libname) + print(path_finder.load_nvidia_dynamic_library(libname)) + print() From 19ad27fcd1f1b444d2ca5ebabc9fc2cb0532ee97 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 13:20:39 -0700 Subject: [PATCH 04/10] Add heuristics for nvidia_cuda_nvrtc Windows wheels. Also fix a couple bugs discovered by ChatGPT: * `glob.glob()` in this code return absolute paths. * stray `error_messages = []` --- .../find_nvidia_dynamic_library.py | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py index 30a9b68f4..56cd9dae3 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py @@ -31,8 +31,7 @@ def _find_so_using_nvidia_lib_dirs(libname, so_basename, error_messages, attachm return so_name # Look for a versioned library # Using sort here mainly to make the result deterministic. - for node in sorted(glob.glob(os.path.join(lib_dir, file_wild))): - so_name = os.path.join(lib_dir, node) + for so_name in sorted(glob.glob(os.path.join(lib_dir, file_wild))): if os.path.isfile(so_name): return so_name _no_such_file_in_sub_dirs(nvidia_sub_dirs, file_wild, error_messages, attachments) @@ -46,10 +45,28 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): nvidia_sub_dirs = ("nvidia", "*", "bin") file_wild = libname + "*.dll" for bin_dir in sys_path_find_sub_dirs(nvidia_sub_dirs): - for node in sorted(glob.glob(os.path.join(bin_dir, file_wild))): - dll_name = os.path.join(bin_dir, node) - if os.path.isfile(dll_name): - return dll_name + dll_name = None + have_builtins = False + for path in sorted(glob.glob(os.path.join(bin_dir, file_wild))): + # nvidia_cuda_nvrtc_cu12-12.8.93-py3-none-win_amd64.whl: + # nvidia\cuda_nvrtc\bin\ + # nvrtc-builtins64_128.dll + # nvrtc64_120_0.alt.dll + # nvrtc64_120_0.dll + node = os.path.basename(path) + if node.endswith(".alt.dll"): + continue + if "-builtins" in node: + have_builtins = True + continue + if dll_name is not None: + continue + if os.path.isfile(path): + dll_name = path + if dll_name is not None: + if have_builtins: + os.add_dll_directory(bin_dir) + return dll_name _no_such_file_in_sub_dirs(nvidia_sub_dirs, file_wild, error_messages, attachments) return None @@ -78,7 +95,6 @@ def _find_so_using_cudalib_dir(so_basename, error_messages, attachments): candidate_so_dirs.append(alt_dir) libs.reverse() candidate_so_names = [so_dirname + so_basename for so_dirname in candidate_so_dirs] - error_messages = [] for so_name in candidate_so_names: if os.path.isfile(so_name): return so_name @@ -98,8 +114,7 @@ def _find_dll_using_cudalib_dir(libname, error_messages, attachments): if cudalib_dir is None: return None file_wild = libname + "*.dll" - for node in sorted(glob.glob(os.path.join(cudalib_dir, file_wild))): - dll_name = os.path.join(cudalib_dir, node) + for dll_name in sorted(glob.glob(os.path.join(cudalib_dir, file_wild))): if os.path.isfile(dll_name): return dll_name error_messages.append(f"No such file: {file_wild}") @@ -123,7 +138,7 @@ def find_nvidia_dynamic_library(name: str) -> str: dll_name = _find_dll_using_cudalib_dir(name, error_messages, attachments) if dll_name is None: attachments = "\n".join(attachments) - raise RuntimeError(f"Failure finding {name}*.dll: {', '.join(error_messages)}\n{attachments}") + raise RuntimeError(f'Failure finding "{name}*.dll": {", ".join(error_messages)}\n{attachments}') return dll_name so_basename = f"lib{name}.so" @@ -135,5 +150,5 @@ def find_nvidia_dynamic_library(name: str) -> str: so_name = _find_so_using_cudalib_dir(so_basename, error_messages, attachments) if so_name is None: attachments = "\n".join(attachments) - raise RuntimeError(f"Failure finding {so_basename}: {', '.join(error_messages)}\n{attachments}") + raise RuntimeError(f'Failure finding "{so_basename}": {", ".join(error_messages)}\n{attachments}') return so_name From c421f12f24490b1961d5b41ec902e765688fb551 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 15:25:52 -0700 Subject: [PATCH 05/10] Add debug prints, mostly for `os.add_dll_directory(bin_dir)` --- .../bindings/_path_finder/find_nvidia_dynamic_library.py | 4 ++++ .../bindings/_path_finder/load_nvidia_dynamic_library.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py index 56cd9dae3..e4ec1c7b4 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py @@ -44,10 +44,13 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): else: nvidia_sub_dirs = ("nvidia", "*", "bin") file_wild = libname + "*.dll" + print(f"\nLOOOK {file_wild=}", flush=True) for bin_dir in sys_path_find_sub_dirs(nvidia_sub_dirs): + print(f"\nLOOOK {bin_dir=}", flush=True) dll_name = None have_builtins = False for path in sorted(glob.glob(os.path.join(bin_dir, file_wild))): + print(f"\nLOOOK {path=}", flush=True) # nvidia_cuda_nvrtc_cu12-12.8.93-py3-none-win_amd64.whl: # nvidia\cuda_nvrtc\bin\ # nvrtc-builtins64_128.dll @@ -65,6 +68,7 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): dll_name = path if dll_name is not None: if have_builtins: + print(f"\nLOOOK os.add_dll_directory({bin_dir=})", flush=True) os.add_dll_directory(bin_dir) return dll_name _no_such_file_in_sub_dirs(nvidia_sub_dirs, file_wild, error_messages, attachments) diff --git a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py index 692e8e0bc..9cf65d202 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py @@ -60,10 +60,12 @@ def _windows_load_with_dll_basename(name: str) -> int: @functools.cache def load_nvidia_dynamic_library(name: str) -> int: + print(f"\nLOOOK load_nvidia_dynamic_library({name=})", flush=True) # First try using the platform-specific dynamic loader search mechanisms if sys.platform == "win32": handle = _windows_load_with_dll_basename(name) if handle: + print("\nLOOOK return handle", flush=True) return handle else: dl_path = f"lib{name}.so" # Version intentionally no specified. @@ -77,11 +79,18 @@ def load_nvidia_dynamic_library(name: str) -> int: dl_path = find_nvidia_dynamic_library(name) if sys.platform == "win32": + print(f"\nLOOOK win32api.LoadLibrary({dl_path=})", flush=True) + dirnm = os.path.dirname(dl_path) + if os.path.isdir(dirnm): + print(f"\nLOOOK {dirnm=}", flush=True) + for node in os.listdir(dirnm): + print(f"\nLOOOK {node=}", flush=True) try: handle = win32api.LoadLibrary(dl_path) except pywintypes.error as e: raise RuntimeError(f"Failed to load DLL at {dl_path}: {e}") from e # Use `cdef void* ptr = ` in cython to convert back to void* + print("\nLOOOK return handle", flush=True) return handle # C signed int, matches win32api.GetProcAddress else: try: From c54696b692ff36eb359a363b4854550cb8ccbd48 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 16:57:21 -0700 Subject: [PATCH 06/10] Fix unfortunate silly oversight (import os missing under Windows) --- .../cuda/bindings/_path_finder/load_nvidia_dynamic_library.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py index 9cf65d202..b6c58ff71 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py @@ -1,4 +1,5 @@ import functools +import os import sys if sys.platform == "win32": @@ -12,7 +13,6 @@ else: import ctypes - import os _LINUX_CDLL_MODE = os.RTLD_NOW | os.RTLD_GLOBAL From a384c0e183d9b091ce3abf27b55d018758df47ed Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 20:45:42 -0700 Subject: [PATCH 07/10] Use `win32api.LoadLibraryEx()` with suitable `flags`; also update `os.environ["PATH"]` --- .../bindings/_path_finder/find_nvidia_dynamic_library.py | 8 ++++++++ .../bindings/_path_finder/load_nvidia_dynamic_library.py | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py index e4ec1c7b4..9706193c5 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py @@ -38,6 +38,11 @@ def _find_so_using_nvidia_lib_dirs(libname, so_basename, error_messages, attachm return None +def _append_to_os_environ_path(dirpath): + curr_path = os.environ.get("PATH") + os.environ["PATH"] = dirpath if curr_path is None else os.pathsep.join((curr_path, dirpath)) + + def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): if libname == "nvvm": # noqa: SIM108 nvidia_sub_dirs = ("nvidia", "*", "nvvm", "bin") @@ -69,7 +74,10 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): if dll_name is not None: if have_builtins: print(f"\nLOOOK os.add_dll_directory({bin_dir=})", flush=True) + # Add the DLL directory to the search path os.add_dll_directory(bin_dir) + # Update PATH as a fallback for dependent DLL resolution + _append_to_os_environ_path(bin_dir) return dll_name _no_such_file_in_sub_dirs(nvidia_sub_dirs, file_wild, error_messages, attachments) return None diff --git a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py index b6c58ff71..b1875f77f 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py @@ -7,6 +7,7 @@ import pywintypes import win32api + import win32con # Mirrors WinBase.h (unfortunately not defined already elsewhere) _WINBASE_LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800 @@ -85,8 +86,9 @@ def load_nvidia_dynamic_library(name: str) -> int: print(f"\nLOOOK {dirnm=}", flush=True) for node in os.listdir(dirnm): print(f"\nLOOOK {node=}", flush=True) + flags = win32con.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | win32con.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR try: - handle = win32api.LoadLibrary(dl_path) + handle = win32api.LoadLibraryEx(dl_path, 0, flags) except pywintypes.error as e: raise RuntimeError(f"Failed to load DLL at {dl_path}: {e}") from e # Use `cdef void* ptr = ` in cython to convert back to void* From 2c9f7d1b78761970746681ffe41d8e3de1a399bb Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 9 Apr 2025 22:34:53 -0700 Subject: [PATCH 08/10] Hard-wire WinBase.h constants (they are not exposed by win32con) --- .../bindings/_path_finder/load_nvidia_dynamic_library.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py index b1875f77f..f4bddd4c4 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py @@ -7,10 +7,10 @@ import pywintypes import win32api - import win32con # Mirrors WinBase.h (unfortunately not defined already elsewhere) - _WINBASE_LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800 + _WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR = 0x00000100 + _WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS = 0x00001000 else: import ctypes @@ -86,7 +86,7 @@ def load_nvidia_dynamic_library(name: str) -> int: print(f"\nLOOOK {dirnm=}", flush=True) for node in os.listdir(dirnm): print(f"\nLOOOK {node=}", flush=True) - flags = win32con.LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | win32con.LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR + flags = _WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | _WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR try: handle = win32api.LoadLibraryEx(dl_path, 0, flags) except pywintypes.error as e: From e94e6d346a2832fdb19d7b579ac6f6b5fc5f23c2 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 10 Apr 2025 15:41:15 -0700 Subject: [PATCH 09/10] Remove debug prints --- .../_path_finder/find_nvidia_dynamic_library.py | 4 ---- .../_path_finder/load_nvidia_dynamic_library.py | 11 +---------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py index 9706193c5..3d6604f08 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/find_nvidia_dynamic_library.py @@ -49,13 +49,10 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): else: nvidia_sub_dirs = ("nvidia", "*", "bin") file_wild = libname + "*.dll" - print(f"\nLOOOK {file_wild=}", flush=True) for bin_dir in sys_path_find_sub_dirs(nvidia_sub_dirs): - print(f"\nLOOOK {bin_dir=}", flush=True) dll_name = None have_builtins = False for path in sorted(glob.glob(os.path.join(bin_dir, file_wild))): - print(f"\nLOOOK {path=}", flush=True) # nvidia_cuda_nvrtc_cu12-12.8.93-py3-none-win_amd64.whl: # nvidia\cuda_nvrtc\bin\ # nvrtc-builtins64_128.dll @@ -73,7 +70,6 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments): dll_name = path if dll_name is not None: if have_builtins: - print(f"\nLOOOK os.add_dll_directory({bin_dir=})", flush=True) # Add the DLL directory to the search path os.add_dll_directory(bin_dir) # Update PATH as a fallback for dependent DLL resolution diff --git a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py index f4bddd4c4..1a52bf0dd 100644 --- a/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py +++ b/cuda_bindings/cuda/bindings/_path_finder/load_nvidia_dynamic_library.py @@ -1,5 +1,4 @@ import functools -import os import sys if sys.platform == "win32": @@ -14,6 +13,7 @@ else: import ctypes + import os _LINUX_CDLL_MODE = os.RTLD_NOW | os.RTLD_GLOBAL @@ -61,12 +61,10 @@ def _windows_load_with_dll_basename(name: str) -> int: @functools.cache def load_nvidia_dynamic_library(name: str) -> int: - print(f"\nLOOOK load_nvidia_dynamic_library({name=})", flush=True) # First try using the platform-specific dynamic loader search mechanisms if sys.platform == "win32": handle = _windows_load_with_dll_basename(name) if handle: - print("\nLOOOK return handle", flush=True) return handle else: dl_path = f"lib{name}.so" # Version intentionally no specified. @@ -80,19 +78,12 @@ def load_nvidia_dynamic_library(name: str) -> int: dl_path = find_nvidia_dynamic_library(name) if sys.platform == "win32": - print(f"\nLOOOK win32api.LoadLibrary({dl_path=})", flush=True) - dirnm = os.path.dirname(dl_path) - if os.path.isdir(dirnm): - print(f"\nLOOOK {dirnm=}", flush=True) - for node in os.listdir(dirnm): - print(f"\nLOOOK {node=}", flush=True) flags = _WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | _WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR try: handle = win32api.LoadLibraryEx(dl_path, 0, flags) except pywintypes.error as e: raise RuntimeError(f"Failed to load DLL at {dl_path}: {e}") from e # Use `cdef void* ptr = ` in cython to convert back to void* - print("\nLOOOK return handle", flush=True) return handle # C signed int, matches win32api.GetProcAddress else: try: From a503ed964a8d309844491eb68a344679ce7a26dd Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 10 Apr 2025 15:41:31 -0700 Subject: [PATCH 10/10] Reapply "Reapply "Revert debug changes under .github/workflows"" This reverts commit b002ff676c681c18f82fb9ebda875ddfec668fc9. --- .github/workflows/build-and-test.yml | 10 ++++++++++ .github/workflows/test-wheel-linux.yml | 8 ++++---- .github/workflows/test-wheel-windows.yml | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index b33bbcf65..288a5624b 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -21,9 +21,14 @@ jobs: matrix: host-platform: - linux-64 + - linux-aarch64 - win-64 python-version: + - "3.13" - "3.12" + - "3.11" + - "3.10" + - "3.9" cuda-version: # Note: this is for build-time only. - "12.8.0" @@ -206,8 +211,13 @@ jobs: matrix: host-platform: - linux-64 + - linux-aarch64 python-version: + - "3.13" - "3.12" + - "3.11" + - "3.10" + - "3.9" cuda-version: # Note: this is for test-time only. - "12.8.0" diff --git a/.github/workflows/test-wheel-linux.yml b/.github/workflows/test-wheel-linux.yml index 19c78c8cc..322f859e3 100644 --- a/.github/workflows/test-wheel-linux.yml +++ b/.github/workflows/test-wheel-linux.yml @@ -194,7 +194,7 @@ jobs: pushd ./cuda_bindings pip install -r requirements.txt - pytest -ra -s -v tests/ + pytest -rxXs -v tests/ # It is a bit convoluted to run the Cython tests against CTK wheels, # so let's just skip them. @@ -205,7 +205,7 @@ jobs: # TODO: enable this once win-64 runners are up exit 1 fi - pytest -ra -s -v tests/cython + pytest -rxXs -v tests/cython fi popd @@ -229,7 +229,7 @@ jobs: pushd ./cuda_core pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt" - pytest -ra -s -v tests/ + pytest -rxXs -v tests/ # It is a bit convoluted to run the Cython tests against CTK wheels, # so let's just skip them. Also, currently our CI always installs the @@ -243,7 +243,7 @@ jobs: # TODO: enable this once win-64 runners are up exit 1 fi - pytest -ra -s -v tests/cython + pytest -rxXs -v tests/cython fi popd diff --git a/.github/workflows/test-wheel-windows.yml b/.github/workflows/test-wheel-windows.yml index 5bfa9bdf0..948d2fae6 100644 --- a/.github/workflows/test-wheel-windows.yml +++ b/.github/workflows/test-wheel-windows.yml @@ -179,7 +179,7 @@ jobs: Push-Location ./cuda_bindings pip install -r requirements.txt - pytest -ra -s -v tests/ + pytest -rxXs -v tests/ # skip Cython tests for now (NVIDIA/cuda-python#466) Pop-Location @@ -203,7 +203,7 @@ jobs: Push-Location ./cuda_core pip install -r "tests/requirements-cu${TEST_CUDA_MAJOR}.txt" - pytest -ra -s -v tests/ + pytest -rxXs -v tests/ Pop-Location - name: Ensure cuda-python installable