Skip to content

heliopause/cubin: prune empty trailing CUDA 13.2 callgraph sections - #70

Draft
FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-e-cuda132-callgraph-cubin
Draft

FujitsuPolycom wants to merge 1 commit into
mainfrom
jetson/pr-e-cuda132-callgraph-cubin

Conversation

@FujitsuPolycom

@FujitsuPolycom FujitsuPolycom commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Why

CUDA 13.2 (ptxas V13.2.86) appends three empty trailing subsection headers—(0, 0xffff_fffe) (CG_PROTO), (0, 0xffff_fffd) (CG_ICALL), and (0, 0xffff_fffc) (an undocumented third empty header observed in ptxas V13.2.86 output)—with zero payload entries to .nv.callgraph in multi-kernel cubins. heliopause/src/export/cubin.rs previously accepted only (0, 0xffff_ffff) and returned None on every other sentinel, falling back to strip_debug and disabling dead-kernel pruning on CUDA 13.2 multi-kernel cubins.

Empty trailing subsection headers contain zero .strtab byte offsets and zero symbol indices, so preserving them verbatim cannot corrupt string offsets or drop indirect call targets. Allowing them only as an empty trailing run—while continuing to fall back to strip_debug whenever any payload pair follows a trailing header, any (0, 0xffff_ffff) appears after a trailing header, or any unknown sentinel appears—restores CUDA 13.2 dead-kernel pruning safely.

What changed

Before this change, heliopause/src/export/cubin.rs duplicated .nv.callgraph pair parsing in compute_reachable_text and filter_callgraph and returned None on every non-direct sentinel, including empty trailing headers.

  • heliopause/src/export/cubin.rs:
    • Before: Both filter_callgraph and the .nv.callgraph edge loop in compute_reachable_text bailed out immediately whenever a == 0 && b != 0xffff_ffff.
    • After: Replaces both loops and is_direct_callgraph_sentinel with a single shared parse_callgraph(raw: &[u8]) -> Option<Vec<(u32, u32)>> (net -2 production LOC). Direct-call edges (a >= 1, b < 0xffff_fff0) and (0, 0xffff_ffff) are accepted before any trailing header; (0, 0xffff_fffe), (0, 0xffff_fffd), and (0, 0xffff_fffc) switch the parser into an empty-trailing-headers state where only further empty trailing headers are accepted and preserved verbatim. Any payload pair following a trailing header, any (0, 0xffff_ffff) after a trailing header, or any unrecognized sentinel returns None and falls back to strip_debug. Updates the adjacent comment in compute_reachable_text to match.
    • Unit tests (heliopause/src/export/cubin.rs):
      • Updates FixtureOptions from extra_callgraph_pair: Option<(u32, u32)> to extra_callgraph_pairs: Vec<(u32, u32)>.
      • Updates pruning_falls_back_on_callgraph_proto_icall_and_prototype_sections using in-bounds symbol indices (1, 2) after each trailing header (0xffff_fffe, 0xffff_fffd, 0xffff_fffc) so parse_callgraph's in_trailing guard is exercised directly rather than masked by compute_reachable_text's syms.len() check, alongside unknown sentinel (0, 0xffff_fffb) and out-of-order (0, 0xffff_fffe), (0, 0xffff_ffff).
      • Adds pruning_allows_empty_trailing_cuda132_callgraph_subsections covering both single-header [(0, 0xffff_fffe)] and 3-header [(0, 0xffff_fffe), (0, 0xffff_fffd), (0, 0xffff_fffc)] empty trailing sequences, verifying .text.dead_kernel removal, validate_pruned_cubin, retention of .text.live_kernel and .text.helper_fn, and exact .nv.callgraph output.
  • Compatibility & defaults: No core format, Protobuf, or runtime behavior change. Existing signed cores load identically; CUDA 12.x cubins without trailing headers produce byte-identical pruned output.

Claimed benefit and result

  • Measured on real CUDA 13.2 (ptxas V13.2.86) multi-kernel cubin (c518dd28b4caffe636cb3d2fbdd29a0c6e0f9c1a vs. base 7bbc6707792aa1cb8633794ee189b7592091cc45):
Target (ptxas V13.2.86, live_kernel + helper_fn + dead_kernel) Base 7bbc6707 strip_and_prune Candidate c518dd28 strip_and_prune .text.dead_kernel after prune
sm_87 (non-Mercury ELF cubin, 5,480 B stripped) 5,480 B (fallback) 3,112 B (-43.2%) Removed (passed validate_pruned_cubin)
sm_120 / sm_121 (Mercury .nv.merc.* cubin, 8,408 B stripped) 8,408 B (fallback) 8,408 B (unchanged .nv.merc.* fallback) Retained (pre-existing Mercury guard)
  • Expected full-model impact on CUDA 13.2 non-Mercury exports: Restores dead-kernel pruning across multi-kernel CUDA 13.2 cubins (such as PyTorch reduction and FlashInfer sampling modules), avoiding the unpruned cubin bloat and cuModuleLoadData memory overhead caused by falling back to strip_debug.

Supporting evidence and limitations

Tested on clean git archive c518dd28b4caffe636cb3d2fbdd29a0c6e0f9c1a atop NVIDIA/hyperflare-inference main (7bbc6707792aa1cb8633794ee189b7592091cc45):

  • Layer 1 — CPU crate & Python extension tests (passed on c518dd28b4caffe636cb3d2fbdd29a0c6e0f9c1a):
    • cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib: 235 passed; 0 failed; 6 ignored (all 11 export::cubin::tests::* passed).
    • cargo build --locked --release --manifest-path heliopause/Cargo.toml --features extension-module + CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_cubin.py tests/preparation/test_core_boundary.py -v: 10 passed (6/6 test_cubin.py, 4/4 test_core_boundary.py).
    • Fault-injection check: Temporarily relaxing (false, 1.., ..0xffff_fff0) to (_, 1.., ..0xffff_fff0) in parse_callgraph immediately failed pruning_falls_back_on_callgraph_proto_icall_and_prototype_sections (0 passed; 1 failed).
    • Real ptxas V13.2.86 cubin check: Assembled a multi-kernel PTX (live_kernel calling helper_fn plus unreachable dead_kernel) with ptxas V13.2.86, verified via readelf -x .nv.callgraph that it emitted (0, 0xffff_ffff), (0, 0xffff_fffe), (0, 0xffff_fffd), (0, 0xffff_fffc), and compared strip_and_prune + validate_pruned_cubin between base 7bbc6707 (5,480 B, .text.dead_kernel retained) and candidate c518dd28 (3,112 B, .text.dead_kernel removed on sm_87).
    • Layers 2 and 3 (scheduling simulator, TLA+, Kani) do not apply because this change is confined to export-time cubin ELF pruning in heliopause.
  • Limitations:
    • Non-empty CG_PROTO, CG_ICALL, and 0xffff_fffc subsections (containing .strtab-offset payload pairs) continue to fall back safely to strip_debug.
    • Mercury cubins (.nv.merc.* on sm_120/sm_121) continue to fall back to strip_debug under the pre-existing Mercury guard.
    • Full-model CUDA 13.2 ignition export, cuModuleLoadData memory measurement, and flare run serving with this Rust binary have not yet been executed on c518dd28b4caffe636cb3d2fbdd29a0c6e0f9c1a.

Discord: Dooner

CUDA 13.2 (ptxas V13.2.86) appends three empty trailing subsection
headers ((0, 0xffff_fffe) CG_PROTO, (0, 0xffff_fffd) CG_ICALL, and
(0, 0xffff_fffc), an undocumented third empty header) with zero payload
entries to .nv.callgraph in multi-kernel cubins. heliopause/src/export/cubin.rs
previously returned None on any sentinel other than (0, 0xffff_ffff),
disabling dead-kernel pruning on CUDA 13.2 multi-kernel cubins.

- heliopause/src/export/cubin.rs:
  - Before: compute_reachable_text and filter_callgraph duplicated
    .nv.callgraph pair loops and bailed out on any non-(0, 0xffff_ffff)
    sentinel.
  - After: introduces a single parse_callgraph(raw) -> Option<Vec<(u32, u32)>>
    shared by both passes (removing duplicated loops and helper functions
    for a net reduction in production LOC). Empty trailing (0, 0xffff_fffe),
    (0, 0xffff_fffd), and (0, 0xffff_fffc) headers are accepted and
    preserved verbatim; any payload pair after a trailing header, any
    direct sentinel after a trailing header, or any unknown sentinel still
    returns None and falls back to strip_debug.
  - Tests: updates pruning_falls_back_on_callgraph_proto_icall_and_prototype_sections
    using in-bounds symbol indices (1, 2) after trailing sentinels so
    parse_callgraph's in_trailing guard is directly exercised, and adds
    pruning_allows_empty_trailing_cuda132_callgraph_subsections covering
    single and 3-header empty trailing sequences.
- Compatibility: zero change for CUDA 12.x cubins or existing signed cores.

Result:
- Restores dead-kernel pruning on real CUDA 13.2 (ptxas V13.2.86)
  multi-kernel cubins while failing closed on non-empty trailing sections.

Evidence:
- Verified on clean git archive via cargo test --locked --release
  --manifest-path heliopause/Cargo.toml --lib,
  CUDA_VISIBLE_DEVICES="" pytest tests/preparation/test_cubin.py
  tests/preparation/test_core_boundary.py, and end-to-end pruning of real
  ptxas V13.2.86 multi-kernel cubins (sm_87 and sm_120) through the
  compiled flare_heliopause extension.
- Limitations: non-empty CG_PROTO/CG_ICALL/0xffff_fffc subsections still
  fall back to strip_debug; full-model CUDA 13.2 export and flare run
  verification with this Rust binary remains unrun.

Discord: Dooner

Design-Signed-Off-By: Antigravity (Gemini 4 Neon); design-review=2e5b
Signed-off-by: Dooner <dooner@users.noreply.github.com>
@FujitsuPolycom
FujitsuPolycom force-pushed the jetson/pr-e-cuda132-callgraph-cubin branch from d0a70b7 to c518dd2 Compare December 4, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants