Improve optional CUDA module import handling for NVVM and nvJitLink#1733
Improve optional CUDA module import handling for NVVM and nvJitLink#1733cpcloud merged 3 commits intoNVIDIA:mainfrom
Conversation
Add a shared `optional_cuda_import` API in cuda.pathfinder so optional module checks only suppress genuinely unavailable modules or dynamic libs while still surfacing nested import bugs. Wire cuda.core NVVM/nvJitLink detection to this helper and declare cuda-pathfinder as a direct cuda-core dependency. Made-with: Cursor
|
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. |
Apply ruff-preferred import ordering in pathfinder exports and rename an unused test lambda argument so repository-wide pre-commit checks pass cleanly. Made-with: Cursor
|
/ok to test |
|
| libraries: site-packages, Conda, then CUDA_HOME/CUDA_PATH. | ||
| (`PR #1690 <https://github.com/NVIDIA/cuda-python/pull/1690>`_) | ||
|
|
||
| * Add ``optional_cuda_import()`` to support robust optional imports of CUDA |
There was a problem hiding this comment.
Ah, did you want to add this into the 1.4.1 release?
You could start the 1.4.2 release notes in this PR, since you have this paragraph already.
cuda_core/pyproject.toml
Outdated
| "Environment :: GPU :: NVIDIA CUDA :: 13", | ||
| ] | ||
| dependencies = [ | ||
| "cuda-pathfinder >=1.1", |
There was a problem hiding this comment.
I think this needs to be >=1.4.2? Because this PR makes cuda_core depending on the optional_cuda_import feature, which will only be in 1.4.2.
There was a problem hiding this comment.
Kind of a chicken-and-egg problem, because the solver will fail to solve until 1.4.2 is released. So I think this needs to remain as is for now.
Raise the cuda-core dependency floor to cuda-pathfinder>=1.4.2, move the new optional import note to 1.4.2 release notes, and simplify nvJitLink warning text by inlining the fixed version detail. Made-with: Cursor
rwgk
left a comment
There was a problem hiding this comment.
Awesome!
I'm slightly worried that we will forget to add the release date into cuda_pathfinder/docs/source/release/1.4.2-notes.rst, but I'll try to remember.
If you get a chance to add in a placeholder (e.g. Released on TBD) then it'll be less likely to slip.
|
/ok to test |
| # Module-level state for NVVM lazy loading | ||
| cdef object_nvvm_module = None | ||
| cdef bint _nvvm_import_attempted = False | ||
| _nvvm_module = None | ||
| _nvvm_import_attempted = False |
There was a problem hiding this comment.
Making them cdef helps us hide the objects from curious Python users.
| from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError | ||
|
|
||
|
|
||
| def optional_cuda_import( |
There was a problem hiding this comment.
Q: Does this have to be a public API? Can we keep it internal instead?
Fixes #980
Summary
cuda.pathfinder.optional_cuda_import()helper that treats only truly optional-module failures as unavailable while re-raising nestedModuleNotFoundErrorcuda.coreNVVM and nvJitLink availability checks to use the shared helper, including dynamic library probing behaviorcuda-pathfindera direct dependency ofcuda-core, and add targeted tests/docs/release-note updates in both subpackagesTest plan
cd cuda_pathfinder && pixi run -e default pytest tests/test_optional_cuda_import.py -qcd cuda_core && pixi run -e cu13 pytest tests/test_optional_dependency_imports.py -qMade with Cursor