Skip to content

Commit b559023

Browse files
cpcloudclaude
andcommitted
fix(core): probe driver version lazily in Linker dispatch
driver_version() was called unconditionally during Linker.__init__, which fails in environments where nvJitLink is installed but the CUDA driver is absent (e.g., build containers). Now catches the exception and sets driver_major=None. When driver_major is unknown and nvJitLink is available, optimistically selects the nvJitLink backend. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 3706bea commit b559023

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

cuda_core/cuda/core/_linker.pyx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,13 @@ cdef inline int Linker_init(Linker self, tuple object_codes, object options) exc
472472
)
473473
lto_requested = bool(options.link_time_optimization) or bool(options.ptx)
474474
nvjitlink_version = _probe_nvjitlink()
475-
driver_major = driver_version()[0]
475+
# Probe driver version lazily: only needed when comparing majors.
476+
# In environments where nvJitLink is installed but the driver is
477+
# absent (e.g., build containers), we can still select nvJitLink.
478+
try:
479+
driver_major = driver_version()[0]
480+
except Exception:
481+
driver_major = None
476482
backend = _choose_backend(
477483
driver_major, nvjitlink_version, inputs_have_ltoir, lto_requested
478484
)
@@ -701,7 +707,7 @@ def _probe_nvjitlink() -> tuple | None:
701707

702708

703709
def _choose_backend(
704-
driver_major: int,
710+
driver_major: int | None,
705711
nvjitlink_version: tuple | None,
706712
inputs_have_ltoir: bool,
707713
lto_requested: bool,
@@ -710,8 +716,9 @@ def _choose_backend(
710716

711717
Parameters
712718
----------
713-
driver_major : int
719+
driver_major : int or None
714720
Major version of the installed CUDA driver (from ``cuDriverGetVersion``).
721+
``None`` when the driver cannot be queried (e.g., no driver installed).
715722
nvjitlink_version : tuple[int, int] or None
716723
``(major, minor)`` if nvJitLink is available and >=12.3; ``None`` otherwise.
717724
inputs_have_ltoir : bool
@@ -746,7 +753,9 @@ def _choose_backend(
746753
return "driver"
747754

748755
nvjitlink_major = nvjitlink_version[0]
749-
if nvjitlink_major == driver_major:
756+
# If driver version is unknown, optimistically use nvJitLink
757+
# (common in build containers with nvJitLink but no driver).
758+
if driver_major is None or nvjitlink_major == driver_major:
750759
return "nvjitlink"
751760

752761
if needs_nvjitlink:

0 commit comments

Comments
 (0)