Skip to content

Every shipped kernel carries an LLVM .local frame, unattributed and unwatched #166

Open

Description

@feitreim

The first run of the .local census (regcount's fifth table, branch regcount-local-depot, commit 956b88a) shipped as a hard gate on the examples crate plus GATED_KERNELS — and failed on every row. Every kernel either crate ships carries an LLVM local-memory frame in its PTX:

kernel frame st.local / ld.local
gemm_cg2_staged_x8x4 (both crates), every gemm_sol_* / gemm_ws_* rung 256 B 64 / 16
gemm_cg2 528 B 419 / 139
flash_forward 1824 B 1362 / 679
groupnorm_tile ~1540 B 1464 / 608

Why nobody saw it

The frame is LLVM's, so it lives in the PTX text and in ptxas' stack column — with zero spill stores/loads. Every audit including #152 read the spill columns, which count only ptxas' own decisions. Disjoint substrates: a ptxas spill happens after PTX and never appears in it, and an LLVM frame is not a ptxas spill. The stack numbers were printed on every regcount run and read by nobody.

What it probably is, and what that claim rests on

The census was built against the depot a value-select among per-stage shared symbols lowers to (cuda-learning kernels/barrier_bench: 710 vs 857 TFLOP/s at 8192³, otherwise-identical kernels). That is not what this is. The rings came out clean by construction; the signature here — many scalar st.local, about a quarter as many loads, so an array built element-wise and read back .v4 — shows up in the pure register-tile probes too (band_roundtrip 272/144, fragment_map_32x128 272/144, store_ring_depth_1 74/42), which points at a dynamically-indexed fragment array in reg.rs that LLVM could not SROA. That is a guess and is marked as one in the census' section comment.

The 64/16 shape is byte-identical across the whole staged-x8x4 family and every gemm_sol_* port — one shared code path, so one fix likely clears most of the shipped set.

What is unestablished

Exit condition

The census reports today because failing on a number nobody understands gates nothing. When the shipped set reads zero, flip the report back to a raise — the arming condition is written where the census prints.

Activity

  1. feitreim commented on Aug 3, 2026

    @feitreim
    OwnerAuthor

    Two independent data points from the oxide-train kernel-rewrite wave (2026-08-03), both this issue's phenomenon surfacing downstream:

    • oxide-train#73's losing families: the RMSNorm and softmax tile ports both fell off a cliff past a 32-column register chunk — 0.39–0.16x of their flat baselines — and the mechanism was the .local depot, not register count. Reproducible kernels + gates live on the feat/issue-70-tile-probes branch there.
    • oxide-train#74 (unified flash forward): holding a whole [32,64] score band as a value beside the 128-register accumulator produced a 1328 B frame with 3546 ld/st.local (the tcgen05.ld block storing what it had just read) and cost 19.9%; chunking register-op width to 16 columns removed it entirely, parity identical.

    Together they sharpen this issue's ask: the depot appears when the width a register op works at crosses a threshold near 32 fp32 columns, and the regcount census (#167) would have caught both before a kernel paid for them.

  2. feitreim commented on Aug 3, 2026

    @feitreim
    OwnerAuthor

    Attributed and two-thirds fixed in #180. The frames are the register tiles themselves: a storage walk that stops unrolling (LLVM's budget, ~32 fp32 columns) leaves a dynamic GEP, SROA cannot split the aggregate, and the tile is homed to .local — one rolled reader is enough to home a tile whose builder unrolled fine. The working fix is cuda-oxide's __unroll_config::<0>() marker plus an inline-const bound (the trip-count analysis reads M / 16 as a runtime division otherwise). Movers (ldst/tmem/global) are done: staged family, gemm_sol rungs and gemm_cg2 read zero, and bench --case gemm moved 0.939 → 0.978 of cuBLASLt at 8192³. The remainder is the reg.rs map walks on flash_forward/groupnorm_tile, and blanket-unrolling those was measured at 255 regs + 208/208 spills on flash_forward — worse than the depot. Arming the gate waits on a per-kernel answer there.

  3. feitreim commented on Aug 3, 2026

    @feitreim
    OwnerAuthor

    groupnorm_tile resolved in #181, and it sharpens what a map-walk frame is: not a rolled loop to unroll but a band that does not fit. The kernel held its whole [32, 128] band — 128 fp32 a thread against launch_bounds' 168-register cap — and the fix is the streaming layernorm_rows already proved, once the kernel had a launcher and reference to make a rewrite checkable (it passed its first-ever check as filed, worst absolute error 7.76e-3 = half a bf16 ulp at the seed's largest outputs). Measured on B200: 168 regs / 1536 B frame / 3 blocks/SM / 594 GB/s → 48 / 0 / 6 / 5996 GB/s, a factor of 10.1 at bit-identical error.

    The census now reads 1 of 12 shipped kernels carry local memory: flash_forward, whose 1824 B is the algorithm's own live state (a [32, 128] fp32 accumulator across the whole key loop). Its launcher + CPU reference (#85) is in flight; only past that check can any register-side change there be honestly measured. The gate arms when that last kernel reads zero — or when its frame is ruled the right cost and the census learns to say so.

  4. feitreim commented on Aug 4, 2026

    @feitreim
    OwnerAuthor

    Downstream attribution: oxide-train's three flash kernels, before and after the c648c67 pin. Posting here rather than opening a duplicate — no ferro change is asked for, but the numbers close out the flash half of this issue's census and confirm #181's category from a second codebase.

    The census, post-#180

    modal run modal_app.py::main --kernel flash-attn --ptx, sm_100a, ferro c648c67. Depots in flash.ptx:

    kernel LLVM depot ptxas regs / spill attribution
    flash_backward_q none 182 / 0 was 244 / 528 — #180 took it whole
    flash_backward_kv none 190 / 0 was 244 / 528 — same
    flash_forward __local_depot2[560], 405 ld/st.local 193 / 560 not a rolled walk

    So #180 did all of the backwards' frames and none of the forward's. That matches the realized timings at [32,1024,24,128] on B200: dQ 1.298 → 1.094 ms (−15.7%), dK/dV 1.990 → 1.552 (−22.0%), forward only 1.343 → 1.211 (−9.8%).

    The 528 B in both backwards was the pipeline::Job struct reached through the mover walks; nothing downstream had to change for it.

    The forward's 560 B is #181's category

    It was a RegTile<32, 128, BaseLdtm> output accumulator held across the whole key stream, address-taken because both writers — reg::online_rescale and a local merge_output_tile — take it by &mut. Not hot in the usual sense: the only in-loop reader is a correction path that fires on 0.00% of tile visits at every gated shape. It cost ~30% anyway, because the two unconditional touches (the tile-0 rescale and the epilogue merge) run once per work item over 128 depot slots each.

    Four formulations, one container, same shape

    form ptxas forward
    resident &mut accumulator (baseline) 193 regs / 560 B 1.212 ms
    segment drained whole into a short-lived &mut band 191 / 1072 0.996
    same band by value (tile_x8(...).mul_row(f)) 253 / 1024 over the ptxas pin, never timed
    64 columns at a time (OutHalf = RegTile<32, 64>) 128 / 0 0.832

    Two things worth recording from that table:

    1. The frame grew and the time fell by 18%. What costs is the local traffic in the loop, not the bytes in the depot — a bigger frame touched twice per work item beats a smaller one touched every key tile. A frame census alone would have called row 2 a regression.
    2. A 128-register fp32 band cannot be transformed on the way out of tensor memory, whichever way it is spelled. By &mut it is address-taken; by value the drain and the result are live together and ptxas allocates 253. Only the 64-wide form is both zero-frame and fastest — exactly groupnorm_tile's streaming fix in A map walk's frame is a band that does not fit, and groupnorm_tile streams its own (#166) #181, one axis over.

    Also worth noting for #181's write-up: the same kernel's .x8 drain at the full 128 is fine when nothing is done to it. Both backward kernels do tile_x8::<32, 128> straight into store_rows and carry 0 B. It is the transform in between that makes the band not fit, not the width by itself.

    What ferro supplied

    TmemTile::store_tile + store_wait (the tcgen05.st path, §2.1) is the whole of the fix: the correction now rescales O in its own segment and keeps enable_d on, instead of restarting the segment and carrying the running output in registers. Device-tested round-trip in device-tests gave enough confidence to write it without a probe of my own, and parity came out identical to the digit at all five gated shapes.

    No API gap found. If anything is wanted in ferro from this, it would be a doc note on reg::online_rescale that its &mut RegTile argument is a band-width decision and not just a calling convention — at 64 it is free, at 128 it is a frame. Happy to send that as a one-paragraph PR if you want it.

    Downstream PR: feitreim/oxide-train#77.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions