-
Notifications
You must be signed in to change notification settings - Fork 157
First version of cuda.bindings.path_finder
#447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Tested interactively with: ``` import cuda_paths nvvm_path = cuda_paths._get_nvvm_path() print(f"{nvvm_path=}") ```
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
get_nvvm_path()
/ok to test |
|
``` ______________________ ERROR collecting test_nvjitlink.py ______________________ tests/test_nvjitlink.py:62: in <module> not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)" tests/test_nvjitlink.py:58: in check_nvjitlink_usable return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0 cuda/bindings/_internal/nvjitlink.pyx:257: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:260: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:208: in cuda.bindings._internal.nvjitlink._inspect_function_pointers ??? cuda/bindings/_internal/nvjitlink.pyx:102: in cuda.bindings._internal.nvjitlink._check_or_init_nvjitlink ??? cuda/bindings/_internal/nvjitlink.pyx:59: in cuda.bindings._internal.nvjitlink.load_library ??? /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:312: in get_cuda_paths "nvvm": _get_nvvm_path(), /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:285: in _get_nvvm_path by, path = _get_nvvm_path_decision() /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:96: in _get_nvvm_path_decision if os.path.exists(nvvm_ctk_dir): <frozen genericpath>:19: in exists ??? E TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType ```
/ok to test |
``` ______________________ ERROR collecting test_nvjitlink.py ______________________ tests/test_nvjitlink.py:62: in <module> not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)" tests/test_nvjitlink.py:58: in check_nvjitlink_usable return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0 cuda/bindings/_internal/nvjitlink.pyx:257: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:260: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:208: in cuda.bindings._internal.nvjitlink._inspect_function_pointers ??? cuda/bindings/_internal/nvjitlink.pyx:102: in cuda.bindings._internal.nvjitlink._check_or_init_nvjitlink ??? cuda/bindings/_internal/nvjitlink.pyx:59: in cuda.bindings._internal.nvjitlink.load_library ??? /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:313: in get_cuda_paths "libdevice": _get_libdevice_paths(), /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:126: in _get_libdevice_paths by, libdir = _get_libdevice_path_decision() /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:73: in _get_libdevice_path_decision if os.path.exists(libdevice_ctk_dir): <frozen genericpath>:19: in exists ??? E TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType ```
/ok to test |
/ok to test |
…ath.join(None, "libnvJitLink.so")
/ok to test |
/ok to test |
/ok to test |
…gs/_bindings/cynvrtc.pyx.in
/ok to test |
/ok to test |
Tracking link provided by @leofang on chat: There, when the |
/ok to test |
cuda.bindings.path_finder
Auto-sync is disabled for ready for review pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
@leofang @kkraus14 This PR is ready for review. It's certain that more work is needed, but I believe what I have now is a meaningful milestone. I backed out my experiments with NVRTC for now (see PR description). After this PR is merged, I want to pick up that work, and then work towards replacing more/all dynamic library loading code with calls to |
To stay organized while we're in a code freeze, I created the "temporary integration branch" with name |
The third iteration of this PR description is:
Closes #453 (expected, but currently not tested)
This PR has these main aspects:
to pure Python code under the new
cuda/bindings/_path_finder
directory.The API for calling from cython is simply:
load_nvidia_dynamic_library()
first attempts to load the dynamic library using the system search features (rpath
|LD_LIBRARY_PATH
|PATH
). If that succeeds, the handle to the library (a Pythonint
on all platforms) is returned.Otherwise,
load_nvidia_dynamic_library()
callsfind_nvidia_dynamic_library()
to determine an absolute pathname for the dynamic library. Then it loads the library given that pathname.find_nvidia_dynamic_library()
first searches for the library undersite-packages/nvidia
, usingsys.path
to search for site-packages, in order. If that fails, it uses a clone ofnumba/cuda/cuda_paths.py
to search for the library.To pass all tests in the cuda-python CI, this trick is needed under Linux:
Here the last
/lib/
is replaced with/lib64/
or vice versa inget_cuda_paths()[name].info
and both are searched.@functools.cache
is used forload_nvidia_dynamic_library(name)
, therefore the involved search & load code is certain to be invoked only once per process, per library.numba/cuda/cuda_paths.py
was changed as little as possible, so that it is feasible to keep our copy in sync with the original while they both exist. The idea is to work towards usingcuda.bindings.path_finder
from numba-cuda. (After that is achieved, the code undercuda/bindings/_path_finder
can probably be refactored significantly.)TODO
.pyx
files need to be backported to the upstream code generator.Deferred (follow-on PRs)
path_finder.load_nvidia_dynamic_library("nvrtc")
— This was attempted but backed out. Special handling ofnvrtc-builtins64_128.dll
is required, to replace or emulate this existing code.The second iteration of this PR description was:
These commits expand the experiment to adopt the entire numba/cuda/cuda_paths.py
Example:
The first iteration of this PR description was:
Experiment related to #441, triggered by this comment (by @kkraus14).
Context: Potentially use this code from cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
This PR: Stripped-down (and ruff'ed) copies of:
https://github.com/NVIDIA/numba-cuda/blob/bf487d78a40eea87f009d636882a5000a7524c95/numba_cuda/numba/cuda/cuda_paths.py
https://github.com/numba/numba/blob/f0d24824fcd6a454827e3c108882395d00befc04/numba/misc/findlib.py
Tested interactively with:
Output:
Advantage of this approach: Battle-tested and time-tested.
Disadvantages: TBD