From 92f45382b30d2f81654a70d3434b8633bc19acf7 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 30 Nov 2026 10:01:19 -0500 Subject: [PATCH] test(cuda.core): run the driver (cuLink) linker tests by forcing the backend test_linker_link_ptx_culink, test_driver_linker_lifetime_no_heap_corruption and test_driver_linker_preserves_error_log_after_close only ran when the linker fell back to the driver backend, which needs a missing or pre-12.3 nvJitLink. Every CI row has a current nvJitLink, so they never ran. Add a culink_backend fixture that forces the driver backend for one test by patching the backend globals in _linker (restored by monkeypatch). Only the selection is faked: the tests still call the real cuLink* APIs. The fixture also skips when the driver cannot load NVRTC's PTX, which every cuLink test needs; test_linker_link_ptx_culink lacked that guard. Remove the "not currently run in any CI job" markers. Closes #3572. Co-Authored-By: Claude Opus 5.5 --- cuda_core/tests/test_linker.py | 39 ++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/cuda_core/tests/test_linker.py b/cuda_core/tests/test_linker.py index aaec64f18a3f..36c600ddd8ef 100644 --- a/cuda_core/tests/test_linker.py +++ b/cuda_core/tests/test_linker.py @@ -21,7 +21,7 @@ ) from cuda.core._module import ObjectCode from cuda.core._program import _can_load_generated_ptx -from cuda.core._utils.cuda_utils import CUDAError +from cuda.core._utils.cuda_utils import CUDAError, driver ARCH = "sm_" + "".join(f"{i}" for i in Device().compute_capability) @@ -46,6 +46,25 @@ class nvJitLinkError(Exception): pass +@pytest.fixture +def culink_backend(monkeypatch, init_cuda): + """Force the driver (cuLink) linker backend for one test. + + Every CI row has a current nvJitLink, so the driver backend, a supported + fallback, is otherwise never selected. Only the backend selection is faked: + linking still calls the real cuLink* APIs. + """ + # cuLink JIT-compiles NVRTC's PTX, so the driver must accept its PTX version. + if not _can_load_generated_ptx(): + pytest.skip("PTX version too new for current driver") + monkeypatch.setattr(_linker, "_use_nvjitlink_backend", False) + monkeypatch.setattr(_linker, "_driver", driver) + # Rebuild the driver input-type table on first use; restored on teardown. + monkeypatch.setattr(_linker, "_inited", False) + monkeypatch.setattr(_linker, "_driver_input_types", None) + assert Linker.which_backend() == "driver" + + @pytest.fixture def compile_ptx_functions(init_cuda): # Without -rdc (relocatable device code) option, the generated ptx will not included any unreferenced @@ -127,9 +146,7 @@ def test_linker_link_ptx_nvjitlink(compile_ltoir_functions): assert linked_code.name == options.name -# This test is not currently run in any CI job -@pytest.mark.skipif(not is_culink_backend, reason="nvjitlink requires lto for ptx linking") -def test_linker_link_ptx_culink(compile_ptx_functions): +def test_linker_link_ptx_culink(culink_backend, compile_ptx_functions): options = LinkerOptions(arch=ARCH) linker = Linker(*compile_ptx_functions, options=options) linked_code = linker.link("ptx") @@ -312,13 +329,8 @@ def test_linker_handle(compile_ptx_functions): assert int(handle) != 0 -# This test is not currently run in any CI job @pytest.mark.agent_authored(model="gpt-5") -@pytest.mark.skipif(not is_culink_backend, reason="driver backend regression test") -def test_driver_linker_lifetime_no_heap_corruption(compile_ptx_functions): - if not _can_load_generated_ptx(): - pytest.skip("PTX version too new for current driver") - +def test_driver_linker_lifetime_no_heap_corruption(culink_backend, compile_ptx_functions): linker = Linker(*compile_ptx_functions, options=LinkerOptions(arch=ARCH)) linker.link("cubin") linker.close() @@ -332,13 +344,8 @@ def test_driver_linker_lifetime_no_heap_corruption(compile_ptx_functions): linker.close() -# This test is not currently run in any CI job @pytest.mark.agent_authored(model="gpt-5") -@pytest.mark.skipif(not is_culink_backend, reason="driver backend regression test") -def test_driver_linker_preserves_error_log_after_close(init_cuda): - if not _can_load_generated_ptx(): - pytest.skip("PTX version too new for current driver") - +def test_driver_linker_preserves_error_log_after_close(culink_backend): bad_kernel = """ extern __device__ int Z(); __global__ void A() { int r = Z(); }