Skip to content

Expose ptxas resource diagnostics from native finalization - #756

Merged
nihalpasham merged 6 commits into
NVIDIA:mainfrom
uurl:feat/ptxas-resource-report-708
Aug 10, 2026
Merged

nihalpasham merged 6 commits into
NVIDIA:mainfrom
uurl:feat/ptxas-resource-report-708

Conversation

@uurl

@uurl uurl commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Part of #708

Summary

Adds structured access to ptxas resource diagnostics produced during nvJitLink finalization.

This is the first part of #708. It provides the resource-reporting infrastructure needed for a later change to warn when kernels compiled with #[launch_bounds] spill registers.

Changes

  • preserve the nvJitLink informational log alongside linked cubin/PTX output;

  • request verbose nvJitLink / ptxas reporting when resource diagnostics are explicitly collected;

  • parse per-kernel:

    • register usage;
    • spill store bytes;
    • spill load bytes;
  • expose the parsed resource data through LinkReport;

  • keep diagnostic-only nvJitLink options separate from semantic link options so they do not affect provenance or artifact cache keys.

Existing finish, finish_ptx, and normal finalization APIs retain their previous behavior.

Testing

Added unit coverage for:

  • zero and non-zero spill reports;
  • multiple kernels in one log;
  • repeated resource sections;
  • unrelated informational output;
  • spill detection in either direction;
  • separation of diagnostic and semantic nvJitLink options.

Validated with:

cargo fmt --all
cargo check
cargo test
cargo clippy --all-targets -- -D warnings

All checks pass.

@uurl
uurl force-pushed the feat/ptxas-resource-report-708 branch 2 times, most recently from eb68a24 to 8a00bfc Compare August 9, 2026 10:41
@uurl
uurl force-pushed the feat/ptxas-resource-report-708 branch from 8a00bfc to f02d68c Compare August 9, 2026 10:51
…OPTION

Expose NvJitLinkError::is_unrecognized_option() so callers passing
optional, non-semantic options can detect an older nvJitLink that
predates them and retry without them. The result code is checked live
against the installed toolkit by a new ignored test that feeds
nvJitLinkCreate a bogus option.

Signed-off-by: Nihal Pasham <[email protected]>
…inated kernel names

Capture the 'N bytes stack frame' figure that sits on the same ptxas
'Function properties' line as the spill counters: local-memory frame
size is distinct from spill traffic and issue NVIDIA#707's census needs it.
Also unwrap kernel names in log shapes that terminate the line with a
colon after a quoted name ("Function properties for '_Z3fooPi':"),
which previously left a stray ': suffix on the parsed name.

Signed-off-by: Nihal Pasham <[email protected]>
…nized diagnostic options

Early 12.x nvJitLink versions reject options they do not know with
NVJITLINK_ERROR_UNRECOGNIZED_OPTION, which would fail the whole link
just because the caller asked for a best-effort report. When the
with-report link fails that way, retry once without the diagnostic
flags and return the linked image with an empty report. The retry runs
inside the same revalidated-tool-identity window as the first attempt,
and the plain link path is unaffected.

Signed-off-by: Nihal Pasham <[email protected]>
…ecting a resource report

Observed live on CUDA 13.3: a warm nvJitLink link serves the cubin from
its own JIT cache, skips ptxas entirely, and replays no info log, so
link_ltoir_with_report silently returned an empty resource report on
every repeat link. Add -no-cache to the cubin diagnostic option set so
the report always observes a real compile. The produced image bytes are
identical, and the flag stays out of artifact digests with the other
reporting options.

Signed-off-by: Nihal Pasham <[email protected]>
…t format

Add an ignored live test in the crate's live_tests style: build
legacy-dialect NVVM IR for a kernel that must spill (64 mutually
entangled live floats under a maxnreg=32 cap), compile it to LTOIR,
link with link_ltoir_with_report, and assert the info log is present
and parses to plausible register, stack-frame, and spill figures. The
generated IR anchors the kernel with @llvm.used exactly as cuda-oxide's
NVVM exporter does; without it nvJitLink dead-strips the kernel and the
log carries no resource lines.

On this host (CUDA 13.3, sm_86 target) the log reads:
  ptxas info    : Compiling entry function 'spill_kernel' for 'sm_86'
  ptxas info    : Function properties for spill_kernel
  ptxas         .     360 bytes stack frame, 476 bytes spill stores, 584 bytes spill loads
  ptxas info    : Used 32 registers, ...
and parses to registers=32, stack_frame=360, spills=476/584.

Signed-off-by: Nihal Pasham <[email protected]>
@nihalpasham nihalpasham added enhancement New feature or request build-related Build scripts, toolchain discovery, or compilation setup host-apis Host-side runtime APIs (cuda-host, cuda-core, cuda-async) labels Aug 10, 2026
@nihalpasham

Copy link
Copy Markdown
Collaborator

Gist: this is the right layer for a build-time resource report. XLA does the same thing, drive ptxas through the toolchain and read its diagnostics back; Triton's structured route reads driver attributes off a loaded module, which needs a GPU and a context a build host can't assume. The structured parse also captures the spill byte counts #708's warning text needs, which a substring check can't.

I pushed five commits on top:

  • typed detection of NVJITLINK_ERROR_UNRECOGNIZED_OPTION with graceful degradation to an empty report on older toolkits,
  • stack-frame-bytes parsing plus the colon-terminated kernel-name fix,
  • a JIT-cache bypass so report collection can't be skipped by a warm cache, and
  • an #[ignore]d live test that runs the real toolkit.

Verified here with CUDA 13.3:

  • the live test links a genuinely spilling kernel and
  • the parsed report matches the raw ptxas log line for line;
  • artifact digests provably exclude the diagnostic flags.

Merging.

Partially addresses #708, the warning itself lands with #757; related to #707.

Follow-up we'll file: the crate's pre-existing live test has been validating an empty module all along, its NVVM IR lacks
@llvm.used so LTO dead-strips the kernel.

@nihalpasham
nihalpasham merged commit 17f006e into NVIDIA:main Aug 10, 2026
36 checks passed
@uurl
uurl deleted the feat/ptxas-resource-report-708 branch August 10, 2026 06:24
nihalpasham added a commit to lucifer1004/cuda-oxide that referenced this pull request Aug 10, 2026
Resolves the overlap with NVIDIA#756's resource-diagnostics refactor: the
PTX route now threads input_type through main's run_link core, so the
unrecognized-option fallback and LinkReport plumbing cover both input
kinds, and run_link selects the LTOIR or PTX option set by input type.
The diagnostic-separation test asserts against both option sets.

Validated: crate + nvjitlink-sys unit tests, all live tests on RTX
5090 / CUDA 13.3 (including the PTX pipeline and the spilling-kernel
resource report), fmt, clippy -D warnings.

Signed-off-by: nihalpasham <[email protected]>
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 enhancement New feature or request 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.

2 participants