@@ -504,19 +504,53 @@ def test_make_program_cache_key_nvvm_use_libdevice_false_equals_none():
504504
505505
506506def 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+
520554def 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