Skip, not error, when nvJitLink is not installed - #2557
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
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.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
DynamicLibNotFoundErrorwhen the library is absent. Nothing catches it — andbecause this runs at module import time (the
pytestmarkline), the whole module is acollection 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_getLocalRuntimeVersion→except pathfinder.DynamicLibNotFoundError: pytest.skip(...)tests/test_utils.py::_is_libnvvm_available→except DynamicLibNotFoundError: return FalseFix
Fold both probes into one
_nvjitlink_exports(symbol_name)helper that catchesDynamicLibNotFoundErrorand returnsFalse. That coverscheck_nvjitlink_get_linked_ltoir_usable()too, which has the identical shape and gatesthe
skipifon line 182.Test
test_check_nvjitlink_usable_without_the_librarystubscuda.bindings._internal.nvjitlinkwith an_inspect_function_pointerthat raisesDynamicLibNotFoundError— reproducing the not-installed condition on a machine thatdoes 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 returnsFalse.ruff checkandruff format --checkare clean.This is the same defect class as #2541, which fixes the production-code copy in
cuda.bindings.utils.check_nvvm_compiler_options().