Skip to content

Commit 21db67c

Browse files
Add LoadedDL.found_via (#1049)
* outline of something functional for linux * adding/refactoring * updates * actually pass tests * findvia * cleanup * reset * pass FoundVia through where necessary * address reviews * already :) * address reviews * Update cuda-pathfinder version to 1.3.1 (for release), move 1.X.Y-notes.rst → 1.3.1-notes.rst, add PR 1049 to release notes. --------- Co-authored-by: Ralf W. Grosse-Kunstleve <rgrossekunst@nvidia.com>
1 parent 84f5aae commit 21db67c

9 files changed

Lines changed: 37 additions & 14 deletions

File tree

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class LoadedDL:
1616
abs_path: Optional[str]
1717
was_already_loaded_from_elsewhere: bool
1818
_handle_uint: int # Platform-agnostic unsigned pointer value
19+
found_via: str
1920

2021

2122
def load_dependencies(libname: str, load_func: Callable[[str], LoadedDL]) -> None:

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_linux.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ def check_if_already_loaded_from_elsewhere(libname: str, _have_abs_path: bool) -
138138
except OSError:
139139
continue
140140
else:
141-
return LoadedDL(abs_path_for_dynamic_library(libname, handle), True, handle._handle)
141+
return LoadedDL(
142+
abs_path_for_dynamic_library(libname, handle), True, handle._handle, "was-already-loaded-from-elsewhere"
143+
)
142144
return None
143145

144146

@@ -170,7 +172,7 @@ def load_with_system_search(libname: str) -> Optional[LoadedDL]:
170172
abs_path = abs_path_for_dynamic_library(libname, handle)
171173
if abs_path is None:
172174
raise RuntimeError(f"No expected symbol for {libname=!r}")
173-
return LoadedDL(abs_path, False, handle._handle)
175+
return LoadedDL(abs_path, False, handle._handle, "system-search")
174176
return None
175177

176178

@@ -193,7 +195,7 @@ def _work_around_known_bugs(libname: str, found_path: str) -> None:
193195
ctypes.CDLL(dep_path, CDLL_MODE)
194196

195197

196-
def load_with_abs_path(libname: str, found_path: str) -> LoadedDL:
198+
def load_with_abs_path(libname: str, found_path: str, found_via: Optional[str] = None) -> LoadedDL:
197199
"""Load a dynamic library from the given path.
198200
199201
Args:
@@ -211,4 +213,4 @@ def load_with_abs_path(libname: str, found_path: str) -> LoadedDL:
211213
handle = _load_lib(libname, found_path)
212214
except OSError as e:
213215
raise RuntimeError(f"Failed to dlopen {found_path}: {e}") from e
214-
return LoadedDL(found_path, False, handle._handle)
216+
return LoadedDL(found_path, False, handle._handle, found_via)

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_dl_windows.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,10 @@ def abs_path_for_dynamic_library(libname: str, handle: ctypes.wintypes.HMODULE)
100100
return buffer.value
101101

102102

103-
def check_if_already_loaded_from_elsewhere(libname: str, have_abs_path: bool) -> Optional[LoadedDL]:
103+
def check_if_already_loaded_from_elsewhere(
104+
libname: str,
105+
have_abs_path: bool,
106+
) -> Optional[LoadedDL]:
104107
for dll_name in SUPPORTED_WINDOWS_DLLS.get(libname, ()):
105108
handle = kernel32.GetModuleHandleW(dll_name)
106109
if handle:
@@ -110,7 +113,7 @@ def check_if_already_loaded_from_elsewhere(libname: str, have_abs_path: bool) ->
110113
# load_with_abs_path(). To make the side-effect more deterministic,
111114
# activate it even if the library was already loaded from elsewhere.
112115
add_dll_directory(abs_path)
113-
return LoadedDL(abs_path, True, ctypes_handle_to_unsigned_int(handle))
116+
return LoadedDL(abs_path, True, ctypes_handle_to_unsigned_int(handle), "was-already-loaded-from-elsewhere")
114117
return None
115118

116119

@@ -128,12 +131,12 @@ def load_with_system_search(libname: str) -> Optional[LoadedDL]:
128131
handle = kernel32.LoadLibraryExW(dll_name, None, 0)
129132
if handle:
130133
abs_path = abs_path_for_dynamic_library(libname, handle)
131-
return LoadedDL(abs_path, False, ctypes_handle_to_unsigned_int(handle))
134+
return LoadedDL(abs_path, False, ctypes_handle_to_unsigned_int(handle), "system-search")
132135

133136
return None
134137

135138

136-
def load_with_abs_path(libname: str, found_path: str) -> LoadedDL:
139+
def load_with_abs_path(libname: str, found_path: str, found_via: Optional[str] = None) -> LoadedDL:
137140
"""Load a dynamic library from the given path.
138141
139142
Args:
@@ -156,4 +159,4 @@ def load_with_abs_path(libname: str, found_path: str) -> LoadedDL:
156159
error_code = ctypes.GetLastError() # type: ignore[attr-defined]
157160
raise RuntimeError(f"Failed to load DLL at {found_path}: Windows error {error_code}")
158161

159-
return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle))
162+
return LoadedDL(found_path, False, ctypes_handle_to_unsigned_int(handle), found_via)

cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,14 @@
2626
def _load_lib_no_cache(libname: str) -> LoadedDL:
2727
finder = _FindNvidiaDynamicLib(libname)
2828
abs_path = finder.try_site_packages()
29-
if abs_path is None:
29+
30+
abs_path = finder.try_site_packages()
31+
if abs_path is not None:
32+
found_via = "site-packages"
33+
else:
3034
abs_path = finder.try_with_conda_prefix()
35+
if abs_path is not None:
36+
found_via = "conda"
3137

3238
# If the library was already loaded by someone else, reproduce any OS-specific
3339
# side-effects we would have applied on a direct absolute-path load (e.g.,
@@ -49,8 +55,10 @@ def _load_lib_no_cache(libname: str) -> LoadedDL:
4955
abs_path = finder.try_with_cuda_home()
5056
if abs_path is None:
5157
finder.raise_not_found_error()
58+
else:
59+
found_via = "CUDA_HOME"
5260

53-
return load_with_abs_path(libname, abs_path)
61+
return load_with_abs_path(libname, abs_path, found_via)
5462

5563

5664
@functools.cache
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
__version__ = "1.3.1a0"
4+
__version__ = "1.3.1"

cuda_pathfinder/docs/nv-versions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
"version": "latest",
44
"url": "https://nvidia.github.io/cuda-python/cuda-pathfinder/latest/"
55
},
6+
{
7+
"version": "1.3.1",
8+
"url": "https://nvidia.github.io/cuda-python/cuda-pathfinder/1.3.1/"
9+
},
610
{
711
"version": "1.3.0",
812
"url": "https://nvidia.github.io/cuda-python/cuda-pathfinder/1.3.0/"

cuda_pathfinder/docs/source/release.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Release Notes
77
.. toctree::
88
:maxdepth: 3
99

10+
1.3.1 <release/1.3.1-notes>
1011
1.3.0 <release/1.3.0-notes>
1112
1.2.3 <release/1.2.3-notes>
1213
1.2.2 <release/1.2.2-notes>

cuda_pathfinder/docs/source/release/1.X.Y-notes.rst renamed to cuda_pathfinder/docs/source/release/1.3.1-notes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
44
.. py:currentmodule:: cuda.pathfinder
55
6-
``cuda-pathfinder`` 1.X.Y Release notes
6+
``cuda-pathfinder`` 1.3.1 Release notes
77
=======================================
88

9-
Released on TBD
9+
Released on Oct 13, 2025
1010

1111
Highlights
1212
----------
1313

1414
* supported_nvidia_libs.py updates:
1515
add nvidia-cublasmp-cu12, nvidia-cublasmp-cu13, nvidia-cudss-cu13
1616
(`PR #1089 <https://github.com/NVIDIA/cuda-python/pull/1089>`_)
17+
18+
* Add ``LoadedDL.found_via``
19+
(`PR #1049 <https://github.com/NVIDIA/cuda-python/pull/1049>`_)

cuda_pathfinder/tests/child_load_nvidia_dynamic_lib_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def child_process_func(libname):
4343
if loaded_dl_fresh.was_already_loaded_from_elsewhere:
4444
raise RuntimeError("loaded_dl_fresh.was_already_loaded_from_elsewhere")
4545
validate_abs_path(loaded_dl_fresh.abs_path)
46+
assert loaded_dl_fresh.found_via is not None
4647

4748
loaded_dl_from_cache = load_nvidia_dynamic_lib(libname)
4849
if loaded_dl_from_cache is not loaded_dl_fresh:

0 commit comments

Comments
 (0)