1212 _loaded_dl ,
1313 _located_bitcode_lib ,
1414 _located_static_lib ,
15+ _make_ctk_root ,
1516 _patch_dynamic_lib_loader ,
1617 _touch ,
18+ _touch_ctk_file ,
1719 _write_cuda_h ,
1820)
1921from packaging .specifiers import SpecifierSet
3436
3537
3638def test_same_dynamic_link_component_requires_exact_ctk_major_minor_match (monkeypatch , tmp_path ):
37- cublas_root = tmp_path / "cuda-12.8"
38- cusolver_root = tmp_path / "cuda-12.9"
39- _write_cuda_h (cublas_root , "12.8.20250303" )
40- _write_cuda_h (cusolver_root , "12.9.20250531" )
41-
42- cublas_path = _touch (cublas_root / "targets" / "x86_64-linux" / "lib" / "libcublas.so.12" )
43- cusolver_path = _touch (cusolver_root / "targets" / "x86_64-linux" / "lib" / "libcusolver.so.12" )
39+ cublas_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "targets/x86_64-linux/lib/libcublas.so.12" )
40+ cusolver_path = _touch_ctk_file (
41+ tmp_path / "cuda-12.9" ,
42+ "12.9.20250531" ,
43+ "targets/x86_64-linux/lib/libcusolver.so.12" ,
44+ )
4445
4546 _patch_dynamic_lib_loader (
4647 monkeypatch ,
@@ -59,13 +60,12 @@ def test_same_dynamic_link_component_requires_exact_ctk_major_minor_match(monkey
5960
6061
6162def test_independent_dynamic_libs_may_resolve_to_different_ctk_minors (monkeypatch , tmp_path ):
62- nvrtc_root = tmp_path / "cuda-12.8"
63- nvjitlink_root = tmp_path / "cuda-12.9"
64- _write_cuda_h (nvrtc_root , "12.8.20250303" )
65- _write_cuda_h (nvjitlink_root , "12.9.20250531" )
66-
67- nvrtc_path = _touch (nvrtc_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
68- nvjitlink_path = _touch (nvjitlink_root / "targets" / "x86_64-linux" / "lib" / "libnvJitLink.so.12" )
63+ nvrtc_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
64+ nvjitlink_path = _touch_ctk_file (
65+ tmp_path / "cuda-12.9" ,
66+ "12.9.20250531" ,
67+ "targets/x86_64-linux/lib/libnvJitLink.so.12" ,
68+ )
6969
7070 _patch_dynamic_lib_loader (
7171 monkeypatch ,
@@ -83,13 +83,8 @@ def test_independent_dynamic_libs_may_resolve_to_different_ctk_minors(monkeypatc
8383
8484
8585def test_toolchain_companions_require_exact_ctk_major_minor_match (monkeypatch , tmp_path ):
86- static_root = tmp_path / "cuda-12.8"
87- binary_root = tmp_path / "cuda-12.9"
88- _write_cuda_h (static_root , "12.8.20250303" )
89- _write_cuda_h (binary_root , "12.9.20250531" )
90-
91- static_path = _touch (static_root / "targets" / "x86_64-linux" / "lib" / "libcudadevrt.a" )
92- binary_path = _touch (binary_root / "bin" / "nvcc" )
86+ static_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "targets/x86_64-linux/lib/libcudadevrt.a" )
87+ binary_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "bin/nvcc" )
9388
9489 monkeypatch .setattr (
9590 compatibility_module ,
@@ -113,13 +108,12 @@ def test_toolchain_companions_require_exact_ctk_major_minor_match(monkeypatch, t
113108
114109
115110def test_declared_ltoir_pipeline_requires_nvjitlink_not_older_than_nvrtc (monkeypatch , tmp_path ):
116- nvrtc_root = tmp_path / "cuda-12.9"
117- nvjitlink_root = tmp_path / "cuda-12.8"
118- _write_cuda_h (nvrtc_root , "12.9.20250531" )
119- _write_cuda_h (nvjitlink_root , "12.8.20250303" )
120-
121- nvrtc_path = _touch (nvrtc_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
122- nvjitlink_path = _touch (nvjitlink_root / "targets" / "x86_64-linux" / "lib" / "libnvJitLink.so.12" )
111+ nvrtc_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
112+ nvjitlink_path = _touch_ctk_file (
113+ tmp_path / "cuda-12.8" ,
114+ "12.8.20250303" ,
115+ "targets/x86_64-linux/lib/libnvJitLink.so.12" ,
116+ )
123117
124118 _patch_dynamic_lib_loader (
125119 monkeypatch ,
@@ -140,13 +134,12 @@ def test_declared_ltoir_pipeline_requires_nvjitlink_not_older_than_nvrtc(monkeyp
140134
141135
142136def test_declared_ltoir_pipeline_allows_same_major_newer_nvjitlink (monkeypatch , tmp_path ):
143- nvrtc_root = tmp_path / "cuda-12.8"
144- nvjitlink_root = tmp_path / "cuda-12.9"
145- _write_cuda_h (nvrtc_root , "12.8.20250303" )
146- _write_cuda_h (nvjitlink_root , "12.9.20250531" )
147-
148- nvrtc_path = _touch (nvrtc_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
149- nvjitlink_path = _touch (nvjitlink_root / "targets" / "x86_64-linux" / "lib" / "libnvJitLink.so.12" )
137+ nvrtc_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
138+ nvjitlink_path = _touch_ctk_file (
139+ tmp_path / "cuda-12.9" ,
140+ "12.9.20250531" ,
141+ "targets/x86_64-linux/lib/libnvJitLink.so.12" ,
142+ )
150143
151144 _patch_dynamic_lib_loader (
152145 monkeypatch ,
@@ -169,13 +162,12 @@ def test_declared_ltoir_pipeline_allows_same_major_newer_nvjitlink(monkeypatch,
169162
170163@pytest .mark .parametrize ("artifact_kind" , ("ptx" , "elf" , "cubin" ))
171164def test_declared_non_lto_pipeline_allows_cross_major_nvrtc_to_nvjitlink (monkeypatch , tmp_path , artifact_kind ):
172- nvrtc_root = tmp_path / "cuda-12.8"
173- nvjitlink_root = tmp_path / "cuda-13.0"
174- _write_cuda_h (nvrtc_root , "12.8.20250303" )
175- _write_cuda_h (nvjitlink_root , "13.0.20251003" )
176-
177- nvrtc_path = _touch (nvrtc_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
178- nvjitlink_path = _touch (nvjitlink_root / "targets" / "x86_64-linux" / "lib" / "libnvJitLink.so.13" )
165+ nvrtc_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
166+ nvjitlink_path = _touch_ctk_file (
167+ tmp_path / "cuda-13.0" ,
168+ "13.0.20251003" ,
169+ "targets/x86_64-linux/lib/libnvJitLink.so.13" ,
170+ )
179171
180172 _patch_dynamic_lib_loader (
181173 monkeypatch ,
@@ -197,13 +189,12 @@ def test_declared_non_lto_pipeline_allows_cross_major_nvrtc_to_nvjitlink(monkeyp
197189
198190
199191def test_declared_nvvm_pipeline_remains_conservative (monkeypatch , tmp_path ):
200- nvvm_root = tmp_path / "cuda-12.8"
201- nvjitlink_root = tmp_path / "cuda-12.9"
202- _write_cuda_h (nvvm_root , "12.8.20250303" )
203- _write_cuda_h (nvjitlink_root , "12.9.20250531" )
204-
205- nvvm_path = _touch (nvvm_root / "nvvm" / "lib64" / "libnvvm.so.4" )
206- nvjitlink_path = _touch (nvjitlink_root / "targets" / "x86_64-linux" / "lib" / "libnvJitLink.so.12" )
192+ nvvm_path = _touch_ctk_file (tmp_path / "cuda-12.8" , "12.8.20250303" , "nvvm/lib64/libnvvm.so.4" )
193+ nvjitlink_path = _touch_ctk_file (
194+ tmp_path / "cuda-12.9" ,
195+ "12.9.20250531" ,
196+ "targets/x86_64-linux/lib/libnvJitLink.so.12" ,
197+ )
207198
208199 _patch_dynamic_lib_loader (
209200 monkeypatch ,
@@ -238,9 +229,7 @@ def test_declared_dynamic_lib_pipeline_rejects_invalid_artifact_kind():
238229
239230
240231def test_driver_major_must_not_be_older_than_ctk_major (monkeypatch , tmp_path ):
241- ctk_root = tmp_path / "cuda-13.0"
242- _write_cuda_h (ctk_root , "13.0.20251003" )
243- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.13" )
232+ lib_path = _touch_ctk_file (tmp_path / "cuda-13.0" , "13.0.20251003" , "targets/x86_64-linux/lib/libnvrtc.so.13" )
244233
245234 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
246235
@@ -292,9 +281,7 @@ def test_other_packaging_raises_insufficient_metadata(monkeypatch, tmp_path):
292281
293282def test_driver_libs_do_not_lock_ctk_anchor (monkeypatch , tmp_path ):
294283 driver_lib_path = _touch (tmp_path / "driver-root" / "libnvidia-ml.so.1" )
295- ctk_root = tmp_path / "cuda-12.9"
296- _write_cuda_h (ctk_root , "12.9.20250531" )
297- ctk_lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
284+ ctk_lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
298285
299286 _patch_dynamic_lib_loader (
300287 monkeypatch ,
@@ -315,12 +302,9 @@ def test_driver_libs_do_not_mask_later_ctk_mismatch(monkeypatch, tmp_path):
315302 driver_lib_path = _touch (tmp_path / "driver-root" / "libnvidia-ml.so.1" )
316303 lib_root = tmp_path / "cuda-12.8"
317304 hdr_root = tmp_path / "cuda-12.9"
318- _write_cuda_h (lib_root , "12.8.20250303" )
319- _write_cuda_h (hdr_root , "12.9.20250531" )
320-
321- lib_path = _touch (lib_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
305+ lib_path = _touch_ctk_file (lib_root , "12.8.20250303" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
322306 hdr_dir = hdr_root / "targets" / "x86_64-linux" / "include"
323- _touch ( hdr_dir / " nvrtc.h" )
307+ _touch_ctk_file ( hdr_root , "12.9.20250531" , "targets/x86_64-linux/include/ nvrtc.h" )
324308
325309 _patch_dynamic_lib_loader (
326310 monkeypatch ,
@@ -385,9 +369,7 @@ def test_wheel_metadata_accepts_exact_and_range_requirements(monkeypatch, tmp_pa
385369
386370
387371def test_ctk_version_constraint_accepts_pep440_string (monkeypatch , tmp_path ):
388- ctk_root = tmp_path / "cuda-12.9"
389- _write_cuda_h (ctk_root , "12.9.20250531" )
390- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
372+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
391373
392374 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
393375
@@ -402,9 +384,7 @@ def test_ctk_version_constraint_accepts_pep440_string(monkeypatch, tmp_path):
402384
403385
404386def test_ctk_version_constraint_accepts_specifier_set_instance (monkeypatch , tmp_path ):
405- ctk_root = tmp_path / "cuda-12.9"
406- _write_cuda_h (ctk_root , "12.9.20250531" )
407- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
387+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
408388
409389 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
410390
@@ -419,9 +399,7 @@ def test_ctk_version_constraint_accepts_specifier_set_instance(monkeypatch, tmp_
419399
420400
421401def test_ctk_version_constraint_failure_raises (monkeypatch , tmp_path ):
422- ctk_root = tmp_path / "cuda-12.9"
423- _write_cuda_h (ctk_root , "12.9.20250531" )
424- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
402+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
425403
426404 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
427405
@@ -440,8 +418,7 @@ def test_ctk_version_constraint_rejects_invalid_specifier():
440418
441419
442420def test_resolved_items_capture_relation_metadata (tmp_path ):
443- ctk_root = tmp_path / "cuda-12.9"
444- _write_cuda_h (ctk_root , "12.9.20250531" )
421+ ctk_root = _make_ctk_root (tmp_path / "cuda-12.9" , "12.9.20250531" )
445422
446423 lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
447424 header_dir = ctk_root / "targets" / "x86_64-linux" / "include"
@@ -471,8 +448,7 @@ def test_resolved_items_capture_relation_metadata(tmp_path):
471448
472449
473450def test_static_bitcode_and_binary_methods_participate_in_checks (monkeypatch , tmp_path ):
474- ctk_root = tmp_path / "cuda-12.9"
475- _write_cuda_h (ctk_root , "12.9.20250531" )
451+ ctk_root = _make_ctk_root (tmp_path / "cuda-12.9" , "12.9.20250531" )
476452
477453 lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
478454 static_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libcudadevrt.a" )
@@ -505,9 +481,7 @@ def test_static_bitcode_and_binary_methods_participate_in_checks(monkeypatch, tm
505481
506482
507483def test_guard_rails_query_driver_cuda_version_by_default (monkeypatch , tmp_path ):
508- ctk_root = tmp_path / "cuda-12.9"
509- _write_cuda_h (ctk_root , "12.9.20250531" )
510- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
484+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
511485
512486 query_calls : list [int ] = []
513487
@@ -533,9 +507,7 @@ def fake_query_driver_cuda_version() -> DriverCudaVersion:
533507
534508
535509def test_guard_rails_wrap_driver_query_failures (monkeypatch , tmp_path ):
536- ctk_root = tmp_path / "cuda-12.9"
537- _write_cuda_h (ctk_root , "12.9.20250531" )
538- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
510+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
539511
540512 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
541513
@@ -556,9 +528,7 @@ def fail_query_driver_cuda_version() -> DriverCudaVersion:
556528
557529
558530def test_guard_rails_accept_minor_version_compatibility_with_driver_release_branch (monkeypatch , tmp_path ):
559- ctk_root = tmp_path / "cuda-12.9"
560- _write_cuda_h (ctk_root , "12.9.20250531" )
561- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
531+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
562532
563533 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
564534
@@ -573,9 +543,7 @@ def test_guard_rails_accept_minor_version_compatibility_with_driver_release_bran
573543
574544
575545def test_guard_rails_reject_same_major_older_driver_when_release_branch_too_old (monkeypatch , tmp_path ):
576- ctk_root = tmp_path / "cuda-12.9"
577- _write_cuda_h (ctk_root , "12.9.20250531" )
578- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
546+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
579547
580548 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
581549
@@ -592,9 +560,7 @@ def test_guard_rails_reject_same_major_older_driver_when_release_branch_too_old(
592560
593561
594562def test_guard_rails_require_driver_release_metadata_for_same_major_older_driver (monkeypatch , tmp_path ):
595- ctk_root = tmp_path / "cuda-12.9"
596- _write_cuda_h (ctk_root , "12.9.20250531" )
597- lib_path = _touch (ctk_root / "targets" / "x86_64-linux" / "lib" / "libnvrtc.so.12" )
563+ lib_path = _touch_ctk_file (tmp_path / "cuda-12.9" , "12.9.20250531" , "targets/x86_64-linux/lib/libnvrtc.so.12" )
598564
599565 monkeypatch .setattr (compatibility_module , "_load_nvidia_dynamic_lib" , lambda _libname : _loaded_dl (lib_path ))
600566
0 commit comments