PR #652: heliopause: prune unreferenced kernels from exported CUDA ELF64 cubins

Raw Markdown for agents: https://autobot.eidonix.com/api/v1/cases/c8ad0a30-d711-4d8f-af12-ba15786ef9a4

Opened by a workflow run, Dec 1, 2026 1:15 AM EST. decide malicious: all_clear (100%): No malicious content found

explore

Author: lukealonso (COLLABORATOR, de facto owner of heliopause/src and the only prior author of cubin.rs; Discord: lukealonso) Motivation: Serving loads every exported cubin whole via cuModuleLoadData, so the thousands of kernels compiled into PyTorch/FlashInfer/CUTLASS modules — over 95% of them never launched by a captured graph — still cost RAM, load time and artifact size. Since export already knows which CUfunctions each graph captured, this PR drops the rest from the ELF. Scale: +937 / −5 in 2 files Proposal:

Full report · Notes

Value Proposition

Value Proposition — PR #652 (heliopause: prune unreferenced kernels from exported CUDA ELF64 cubins)

1. Charter alignment — aligned, and in the right layer. The work lives in the export path (heliopause/src/export/cubin.rs, capture.rs), not in Helios scheduling/requests: no wire-format, protobuf, runtime, CLI, dependency or Cargo change, no per-model branches, no flags. That matches "keep the runtime small and model-agnostic" and "smallest footprint in shared code." The symptom is real in-repo: every module cubin is loaded whole via driver.module_load (helios/src/runtime_core/mod.rs:790-799), with ambient evidence in #394 (32 SM120 cubins, 3,422,080 bytes) and #479 (9,488 kernels / 436.17 MiB cubin for 314 graphs). The charter's merge bar explicitly includes "a measured performance/memory issue," and the description follows the required four-part format. Author @lukealonso is a priority contributor and the de facto owner of this area (62 commits in heliopause/src over 180 days, sole prior toucher of cubin.rs), which carries extra weight per #229.

2. Novelty & status — genuinely additive, neither obsolete nor superseded. No merged commit fixes this; items_touching(heliopause/src/export/cubin.rs) returns nothing else in 180 days, and only this PR adds strip_and_prune. #646/#647 (same author, merged) are the base it builds on. #642 (open) attacks the same goal one layer up in Python with unrelated files; #394 touches the same export staging but for fsync avoidance. Nothing supersedes it.

3. Value vs. cost — real value, but the evidence and safety envelope are incomplete. Benefit is concentrated where it matters most (memory-constrained devices: −287 MiB pre-cache, KV 15,488→32,768 tokens on Jetson Orin Nano 8 GB — a step-change, not a marginal one). Cost is one self-contained ~930-line ELF rewriter in export-only code, reviewed once by an area owner. Concerns are concrete, not stylistic: all numbers are unattached to any script/log/artifact; no CI lane runs the new tests (manual-only); all live validation is SM87, while the CUTLASS-heavy modules targeted are precisely the unverified SM120/121 case (charter line 21); the stated 35-of-123 prune rate sits alongside two silent, undocumented all-or-nothing fallbacks (cubin.rs:434-436, 452-457); p_align is hardcoded to 8 (cubin.rs:883); nothing loads the rewritten image through the driver at export time, so failures surface at serving load; and docs/core-format-design.md:380-381 / runtime-core-design.md:76 now contradict the code.

Verdict: Worth it with changes. Merge after (a) at least one SM120/121 export+serve run, (b) a reproducer artifact for the headline numbers and an explicit explanation of the 88 unpruned modules, (c) the cubin tests wired into a CI lane, (d) export-time driver validation of the pruned image and a documented rationale for p_align, and (e) the two docs updated.

Full report Decide Value: yes (100%): This change is worth reviewing: it provides value to the project in line with its charter.

Classify intake

Selected: triage:review, performance, area:memory, area:preparation

Threshold: 65%

Triage

Priority

Type

Area

Model

Apply Labels (Intake)

Applied: +triage:review, +performance, +area:memory, +area:preparation

Subtraction and simplicity

Subtraction/Simplicity/Conventions review of PR #652 (heliopause/src/export/cubin.rs +927/−1, capture.rs +10/−4). The diff adds no speculative machinery — no flag, config, env var, trait or Python surface — and the passthrough branches are justified by real layout variance, so AGENTS.md:188-193 is not violated. What is removable is code left behind inside the implementation:

  1. Duplicated debug-section predicate (high). The new is_debug_section (cubin.rs:254-259) is byte-identical to the copy still inlined in strip_debug (cubin.rs:187-195): 5 lines to delete.
  2. One 530-line function with a triplicated predicate (high). try_prune_unused_kernels (cubin.rs:372-904) fuses gate, reachability, cascade, table rebuild and ELF emission; the same five-condition .text.* callee test appears at cubin.rs:512-517, 558-568 and 588-600. Split along its own comment headers plus one callee_text helper.
  3. EIATTR record decoder duplicated with drifting failure policy (high). cubin.rs:305-311 (return None) and :578-587 (break) decode the same fmt→length framing; one nvinfo() record iterator replaces both.
  4. Three small ones (medium). capture.rs:3282-3287 rescans output.index.ranks[0].functions when the local functions vec built at capture.rs:3134 already holds the same data; align_up (cubin.rs:282-289) reinvents usize::next_multiple_of, already used for padding at archive.rs:209/io.rs:252 (not opened); the discarded Elf::parse(&pruned)? at cubin.rs:365 validates only its own output.

Explicitly not this lens: p_align == 8 hardcode and zero vaddr/paddr (correctness), docs drift at docs/core-format-design.md:380-381/docs/runtime-core-design.md:76 (documentation). No formatting/lint suggestions — the repo runs neither lane.

Open: whether the missing prune on 88 of 123 modules is the silent unmatched-name fallback (cubin.rs:452-457) or intended passthrough, and whether the keep-set duplication is deliberate coupling to the exported index.

Full report · Notes

Correctness and contracts

Review of PR #652 (heliopause: prune unreferenced kernels from exported CUDA ELF64 cubins, +937/−5) through the correctness/contracts/system-consequences lens. Six findings: four Major, two Minor.

Major: (1) the rewritten ELF is internally inconsistent for any cubin carrying a non-SHT_SYMTAB symbol table or a section whose sh_info the code does not recognise — those carry pre-compaction section indices that are never remapped (cubin.rs:145, 261-280, 426-431, 694-722, 849-856), and the codebase itself knows about kind 0x70000085. (2) Two all-or-nothing passthroughs disable pruning for an entire module with no log or counter — one captured symbol name without a matching .text. section (cubin.rs:451-457) or one module with no surplus .text sections (cubin.rs:434-436) — which likely explains the description's 35-of-123 pruned modules and is undocumented in the PR text. (3) The only validation of the output is a bounds-only Elf::parse (cubin.rs:365); the first real load is cuModuleLoadData on the serving host (helios/src/runtime_core/mod.rs:790-798), and no CI lane runs the heliopause tests, so all five cubin tests are manual-only. (4) All live evidence is SM87/AGX Orin while the change is unconditional (capture.rs:3288) for the charter's SM103/SM120/SM121 matrix — exactly the CUTLASS-heavy cubins the change targets.

Minor: design docs now contradict the code (docs/core-format-design.md:380-381 still promises symbol names are preserved; docs/runtime-core-design.md:76 still says debug stripping only), and per-module export-time peak memory roughly triples with no cost claim.

Verified sound: standalone/KV-codec passthrough, the switch to global_symbols(&exported), byte accounting, and the absence of any wire/proto/runtime contract change; no concurrency hazard in the module loop.

Open: whether the unpruned modules are intended passthrough or the silent fallback; whether p_align=8 reproduces NVIDIA's SM120/121 layout; whether a driver-load check at export time is feasible.

Full report · Notes

Final review

Recommendation: Changes Requested

This PR solves a real, well-scoped memory and load-time problem in the right layer (export-only, zero Helios runtime/wire/CLI changes), and the core design—preserving .symtab indices while compacting dead .text.* sections and companion metadata, and re-enumerating globals from &exported—is sound. However, direct verification of heliopause/src/export/cubin.rs at 9ea2491 uncovered two concrete ELF64/CUDA binary-corruption paths on valid cubins (.nv.merc.*/Mercury symbol tables and unrecognized non-zero sh_info, plus .nv.callgraph indirect-call/prototype subsections), an unsafe break in the EIATTR_EXTERNS walk, and zero CI or SM103/SM120/SM121 verification for an unconditional export-path binary rewriter. All technical blockers can be closed cleanly with small fail-safe passthrough guards and targeted unit tests, plus at least one SM120/SM121 export+serve validation pass.

Merge Risk

Level: Medium

Walkthrough

Pre-merge Checks

Blockers

  1. Mercury (.nv.merc.* / 0x70000085) sections and unrecognized non-zero sh_info silently corrupt pruned cubins (heliopause/src/export/cubin.rs:145, :412-432, :674-734, :790-792, :849-856).

    • Verified behavior & impact: The file already recognizes CUDA Mercury symbol tables (s.kind == 0x70000085) at cubin.rs:145, and tests/preparation/test_cubin.py:14,35 explicitly models .nv.merc.symtab (kind = 0x70000085, flags = 0x10000000, sh_link = .strtab). However, try_prune_unused_kernels's layout gate (cubin.rs:412-432) only checks SHT_SYMTAB (2). When a cubin contains .nv.merc.symtab (standard on Blackwell SM100/SM103/SM120/SM121 toolchains), pruning compacts .strtab (cubin.rs:674-734) and renumbers sections (cubin.rs:652-659), while copying .nv.merc.symtab verbatim (cubin.rs:790-792) and remapping its sh_link (cubin.rs:841-848). Every entry in .nv.merc.symtab is left with stale pre-compaction st_shndx (pointing to wrong sections or past e_shnum) and stale st_name offsets into the compacted .strtab. Similarly, cubin.rs:849-856 copies s.info raw for any surviving section not matched by sh_info_is_section (cubin.rs:261-280), leaving stale section indices on any unrecognized companion section that omits SHF_INFO_LINK.
    • Fix: In the layout gate (cubin.rs:412-432), bail to Ok(None) (passthrough) if any section has s.kind == 0x7000_0085 (or Mercury section kinds 0x7000_0080..=0x7000_00ff / SHF_CUDA_MERCURY 0x1000_0000 / name prefix .nv.merc). In the section-header emitter (cubin.rs:849-856), if s.info != 0 on a surviving section that is neither SHT_SYMTAB, .text.*, nor recognized by sh_info_is_section, return Ok(None) instead of passing s.info through raw. Add unit tests covering both cases.
  2. .nv.callgraph prototype and indirect-call subsections (0xfffffffe / 0xfffffffd) leave dangling .strtab offsets and mis-filter entries (heliopause/src/export/cubin.rs:330-347, :522-537, :674-722).

    • Verified behavior & impact: NVIDIA's .nv.callgraph groups 8-byte (a, b) records into subsections headed by (0, marker) sentinels: (0, 0xffff_ffff) introduces (caller_sym, callee_sym) pairs, whereas (0, 0xffff_fffe) (CG_PROTO) and (0, 0xffff_fffd) (CG_ICALL) introduce (sym_idx, strtab_offset) pairs where b is a byte offset into .strtab, not a symbol index. Currently: (a) .strtab compaction (cubin.rs:674-722) retains only strings referenced by surviving .symtab st_name, deleting prototype strings and shifting offsets, leaving dangling/out-of-bounds .strtab offsets in .nv.callgraph; (b) filter_callgraph (cubin.rs:340) checks dead_syms.contains(&(b as usize)), treating a .strtab byte offset as a symbol index and dropping live prototype/indirect-call entries whenever the offset numerically collides with a dead symbol index; and (c) reachability (cubin.rs:532) does not follow indirect-call prototype matches.
    • Fix: In .nv.callgraph parsing (cubin.rs:522-537) and filter_callgraph (cubin.rs:330-347), bail to Ok(None) (passthrough) whenever a non-direct-call sentinel appears (any (a, b) with a == 0 && b != 0xffff_ffff or b >= 0xffff_fff0 && !(a == 0 && b == 0xffff_ffff)), or explicitly parse the subsections and preserve/remap referenced .strtab prototype strings. Add a unit test covering (0, 0xffff_fffe) / (0, 0xffff_fffd) passthrough.

Should Fix

  1. Unsafe break on unrecognized/malformed .nv.info.<fn> records in EIATTR_EXTERNS walk (heliopause/src/export/cubin.rs:577-587).

    • While filter_global_nvinfo (cubin.rs:301-315) returns None (safe passthrough) on unknown fmt or out-of-bounds rec_len, the per-function .nv.info.<fn> reachability loop (cubin.rs:580-587) uses break. Truncating the walk early can miss a subsequent EIATTR_EXTERNS (0x0f) record and drop a live callee.
    • Fix: Extract a single EIATTR record-framing parser/iterator shared by filter_global_nvinfo and the EIATTR_EXTERNS walk, and return Ok(None) on any unknown fmt or truncated record.
  2. rx_alloc SHT_NOBITS handling and PT_LOAD segment alignment (heliopause/src/export/cubin.rs:779-783, :801-832, :883).

    • If any section in rx_alloc has s.kind == SHT_NOBITS, place (cubin.rs:779-783) does not advance out.len(), so rx_end - rx_start (cubin.rs:806, :887) omits its size from p_memsz and allows subsequent sections to overlap its sh_offset.
    • rx_start (cubin.rs:801) and rw_start (cubin.rs:813) are only padded to 8 bytes and every PT_LOAD hardcodes p_align = 8 (cubin.rs:883), even when sections inside the segment require higher alignment (e.g., .text.* sh_align = 128 at cubin.rs:1164, or aligned .nv.global SHT_NOBITS). As a result, (sh_offset - p_offset) % sh_align is not guaranteed to be zero, and an SHT_NOBITS-only rw_alloc section with sh_align > 8 gets its sh_offset pushed into the section-header table range (cubin.rs:825-826).
    • Fix: Return Ok(None) if any rx_alloc section is SHT_NOBITS. Pad rx_start and rw_start to the max sh_align of their respective sections (at least 8) and emit that alignment in p_align (or preserve input p_align).
  3. Charter-target validation, post-prune cross-reference self-check, and CI wiring (heliopause/src/export/cubin.rs:365, .github/workflows/).

    • All live validation was run on SM87; SM103/SM120/SM121 were not exercised (docs/design-review.md:62, :106-115), and no CI workflow compiles or tests heliopause (.github/workflows/native-serving.yml (not opened), python-cpu.yml).
    • Fix: (a) Run at least one SM120 or SM121 export + flare run on a multi-kernel CUTLASS/FlashInfer workload before merge and attach the pruned/skipped module breakdown; (b) wire cargo test --locked --release --manifest-path heliopause/Cargo.toml --lib into CI; and (c) strengthen the post-prune validation at cubin.rs:365 beyond header-only Elf::parse to verify all surviving sh_link, sh_info, st_shndx, st_name, and PT_LOAD bounds.

Subtract / Simplify

  1. Deduplicate is_debug_section and reuse SHT_*/SHF_* constants (heliopause/src/export/cubin.rs:189-193, :254-259, :113, :126, :145, :200, :208, :224).
    • strip_debug (cubin.rs:189-193) retains an exact 5-line inline copy of the newly added is_debug_section helper (cubin.rs:254-259). Call is_debug_section(name) in strip_debug to delete the duplicate policy, and replace raw section-type/flag literals (2, 3, 8, & 2) in the same file with the constants just added at cubin.rs:14-23.
  2. Delete align_up in favor of usize::next_multiple_of (heliopause/src/export/cubin.rs:282-289).
    • heliopause/Cargo.toml:6 pins rust-version = "1.88", and the crate already uses next_multiple_of (heliopause/src/export/archive.rs:209, heliopause/src/export/io.rs:252 (not opened), :647). Replace align_up(value, align) with value.next_multiple_of(align.max(1)) at its three call sites (cubin.rs:292, :780, :825).
  3. Deduplicate the triplicated .text.* callee check and split try_prune_unused_kernels (heliopause/src/export/cubin.rs:372-904, :513-516, :560-567, :592-599).
    • Extract a small callee_text_section(syms, sec_names, sym_idx) -> Option<usize> helper used across the relocation, .nv.callgraph, and EIATTR_EXTERNS arms (dropping the redundant !keep_text.contains(&shx) checks at :564 and :596 since keep_text.insert(shx) deduplicates at :607), and split the 530-line body along its existing comment boundaries (layout gate, reachability, emit).

Nits

Dropped on verification

Full report Decision to Test: no (100%): Testing will not add significant value as the code stands today. The code is either not yet ready to merge, or adequate testing has already been done to validate the contents of the code, or the available hardware is not suitable to test with.

Classify triage

Selected: triage:review

Threshold: 65%

Triage

Apply labels

No label changes