Skip to content

Improve optional CUDA module import handling for NVVM and nvJitLink#1733

Merged
cpcloud merged 3 commits intoNVIDIA:mainfrom
cpcloud:pathfinder-issue-980
Mar 6, 2026
Merged

Improve optional CUDA module import handling for NVVM and nvJitLink#1733
cpcloud merged 3 commits intoNVIDIA:mainfrom
cpcloud:pathfinder-issue-980

Conversation

@cpcloud
Copy link
Contributor

@cpcloud cpcloud commented Mar 6, 2026

Fixes #980

Summary

  • add a public cuda.pathfinder.optional_cuda_import() helper that treats only truly optional-module failures as unavailable while re-raising nested ModuleNotFoundError
  • switch cuda.core NVVM and nvJitLink availability checks to use the shared helper, including dynamic library probing behavior
  • make cuda-pathfinder a direct dependency of cuda-core, and add targeted tests/docs/release-note updates in both subpackages

Test plan

  • cd cuda_pathfinder && pixi run -e default pytest tests/test_optional_cuda_import.py -q
  • cd cuda_core && pixi run -e cu13 pytest tests/test_optional_dependency_imports.py -q

Made with Cursor

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
@copy-pr-bot
Copy link
Contributor

copy-pr-bot bot commented Mar 6, 2026

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
@cpcloud
Copy link
Contributor Author

cpcloud commented Mar 6, 2026

/ok to test

@cpcloud cpcloud requested a review from rwgk March 6, 2026 21:18
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

"Environment :: GPU :: NVIDIA CUDA :: 13",
]
dependencies = [
"cuda-pathfinder >=1.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Collaborator

@rwgk rwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cpcloud
Copy link
Contributor Author

cpcloud commented Mar 6, 2026

/ok to test

@cpcloud cpcloud enabled auto-merge (squash) March 6, 2026 22:54
@cpcloud cpcloud merged commit f720e48 into NVIDIA:main Mar 6, 2026
10 of 28 checks passed
github-actions bot pushed a commit that referenced this pull request Mar 7, 2026
Removed preview folders for the following PRs:
- PR #1713
- PR #1724
- PR #1728
- PR #1733
Comment on lines 464 to +466
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Does this have to be a public API? Can we keep it internal instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENH]: Robust imports of optional dependencies (nvvm, nvJitLink)

3 participants