Skip to content

fix(finalizer): reject links that drop expected kernels - #1167

Closed
uurl wants to merge 1 commit into
NVIDIA:mainfrom
uurl:fix/finalizer-expected-kernel-retention
Closed

uurl wants to merge 1 commit into
NVIDIA:mainfrom
uurl:fix/finalizer-expected-kernel-retention

Conversation

@uurl

@uurl uurl commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Closes #1166
Part of #1071.

Summary

This adds a final-link safety invariant for expected CUDA kernels.

A successful nvJitLink call is no longer considered sufficient when the
caller knows which kernel entry points must survive. The finalizer now roots
those kernels during linking and verifies that they are present in the emitted
PTX or cubin.

What changed

  • Added expected-kernel-aware finalization APIs while preserving the existing
    public entry points.
  • Passed expected kernel names to nvJitLink as repeated
    -kernels-used=<name> options.
  • Canonicalized the expected-kernel set for deterministic linker options and
    artifact digests.
  • Included expected kernels in LTOIR finalization artifact identity.
  • Added structural PTX entry-point inventory rather than substring matching.
  • Added cubin kernel inventory by inspecting ELF symbol tables and CUDA entry
    symbols.
  • Added explicit errors for:
    • invalid expected kernel names,
    • unavailable final kernel inventory,
    • missing expected kernels.
  • Propagated known kernel metadata through:
    • build-time NVVM IR/LTOIR materialization,
    • embedded deferred NVVM IR/LTOIR finalization.
  • Kept existing raw/file-backed finalization APIs compatible when no expected
    kernel metadata is available.

The enforced invariant is:

nvJitLink success + missing expected kernel = error

Validation

The following pass locally:

cargo fmt --all -- --check
cargo test -p cuda-artifact-finalizer --all-targets
cargo test -p cuda-host --all-targets
cargo clippy -p cuda-artifact-finalizer --all-targets -- -D warnings
cargo clippy -p cuda-host --all-targets -- -D warnings

The CUDA Toolkit live regressions also pass:

live_tests::live_pipeline_accepts_toolkit_cubins_and_emits_ptx_for_both_fma_policies
live_tests::live_link_report_parses_ptxas_resource_usage_for_a_spilling_kernel

And the broader validation passes:

cargo test --workspace --all-targets
cargo clippy --workspace --all-targets -- -D warnings

rustc-codegen-cuda was also validated independently with formatting, unit
tests, and Clippy.

Scope

This is intentionally limited to the final-link safety portion of #1071.

It does not add libcudadevrt discovery/linking and does not implement the
public CUDA Graph API. Those remain separate follow-up changes.

@nihalpasham nihalpasham added declined PR intentionally not merged (closed without merging) build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX) host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Aug 24, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Closing this PR because expected-kernel validation is not consistently derived or applied.

  • The implementation hardcodes wire tag 1 instead of using ArtifactEntryKind as the shared source of truth.
  • The cargo-oxide compatibility finalization path remains unguarded.
  • There is no real negative nvJitLink regression showing a kernel dropped before the fix and preserved afterward.

The underlying benefit is clear, but this needs cross-path design work rather than a small maintainer correction. A replacement should follow the existing abstractions and evidence requirements in the Discord announcement.

vyncint added a commit to vyncint/cuda-oxide that referenced this pull request Aug 24, 2026
… from CI

Follow-up to the same review, from re-reading the twenty PRs closed on
2026-08-24. NVIDIA#1167 was closed partly because "the cargo-oxide compatibility
finalization path remains unguarded" and NVIDIA#1169 because its instruction table
"omits" families -- neither for an observed failure, both for a path the change
did not enumerate. This guard had one of those.

`workflow_coverage` read literal `bash scripts/check-*.sh` commands out of a
`run:` script. A step that runs `just check-guards` executes every guard in that
recipe, and the walk saw only the command `just`. So a workflow written that way
would have every one of its guards reported as "executed by `just check` but by
no pull-request workflow" -- a false failure, blocking CI, with the verdict
exactly backwards.

Nothing in `.github/workflows/` invokes `just` today, which is why the corpus
did not show it. That is the point: the guard's job is to be right about the
wiring, not about this week's wiring.

A `just <recipe>` command is now resolved through the Justfile recipe graph the
script already parses -- the authoritative list in that case, rather than a
second one derived here -- and the guards that recipe reaches are credited to
that step. The `-` prefix still does not enforce inside a recipe reached that
way, and the recipe named on the command line is its own entry point, so
reachability from `check` does not apply to it.

Three fixtures, each failing before the change: a step running
`just check-guards` credits a guard nested one dependency deep; the same step
credits nothing when no Justfile is supplied; and a `-` prefixed line inside the
recipe `just` runs is still not counted.

`recipes_reachable_from` and `recipe_guards` are now shared by both halves
rather than the walk existing twice.

Unmutated: all fourteen guards pass, the nine end-to-end defeats still fail, the
subset reader still agrees with PyYAML on all 11 workflows, 0.02s.

Signed-off-by: Vyncint Ng <[email protected]>
@uurl
uurl deleted the fix/finalizer-expected-kernel-retention branch August 31, 2026 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build-related Build scripts, toolchain discovery, or compilation setup codegen Device code-generation pipeline (Rust MIR to IR to PTX) declined PR intentionally not merged (closed without merging) host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

finalizer: reject successful links that drop expected kernels

2 participants