Skip to content

Commit a9fbab0

Browse files
committed
fixup! feat(core.utils): use cuda.bindings.nvvm.version() in NVVM fingerprint
1 parent 1bf28b9 commit a9fbab0

File tree

2 files changed

+30
-10
lines changed

2 files changed

+30
-10
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,20 @@ def _linker_backend_and_version() -> tuple[str, str]:
344344
def _nvvm_fingerprint() -> str:
345345
"""Stable identifier for the loaded NVVM toolchain.
346346
347-
NVVM lacks a direct version API (nvbugs 5312315), but ``ir_version()``
348-
reports the IR major/minor/debug pair the toolchain emits -- enough to
349-
keep pre-/post-upgrade caches separate. Paired with the driver and
350-
cuda-core versions already in the digest, this is a practical substitute
351-
for a true libNVVM version.
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.
352353
"""
354+
from cuda.bindings import nvvm
353355
from cuda.core._program import _get_nvvm_module
354356

355-
nvvm = _get_nvvm_module()
356-
major, minor, debug_major, debug_minor = nvvm.ir_version()
357-
return f"ir={major}.{minor}.{debug_major}.{debug_minor}"
357+
module = _get_nvvm_module()
358+
lib_major, lib_minor = nvvm.version()
359+
major, minor, debug_major, debug_minor = module.ir_version()
360+
return f"lib={lib_major}.{lib_minor};ir={major}.{minor}.{debug_major}.{debug_minor}"
358361

359362

360363
def _cuda_core_version() -> str:
@@ -1083,8 +1086,11 @@ class FileStreamProgramCache(ProgramCacheResource):
10831086
``cuda.core`` patch releases because every entry's key encodes
10841087
the relevant backend/compiler/runtime fingerprints for its
10851088
compilation path (NVRTC entries pin the NVRTC version, NVVM
1086-
entries pin the NVVM IR version, PTX/linker entries pin the
1087-
chosen linker backend, its version, and the driver version).
1089+
entries pin the libNVVM library and IR versions, PTX/linker
1090+
entries pin the chosen linker backend and its version -- and,
1091+
when the cuLink/driver backend is selected, the driver version
1092+
too; nvJitLink-backed PTX entries are deliberately driver-version
1093+
independent).
10881094
10891095
Parameters
10901096
----------

cuda_core/tests/test_program_cache.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,20 @@ def test_make_program_cache_key_nvvm_use_libdevice_false_equals_none():
503503
assert k_true != k_none
504504

505505

506+
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
512+
513+
monkeypatch.setattr(_program_cache, "_nvvm_fingerprint", lambda: "lib=12.3;ir=1.8.3.0")
514+
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")
516+
k_new = _make_key(code="abc", code_type="nvvm", target_type="ptx")
517+
assert k_old != k_new
518+
519+
506520
def test_make_program_cache_key_nvvm_probe_changes_key(monkeypatch):
507521
"""NVVM keys must reflect the NVVM toolchain identity (IR version)
508522
so an upgraded libNVVM does not silently reuse pre-upgrade entries."""

0 commit comments

Comments
 (0)