Skip to content

Ship the epilogue the evidence picked, and it is not the same one twice (#119) - #120

Merged
feitreim merged 1 commit into
mainfrom
ship-staged-epilogue-defaults
Jul 29, 2026
Merged

feitreim merged 1 commit into
mainfrom
ship-staged-epilogue-defaults

Conversation

@feitreim

Copy link
Copy Markdown
Owner

gemm's default epilogue becomes staged84 and gemm_ws's becomes
staged8. #116, #117 and #118 each ended by saying the rung was worth
shipping and that shipping it belonged in its own change. This is that change
and it is the whole of it: no rung added, none deleted, nothing retuned, every
entry point still launchable and still on the correctness gate.

The two differ on purpose

.x8 costs +52 and +50 registers, identically. What differs is what .x4
hands back — 14 on gemm_cg2 (94 → 80) and 2 on gemm_ws (94 → 92) —
and that recovery is the composition gain. There the pair is +5.1% at 16384³
against .x8 alone's +3.6%; here staged8 and staged84 land inside 1.1% and
trade places between sessions, so the tie goes to the rung with less surface.
This run is the third session inside that tie and the second to order it
differently.

The confirming benchmark

One container, min of 30 timed launches, every row checked element-by-element
first, cuBLASLt re-measured in the same container (0.0836 / 0.6275 / 4.8020
ms = 1645.0 / 1752.2 / 1831.8 TFLOP/s) rather than quoted — #109 would have
published a false +3.6% had it not noticed its own commit moved the baseline.

shape gemm was (lcf) gemm ships (staged84) gain of cuBLASLt
4096³ 0.1432 0.1044 +37.2% 0.583 → 0.801
8192³ 0.7584 0.6684 +13.5% 0.827 → 0.939
16384³ 5.5157 5.0132 +10.0% 0.871 → 0.958
shape gemm_ws was (ws s4) gemm_ws ships (staged8) gain of cuBLASLt
4096³ 0.1395 0.1166 +19.6% 0.599 → 0.717
8192³ 0.7947 0.7310 +8.7% 0.790 → 0.858
16384³ 5.9157 5.5663 +6.3% 0.812 → 0.863

#117's 0.796 / 0.944 / 0.922 reproduces at 0.801 / 0.939 / 0.958 and #118's
0.726 / 0.856 / 0.852 at 0.717 / 0.858 / 0.863. The 16384³ rows moved because
the denominator did — the library ran 1831.8 here against #117's 1869.1.

Verification

  • scripts/modal-run build — green, no new warnings.
  • scripts/modal-run regcount — every gated kernel inside its step. gemm_cg2
    166, gemm_cg2_staged 42, gemm_cg2_staged_x8x4 80, ceiling 255
    (not 168: Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87 gave up the third CTA, so two CTAs at 128 threads admit the
    whole file). Zero spill in every gemm_* kernel. Opcode census unchanged
    rung for rung.
  • scripts/modal-run examples — every rung of both kernels, both check sizes,
    all three traversal widths, both schedulers where a rung has both. == on
    bf16 words, no tolerance.
  • scripts/modal-run ws_bench — the table above.

What moved that was not a default

Stated plainly, all of it downstream of the flip:

  • main.rs's envelope row now reports 114 816 B and 147 584 B — the plans
    the shipped launches declare. CTAS_PER_SM does not move on either kernel:
    the tensor-memory term of min(512 / columns, shared per SM / plan) binds at
    both envelopes.
  • modal_app.py's GATED_KERNELS gained gemm_cg2_staged_x8x4, because
    the occupancy gate is a gate on the kernel the crate launches and that moved.
    The gate's kernel column widened 20 → 24 to fit the name.
  • ws_bench table 1 now names lcf on both sides instead of calling
    gemm::bench. Its one variable is where the overlap comes from; a default
    moving under it would have made it two. Table 5 is where each side gets its
    best rung.
  • Two stale figures corrected on the way, both pre-dating this change: the
    root README.md and modal_app.py said gemm_cg2 sits at 167 against a 168
    step. It reads 166 against a ceiling of 255 and has since Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87.
  • GAPS.md said the GEMM's whole epilogue is one store_rows; that is now
    the control rung, and the shipped one is store_tile_x4 +
    store_shared_rows.

What deliberately did not move

The ablation cube, bench --case epilogue and bench --case staged stay built
at lcf — they decompose the register drain and reproduce #114's 20.43 µs a
tile, and a ladder that moved with the default would stop being comparable to
every earlier run of itself. lcf is also the only epilogue with a clc entry
point.

Every bench --case gemm* row published before this is against a different
kernel now, including the gemm-depth fit. Those rows are kept and labelled
rather than re-run; re-fitting on staged84 is a measurement of its own.

…ce (#119)

`gemm`'s default epilogue becomes `staged84` and `gemm_ws`'s becomes `staged8`.
#116, #117 and #118 each ended by saying the rung was worth shipping and that
shipping it belonged in its own change; this is that change and it is the whole
of it. No rung added, none deleted, nothing retuned — every entry point still
launches and is still on the correctness gate.

The two differ on purpose. `.x8` costs +52 and +50 registers identically; what
differs is what `.x4` hands back — 14 on `gemm_cg2` (94 -> 80) and 2 on
`gemm_ws` (94 -> 92) — and that recovery IS the composition gain. There the
pair is +5.1% at 16384^3 against `.x8` alone's +3.6%; here `staged8` and
`staged84` land inside 1.1% and trade places between sessions, so the tie goes
to the rung with less surface.

Confirmed in one container with cuBLASLt re-measured in it (#109's lesson):
`gemm` 0.1432 -> 0.1044, 0.7584 -> 0.6684 and 5.5157 -> 5.0132 ms, which is
+37.2% / +13.5% / +10.0% and 0.583 -> 0.801, 0.827 -> 0.939 and 0.871 -> 0.958
of the library. `gemm_ws` +19.6% / +8.7% / +6.3% and 0.599 -> 0.717,
0.790 -> 0.858, 0.812 -> 0.863. Both reproduce their published ratios; the
16384^3 rows moved because the denominator did.

The constants that describe the shipped launch moved with it: `main.rs` reports
114 816 B and 147 584 B, and `CTAS_PER_SM` does not move on either kernel
because the tensor-memory term of `min(512 / columns, shared per SM / plan)`
binds at both envelopes. `regcount`'s occupancy gate gained
`gemm_cg2_staged_x8x4` and reads 166 / 42 / 80 against a ceiling of 255.

Deliberately unmoved: the ablation cube, `bench --case epilogue` and
`bench --case staged` stay built at `lcf`, and `ws_bench` table 1 now NAMES
`lcf` on both sides rather than taking `gemm`'s default, so its one variable is
still where the overlap comes from.
@feitreim
feitreim merged commit 6e0545c into main Jul 29, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 29, 2026
#122) (#122)

#121 took the first reproducibility control on `whole - no drain` and it came back
39-46% at 16384^3 against 1-5% at 8192^3, with #116's 16.34 us/tile, #117's 5.81
and #118's 2.91 all inside the band. This is what the band is.

**It is error propagation, and the arithmetic reaches backwards with nothing
measured.** A difference carries its arms' error divided by its own share of them.
Reconstructed from #121's own printed table 6: share 17.9% / 7.8% / 5.3% at
4096/8192/16384^3, so 1/s of 5.6 / 12.9 / 19.0, and against arms that repeat to
0.86+0.58% / 0.15+0.10% / 0.45+2.11% that predicts 8.1% / 3.2% / **49%** against
#121's observed 7% / 1% / **46%**. The launches were never the problem -- they
repeat to 0.1-2.1% everywhere. The epilogue is per output tile and the launch is
per tile times K, so the share falls as 1/K by construction. **The instrument did
not degrade at 16384^3; it never worked there.**

Three things it is not, each checked: sampling (`min` of 30 is the same estimator
at every size and the arms repeat to 0.10% at 8192^3), the wave (8192^2 and
16384^2 are both 98.8% full and every comparison holds the grid fixed between its
arms), and -- against the hypothesis -- **adding rather than deleting**.
`drain_staged_twice` retires the dead-code hazard, which is real and different,
but one added link is a *smaller* share than the whole epilogue, so the ladder is
more amplified. #121's own 16384^3 ladder row is +4.01 and -2.69 for one quantity.

**And a second term nobody could see, because `bench` sorted the order away.**
`Timings` now keeps launch order; `drift` is the second fifteen launches over the
first. At 16384^3 and nowhere in the sweep, all six arms over two containers, the
device is **+6.85 to +11.33% slower by the end of a call** -- essentially the whole
of its 18-23% in-call spread -- where every other size drifts *negative*. Not the
problem size: `16384^2 x k1024` has the same tiles, items, C and wave and drifts
-1.0 to +0.6%. It is the duration, 154 ms of continuous 1.1 PFLOP/s against 16.
A 16384^3 `min` is a boost-clock reading from a call whose last launches run 10%
slower, which is also the mechanism under cuBLASLt's 1.15-1.19 max/min there.

**The fix is `bench repro`: same output geometry, shorter reduction.** K is the one
axis the epilogue's cost does not sit on, so shortening it holds the tiles, the
waves, the items, the C traffic and the epilogue total and moves only the launch
it is a fraction of. Four whole measurements per arm, round-robin so every pair is
adjacent in time, and the spread the amplification *predicts* printed beside the
one it got. One `ld.shared` + `st.global.v4` pass, two containers:

| shape | us/tile | s | observed | predicted | session to session |
| --- | ---: | ---: | ---: | ---: | ---: |
| 8192^2 x k1024 | **2.34 / 2.34** | 10.8% | 17 / 17% | 16 / 18% | **0.0%** |
| 8192^3 | 2.07 / 2.29 | 2.2% | 33 / 18% | 41 / 30% | 10.6% |
| 16384^2 x k1024 | **2.11 / 2.12** | 10.8% | 5 / 8% | 12 / 13% | **0.5%** |
| 16384^3 | 3.01 / 3.82 | 1.6% | **167 / 111%** | 235 / 177% | **26.9%** |

`predicted` tracks `observed` across a twentyfold range and bounds it above in
nine rows of ten. The 16384^2 number nobody could measure is **2.11 us/tile**,
reproduced to 0.5%; #121's ladder put it at 0.45 and 4.22. The us/tile is flat in
K (2.34/2.42/2.07 and 2.34/2.61/2.29 over an eightfold range), which is what makes
the substitution legal and is the design's own check.

**`staged8` and `staged84` are not tied, and the sign is the geometry's.** At
8192^2 `staged8` leads by 1.4-2.4% in four cells, no range reaching 1.000; at
16384^2 `staged84` leads by 0.4-1.0%, same sign both containers. The full-depth
rows do not merely fail to order them -- 16384^3 centres on `staged8` ahead by
1.4-2.3 us/tile where the shortened row says `staged84` ahead by 0.07-0.20, and
both its ranges straddle. **So #120's default is right for a reason its own row
could not carry**, and #121's advice to break the tie at 8192^3 would have broken
it the other way. Not a request to move the default.

New: `Timings::spread` / `Timings::drift` and the launch order behind them, `bench
repro`, rule 5 in the module docs, a section in README §7. Nothing measured is
inherited; no default, constant or kernel moved; `gemm.rs` untouched. `build` green
twice, `bench --case repro` run in two containers at 96 s of GPU each.
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.

1 participant