Skip to content

The warpgroup split lost to a .local depot rather than to the lanes, and both 256-wide entries take it now - #197

Merged
feitreim merged 2 commits into
mainfrom
perf/wide-drain-remeasure
Aug 6, 2026
Merged

feitreim merged 2 commits into
mainfrom
perf/wide-drain-remeasure

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

The brief was to port oxide-train's recent GEMM work back, led by
#86 — "One CTA an SM, six K
stages and two accumulators: the configuration cuBLASLt runs"
, which moved that
tree's model-shape mean from 0.906 to 0.939 of cuBLASLt.

Almost none of #86 is portable, because almost all of it is already here.
The one thing it genuinely contributed was a reason to re-open a closed
question
, and re-opening it found that the epilogue's warpgroup split — recorded
in docs/kernels/gemm_sol.md as a null attributed to the hardware — was measured
through a .local depot that #166's walk marking has since removed. Re-run, it
wins at both entries and both passes, and it ships here.

bench --case gemm-sol, ours against a cuBLASLt FP16 taken in the same process,
same stream, same clock:

shape entry ours before ours after Δ ours cuBLASLt before → after ratio before ratio after
4096³ [256, 256] 0.0987 ms 0.0972 −1.52% 0.0855 → 0.0837 (−2.11%) 0.866 0.861
8192³ [512, 256] 0.5502 ms 0.5396 −1.93% 0.5117 → 0.5117 (0.00%) 0.930 0.948
16384³ [512, 256] 4.1602 ms 4.1120 −1.16% 4.0675 → 4.0657 (−0.04%) 0.978 0.989

Read the two large rows' ratios and not the small one's. The denominator held to
0.04% across the two containers at 8192³ and 16384³, so 0.930 → 0.948 and
0.978 → 0.989 are the measurement
. At 4096³ cuBLASLt's own time moved 2.11%
between containers — more than the change is worth — so that ratio says nothing;
our own time still improved 1.52%, and the same-container A/B below is what
covers that shape.

The same-container A/B, which is the actual evidence

bench sol-ablate table 6 already runs both geometries round-robin in one
container against a no drain control at each thread count. It is the table that
recorded the loss, so it is the table re-run — two passes, unchanged code, at
f64a27b:

4096³ [256, 256] 8192³ [512, 256]
launch, as recorded −1.4%, −1.8% +0.3%, +0.4%
launch, re-run +0.8%, +0.9% +2.1%, +2.1%
drain alone, re-run 3.35 → 3.10 µs, 3.28 → 3.17 4.72 → 3.05 µs, 4.70 → 3.04
no drain control, 192 vs 320 threads 0.0827/0.0831 vs 0.0829/0.0828 ms 0.5155/0.5155 vs 0.5157/0.5157 ms

The sign reverses at both entries and both passes, and the term that was blamed
is the term that moves: at [512, 256] the drain gets 35% cheaper rather
than slower. The no drain controls still match to a tenth of a percent, so the
two extra warps remain free when they do nothing and the whole difference is the
drain.

Why it was wrong the first time

The lane argument in the docs is still true — warps 0 and 4 own the same 32
tensor-memory lanes, so a column split puts two requesters on each of four
sub-partitions instead of spreading over eight. It was simply not the term the
table was reaching.

Every row of the original was taken through a .local depot the library no
longer emits. store_tile_x4 homed each drained band to local memory until the
rolled walks were marked (#166, landed in #180/#181/#184), and a band is the
frame
— a RegTile<32, 64> is 64 f32 is 256 B, which is the staged family's
recorded frame exactly. The split pays that frame twice per accumulator where
one warpgroup pays it once, so the arm doing more of the broken thing read as the
arm that was worse. regcount now reads zero stack and zero spill on every
gemm_sol rung
.

Registers and occupancy

The three entries join GATED_KERNELS. Their residency is fixed by the shared
plan — 196 864 and 229 632 B of the 233 472 an SM divides — so no register count
can raise it; what the gate watches is the other direction, _ctas_by_registers
reaching zero, which is a launch the driver refuses rather than a slow one.
At 320 threads that step is 168 registers a thread:

kernel                               threads  wants  regs  ceiling  headroom  allows
examples/gemm_sol_m256                   320      1    82      168        86       2
examples/gemm_sol_m256_n128              192      1    80      255       175       4
examples/gemm_sol_m512                   320      1    83      168        85       2

82 and 83 against 89 and 80 before, zero spill and zero stack throughout. The
split lowers the register count at [256, 256] — each warp carries half the
columns.

The shared plan is byte-identical either way (eight warps stage half the
columns each), so no dynamic_shared moves. What moves is the block, to 320,
which is why Variant::threads now sits beside Variant::shared_bytes and the
launcher asks the variant rather than reading one THREADS.

What did not ship, and why

  • gemm_sol_m256_n128 keeps one warpgroup. The split is legal there and the
    asserts cover it, but table 6 has arms at [256, 256] and [512, 256] only,
    so [256, 128] has no A/B of its own. Shipping it would be shipping a geometry
    nothing in this tree has timed.
  • The wide drain rung stays a rung. It was the other candidate confounded
    by the same frame (the docs say outright "the loss is not separated from that
    frame"), and re-measuring it was worth doing: 1.001 / 0.998 of paired at
    4096³ and 1.004 / 1.007 at 8192³
    , against −1.1 to −1.3% as recorded. So about
    a point and a quarter of its original loss was the frame. But it does not
    compose with the bigger win — at two warpgroups [512, 256]'s per-warp tile is
    64 columns, which a 128-column band does not divide — and the warpgroup split
    is worth four times as much at the same entry. Documented, not shipped.

The ablation and watch probes are pinned to ONE_WARPGROUP explicitly rather
than following SHIPPED_GROUPS. They had been reading the shipped constant to
mean "the geometry this ladder is held at", and those are two different facts:
flipping SHIPPED_GROUPS would otherwise have silently reshaped thirty-three
probe kernels and stopped every historical arm comparing to itself.

The port decisions

From #86 — the configuration is already here

# Increment Decision
1 Accumulator ping-pong (SLOTS = 2, release moves to empty(i + SLOTS)) Already present. ACCUMULATORS = 2 with a SemaphoreRing<2>; Small::multiply waits empty.wait(sequence - ACCUMULATORS). Algebraically identical — oxide spells it as a release at sem(sequence + SLOTS) over a 4-deep ring, we let the phase parity carry it over a 2-deep one.
2 One CTA an SM Already present at all three entries, and forced by the shared plan rather than tuned.
3 512 TMEM columns Already present — alloc_cluster(.., 2 * BLOCK_N) at both 256-wide entries.
4 STAGES 3 → 6 Rejected, blocked twice. Our shape contract is k % (STAGES · BLOCK_K) == 0; at six that is k % 384, which excludes every shape this repo benchmarks — k blocks 16/32/64/128/256, none divisible by 6. oxide's model shapes are multiples of 3072 and divide by 384; powers of two cannot. The only depth above 4 that divides them is 8. And the memory says no independently: [256, 256] at six stages is 262 400 B against the 232 448 optin, fitting only if the staging tile is halved back to 128 — i.e. by giving up increment 2 to buy the stages — and [512, 256] is 294 912 B of ring alone.
5 STAGE_N 64 → 128 (wide staging tile) Superseded. Our [256, 256] entry stages 256 columns per warp, twice oxide's, so its drain is already one shared→global pass where oxide's is two. #86 attributes this increment to two effects — half the TMEM waits and half the store passes — and we already had the second at its floor. The first half is the wide rung above.
6 GROUP stays 8 at 74 clusters Already present, and bench sol table 3 has it flat to 0.2% over {1,2,4,8,16}.

From everything merged after ea8e147

Change Decision
c3c2d66 — dK/dV epilogue deferred into the next item's opening move Reject: nothing to bring back. This is already a documented first-class capability of our pipeline::Job (src/pipeline.rs), tail-flush obligation and all. oxide applied the library's existing feature to a second kernel.
PR #102 — flash-kv-forensics Reject. Phase-probe tick-budget instrumentation, not kernel logic.
PR #104 / 525d1ce / 2f1e016 — AdamW load-before-store Reject. No optimizer or elementwise kernels here, and the hazard is NVVM alias analysis across interleaved plain-Rust loads and stores — our hot-path loads and stores are ptx_asm! with order fixed by construction.
a5d3359, 3927b5c — MoE dead-bin walk, router reduction width Reject. Router/expert dispatch shaping; there is no notion of experts or capacity in a tile library.
dab1c44, 8996e6a Reject. Host-side test scaffolding.

Portable, real, and deliberately not in this PR

Two things oxide has that we do not, both genuine and both wanting their own A/B
rather than a ride on this one:

  • The mid-drain early release. oxide's Release::now fires between the two
    TMEM lifts, as soon as the last tcgen05.ld has its registers; ours releases
    only after the whole drain returns. What binds the GEMM at 1081 TFLOP/s, and does the curve flatten at 16384 cubed #86's own text says it "costs nothing and
    still bounds the worst case", and this PR reshapes the drain underneath it.
  • Warp-scope accumulator arrivals. release_accumulator has no lane guard,
    so all 32 lanes of every epilogue warp arrive: 256 arrivals a slot against
    oxide's 8 — and this PR doubles that to 512. Three lines, on a barrier on the
    critical path, and therefore exactly the kind of change that should be timed
    rather than assumed. The most concrete follow-up here.

On gemm_ws

The brief flagged a tension: our warp-specialized GEMM at 1 CTA/SM measured −7.3%
at 16384³, while #86 runs 1 CTA/SM and wins. It dissolves without a measurement.
gemm_ws's −7.3% is against gemm_cg2, the other GEMM lineage, which runs two
CTAs an SM. gemm_sol — the faster lineage, and the one this PR touches — has run
one CTA an SM at all three entries since it was ported, forced by its shared plan
and not chosen. Residency was never the variable in the gemm_ws result; warp
specialization inside a single CTA was. #86's residency is not something this repo
can adopt, because it already has it.

Gates

  • scripts/modal-run build — clippy clean on all four manifests, sm_100a
    codegen for device-tests, examples and experiments, ptxas clean.
    (The run exited 4 on Timed out waiting for final app logs after the last
    command completed — the client lost the tail, not a failure.)
  • scripts/modal-run regcount — occupancy gate green, table above; zero stack
    and zero spill on every gemm_sol rung.
  • bench --case gemm-sol — every row checked exact against the CPU reference
    before it is timed, all three green.
  • bench --case sol-ablate — every arm checked, both passes.

…, and both 256-wide entries take it now

`bench sol-ablate`'s table 6 recorded the epilogue's column split losing 1.4 to
1.8% at 4096³ and winning 0.3 to 0.4% at 8192³, and the reading offered was
hardware: warps 0 and 4 own the same 32 tensor-memory lanes, so splitting an
accumulator's columns puts two requesters on each of four sub-partitions rather
than spreading over eight.

That argument is still true and it was not what the table measured. Every row
of it was taken through a `.local` depot the library no longer emits —
`store_tile_x4` homed each drained band to local memory until the rolled walks
were marked (#166, landed in #180/#181/#184), and a band *is* the frame, a
`RegTile<32, 64>` being 64 f32 being 256 B. The split pays that frame twice per
accumulator where one warpgroup pays it once, so the arm doing more of the
broken thing read as the arm that was worse.

Re-run at f64a27b, same table, same two round-robin passes, `regcount` reading
zero stack and zero spill on every `gemm_sol` rung:

  4096³ [256, 256]   launch +0.8%, +0.9%   drain 3.35 -> 3.10, 3.28 -> 3.17 us
  8192³ [512, 256]   launch +2.1%, +2.1%   drain 4.72 -> 3.05, 4.70 -> 3.04 us

The sign reverses at both entries and both passes, and the term that was blamed
is the term that moves: the drain gets 35% cheaper at [512, 256] rather than
slower. The `no drain` control at its own 320 threads still matches the
192-thread one to a tenth of a percent, so the extra warps remain free when
they do nothing.

`SHIPPED_GROUPS` is `TWO_WARPGROUPS` for `gemm_sol_m256` and `gemm_sol_m512`.
The shared plan is byte-identical either way — eight warps stage half the
columns each — so no `dynamic_shared` moves; what moves is the block, to 320,
which is why `Variant::threads` now sits beside `Variant::shared_bytes` and the
launcher asks the variant instead of reading one `THREADS`.

`gemm_sol_m256_n128` keeps one warpgroup. The split is legal there and the
asserts cover it; table 6 simply has no `[256, 128]` arm, and shipping it would
be shipping a geometry nothing here has timed.

The ablation and watch probes are pinned to `ONE_WARPGROUP` explicitly rather
than following `SHIPPED_GROUPS`. They were reading the shipped constant to mean
"the geometry this ladder is held at", and those are two different facts: with
`SHIPPED_GROUPS` flipped, thirty-three probe kernels would have silently
reshaped and every historical arm would have stopped comparing to itself.

The three entries join `GATED_KERNELS`. Their residency is fixed by the shared
plan and no register count can raise it, but at 320 threads a thread may have
168 registers before an SM cannot place one CTA at all — a launch the driver
refuses rather than a slow one. They read 82 and 83 against that step.
@feitreim
feitreim merged commit ada5f34 into main Aug 6, 2026
4 checks passed
feitreim added a commit that referenced this pull request Aug 6, 2026
`Drain<const LDTM_X8: bool, const STMATRIX_X4: bool>` shipped with #126 and the
shape is wrong twice over. The TMEM axis has three instructions a drain can
issue and not two — `.x1`, `.x8`, and `.x8` with the band's issues batched
behind one `tcgen05.wait::ld` — and the third carries an `ISSUES` count no
`bool` can hold. And a `bool` puts the rung in the *walk*: each arm is an `if`
inside the loop and a position in every dial that reaches it, so a fourth rung
edits the epilogue and five launch sites rather than adding an impl.

So the axes are traits, in `Swizzle`'s and `Scope`'s idiom: `TmemRead` with
`X1`, `X8` and `X8Batched<ISSUES>`, `FragmentStore` with `X2` and `X4`, one unit
struct per rung with the instruction on the impl. `Drain::<X8, X4>` is the pair
that ships and it says which pair at the launch site where `Drain::<true, true>`
said only where in a table it sat — which is the complaint `gemm_ws`' own doc
makes about `Ws::<STAGES, true, false, false, true>`, answered on this axis.
`experiments`' `Staged` job takes the two rungs the same way, so its five
entry points read `Staged::<true, X8, X2>` instead of `Staged::<true, true,
false>`.

An `adt_const_params` enum would express the same set; it is unstable and this
crate takes no incomplete features. The traits need none.

Two things are deliberately not rungs, and the docs say why for both.
`stmatrix.m8n8.x1` is in the ISA and not in the library: four instructions per
block where `.x2` is two and `.x4` is one, at identical addresses, in the
direction #117 measured as losing — it is an `ldst` entry point plus an impl
whenever someone wants it priced. `TmemTile::fragments_pack16_x8` returns packed
b16 words rather than an fp32 `RegTile`, so it is not a width of the read axis
but a different route: the only thing that can store its product is
`store_packed_x4`, which by its own doc computes a wrong `C`. Admitting it would
make the read's product an associated type and bind the write axis to it — the
two axes would stop being independent, for an ablation that never ships.

`X8Batched` is the rung `gemm_sol`'s drain reads with, and a doctest compiles
`Drain::<X8Batched<2>, X4>::staged` so that is checked rather than claimed. It
is not enough to migrate that kernel and the axes are no longer what separates
them — the walk is. It fills a 128-wide staging tile out of two 64-wide bands on
purpose, because four `.x8` issues behind one wait is 176 registers against 96;
it drains a column *span* of a wider accumulator because two warpgroups split
the tile (#197); and it converges twice a pass. Those are three parameters on
the walk, and `gemm_sol` is the tightest register count in the repo, so the
migration is a measurement and not a refactor.

No instruction moves: this is a pure API change and `regcount`'s opcode census,
registers, spills and frames are identical on every kernel.
feitreim added a commit that referenced this pull request Aug 6, 2026
… replaces measured as nothing (#218)

* An accumulator releases from one lane a warp, and the 512 arrivals it replaces measured as nothing

`release_accumulator` had every lane of every epilogue warp arrive on `empty`,
for a fact that is one per warp: a warp is done with the accumulator when its
last `tcgen05.wait::ld` has retired, and that instruction retires the warp's
loads and not the lane's. #197's split doubled the epilogue's warps and doubled
the count with them -- 256 arrivals a slot to 512, against oxide-train's 8 --
on the barrier between an accumulator's drain and the next item's MMA. It was
the most concrete follow-up that PR's review left, and it is worth nothing.

The guard is a lane test and the count `empty` is armed with is the same
statement read from the other end, so both move together:

  [256, 256] and [512, 256]   RANKS * epilogue_warps(2) * 32 = 512  ->  16
  [256, 128]                  RANKS * epilogue_warps(1) * 32 = 256  ->   8

Nothing else arrives on `empty` at either entry. The `[512, 256]` epilogue's
two halves are two slots of the same ring signalled by the same call -- which
is why `Large::epilogue` stops spelling the arrival itself and calls
`release_accumulator(half)`, so one lane guard covers both entries and both
slots. The epilogue and the MMA warp break their item loops on the same
`has_work == 0`, so a launch's last item leaves no half-signalled slot behind.
What makes the guard legal is the drain's closing `warp::sync_mask`: past it,
no lane of the warp still has the accumulator in flight.

`bench sol-ablate` table 7 is the A/B, both arms in one container, round-robin,
two passes, against the `no drain` control at the same 320 threads:

  4096^3 [256, 256]   all lanes 0.0980, 0.0969 ms   one lane 0.0979, 0.0980
                      ratio 1.001, 0.989   drain 3.46 -> 3.42, 3.16 -> 3.43 us
  8192^3 [512, 256]   all lanes 0.5385, 0.5387 ms   one lane 0.5384, 0.5387
                      ratio 1.000, 1.000   drain 3.13 -> 3.11, 3.19 -> 3.19 us

At [512, 256] the arms agree to four figures in both passes. At [256, 256] the
passes disagree in sign by less than that shape's own spread on a fixed arm --
the all-lanes row alone moves 1.1% between them. It is a null: an arrival is
one atomic increment on a shared word, a warp issues its 32 in one instruction,
and the waiter is a parity spin that does not care how many ended it. It ships
guarded anyway, because one a warp is what the code means.

`bench sol-ablate` also could not run at all before this. #197 pinned the
ablation probes to ONE_WARPGROUP and took the shipped kernels to 320 threads,
but `Arm::Whole` launches the shipped kernel and kept asking for 192 -- which
the launch contract rejects rather than runs, so table 1 died on
`block (192, 1, 1) does not match required block (320, 1, 1)` and every table
after it was lost. `whole` gets pinned probes of its own at the geometry every
ladder here is held at, which is what #197 intended for the other thirty-three.

regcount: the gate is green and every `gemm_sol` rung reads zero stack and zero
spill. `gemm_sol_m512` moves 83 -> 95 registers and `gemm_sol_m256` does not
move at all, and the two arms in one crate say the guard is what did it --
`gemm_sol_m512_wg2` 84 against `gemm_sol_m512_wg2_lane` 95. Residency is fixed
by the shared plan either way; the step at 320 threads is 168 and 95 leaves 73.

* The PR number the release-scope notes point at is 218
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