Skip to content

test(cuda.core): run the driver (cuLink) linker tests by forcing the backend - #3649

Merged
mdboom merged 1 commit into
NVIDIA:mainfrom
mdboom:issue3572
Nov 30, 2026
Merged

mdboom merged 1 commit into
NVIDIA:mainfrom
mdboom:issue3572

Conversation

@mdboom

@mdboom mdboom commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Closes #3572. Part of #2077.

Summary

Three driver-linker (cuLink) tests ran only when cuda.core falls back to the driver backend, which needs a missing or pre-12.3 nvJitLink. Every CI row has a current nvJitLink, so the driver backend, a supported fallback, was never tested:

  • test_linker_link_ptx_culink
  • test_driver_linker_lifetime_no_heap_corruption
  • test_driver_linker_preserves_error_log_after_close

A new culink_backend fixture forces the driver backend for one test:

@pytest.fixture
def culink_backend(monkeypatch, init_cuda):
    # 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)
    monkeypatch.setattr(_linker, "_inited", False)            # rebuild the driver input-type table
    monkeypatch.setattr(_linker, "_driver_input_types", None)
    assert Linker.which_backend() == "driver"
  • Only backend selection is faked. The tests still call the real cuLink* APIs.
  • monkeypatch restores the module state on teardown. Each Linker records its backend at construction, so nothing created under the other backend is affected.
  • The PTX-version skip is now in one place. Two tests had it; test_linker_link_ptx_culink did not, and would have failed instead of skipping on CTK 13.5 rows.
  • The "not currently run in any CI job" markers are removed.

Evidence

CI coverage: the three tests should now run in the 35 CI configurations where the existing PTX-loading tests (for example test_object_code_load_ptx) pass on main. Those are every CTK 12.9.1 and 13.0.2 row: Linux x86-64 and aarch64, WSL, and Windows, on T4, V100, L4, A100, H100, RTX 4090 and RTX PRO 6000. On CTK 13.5 rows, NVRTC 13.5 PTX is too new for the installed driver, so they skip until #3579 is fixed.

Locally: with the CUDA 13.0 toolkit's NVRTC (matching the CTK 13.0.2 rows), all three pass on the forced cuLink backend. The whole file passes in random order (125 passed, 7 skipped), so the backend state does not leak between tests.

Confirming in CI: in this PR's CI run, the CTK 12.9.1 and 13.0.2 cuda.core jobs should report all three tests PASSED, where main reports them SKIPPED. For example:

gh run view <CI run id> --repo NVIDIA/cuda-python --log | grep -E "test_linker_link_ptx_culink|test_driver_linker_(lifetime_no_heap_corruption|preserves_error_log_after_close)"

Merge Danger

Door: two-way. Test-only change.

Blast Radius: three tests in cuda_core/tests/test_linker.py. They now exercise the cuLink path on CTK 12.9/13.0 rows, so a real driver-backend regression would fail there, which is the point.

Reviewers: please feel free to push commits directly to this PR to improve it.

🤖 Generated with Claude Code

…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 NVIDIA#3572.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdboom mdboom added this to the cuda.core 1.4.0 milestone Nov 30, 2026
@mdboom mdboom added test Improvements or additions to tests cuda.core Everything related to the cuda.core module labels Nov 30, 2026
@mdboom mdboom self-assigned this Nov 30, 2026
@coderabbitai

coderabbitai Bot commented Nov 30, 2026

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Tests
    • Expanded coverage for CUDA PTX linking and driver lifetime and error-log behavior when the CUDA driver can load generated PTX.
    • Removed redundant PTX-version checks from the affected tests.

The linker tests now use a fixture to select the driver backend. The fixture skips when the driver cannot load generated PTX. Three cuLink tests use the fixture instead of requiring cuLink to be the selected backend.

Changes: Driver cuLink test coverage

Layer / File(s) Summary
Driver backend fixture and test use
cuda_core/tests/test_linker.py
The new fixture selects and verifies the driver backend, supplies the real driver module, and resets cached driver input-type state. The PTX-linking, lifetime, and error-log tests use the fixture. The lifetime and error-log tests remove their duplicate PTX-version checks.

Assessment against linked issues

Objective Addressed Explanation
Add a fixture that forces driver-backend selection and use it for the three cuLink tests [#3572] ✅
Restore the backend globals and cached state after each test, and check that state does not leak across backend switches [#3572] ❓ The supplied summaries do not specify whether the fixture restores these values or checks for leaked Linker state.

Possibly related issues

  • NVIDIA/cuda-python#3579 — The fixture skips when the driver cannot load generated PTX, but the supplied summary does not show a fix for the PTX compatibility constraint.

Suggested reviewers: isvoid, jpascucci-nv

Change: Other

Merge Risk: Minimal · up to 92f45

This PR changes test setup so three cuLink tests use the driver backend and skip when the driver cannot load the generated PTX. Production behavior is unchanged, and no concrete merge-blocking risk was found.

Security architecture risk: Minimal · up to 92f45

The change improves coverage of an existing fallback without changing how applications select or use the linker.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 1c9ed66 and 92f4538.

Files selected for processing: 1

  • cuda_core/tests/test_linker.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 6 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

@jpascucci-nv jpascucci-nv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sol 6.1 high finds no actionable findings. LGTM.

@mdboom
mdboom enabled auto-merge (squash) November 30, 2026 16:58
@mdboom
mdboom merged commit df1f70d into NVIDIA:main Nov 30, 2026
222 of 225 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cuda.core Everything related to the cuda.core module test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(cuda.core): run the driver (cuLink) linker tests by forcing the backend in a fixture

2 participants