Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions cuda_core/tests/test_linker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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()
Expand All @@ -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(); }
Expand Down
Loading