You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pathfinder: add locate_nvidia_dynamic_lib and find_nvidia_dynamic_lib - #3233
Add locate_nvidia_dynamic_lib(libname) -> LocatedDynamicLib and find_nvidia_dynamic_lib(libname) -> str. They return the file load_nvidia_dynamic_lib would load in a fresh process, without loading it into the caller's process. The pair matches locate_static_lib/find_static_lib and locate_bitcode_lib/find_bitcode_lib.
Motivation
The only way to get a shared library's path today is load_nvidia_dynamic_lib, which loads the library to report where it is. A build backend that only needs the path pays for the load, and has to handle a LoadedDL whose abs_path is None. My downstream CUDA extension library does this in its CMake probe script: cmake/cuda_pathfinder_probe.py.
Design
Same search steps and order as load_nvidia_dynamic_lib: site-packages, conda, native loader search, library-specific roots and CUDA_PATH/CUDA_HOME, Program Files, CTK root canary. Driver libraries use the native loader search only.
The native loader search can only be observed by loading, so it runs in the existing canary subprocess (_resolve_system_loaded_abs_path_in_subprocess). Nothing is loaded in the caller's process.
A library already loaded in the current process is not taken into account. This follows the discussion in [FEA]: Add find_nvidia_dynamic_library to find the DSO location without loading #757: the result is what pathfinder would find without other DSOs influencing it. The docstring says when the result can differ from load_nvidia_dynamic_lib.
Same error contract as load_nvidia_dynamic_lib: DynamicLibUnknownError, DynamicLibNotAvailableError, DynamicLibNotFoundError.
find_nvidia_dynamic_lib is cached with functools.cache, like find_static_lib. locate_nvidia_dynamic_lib is not.
Tests
test_locate_matches_load_in_fresh_process: for every supported library, runs load_nvidia_dynamic_lib in a child process with the existing helper and checks that locate_nvidia_dynamic_lib in the parent returns the same file, or raises DynamicLibNotFoundError when the child finds nothing.
Mocked tests for the search order, driver libraries, not-found errors, the find_ cache, and that no LOADER load or already-loaded check runs.
Full pathfinder suite passes locally (Linux x86-64, CUDA 13.4 wheels plus a system CTK). The real-library test covered site-packages, system-search and not-found results.
Added utilities to locate NVIDIA dynamic libraries without loading them into the current process. Results can include the absolute path, filename, and discovery method.
Added cached path lookup and clearer errors for unknown, unavailable, or missing libraries. Discovery checks supported search locations and required dependencies.
Documentation
Updated the API reference to cover the library-location utilities and the information they return.
The change adds public functions to locate supported NVIDIA dynamic libraries without loading them into the caller’s process. The lookup follows the library search order, reports the path and discovery method, and includes a cached path-only wrapper.
Changes: Dynamic-library location
Layer / File(s)
Summary
Lookup flow and validation cuda_pathfinder/cuda/pathfinder/_dynamic_libs/find_nvidia_dynamic_lib.py, cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py, cuda_pathfinder/tests/test_find_nvidia_dynamic_lib.py
Adds a result type and lookup functions. The lookup checks early search steps, system search, late search steps, and the configured CTK root canary. Driver libraries use system search only. Library-name validation and driver-not-found error construction are factored into helpers. Tests cover search order, dependencies, errors, and caching.
Public API exposure cuda_pathfinder/cuda/pathfinder/__init__.py, cuda_pathfinder/docs/source/api.rst
Re-exports the result type and lookup functions, and adds them to the API reference.
Assessment against linked issues
Objective
Addressed
Explanation
[#757] Find the DSO location that the path finder would load without loading it.
NVIDIA/cuda-python#3188: This PR updates cuDSS descriptor catalog names, which the new lookup uses to validate and locate supported libraries.
Suggested labels:enhancement
Suggested reviewers:rwgk
Priority: Normal
Change: Feature
Merge Risk: Moderate · up to 0d0bc
Path lookup can disagree with loading when a required dependency is available only outside the native loader search. Resolve that mismatch before merging; a cached native-search miss can also remain stale if library availability changes during a process’s lifetime.
Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.
Move the libname validation and the driver-lib not-found error of
load_nvidia_dynamic_lib into helpers so a lookup that does not load can
reuse them. No behavior change.
Return the file load_nvidia_dynamic_lib would load in a fresh process,
without loading it into the caller's process. The native loader search
runs in the existing subprocess probe. A library already loaded in the
current process is not taken into account.
ClosesNVIDIA#757
load_nvidia_dynamic_lib fails when a required dependency cannot be
found, so locate_nvidia_dynamic_lib now does too, at the same point in
the search. Also document that the native loader search result is
cached for the process.
Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.
important: Locate the required dependencies in the probe subprocess before the system search.
_locate_lib locates each required dependency with locate_nvidia_dynamic_lib(dep), but it does not load it. The system-search probe then calls _resolve_system_loaded_abs_path_in_subprocess(libname), which takes only the library name and loads only that library in a fresh process. load_nvidia_dynamic_lib loads the same dependencies before its native-loader search.
When the target is reached through the system search and a required dependency exists only at a wheel path, the probe's native loader may not resolve that dependency. The probe then returns None, and _locate_lib can raise DynamicLibNotFoundError. load_nvidia_dynamic_lib can load the same target in that environment. The locate_nvidia_dynamic_lib docstring says the result is the file that load_nvidia_dynamic_lib would load in a fresh process. Its Notes list only already-loaded libraries and RPATH as sources of difference, not dependency preloading.
Pass the located dependency paths to the probe subprocess. The child should load them by absolute path before it loads the target. This keeps the caller's process unloaded. If the native-loader result is cached by library name alone, include the dependency paths in the cache key. Otherwise a cached result can be reused with a different dependency state.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cuda.pathfinderEverything related to the cuda.pathfinder module
1 participant
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #757
Summary
Add
locate_nvidia_dynamic_lib(libname) -> LocatedDynamicLibandfind_nvidia_dynamic_lib(libname) -> str. They return the fileload_nvidia_dynamic_libwould load in a fresh process, without loading it into the caller's process. The pair matcheslocate_static_lib/find_static_libandlocate_bitcode_lib/find_bitcode_lib.Motivation
The only way to get a shared library's path today is
load_nvidia_dynamic_lib, which loads the library to report where it is. A build backend that only needs the path pays for the load, and has to handle aLoadedDLwhoseabs_pathisNone. My downstream CUDA extension library does this in its CMake probe script: cmake/cuda_pathfinder_probe.py.Design
load_nvidia_dynamic_lib: site-packages, conda, native loader search, library-specific roots andCUDA_PATH/CUDA_HOME, Program Files, CTK root canary. Driver libraries use the native loader search only._resolve_system_loaded_abs_path_in_subprocess). Nothing is loaded in the caller's process.find_nvidia_dynamic_libraryto find the DSO location without loading #757: the result is what pathfinder would find without other DSOs influencing it. The docstring says when the result can differ fromload_nvidia_dynamic_lib.load_nvidia_dynamic_lib:DynamicLibUnknownError,DynamicLibNotAvailableError,DynamicLibNotFoundError.find_nvidia_dynamic_libis cached withfunctools.cache, likefind_static_lib.locate_nvidia_dynamic_libis not.Tests
test_locate_matches_load_in_fresh_process: for every supported library, runsload_nvidia_dynamic_libin a child process with the existing helper and checks thatlocate_nvidia_dynamic_libin the parent returns the same file, or raisesDynamicLibNotFoundErrorwhen the child finds nothing.find_cache, and that noLOADERload or already-loaded check runs.site-packages,system-searchand not-found results.