Skip to content

Commit 50bf893

Browse files
fix(cuda.core): fall back to driver when nvJitLink < 12.3 is installed
Stop probing nvJitLink availability via module.version(), which calls the unversioned nvJitLinkVersion symbol missing in nvJitLink 12.0-12.2. Use symbol pointer inspection via _nvjitlink_has_version_symbol() instead, restoring cuda-core 0.6.0 fallback behavior. Fixes NVIDIA#2408 Signed-off-by: Omar Atie <[email protected]> Co-authored-by: Cursor <[email protected]>
1 parent 608cc5f commit 50bf893

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

‎cuda_core/cuda/core/_linker.pyx‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -683,10 +683,10 @@ def _decide_nvjitlink_or_driver() -> bool:
683683
" For best results, consider upgrading to a recent version of"
684684
)
685685

686-
nvjitlink_module = _optional_cuda_import(
687-
"cuda.bindings.nvjitlink",
688-
probe_function=lambda module: module.version(), # probe triggers nvJitLink runtime load
689-
)
686+
# Do not probe via module.version(): nvJitLink 12.0-12.2 lacks the unversioned
687+
# nvJitLinkVersion symbol, so calling version() raises FunctionNotFoundError.
688+
# Use _nvjitlink_has_version_symbol() below instead (symbol pointer inspection).
689+
nvjitlink_module = _optional_cuda_import("cuda.bindings.nvjitlink")
690690
if nvjitlink_module is None:
691691
warn_txt = f"cuda.bindings.nvjitlink is not available, therefore {warn_txt_common} cuda-bindings."
692692
else:

‎cuda_core/tests/test_optional_dependency_imports.py‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def fake__optional_cuda_import(modname, probe_function=None):
7878
def test_decide_nvjitlink_or_driver_reraises_nested_module_not_found(monkeypatch):
7979
def fake__optional_cuda_import(modname, probe_function=None):
8080
assert modname == "cuda.bindings.nvjitlink"
81-
assert probe_function is not None
81+
assert probe_function is None
8282
err = ModuleNotFoundError("No module named 'not_a_real_dependency'")
8383
err.name = "not_a_real_dependency"
8484
raise err
@@ -93,7 +93,7 @@ def fake__optional_cuda_import(modname, probe_function=None):
9393
def test_decide_nvjitlink_or_driver_falls_back_when_module_missing(monkeypatch):
9494
def fake__optional_cuda_import(modname, probe_function=None):
9595
assert modname == "cuda.bindings.nvjitlink"
96-
assert probe_function is not None
96+
assert probe_function is None
9797
return None
9898

9999
monkeypatch.setattr(_linker, "_optional_cuda_import", fake__optional_cuda_import)
@@ -103,3 +103,34 @@ def fake__optional_cuda_import(modname, probe_function=None):
103103

104104
assert use_driver_backend is True
105105
assert _linker._use_nvjitlink_backend is False
106+
107+
108+
def test_decide_nvjitlink_or_driver_falls_back_when_nvjitlink_too_old(monkeypatch):
109+
def fake__optional_cuda_import(modname, probe_function=None):
110+
assert modname == "cuda.bindings.nvjitlink"
111+
assert probe_function is None
112+
return object()
113+
114+
monkeypatch.setattr(_linker, "_optional_cuda_import", fake__optional_cuda_import)
115+
monkeypatch.setattr(_linker, "_nvjitlink_has_version_symbol", lambda _nvjitlink: False)
116+
117+
with pytest.warns(RuntimeWarning, match="too old \\(<12.3\\)"):
118+
use_driver_backend = _linker._decide_nvjitlink_or_driver()
119+
120+
assert use_driver_backend is True
121+
assert _linker._use_nvjitlink_backend is False
122+
123+
124+
def test_decide_nvjitlink_or_driver_selects_nvjitlink_when_version_symbol_present(monkeypatch):
125+
def fake__optional_cuda_import(modname, probe_function=None):
126+
assert modname == "cuda.bindings.nvjitlink"
127+
assert probe_function is None
128+
return object()
129+
130+
monkeypatch.setattr(_linker, "_optional_cuda_import", fake__optional_cuda_import)
131+
monkeypatch.setattr(_linker, "_nvjitlink_has_version_symbol", lambda _nvjitlink: True)
132+
133+
use_driver_backend = _linker._decide_nvjitlink_or_driver()
134+
135+
assert use_driver_backend is False
136+
assert _linker._use_nvjitlink_backend is True

0 commit comments

Comments
 (0)