From 7f56f015168ae18ede6e8bb6fda76ba5e7bd2054 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 17 Jun 2025 13:35:08 -0700 Subject: [PATCH 01/24] use pathfinder naively for dynamic libs --- numba_cuda/numba/cuda/cudadrv/libs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index ce4d99113..072bf4401 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -51,7 +51,9 @@ def get_cudalib(lib, static=False): loader's search mechanism. """ if lib in {"nvrtc", "nvvm"}: - return get_cuda_paths()[lib].info or _dllnamepattern % lib + from cuda.bindings import path_finder + + return path_finder._load_nvidia_dynamic_library(lib).abs_path else: dir_type = "static_cudalib_dir" if static else "cudalib_dir" libdir = get_cuda_paths()[dir_type].info From c2f7611bc2f26ca7fa542017baf9fae95ac635c6 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 24 Jun 2025 08:30:12 -0700 Subject: [PATCH 02/24] other needed cuda components --- numba_cuda/numba/cuda/cuda_paths.py | 6 ++++++ numba_cuda/numba/cuda/cudadrv/libs.py | 7 ++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 9bcccf9ce..3636e1d1d 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -9,6 +9,7 @@ from numba.misc.findlib import find_lib from numba import config import ctypes +import warnings _env_path_tuple = namedtuple("_env_path_tuple", ["by", "info"]) @@ -417,6 +418,11 @@ def get_cuda_paths(): Note: The result of the function is cached. """ + warnings.warn( + "get_cuda_paths() is deprecated, use `cuda.bindings.path_finder`.", + DeprecationWarning, + stacklevel=2, + ) # Check cache if hasattr(get_cuda_paths, "_cached_result"): return get_cuda_paths._cached_result diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 072bf4401..c18b1b75d 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -19,6 +19,7 @@ from numba.cuda.cudadrv.driver import locate_driver_and_loader, load_driver from numba.cuda.cudadrv.error import CudaSupportError from numba.core import config +from cuda.bindings import path_finder if sys.platform == "win32": @@ -33,6 +34,7 @@ def get_libdevice(): + # libdevice d = get_cuda_paths() paths = d["libdevice"].info return paths @@ -51,10 +53,9 @@ def get_cudalib(lib, static=False): loader's search mechanism. """ if lib in {"nvrtc", "nvvm"}: - from cuda.bindings import path_finder - return path_finder._load_nvidia_dynamic_library(lib).abs_path else: + # cudart, cudadevrt dir_type = "static_cudalib_dir" if static else "cudalib_dir" libdir = get_cuda_paths()[dir_type].info @@ -69,7 +70,7 @@ def get_cuda_include_dir(): Note that this does not list the `CUDA_INCLUDE_PATH` entry in user configuration. """ - + # CUDA headers return get_cuda_paths()["include_dir"].info From 977c8c9cf2ad975282b7b21112798f4af9cc4947 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 24 Jun 2025 08:30:59 -0700 Subject: [PATCH 03/24] a comment --- numba_cuda/numba/cuda/cudadrv/libs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index c18b1b75d..388ed5138 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -93,6 +93,7 @@ def check_static_lib(path): def _get_source_variable(lib, static=False): + # remove? only used in test() if lib == "nvvm": return get_cuda_paths()["nvvm"].by elif lib == "nvrtc": From 738702c5f49e2d74f6fd601a44e9f32ddd2ee872 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Wed, 15 Oct 2025 12:01:45 -0700 Subject: [PATCH 04/24] deps --- conda/recipes/numba-cuda/meta.yaml | 1 + pyproject.toml | 2 ++ 2 files changed, 3 insertions(+) diff --git a/conda/recipes/numba-cuda/meta.yaml b/conda/recipes/numba-cuda/meta.yaml index b03309822..e66542416 100644 --- a/conda/recipes/numba-cuda/meta.yaml +++ b/conda/recipes/numba-cuda/meta.yaml @@ -31,6 +31,7 @@ requirements: - numba >=0.59.1 - cuda-bindings >=12.9.1 - cuda-core ==0.3.* + - cuda-pathfinder >=1.3.1 about: home: {{ project_urls["Homepage"] }} diff --git a/pyproject.toml b/pyproject.toml index 4bc13e525..db8254f6a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,6 +28,7 @@ cu12 = [ "cuda-bindings>=12.9.1,<13.0.0", "cuda-core==0.3.*", "cuda-python==12.9.*", # supports all CTK 12.x + "cuda-pathfinder>=1.3.1", "nvidia-cuda-nvcc-cu12", # for libNVVM "nvidia-cuda-runtime-cu12", "nvidia-cuda-nvrtc-cu12", @@ -38,6 +39,7 @@ cu12 = [ cu13 = [ "cuda-bindings==13.*", "cuda-core==0.3.2,<0.4.0dev0", + "cuda-pathfinder>=1.3.1", "cuda-python==13.*", "nvidia-nvvm==13.*", "nvidia-cuda-runtime==13.*", From 2bfa54308f1a87b2c5b102ca75708f5ace5c561f Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Thu, 16 Oct 2025 14:02:35 -0700 Subject: [PATCH 05/24] updates --- numba_cuda/numba/cuda/cuda_paths.py | 24 ++++++++++++++++++++++++ numba_cuda/numba/cuda/cudadrv/libs.py | 8 +++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 9fc3163e1..e799fc22b 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -10,6 +10,8 @@ from numba.cuda.misc.findlib import find_lib from numba.cuda import config import warnings +from cuda import pathfinder +import pathlib _env_path_tuple = namedtuple("_env_path_tuple", ["by", "info"]) @@ -516,3 +518,25 @@ def _get_include_dir(): ] by, include_dir = _find_valid_path(options) return _env_path_tuple(by, include_dir) + + +def _get_nvvm(): + try: + nvvm = pathfinder.load_nvidia_dynamic_lib("nvvm") + return nvvm + except pathfinder.DynamicLibNotFoundError: + nvrtc = _get_nvrtc() + path = pathlib.Path(nvrtc.abs_path) + nvvm = path.parents[1] / "nvvm" / "lib64" / "libnvvm.so" + + if nvvm.exists(): + dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( + "nvvm", path, "system-search" + ) + return dl + else: + raise pathfinder.DynamicLibNotFoundError("nvvm not found") + + +def _get_nvrtc(): + return pathfinder.load_nvidia_dynamic_lib("nvrtc") diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 59d9fa725..89c4f8670 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -17,7 +17,7 @@ import ctypes from numba.cuda.misc.findlib import find_lib -from numba.cuda.cuda_paths import get_cuda_paths +from numba.cuda.cuda_paths import get_cuda_paths, _get_nvvm, _get_nvrtc from numba.cuda.cudadrv.driver import locate_driver_and_loader, load_driver from numba.cuda.cudadrv.error import CudaSupportError from numba.core import config @@ -54,8 +54,10 @@ def get_cudalib(lib, static=False): 'libnvvm.so' for 'nvvm') so that we may attempt to load it using the system loader's search mechanism. """ - if lib in {"nvrtc", "nvvm"}: - return pathfinder.load_nvidia_dynamic_lib(lib).abs_path + if lib == "nvrtc": + return _get_nvrtc().abs_path + elif lib == "nvvm": + return _get_nvvm().abs_path else: # cudart, cudadevrt dir_type = "static_cudalib_dir" if static else "cudalib_dir" From a0756f747d398ac3365e6586698d3ee67bef0b61 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Thu, 16 Oct 2025 15:03:30 -0700 Subject: [PATCH 06/24] simpler --- numba_cuda/numba/cuda/cuda_paths.py | 18 ++++++++++++------ numba_cuda/numba/cuda/cudadrv/libs.py | 8 +++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index e799fc22b..aab14e284 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -9,7 +9,6 @@ from numba.cuda.core.config import IS_WIN32 from numba.cuda.misc.findlib import find_lib from numba.cuda import config -import warnings from cuda import pathfinder import pathlib @@ -398,17 +397,14 @@ def get_cuda_paths(): Note: The result of the function is cached. """ - warnings.warn( - "get_cuda_paths() is deprecated, use `cuda.bindings.path_finder`.", - DeprecationWarning, - stacklevel=2, - ) # Check cache if hasattr(get_cuda_paths, "_cached_result"): return get_cuda_paths._cached_result else: # Not in cache d = { + "nvrtc": _get_nvrtc_path(), + "nvvm": _get_nvvm_path(), "libdevice": _get_libdevice_path(), "cudalib_dir": _get_cudalib_dir(), "static_cudalib_dir": _get_static_cudalib_dir(), @@ -540,3 +536,13 @@ def _get_nvvm(): def _get_nvrtc(): return pathfinder.load_nvidia_dynamic_lib("nvrtc") + + +def _get_nvrtc_path(): + nvrtc = _get_nvrtc() + return _env_path_tuple(nvrtc.found_via, nvrtc.abs_path) + + +def _get_nvvm_path(): + nvvm = _get_nvvm() + return _env_path_tuple(nvvm.found_via, nvvm.abs_path) diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 89c4f8670..31ca29002 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -17,7 +17,7 @@ import ctypes from numba.cuda.misc.findlib import find_lib -from numba.cuda.cuda_paths import get_cuda_paths, _get_nvvm, _get_nvrtc +from numba.cuda.cuda_paths import get_cuda_paths from numba.cuda.cudadrv.driver import locate_driver_and_loader, load_driver from numba.cuda.cudadrv.error import CudaSupportError from numba.core import config @@ -54,10 +54,8 @@ def get_cudalib(lib, static=False): 'libnvvm.so' for 'nvvm') so that we may attempt to load it using the system loader's search mechanism. """ - if lib == "nvrtc": - return _get_nvrtc().abs_path - elif lib == "nvvm": - return _get_nvvm().abs_path + if lib in {"nvrtc", "nvvm"}: + return get_cuda_paths()[lib].info else: # cudart, cudadevrt dir_type = "static_cudalib_dir" if static else "cudalib_dir" From 03cddf230616ea3fe57a9fe63dd4b53951b50818 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Thu, 16 Oct 2025 15:06:36 -0700 Subject: [PATCH 07/24] clean --- numba_cuda/numba/cuda/cudadrv/libs.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 31ca29002..4347ea124 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -21,7 +21,6 @@ from numba.cuda.cudadrv.driver import locate_driver_and_loader, load_driver from numba.cuda.cudadrv.error import CudaSupportError from numba.core import config -from cuda import pathfinder if sys.platform == "win32": @@ -36,7 +35,6 @@ def get_libdevice(): - # libdevice d = get_cuda_paths() paths = d["libdevice"].info return paths @@ -57,7 +55,6 @@ def get_cudalib(lib, static=False): if lib in {"nvrtc", "nvvm"}: return get_cuda_paths()[lib].info else: - # cudart, cudadevrt dir_type = "static_cudalib_dir" if static else "cudalib_dir" libdir = get_cuda_paths()[dir_type].info @@ -72,7 +69,6 @@ def get_cuda_include_dir(): Note that this does not list the `CUDA_INCLUDE_PATH` entry in user configuration. """ - # CUDA headers return get_cuda_paths()["include_dir"].info @@ -95,11 +91,10 @@ def check_static_lib(path): def _get_source_variable(lib, static=False): - # remove? only used in test() if lib == "nvvm": - return pathfinder.load_nvidia_dynamic_lib(lib).found_via + return get_cuda_paths()["nvvm"].by elif lib == "nvrtc": - return pathfinder.load_nvidia_dynamic_lib(lib).found_via + return get_cuda_paths()["nvrtc"].by elif lib == "libdevice": return get_cuda_paths()["libdevice"].by elif lib == "include_dir": From 0ab6939a55750eda109715af672f1edb5cce094c Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Fri, 17 Oct 2025 09:44:04 -0700 Subject: [PATCH 08/24] small fixes --- numba_cuda/numba/cuda/cuda_paths.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index aab14e284..bf73b0150 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -523,11 +523,11 @@ def _get_nvvm(): except pathfinder.DynamicLibNotFoundError: nvrtc = _get_nvrtc() path = pathlib.Path(nvrtc.abs_path) - nvvm = path.parents[1] / "nvvm" / "lib64" / "libnvvm.so" + nvvm = path.parents[3] / "nvvm" / "lib64" / "libnvvm.so" if nvvm.exists(): dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( - "nvvm", path, "system-search" + "nvvm", nvvm, "system-search" ) return dl else: From 64ab7a9826418fed4c03079368d3c5cf564fbad7 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Fri, 9 Jan 2026 07:55:38 -0800 Subject: [PATCH 09/24] fixi --- pixi.lock | 60 ------------------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/pixi.lock b/pixi.lock index b6bf0e4e8..890f7690a 100644 --- a/pixi.lock +++ b/pixi.lock @@ -18053,10 +18053,6 @@ packages: - python_abi 3.10.* *_cp310 - numpy >=1.21,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18077,10 +18073,6 @@ packages: - python_abi 3.10.* *_cp310 - numpy >=1.21,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18101,10 +18093,6 @@ packages: - python_abi 3.10.* *_cp310 - numpy >=1.21,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18125,10 +18113,6 @@ packages: - python_abi 3.11.* *_cp311 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18149,10 +18133,6 @@ packages: - python_abi 3.11.* *_cp311 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18173,10 +18153,6 @@ packages: - python_abi 3.11.* *_cp311 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18197,10 +18173,6 @@ packages: - python_abi 3.12.* *_cp312 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18221,10 +18193,6 @@ packages: - python_abi 3.12.* *_cp312 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18245,10 +18213,6 @@ packages: - python_abi 3.12.* *_cp312 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18269,10 +18233,6 @@ packages: - python_abi 3.13.* *_cp313 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18293,10 +18253,6 @@ packages: - python_abi 3.13.* *_cp313 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18317,10 +18273,6 @@ packages: - python_abi 3.13.* *_cp313 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18341,10 +18293,6 @@ packages: - python_abi 3.14.* *_cp314 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18365,10 +18313,6 @@ packages: - python_abi 3.14.* *_cp314 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - conda: . name: numba-cuda version: 0.23.0 @@ -18389,10 +18333,6 @@ packages: - python_abi 3.14.* *_cp314 - numpy >=1.23,<3 license: BSD-2-Clause - input: - hash: 2a1b1407e123167bcf4af0d488c2c2ad1bd42711c50bef7a9b2990890a9542d7 - globs: - - pyproject.toml - pypi: https://files.pythonhosted.org/packages/5e/a6/9ca0eecc489640615642a6cbc0ca9e10df70df38c4d43f5a928ff18d8827/numpy-2.3.5-cp314-cp314-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl name: numpy version: 2.3.5 From 109e3e683826cad882b74201cb310d6f4fbad4ab Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Fri, 9 Jan 2026 14:15:51 -0800 Subject: [PATCH 10/24] fallback to old logic for nvvm --- numba_cuda/numba/cuda/cuda_paths.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index bf73b0150..2091bd803 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -521,10 +521,9 @@ def _get_nvvm(): nvvm = pathfinder.load_nvidia_dynamic_lib("nvvm") return nvvm except pathfinder.DynamicLibNotFoundError: - nvrtc = _get_nvrtc() - path = pathlib.Path(nvrtc.abs_path) - nvvm = path.parents[3] / "nvvm" / "lib64" / "libnvvm.so" - + # Try system search + # TODO: remove after cuda-python/1157 is resolved + nvvm = pathlib.Path(_get_nvvm_system_path()) if nvvm.exists(): dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( "nvvm", nvvm, "system-search" @@ -546,3 +545,19 @@ def _get_nvrtc_path(): def _get_nvvm_path(): nvvm = _get_nvvm() return _env_path_tuple(nvvm.found_via, nvvm.abs_path) + + +def _get_nvvm_system_path(): + nvvm_lib_dir = get_system_ctk("nvvm") + if nvvm_lib_dir is None: + return None + nvvm_lib_dir = os.path.join(nvvm_lib_dir, "bin" if IS_WIN32 else "lib64") + if IS_WIN32 and os.path.isdir(os.path.join(nvvm_lib_dir, "x64")): + nvvm_lib_dir = os.path.join(nvvm_lib_dir, "x64") + + nvvm_path = os.path.join( + nvvm_lib_dir, "nvvm64_40_0.dll" if IS_WIN32 else "libnvvm.so.4" + ) + # if os.path.isfile(nvvm_path): + # return nvvm_path + return nvvm_path From 074f63d44287553e47d74b2ccefa1e75bffceae2 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 12 Jan 2026 05:43:24 -0800 Subject: [PATCH 11/24] greptile --- numba_cuda/numba/cuda/cuda_paths.py | 14 ++++++++------ numba_cuda/numba/cuda/cudadrv/libs.py | 8 ++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 2091bd803..6178b3281 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -523,12 +523,14 @@ def _get_nvvm(): except pathfinder.DynamicLibNotFoundError: # Try system search # TODO: remove after cuda-python/1157 is resolved - nvvm = pathlib.Path(_get_nvvm_system_path()) - if nvvm.exists(): - dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( - "nvvm", nvvm, "system-search" - ) - return dl + path_or_none = _get_nvvm_system_path() + if path_or_none is not None: + nvvm = pathlib.Path(path_or_none) + if nvvm.exists(): + dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( + "nvvm", nvvm, "system-search" + ) + return dl else: raise pathfinder.DynamicLibNotFoundError("nvvm not found") diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 4347ea124..2d6290caa 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -20,7 +20,7 @@ from numba.cuda.cuda_paths import get_cuda_paths from numba.cuda.cudadrv.driver import locate_driver_and_loader, load_driver from numba.cuda.cudadrv.error import CudaSupportError -from numba.core import config +from numba.cuda import config if sys.platform == "win32": @@ -54,9 +54,9 @@ def get_cudalib(lib, static=False): """ if lib in {"nvrtc", "nvvm"}: return get_cuda_paths()[lib].info - else: - dir_type = "static_cudalib_dir" if static else "cudalib_dir" - libdir = get_cuda_paths()[dir_type].info + + dir_type = "static_cudalib_dir" if static else "cudalib_dir" + libdir = get_cuda_paths()[dir_type].info candidates = find_lib(lib, libdir, static=static) namepattern = _staticnamepattern if static else _dllnamepattern From ab9c36381bda41c875b9e6c83e42788d36b28c70 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 12 Jan 2026 05:52:28 -0800 Subject: [PATCH 12/24] none case --- numba_cuda/numba/cuda/cuda_paths.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 6178b3281..ef045e371 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -531,8 +531,7 @@ def _get_nvvm(): "nvvm", nvvm, "system-search" ) return dl - else: - raise pathfinder.DynamicLibNotFoundError("nvvm not found") + raise pathfinder.DynamicLibNotFoundError("nvvm not found") def _get_nvrtc(): From d657f9ad97e8123be0ae9ea2577fd23694a4f24c Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 12 Jan 2026 13:04:49 -0800 Subject: [PATCH 13/24] remove commented code --- numba_cuda/numba/cuda/cuda_paths.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index ef045e371..b075ec04b 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -559,6 +559,4 @@ def _get_nvvm_system_path(): nvvm_path = os.path.join( nvvm_lib_dir, "nvvm64_40_0.dll" if IS_WIN32 else "libnvvm.so.4" ) - # if os.path.isfile(nvvm_path): - # return nvvm_path return nvvm_path From a9d1c07582b9e52541d60dec0945857e495a7a1a Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 12 Jan 2026 15:08:11 -0800 Subject: [PATCH 14/24] small changes --- numba_cuda/numba/cuda/cuda_paths.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index b075ec04b..ec144a36e 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -520,18 +520,19 @@ def _get_nvvm(): try: nvvm = pathfinder.load_nvidia_dynamic_lib("nvvm") return nvvm - except pathfinder.DynamicLibNotFoundError: + except pathfinder.DynamicLibNotFoundError as e: # Try system search # TODO: remove after cuda-python/1157 is resolved path_or_none = _get_nvvm_system_path() if path_or_none is not None: nvvm = pathlib.Path(path_or_none) if nvvm.exists(): + # TODO: Expose private cuda-python APIs dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( "nvvm", nvvm, "system-search" ) return dl - raise pathfinder.DynamicLibNotFoundError("nvvm not found") + raise pathfinder.DynamicLibNotFoundError("nvvm not found") from e def _get_nvrtc(): From f49647b854e8360f7b7521f7c43f9c2a27aa0348 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 07:22:17 -0800 Subject: [PATCH 15/24] _get_nvvm from review/test --- numba_cuda/numba/cuda/cuda_paths.py | 88 +++++++++++++++---- .../cuda/tests/nocuda/test_library_lookup.py | 38 +++++++- 2 files changed, 110 insertions(+), 16 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index ec144a36e..971de5e9b 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -11,6 +11,7 @@ from numba.cuda import config from cuda import pathfinder import pathlib +from contextlib import contextmanager _env_path_tuple = namedtuple("_env_path_tuple", ["by", "info"]) @@ -22,6 +23,20 @@ ] +@contextmanager +def temporary_env_var(key, value): + """Context manager to temporarily set an environment variable.""" + old_value = os.environ.get(key) + os.environ[key] = value + try: + yield + finally: + if old_value is None: + del os.environ[key] + else: + os.environ[key] = old_value + + def _get_distribution(distribution_name): """Get the distribution path using importlib.metadata, returning None if not found.""" try: @@ -516,23 +531,66 @@ def _get_include_dir(): return _env_path_tuple(by, include_dir) +def _find_cuda_home_from_lib_path(lib_path): + """ + Walk up from a library path to find a directory containing 'nvvm' subdirectory. + + For example, given /usr/local/cuda/lib64/libnvrtc.so.12, + this would find /usr/local/cuda (which contains nvvm/). + + Returns the path if found, None otherwise. + """ + current = pathlib.Path(lib_path).resolve() + + # Walk up the directory tree + for parent in current.parents: + nvvm_subdir = parent / "nvvm" + if nvvm_subdir.is_dir(): + return str(parent) + + return None + + def _get_nvvm(): + # Strategy: + # 1. Try pathfinder directly + # 2. If CUDA_HOME/CUDA_PATH are set, pathfinder would have found it - give up + # 3. Use nvrtc's location to infer CUDA installation root + # 4. Temporarily set CUDA_HOME and retry pathfinder + + # First, try pathfinder directly + try: + return pathfinder.load_nvidia_dynamic_lib("nvvm") + except pathfinder.DynamicLibNotFoundError: + pass + + # If CUDA_HOME or CUDA_PATH is set, pathfinder would have found libnvvm + # based on the environment variable(s) - nothing more we can do + if os.environ.get("CUDA_HOME") or os.environ.get("CUDA_PATH"): + return None + + # Try to locate nvrtc - this library is almost certainly needed if nvvm is needed (in the context of numba-cuda) try: - nvvm = pathfinder.load_nvidia_dynamic_lib("nvvm") - return nvvm - except pathfinder.DynamicLibNotFoundError as e: - # Try system search - # TODO: remove after cuda-python/1157 is resolved - path_or_none = _get_nvvm_system_path() - if path_or_none is not None: - nvvm = pathlib.Path(path_or_none) - if nvvm.exists(): - # TODO: Expose private cuda-python APIs - dl = pathfinder._dynamic_libs.load_nvidia_dynamic_lib.load_with_abs_path( - "nvvm", nvvm, "system-search" - ) - return dl - raise pathfinder.DynamicLibNotFoundError("nvvm not found") from e + loaded_nvrtc = _get_nvrtc() + except pathfinder.DynamicLibNotFoundError: + return None + + # If nvrtc was not found via system-search, we can't reliably determine + # the CUDA installation structure + if loaded_nvrtc.found_via != "system-search": + return None + + # Search backward from nvrtc's location to find a directory with "nvvm" subdirectory + cuda_home = _find_cuda_home_from_lib_path(loaded_nvrtc.abs_path) + if cuda_home is None: + return None + + # Temporarily set CUDA_HOME and retry pathfinder + with temporary_env_var("CUDA_HOME", cuda_home): + try: + return pathfinder.load_nvidia_dynamic_lib("nvvm") + except pathfinder.DynamicLibNotFoundError: + return None def _get_nvrtc(): diff --git a/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py b/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py index 1f7ea04e7..901ea867b 100644 --- a/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +++ b/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py @@ -5,7 +5,7 @@ import os import multiprocessing as mp import warnings - +import pathlib from numba.cuda.core.config import IS_WIN32 from numba.cuda.core.errors import NumbaWarning @@ -20,6 +20,7 @@ _get_cudalib_dir_path_decision, get_system_ctk, get_system_ctk_libdir, + _find_cuda_home_from_lib_path, ) @@ -195,5 +196,40 @@ def _fake_non_conda_env(): sys.prefix = "" +class LibraryLookupBase(unittest.TestCase): + def test_find_cuda_home(self): + """Test the directory walking logic.""" + import tempfile + + # Create a mock CUDA installation structure + with tempfile.TemporaryDirectory() as tmpdir: + cuda_root = pathlib.Path(tmpdir) / "cuda" + lib64 = cuda_root / "lib64" + nvvm = cuda_root / "nvvm" + nvvm_lib64 = nvvm / "lib64" + + lib64.mkdir(parents=True) + nvvm_lib64.mkdir(parents=True) + + # Create mock library files + nvrtc_path = lib64 / "libnvrtc.so.12" + nvrtc_path.touch() + + nvvm_lib = nvvm_lib64 / "libnvvm.so.4" + nvvm_lib.touch() + + # Test finding CUDA_HOME from nvrtc path + found_cuda_home = _find_cuda_home_from_lib_path(str(nvrtc_path)) + + # Compare resolved paths to handle Windows short path names (e.g., RGROSS~1) + expected = str(cuda_root.resolve()) + assert found_cuda_home == expected, ( + f"Expected {expected}, got {found_cuda_home}" + ) + + # Test that the nvvm directory exists at the found location + assert (pathlib.Path(found_cuda_home) / "nvvm").is_dir() + + if __name__ == "__main__": unittest.main() From 32178c070185574f8980f3b45070216d785da008 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 09:07:58 -0800 Subject: [PATCH 16/24] fix awkward job --- ci/test_thirdparty_awkward.sh | 6 ++---- numba_cuda/numba/cuda/cuda_paths.py | 20 ++++++++------------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ci/test_thirdparty_awkward.sh b/ci/test_thirdparty_awkward.sh index a52c31503..502ab78b9 100755 --- a/ci/test_thirdparty_awkward.sh +++ b/ci/test_thirdparty_awkward.sh @@ -5,6 +5,7 @@ set -euo pipefail CUDA_VER_MAJOR_MINOR=${CUDA_VER%.*} +CUDA_VER_MAJOR=${CUDA_VER%.*.*} AWKWARD_VERSION="2.8.10" rapids-logger "Install awkward and related libraries" @@ -15,10 +16,7 @@ rapids-logger "Install wheel with test dependencies" package=$(realpath "${NUMBA_CUDA_ARTIFACTS_DIR}"/*.whl) echo "Package path: ${package}" python -m pip install \ - "${package}" \ - "cuda-python==${CUDA_VER_MAJOR_MINOR%.*}.*" \ - "cuda-core" \ - "nvidia-nvjitlink-cu12" \ + "${package}[cu${CUDA_VER_MAJOR}] --group test diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 971de5e9b..199a2df13 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -567,30 +567,26 @@ def _get_nvvm(): # If CUDA_HOME or CUDA_PATH is set, pathfinder would have found libnvvm # based on the environment variable(s) - nothing more we can do if os.environ.get("CUDA_HOME") or os.environ.get("CUDA_PATH"): - return None + raise pathfinder.DynamicLibNotFoundError # Try to locate nvrtc - this library is almost certainly needed if nvvm is needed (in the context of numba-cuda) - try: - loaded_nvrtc = _get_nvrtc() - except pathfinder.DynamicLibNotFoundError: - return None + loaded_nvrtc = _get_nvrtc() # If nvrtc was not found via system-search, we can't reliably determine # the CUDA installation structure if loaded_nvrtc.found_via != "system-search": - return None - + raise pathfinder.DynamicLibNotFoundError # Search backward from nvrtc's location to find a directory with "nvvm" subdirectory cuda_home = _find_cuda_home_from_lib_path(loaded_nvrtc.abs_path) if cuda_home is None: - return None + raise pathfinder.DynamicLibNotFoundError # Temporarily set CUDA_HOME and retry pathfinder with temporary_env_var("CUDA_HOME", cuda_home): - try: - return pathfinder.load_nvidia_dynamic_lib("nvvm") - except pathfinder.DynamicLibNotFoundError: - return None + library = pathfinder.load_nvidia_dynamic_lib("nvvm") + library.found_via = "system-search" + return library + raise pathfinder.DynamicLibNotFoundError def _get_nvrtc(): From 0b822ff9f3d07e807356fb40c27b71d5c4d70623 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 09:14:12 -0800 Subject: [PATCH 17/24] fix --- ci/test_thirdparty_awkward.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test_thirdparty_awkward.sh b/ci/test_thirdparty_awkward.sh index 502ab78b9..cfd95d1be 100755 --- a/ci/test_thirdparty_awkward.sh +++ b/ci/test_thirdparty_awkward.sh @@ -16,7 +16,7 @@ rapids-logger "Install wheel with test dependencies" package=$(realpath "${NUMBA_CUDA_ARTIFACTS_DIR}"/*.whl) echo "Package path: ${package}" python -m pip install \ - "${package}[cu${CUDA_VER_MAJOR}] + "${package}[cu${CUDA_VER_MAJOR}]" --group test From 8630f4150626996c910a26a4f23330ad8b6a6564 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 09:40:39 -0800 Subject: [PATCH 18/24] fix --- ci/test_thirdparty_awkward.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test_thirdparty_awkward.sh b/ci/test_thirdparty_awkward.sh index cfd95d1be..20c3648cc 100755 --- a/ci/test_thirdparty_awkward.sh +++ b/ci/test_thirdparty_awkward.sh @@ -16,7 +16,7 @@ rapids-logger "Install wheel with test dependencies" package=$(realpath "${NUMBA_CUDA_ARTIFACTS_DIR}"/*.whl) echo "Package path: ${package}" python -m pip install \ - "${package}[cu${CUDA_VER_MAJOR}]" + "${package}[cu${CUDA_VER_MAJOR}]" \ --group test From 7d84f935d0809ffdc3b3c51b638e6f2f42a81db8 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 10:18:26 -0800 Subject: [PATCH 19/24] minor updates --- numba_cuda/numba/cuda/cuda_paths.py | 1 - numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 199a2df13..563adade5 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -586,7 +586,6 @@ def _get_nvvm(): library = pathfinder.load_nvidia_dynamic_lib("nvvm") library.found_via = "system-search" return library - raise pathfinder.DynamicLibNotFoundError def _get_nvrtc(): diff --git a/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py b/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py index 901ea867b..83f9de5cf 100644 --- a/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py +++ b/numba_cuda/numba/cuda/tests/nocuda/test_library_lookup.py @@ -196,7 +196,7 @@ def _fake_non_conda_env(): sys.prefix = "" -class LibraryLookupBase(unittest.TestCase): +class TestCudaHomeDetection(unittest.TestCase): def test_find_cuda_home(self): """Test the directory walking logic.""" import tempfile From f88abb0c630d4d5a513e81df7a12bb6969a87ea4 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 10:56:03 -0800 Subject: [PATCH 20/24] code cleanup --- numba_cuda/numba/cuda/cuda_paths.py | 16 ++-------------- numba_cuda/numba/cuda/cudadrv/libs.py | 2 ++ 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 563adade5..04d538e7c 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -593,24 +593,12 @@ def _get_nvrtc(): def _get_nvrtc_path(): + # the pathfinder API will either find the library or raise nvrtc = _get_nvrtc() return _env_path_tuple(nvrtc.found_via, nvrtc.abs_path) def _get_nvvm_path(): + # the pathfinder API will either find the library or raise nvvm = _get_nvvm() return _env_path_tuple(nvvm.found_via, nvvm.abs_path) - - -def _get_nvvm_system_path(): - nvvm_lib_dir = get_system_ctk("nvvm") - if nvvm_lib_dir is None: - return None - nvvm_lib_dir = os.path.join(nvvm_lib_dir, "bin" if IS_WIN32 else "lib64") - if IS_WIN32 and os.path.isdir(os.path.join(nvvm_lib_dir, "x64")): - nvvm_lib_dir = os.path.join(nvvm_lib_dir, "x64") - - nvvm_path = os.path.join( - nvvm_lib_dir, "nvvm64_40_0.dll" if IS_WIN32 else "libnvvm.so.4" - ) - return nvvm_path diff --git a/numba_cuda/numba/cuda/cudadrv/libs.py b/numba_cuda/numba/cuda/cudadrv/libs.py index 2d6290caa..f99eb2b71 100644 --- a/numba_cuda/numba/cuda/cudadrv/libs.py +++ b/numba_cuda/numba/cuda/cudadrv/libs.py @@ -53,6 +53,8 @@ def get_cudalib(lib, static=False): loader's search mechanism. """ if lib in {"nvrtc", "nvvm"}: + # System search either invoked inside cuda-pathfinder + # or, for nvvm, using custom logic inside cuda-paths return get_cuda_paths()[lib].info dir_type = "static_cudalib_dir" if static else "cudalib_dir" From 71b800abb2a688a8e710f78323a8729ca695faf1 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 11:09:44 -0800 Subject: [PATCH 21/24] suggestion from greptile --- ci/test_thirdparty_awkward.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/test_thirdparty_awkward.sh b/ci/test_thirdparty_awkward.sh index 20c3648cc..6349ac1c2 100755 --- a/ci/test_thirdparty_awkward.sh +++ b/ci/test_thirdparty_awkward.sh @@ -16,7 +16,7 @@ rapids-logger "Install wheel with test dependencies" package=$(realpath "${NUMBA_CUDA_ARTIFACTS_DIR}"/*.whl) echo "Package path: ${package}" python -m pip install \ - "${package}[cu${CUDA_VER_MAJOR}]" \ + "${package}[cu${CUDA_VER_MAJOR}]" \ --group test From ae330ca2e20a0ef88959f91be0f4907f3640c64a Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 13:39:01 -0800 Subject: [PATCH 22/24] address reviews --- numba_cuda/numba/cuda/cuda_paths.py | 2 ++ pyproject.toml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 04d538e7c..3e6a36d24 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -405,6 +405,8 @@ def get_cuda_paths(): of (source_variable, info). The returned dictionary will have the following keys and infos: + - "nvrtc": file_path + - "nvvm": file_path - "libdevice": file_path - "cudalib_dir": directory_path - "static_cudalib_dir": directory_path diff --git a/pyproject.toml b/pyproject.toml index 7c3beff5b..f68492307 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,14 +27,14 @@ dependencies = ["numba>=0.60.0", "cuda-bindings>=12.9.1,<14.0.0", "cuda-core>=0. cu12 = [ "cuda-bindings>=12.9.1,<13.0.0", "cuda-core>=0.3.0,<1.0.0", - "cuda-pathfinder>=1.3.1", + "cuda-pathfinder>=1.3.1,2.0.0", # install nvcc for libNVVM "cuda-toolkit[cudart,nvcc,nvrtc,nvjitlink,cccl]==12.*", ] cu13 = [ "cuda-bindings==13.*", "cuda-core>=0.3.2,<1.0.0", - "cuda-pathfinder>=1.3.1", + "cuda-pathfinder>=1.3.1,<2.0.0", "cuda-toolkit[cudart,nvvm,nvrtc,nvjitlink,cccl]==13.*", ] From 7da093f19e86aaa9102342f4ee1f4818495da1ea Mon Sep 17 00:00:00 2001 From: brandon-b-miller <53796099+brandon-b-miller@users.noreply.github.com> Date: Tue, 20 Jan 2026 16:41:58 -0600 Subject: [PATCH 23/24] Update pyproject.toml Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f68492307..0f66fbb98 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ dependencies = ["numba>=0.60.0", "cuda-bindings>=12.9.1,<14.0.0", "cuda-core>=0. cu12 = [ "cuda-bindings>=12.9.1,<13.0.0", "cuda-core>=0.3.0,<1.0.0", - "cuda-pathfinder>=1.3.1,2.0.0", + "cuda-pathfinder>=1.3.1,<2.0.0", # install nvcc for libNVVM "cuda-toolkit[cudart,nvcc,nvrtc,nvjitlink,cccl]==12.*", ] From b87fab22843a3864476c09cc700020b80ecdd873 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 20 Jan 2026 18:23:36 -0800 Subject: [PATCH 24/24] address reviews --- numba_cuda/numba/cuda/cuda_paths.py | 40 ++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/numba_cuda/numba/cuda/cuda_paths.py b/numba_cuda/numba/cuda/cuda_paths.py index 3e6a36d24..0b7f031d3 100644 --- a/numba_cuda/numba/cuda/cuda_paths.py +++ b/numba_cuda/numba/cuda/cuda_paths.py @@ -32,7 +32,7 @@ def temporary_env_var(key, value): yield finally: if old_value is None: - del os.environ[key] + os.environ.pop(key, None) else: os.environ[key] = old_value @@ -559,33 +559,49 @@ def _get_nvvm(): # 2. If CUDA_HOME/CUDA_PATH are set, pathfinder would have found it - give up # 3. Use nvrtc's location to infer CUDA installation root # 4. Temporarily set CUDA_HOME and retry pathfinder - # First, try pathfinder directly try: return pathfinder.load_nvidia_dynamic_lib("nvvm") - except pathfinder.DynamicLibNotFoundError: - pass + except pathfinder.DynamicLibNotFoundError as e: + nvvm_exc = e + + def _raise_original(reason: str) -> None: + raise pathfinder.DynamicLibNotFoundError( + f"{reason}; original nvvm error: {nvvm_exc}" + ) from nvvm_exc # If CUDA_HOME or CUDA_PATH is set, pathfinder would have found libnvvm # based on the environment variable(s) - nothing more we can do if os.environ.get("CUDA_HOME") or os.environ.get("CUDA_PATH"): - raise pathfinder.DynamicLibNotFoundError - + _raise_original("nvvm not found and CUDA_HOME/CUDA_PATH is set") # Try to locate nvrtc - this library is almost certainly needed if nvvm is needed (in the context of numba-cuda) - loaded_nvrtc = _get_nvrtc() - + try: + loaded_nvrtc = _get_nvrtc() + except Exception as nvrtc_exc: + raise pathfinder.DynamicLibNotFoundError( + f"nvrtc load failed while inferring CUDA_HOME; original nvvm error: {nvvm_exc}" + ) from nvrtc_exc # If nvrtc was not found via system-search, we can't reliably determine # the CUDA installation structure if loaded_nvrtc.found_via != "system-search": - raise pathfinder.DynamicLibNotFoundError + _raise_original( + f"nvrtc found via {loaded_nvrtc.found_via}, cannot infer CUDA_HOME" + ) # Search backward from nvrtc's location to find a directory with "nvvm" subdirectory cuda_home = _find_cuda_home_from_lib_path(loaded_nvrtc.abs_path) if cuda_home is None: - raise pathfinder.DynamicLibNotFoundError - + _raise_original( + f"nvrtc path did not map to CUDA_HOME ({loaded_nvrtc.abs_path})" + ) # Temporarily set CUDA_HOME and retry pathfinder with temporary_env_var("CUDA_HOME", cuda_home): - library = pathfinder.load_nvidia_dynamic_lib("nvvm") + try: + library = pathfinder.load_nvidia_dynamic_lib("nvvm") + except pathfinder.DynamicLibNotFoundError as exc: + raise pathfinder.DynamicLibNotFoundError( + f"nvvm not found after inferring CUDA_HOME={cuda_home}; " + f"original nvvm error: {nvvm_exc}" + ) from exc library.found_via = "system-search" return library