Skip to content

Commit 8d7f9ca

Browse files
committed
fixup! feat(core.utils): NVVM fingerprint goes through _get_nvvm_module
1 parent a9fbab0 commit 8d7f9ca

File tree

2 files changed

+53
-15
lines changed

2 files changed

+53
-15
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,22 @@ def _linker_backend_and_version() -> tuple[str, str]:
344344
def _nvvm_fingerprint() -> str:
345345
"""Stable identifier for the loaded NVVM toolchain.
346346
347-
Combines the libNVVM library version (``cuda.bindings.nvvm.version()``)
348-
with the IR version reported by ``ir_version()``. The library version is
349-
the primary invalidation lever: a libNVVM patch upgrade can change
350-
codegen while keeping the same IR major/minor, so keying only on the IR
351-
pair would silently reuse stale entries. Paired with cuda-core, the IR
352-
pair adds defence in depth without making the key any less stable.
347+
Combines the libNVVM library version (``module.version()``) with the IR
348+
version reported by ``module.ir_version()``. The library version is the
349+
primary invalidation lever: a libNVVM patch upgrade can change codegen
350+
while keeping the same IR major/minor, so keying only on the IR pair
351+
would silently reuse stale entries. Paired with cuda-core, the IR pair
352+
adds defence in depth without making the key any less stable.
353+
354+
Both calls go through ``_get_nvvm_module()`` so this fingerprint follows
355+
the same availability / cuda-bindings-version gate that real NVVM
356+
compilation does -- if NVVM is unusable at compile time, the probe
357+
fails the same way and ``_probe`` mixes the failure label into the key.
353358
"""
354-
from cuda.bindings import nvvm
355359
from cuda.core._program import _get_nvvm_module
356360

357361
module = _get_nvvm_module()
358-
lib_major, lib_minor = nvvm.version()
362+
lib_major, lib_minor = module.version()
359363
major, minor, debug_major, debug_minor = module.ir_version()
360364
return f"lib={lib_major}.{lib_minor};ir={major}.{minor}.{debug_major}.{debug_minor}"
361365

cuda_core/tests/test_program_cache.py

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,19 +504,53 @@ def test_make_program_cache_key_nvvm_use_libdevice_false_equals_none():
504504

505505

506506
def test_make_program_cache_key_nvvm_library_version_changes_key(monkeypatch):
507-
"""Updating libNVVM (different ``cuda.bindings.nvvm.version()``) must
508-
invalidate NVVM cache entries -- a patch upgrade can change codegen
509-
without bumping the IR version, so keying only on IR would silently
510-
return stale entries."""
511-
from cuda.core.utils import _program_cache
507+
"""Updating libNVVM (different ``module.version()``) must invalidate
508+
NVVM cache entries even when the IR version stays constant; a patch
509+
upgrade can change codegen without bumping the IR pair."""
510+
511+
class _FakeNVVM:
512+
def __init__(self, lib_version):
513+
self._lib_version = lib_version
514+
515+
def version(self):
516+
return self._lib_version
512517

513-
monkeypatch.setattr(_program_cache, "_nvvm_fingerprint", lambda: "lib=12.3;ir=1.8.3.0")
518+
def ir_version(self):
519+
return (1, 8, 3, 0) # constant -- only the lib version varies
520+
521+
fake_old = _FakeNVVM((12, 3))
522+
fake_new = _FakeNVVM((12, 4))
523+
from cuda.core import _program
524+
525+
monkeypatch.setattr(_program, "_get_nvvm_module", lambda: fake_old)
514526
k_old = _make_key(code="abc", code_type="nvvm", target_type="ptx")
515-
monkeypatch.setattr(_program_cache, "_nvvm_fingerprint", lambda: "lib=12.4;ir=1.8.3.0")
527+
monkeypatch.setattr(_program, "_get_nvvm_module", lambda: fake_new)
516528
k_new = _make_key(code="abc", code_type="nvvm", target_type="ptx")
517529
assert k_old != k_new
518530

519531

532+
def test_make_program_cache_key_nvvm_fingerprint_uses_get_nvvm_module(monkeypatch):
533+
"""The fingerprint must call _get_nvvm_module() rather than importing
534+
cuda.bindings.nvvm directly -- otherwise it bypasses the availability
535+
/cuda-bindings-version gate and could disagree with the actual NVVM
536+
compile path."""
537+
sentinel_called = {"n": 0}
538+
539+
class _SentinelNVVM:
540+
def version(self):
541+
sentinel_called["n"] += 1
542+
return (12, 9)
543+
544+
def ir_version(self):
545+
return (1, 8, 3, 0)
546+
547+
from cuda.core import _program
548+
549+
monkeypatch.setattr(_program, "_get_nvvm_module", lambda: _SentinelNVVM())
550+
_make_key(code="abc", code_type="nvvm", target_type="ptx")
551+
assert sentinel_called["n"] == 1
552+
553+
520554
def test_make_program_cache_key_nvvm_probe_changes_key(monkeypatch):
521555
"""NVVM keys must reflect the NVVM toolchain identity (IR version)
522556
so an upgraded libNVVM does not silently reuse pre-upgrade entries."""

0 commit comments

Comments
 (0)