Skip to content

Skip, not error, when nvJitLink is not installed - #2557

Open
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:nvjitlink-usable-not-found
Open

Skip, not error, when nvJitLink is not installed#2557
LeSingh1 wants to merge 1 commit into
NVIDIA:mainfrom
LeSingh1:nvjitlink-usable-not-found

Conversation

@LeSingh1

@LeSingh1 LeSingh1 commented Aug 9, 2026

Copy link
Copy Markdown
Contributor
def check_nvjitlink_usable():
    from cuda.bindings._internal import nvjitlink as inner_nvjitlink

    return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0


pytestmark = pytest.mark.skipif(
    not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)"
)

The reason string covers "maybe not installed", but the check cannot detect that case. A
zero pointer only means "library loaded, symbol not exported".
_inspect_function_pointer() loads nvJitLink lazily:

_inspect_function_pointer_inspect_function_pointers_check_or_init_nvjitlink
load_library()load_nvidia_dynamic_lib("nvJitLink")

which raises DynamicLibNotFoundError when the library is absent. Nothing catches it — and
because this runs at module import time (the pytestmark line), the whole module is a
collection ERROR on a machine without nvJitLink, rather than the skip it asks for.

The repo already handles exactly this call shape correctly in two other places:

  • tests/test_cudart.py::test_getLocalRuntimeVersionexcept pathfinder.DynamicLibNotFoundError: pytest.skip(...)
  • tests/test_utils.py::_is_libnvvm_availableexcept DynamicLibNotFoundError: return False

Fix

Fold both probes into one _nvjitlink_exports(symbol_name) helper that catches
DynamicLibNotFoundError and returns False. That covers
check_nvjitlink_get_linked_ltoir_usable() too, which has the identical shape and gates
the skipif on line 182.

Test

test_check_nvjitlink_usable_without_the_library stubs
cuda.bindings._internal.nvjitlink with an _inspect_function_pointer that raises
DynamicLibNotFoundError — reproducing the not-installed condition on a machine that
does have nvJitLink
, so it actually runs in CI. It fails on main (the exception escapes)
and passes with this change. Both probes are asserted.

I verified the stubbing mechanism locally against both the old and new helper shapes: the
old one propagates DynamicLibNotFoundError, the new one returns False.

ruff check and ruff format --check are clean.

This is the same defect class as #2541, which fixes the production-code copy in
cuda.bindings.utils.check_nvvm_compiler_options().

    def check_nvjitlink_usable():
        from cuda.bindings._internal import nvjitlink as inner_nvjitlink

        return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0

    pytestmark = pytest.mark.skipif(
        not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)"
    )

The reason string covers "maybe not installed", but the check cannot detect
that. A zero pointer only means "library loaded, symbol not exported".
_inspect_function_pointer() loads nvJitLink lazily -- _inspect_function_pointers
-> _check_or_init_nvjitlink -> load_library -> load_nvidia_dynamic_lib
("nvJitLink") -- so when it is not installed the call raises
DynamicLibNotFoundError. Nothing catches it, and this runs at module import
time, so the whole module is a collection ERROR instead of a skip.

The repo already handles this correctly elsewhere for the same call shape:
test_cudart.test_getLocalRuntimeVersion catches
pathfinder.DynamicLibNotFoundError, and test_utils._is_libnvvm_available does
the same for nvvm.

Fold both probes into one _nvjitlink_exports() helper that catches it and
returns False, so check_nvjitlink_get_linked_ltoir_usable() (used by the
skipif on line 182) is covered too.

Adds a test that stubs cuda.bindings._internal.nvjitlink with a
_inspect_function_pointer that raises, so it reproduces the not-installed
condition on a machine that does have nvJitLink. It fails before this change.
@copy-pr-bot

copy-pr-bot Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the cuda.bindings Everything related to the cuda.bindings module label Aug 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.bindings Everything related to the cuda.bindings module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant