@@ -395,6 +395,26 @@ def test_make_program_cache_key_ptx_driver_ignored_fields_collapse(field, a, b,
395395 assert k_a == k_b
396396
397397
398+ @pytest .mark .parametrize (
399+ "a, b" ,
400+ [
401+ pytest .param ("-v" , ["-v" ], id = "str_vs_list" ),
402+ pytest .param ("-v" , ("-v" ,), id = "str_vs_tuple" ),
403+ pytest .param (["-v" ], ("-v" ,), id = "list_vs_tuple" ),
404+ ],
405+ )
406+ def test_make_program_cache_key_ptx_ptxas_options_canonicalized (a , b , monkeypatch ):
407+ """_prepare_nvjitlink_options emits the same -Xptxas= flags for str,
408+ list, and tuple shapes of ptxas_options. The cache key must treat them
409+ as equivalent so equivalent compiles don't miss the cache."""
410+ from cuda .core import _linker
411+
412+ monkeypatch .setattr (_linker , "_decide_nvjitlink_or_driver" , lambda : False ) # nvJitLink
413+ k_a = _make_key (code = ".version 7.0" , code_type = "ptx" , options = _opts (ptxas_options = a ))
414+ k_b = _make_key (code = ".version 7.0" , code_type = "ptx" , options = _opts (ptxas_options = b ))
415+ assert k_a == k_b
416+
417+
398418def test_make_program_cache_key_ptx_driver_ignored_fields_still_matter_under_nvjitlink (monkeypatch ):
399419 """nvJitLink does honour those fields; they must still differentiate keys there."""
400420 from cuda .core import _linker
@@ -405,6 +425,22 @@ def test_make_program_cache_key_ptx_driver_ignored_fields_still_matter_under_nvj
405425 assert k_a != k_b
406426
407427
428+ @pytest .mark .parametrize (
429+ "code_type, code, target_type" ,
430+ [
431+ pytest .param ("c++" , "void k(){}" , "cubin" , id = "nvrtc" ),
432+ pytest .param ("ptx" , ".version 7.0" , "cubin" , id = "ptx" ),
433+ ],
434+ )
435+ def test_make_program_cache_key_use_libdevice_ignored_for_non_nvvm (code_type , code , target_type ):
436+ """``use_libdevice`` is only consumed on the NVVM path; NVRTC and PTX
437+ ignore it, so toggling it must not perturb the cache key elsewhere."""
438+ k_off = _make_key (code = code , code_type = code_type , target_type = target_type , options = _opts (use_libdevice = False ))
439+ k_on = _make_key (code = code , code_type = code_type , target_type = target_type , options = _opts (use_libdevice = True ))
440+ k_none = _make_key (code = code , code_type = code_type , target_type = target_type , options = _opts (use_libdevice = None ))
441+ assert k_off == k_on == k_none
442+
443+
408444def test_make_program_cache_key_nvvm_use_libdevice_false_equals_none ():
409445 """Program_init gates ``use_libdevice`` on truthiness, so False and None
410446 compile identically and must hash the same way."""
0 commit comments