Skip to content

fix(cuda.bindings): return False from check_nvvm_compiler_options without libNVVM - #3598

Open
mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3565
Open

mdboom wants to merge 1 commit into
NVIDIA:mainfrom
mdboom:issue3565

Conversation

@mdboom

@mdboom mdboom commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3565. Part of #2077.

Warning

⚠️🚨 BEHAVIOR CHANGE 🚨⚠️

This PR changes library behavior so that a test that has never run in CI can pass. When libNVVM cannot be found, cuda.bindings.utils.check_nvvm_compiler_options() now returns False. Before, it raised cuda.pathfinder.DynamicLibNotFoundError.

🧑‍🔬 Needs a domain expert before merging 🧑‍🔬

Either the library or the test is wrong, and this PR assumes it is the library. If raising is the intended behavior, keep the library unchanged and rewrite the test to expect DynamicLibNotFoundError. Either way the test now runs in CI; only its expected result differs. The history below supports both answers.

Summary

test_check_nvvm_compiler_options_no_libnvvm skipped whenever libNVVM was present, which is every CI configuration, so it never ran. When run with libNVVM missing, it fails: the function raises instead of returning False.

 check_nvvm_compiler_options(options)
   import cuda.bindings.nvvm                          # missing module -> False
-  _inspect_function_pointer("__nvvmCreateProgram")   # missing libNVVM -> DynamicLibNotFoundError escapes
+  try: _inspect_function_pointer("__nvvmCreateProgram")
+  except DynamicLibNotFoundError: return False       # missing libNVVM -> False
   compile a small NVVM IR program with `options`
     ERROR_INVALID_OPTION -> False
   -> True

The test now simulates a missing libNVVM, so it runs everywhere. NVVM is loaded once per process, so the simulation runs in a fresh interpreter:

-if libNVVM is available: skip        # true on every CI runner
-assert check_nvvm_compiler_options(["-arch=compute_90"]) is False
+in a fresh interpreter:
+  replace the libNVVM loader with one that raises DynamicLibNotFoundError
+  assert check_nvvm_compiler_options(["-arch=compute_90"]) is False
+  assert the replacement loader was called

Other changes:

  • The test's "not currently run in any CI job" marker is removed.
  • New paired 13.6.0 release notes: the cuda-bindings note lists this under "Behavior changes". The cuda-python note is a placeholder that the release-note pairing pre-commit check requires.
  • The CUDA 12 bindings (cuda_bindings_12) have no check_nvvm_compiler_options, so there is no counterpart change.

History: library or test?

Both the function and the test were added in #1837.

  • For returning False (this PR):
    • The test, added in the same PR, asserts False when libNVVM is missing.
    • The test's _is_libnvvm_available() helper catches DynamicLibNotFoundError, following a review suggestion: "The only expected exception is DynamicLibNotFoundError (or subclasses) when libNVVM isn't installed."
    • The function already returns False when the nvvm module is missing.
  • For raising (current behavior): during review, the reviewer asked that this call not be guarded: "If that import works, we don't want to guard the _inspect_function_pointer import, or the _inspect_function_pointer() call. If those don't work, that's a bug we want to surface." (discussion_r3019673778). That comment replaced a broad except Exception. This PR catches only DynamicLibNotFoundError, so other loader failures still raise.

Evidence

Run locally on Linux with CUDA 13 bindings:

  • Before: test_check_nvvm_compiler_options_no_libnvvm FAILED with DynamicLibNotFoundError: simulated: nvvm not found.
  • After: PASSED. All 38 tests in cuda_bindings_13/tests/test_utils.py pass, including the libNVVM-present tests (valid, invalid, empty, multiple_valid, arch_detection).

On Windows the NVVM loader calls the same replaceable load_nvidia_dynamic_lib, so the test should run there too. That is not run locally.

Confirming it runs in CI: in this PR's CI run, every CUDA 13 bindings test job should report test_check_nvvm_compiler_options_no_libnvvm PASSED, where main reports it SKIPPED. For example:

gh run view <CI run id> --repo NVIDIA/cuda-python --log | grep -F "test_check_nvvm_compiler_options_no_libnvvm"

Merge Danger

Door: two-way. A one-line change in the function's exception handling, plus the test.

Blast Radius: callers of check_nvvm_compiler_options() on systems without libNVVM. Code that caught DynamicLibNotFoundError from this function now gets False instead. Callers that treat False as "option unsupported" now get that answer, where before they had to handle an exception.

  • In this repository, only cuda_core/tests/test_program.py calls it, in skipif conditions. Without libNVVM, those cases now skip instead of erroring during collection.
  • The function was abstracted from numba-cuda (its docstring cites numba-cuda PR 681), so numba-cuda is the main external caller to check.

Reviewers: please feel free to push commits directly to this PR to improve it.

🤖 Generated with Claude Code

…hout libNVVM

check_nvvm_compiler_options() raised DynamicLibNotFoundError when libNVVM
could not be found, but test_check_nvvm_compiler_options_no_libnvvm
expected False. The test skipped whenever libNVVM was present, so it never
ran in CI and the mismatch went unnoticed.

Catch DynamicLibNotFoundError around the libNVVM lookup and return False.
Rewrite the test to simulate a missing libNVVM in a fresh interpreter, so
it runs in every configuration. Add paired cuda-bindings and cuda-python
13.6.0 release notes recording the behavior change.

Closes NVIDIA#3565.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdboom mdboom added this to the cuda.bindings 13.6.0 & 12.9.12 milestone Nov 25, 2026
@mdboom mdboom added bug Something isn't working test Improvements or additions to tests cuda.bindings Everything related to the cuda.bindings module labels Nov 25, 2026
@mdboom mdboom self-assigned this Nov 25, 2026
@mdboom
mdboom requested a review from leofang November 25, 2026 18:26
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Checking NVVM compiler options now returns False when the NVVM compiler library is unavailable, instead of raising an error.
  • Documentation
    • Updated release notes with the NVVM behavior change and guidance for resolving a possible upgrade issue when installing CUDA Python over version 12.6.2.post1 or earlier.

check_nvvm_compiler_options now returns False when libNVVM cannot be found. A subprocess test simulates that condition. The release notes describe the change and CUDA Python 13.6.0.

Changes: NVVM availability fallback

Layer / File(s) Summary
Missing-library fallback and release coverage
cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py, cuda_bindings_13/tests/test_utils.py, cuda_bindings_13/docs/source/release/13.6.0-notes.rst, cuda_python/docs/source/release/13.6.0-notes.rst
The compiler-option check returns False when the NVVM function-pointer lookup raises DynamicLibNotFoundError. A subprocess test simulates the missing library and checks the result and load attempt. The release notes describe the change and CUDA Python 13.6.0.

Assessment against linked issues

Objective Addressed Explanation
#3565: Return False instead of raising DynamicLibNotFoundError when libNVVM is missing, and test the behavior in a subprocess. ✅

Suggested reviewers: abhilash1910, rwgk

Change: Bug fix

Merge Risk: Low · up to bbe68

When libNVVM is missing, check_nvvm_compiler_options now returns False instead of raising. The public API reference does not yet list the function, so the new return value is not documented there. Add the entry before or shortly after merging.

Security architecture risk: Minimal · up to bbe68

This is a compatibility change, not a change to which libraries or compiler operations callers can access. Code that caught the missing-library exception will now receive False from the check.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The direct exposure is to processes calling the existing option check. The changed branch reports a negative result without creating a compiler program; it adds no entrypoint or route to native compilation. External callers' handling of False was not verified.

Trust Boundaries and Controls

  • observed — The native loader still receives the fixed library name nvvm. Caller-provided options are passed to compilation only after the existing pointer check succeeds and a program is created; the new catch does not bypass those steps.

Resilience and Maintainability Implications

  • inferred — A failed load still exits the existing initialization lock without setting the completion flag or publishing the pointer map. Linux can write some slots before the failure, but a later attempt still runs initialization rather than treating those slots as a completed table. The new catch changes what the caller sees, not what a retry sees.
- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c29b214 and bbe68d7.

Files selected for processing: 4

  • cuda_bindings_13/cuda/bindings/utils/_nvvm_utils.py
  • cuda_bindings_13/docs/source/release/13.6.0-notes.rst
  • cuda_bindings_13/tests/test_utils.py
  • cuda_python/docs/source/release/13.6.0-notes.rst

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 8 remain after this review.


If the test program compiles successfully, True is returned.

If libNVVM cannot be found, False is returned.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor · Maintainability & Code Quality · Quick win

Add check_nvvm_compiler_options to the utils module reference.

docs/source/module/utils.rst autosummary omits check_nvvm_compiler_options, even though cuda.bindings.utils exports it. Its return contract changes in this PR, so the module reference should list it. This keeps the new False return documented where users look for the API.

Suggested fix

 .. autosummary::
    :toctree: generated/
 
+   check_nvvm_compiler_options
    get_cuda_native_handle
    get_minimal_required_cuda_ver_from_ptx_ver
    get_ptx_ver

@github-actions

Copy link
Copy Markdown
Contributor

This branch has not been deployed

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

Labels

bug Something isn't working cuda.bindings Everything related to the cuda.bindings module test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cuda.bindings: check_nvvm_compiler_options raises DynamicLibNotFoundError instead of returning False when libNVVM is missing

1 participant