Skip to content

Eight epilogue warps split the columns and the drain does not get faster: the axis that is free is not the axis the hardware parallelizes - #153

Merged
feitreim merged 1 commit into
mainfrom
epilogue-warpgroup-split
Jul 30, 2026
Merged

feitreim merged 1 commit into
mainfrom
epilogue-warpgroup-split

Conversation

@feitreim

@feitreim feitreim commented Jul 30, 2026 •

Copy link
Copy Markdown
Owner

The lever, and the null

The drain is the largest remaining term in gemm_sol, and #147 left it with three
of its four internal levers measured at zero: LDTM waits (doubling them costs
nothing), the convert (the nocvt oracle is 0.0-1.4% slower), and store width
(stmatrix.m8n8.x4 is the widest b16 form there is). E > D says it interferes
with the phase beside it rather than failing to overlap. A latency-bound chain that
cannot be widened or shortened leaves adding parallelism — and lane ownership
forbids a fifth epilogue warp per warpgroup, but warp 4 is warpgroup 1's warp 0 and
owns the same rows, so eight warps can split the accumulator's columns.

Built, exact, and it does not pay. More usefully: the reason it does not pay
closes the direction rather than just declining it.

These numbers are from a tree that no longer exists, and the re-timing is
blocked.
Every figure in this section was taken on a7c26f7, this branch's
pre-rebase base — gemm-sol before #154. The branch now sits on 6babbfa
(on top of aaadcc2) and #154 changed the shipped kernel, so these describe a
different tree and are labelled as such rather than presented as current.

The blocker is account-level, not this diff: the Modal workspace is disabled
(ConflictError('workspace ac-… is disabled')), which fails every entry point in
~35 s after a partial compile. It stopped this base's gate chain mid-way —
bench exit 2, examples exit 1 — and it is why the CI build and regcount
checks on this PR are red. device-surface, which runs entirely on GitHub and
touches no container, passes on 6babbfa, as do cargo fmt --check and
cargo metadata --locked across all four crates.

The conclusion is not expected to flip: the comparison is internal to one
container and both arms move together. But that expectation is not a
measurement, so this PR should not land on these tables — they will be
re-taken on 6babbfa when the workspace returns.

Pre-rebase base a7c26f7, cuBLASLt 1683.6 and 2157.9 TFLOP/s in that
container:

4096³ [256,256] 8192³ [512,256]
one warpgroup, 192 threads 0.1033 / 0.1034 ms 0.5807 / 0.5805 ms
two warpgroups, 320 threads 0.1048 / 0.1052 ms 0.5787 / 0.5784 ms
of one warpgroup 0.986 / 0.982 1.003 / 1.004
epilogue, one wg 4.83 / 5.01 µs a tile 9.23 / 9.20 µs a tile
epilogue, two wg 5.27 / 5.33 µs a tile 8.96 / 8.90 µs a tile
the drain itself −9% +3%

−1.4% and −1.8% of the launch at 4096³; +0.3% and +0.4% at 8192³, both passes
agreeing in sign at both shapes.

Two round-robin passes at each shape. Not shippable, kept as a rung.

The control that makes it a finding rather than a wash

Each arm subtracts the no drain at its own thread count, because the split
changes the launch geometry and a shared control would carry two warps of
scheduling into the subtraction. Those two controls come out identical:

4096³ 8192³
no drain, 192 threads 0.0839 / 0.0834 ms 0.5161 / 0.5161 ms
no drain, 320 threads 0.0837 / 0.0839 ms 0.5160 / 0.5161 ms

To a tenth of a percent, at both shapes, on a7c26f7.

So the two extra warps are free when they do nothing, at both shapes. The loss
is not "320 threads is slower" — it is the drain being slower once it is split, at
the same total work.

Why, and why there is no third axis

The mechanism is the same resource that fixed the row axis in the first place.

tcgen05.ld reaches the 32 tensor-memory lanes of the issuing warp's own
sub-partition, and which sub-partition that is comes from the warp's index within
its warpgroup
. Warps 0 and 4 therefore own the same 32 lanes. A column split
does not spread the LDTM traffic over more sub-partitions — it puts two
requesters on each of the same four
. Same ports, twice the queueing.

  • Rows are tiled out at four warps by lane ownership: EPILOGUE_ROWS = BLOCK_M / 32 is hardware arithmetic, and a fifth warp of a warpgroup has no rows
    left to own.
  • Columns are free to split — and are shared with the warp that already owns
    those lanes, which is what this PR measures.

There is no third axis. So the drain is bound by something shared across warps
rather than by per-warp latency, and per-warp parallelism cannot reach it.

What that leaves, by elimination

Not bytes: 262 144 B into shared per cluster per tile in ~6 µs is 3.5 TB/s
device-wide against an SM's ~230 GB/s of shared write bandwidth — under 10% of it.
Not bank conflicts: Swizzle128B maps one stmatrix.m8n8 matrix's eight rows onto
eight distinct 16-byte chunks whose banks tile all 32 exactly once, at every staging
pitch here, because every row pitch is a whole multiple of 128 B and the row term
drops out of the bank index. Not width, not the convert, not the waits.

What is left is the stmatrix scatter's transaction rate, which nothing here
separates from its byte rate. That is the honest end of the chain, and the arm that
would separate them changes the access pattern at constant bytes and constant
instruction count.

The two things carried in

1. The [512, 256] entry's two-half handshake inherits the split, and that is a
finding rather than an assumption.
I flagged it as the one thing the split might
not get for free. Re-read: for each sequence the epilogue waits full.sem(half),
drains, and arrives on empty.sem(half), for each of two halves. A column split
leaves the set of warps touching each half unchanged — all of them, once — so the
only thing that moves is the arrival count, from RANKS · 4 · 32 to
RANKS · 8 · 32. initialize now takes that count as an argument rather than
deriving it from a module constant. A wrong count would have hung rather than
mis-answered; it is exact at both entries instead.

2. Shared bytes: zero delta, at all three entries — and now an assert, not
prose.
shared_plan takes the entry's staging width, and doubling the warps
halves each warp's width, so the product is unmoved by construction:

entry one warpgroup two warpgroups plan
[256, 256] 4 × [32, 256] 8 × [32, 128] 65 536 B
[256, 128] 4 × [32, 128] 8 × [32, 64] 32 768 B
[512, 256] 4 × [32, 128] 8 × [32, 64] 32 768 B
assert!(epilogue_warps(ONE_WARPGROUP) as usize * BLOCK_N
     == epilogue_warps(TWO_WARPGROUPS) as usize * (BLOCK_N / 2));

…and the same for the other two entries. dynamic_shared is 196 864 / 131 328 /
229 632 either way, which is what lets one no drain control at each thread count
serve its arm and keeps residency at the one CTA/SM that binds.

Correctness is the gate, because the census cannot be

Exact over 1 048 576 BF16 outputs at both wide entries, == and no tolerance,
through gemm_sol_drains in the experiments crate's check — plus all three
shipped entries unchanged and exact.

That is load-bearing here in a way it usually is not: the split's opcode census is
identical to the shipped kernel's in every column
, because each warp runs half as
many staged passes through the same rolled loop. So the census can only be negative
evidence — it proves the shipped kernels did not move, and it cannot say the split
happened. A split that sent both column groups to the same columns would have left
half of C untouched and censused exactly the same. The exact outputs are also the
only evidence anywhere that warp 4 really does own warp 0's tensor-memory lanes:
no document at this pin states it, and nothing in tree had asked before.

regcount on 6babbfa: 4 kernel(s) in both crates: identical opcode counts, and all three shipped entries identical in examples/ and experiments/
with ldtm.wait at 1 — the only column this branch moves in a shipped kernel.

kernel                       mma  ldtm  ldtm.wait  tma  stmatrix  ld.sh.v4  st.g.v4  st.g.b32  cvt  regs  frame
gemm_sol_m256                 16     2          1    3         2         1        1         4    8    96    256
gemm_sol_m256_n128            16     2          1    2         2         1        1         4    8    86    256
gemm_sol_m512                 32     2          1    4         2         1        1         4    8    94    256
gemm_sol_m256_wg2             16     2          1    3         2         1        1         4    8    85    256
gemm_sol_m256_wg2_nodrain     16     0          0    3         0         0        0         0    0    47      0
gemm_sol_m512_wg2             32     2          1    4         2         1        1         4    8    95    256
gemm_sol_m512_wg2_nodrain     32     0          0    4         0         0        0         0    0    90      0
gemm_sol_m512_per_issue       32     2          2    4         2         1        1         4    8   112    256
gemm_sol_m512_nocvt           32     2          1    4         1         1        1         4    0    91    256
gemm_sol_m512_pack16          32     1          1    4         1         1        1         4    0    68    128
gemm_sol_m512_twice_all       32     4          4    4         4         2        2         8   16    94    256
gemm_sol_m512_twice_global    32     2          2    4         2         2        2         8    8    94    256

Every arm still reads as its name claims on this base — the ladder doubles exactly
the columns it names, nocvt and pack16 show cvt 0 with the stores intact, and
the split is opcode-identical to the shipped kernel, which is the point of the
section above. Zero spills everywhere; the split's controls carry no frame.

The exactness bar has not been re-run on 6babbfa. It passed on a7c26f7 —
paired, per issue, wide and two warpgroups exact over 1 048 576 BF16
outputs at both wide entries, plus all three shipped entries — and examples on
this base died on the spend limit before launching. Since that gate is the only
evidence both that the split happened and that warp 4 owns warp 0's TMEM lanes,
this PR should not land until it has run on 6babbfa.

PTX counts as hypotheses

Taken as instructed. Nothing here concludes from an instruction count: the census's
role is entirely negative, and every claim about the split is a timing with a
control and two passes. The one place a count appears is the shared-bytes table,
which is arithmetic on a plan rather than a count of emitted instructions.

The rebase

git rebase --onto origin/main origin/gemm-sol, as instructed. It did not apply
cleanly — 43 conflicts — so it was resolved rather than replayed:

The two parameterisations do not interact

#154 changed the arrival count's neighbour, not the count. The resolved code shows
it in adjacent lines:

self.empty.init_all(empty_arrivals);   // this branch: arrival COUNT, RANKS·4·32 → RANKS·8·32
self.ready.init_all(1);                // #154: one arrival, DEPTH via sem(index % items)
self.stop.write(0);

empty is the accumulator handshake and scales in arrivals with epilogue warps;
ready/info are the item handoff and scale in depth with ITEMS. Neither
quantity appears in the other's expression, so neither can silently override the
other, and ready's waiters are unbounded so eight warps waiting on one barrier
needs no change.

One convention, generalised out of this PR

DRAIN_WIDE's band is 128 columns and a band must divide the per-warp staging
width, which is 64 at two warpgroups. A literal 128 in the drain dial is then an
illegal instantiation even in the dead match arm — Rust monomorphizes both sides
of a match on a const before anything folds it away. So the band and its issue
count became parameters supplied by the entry, which is the only place that knows
both numbers.

That is the same class as #147's dial collision, so it is now written on
dial_is_a_permutation itself as the second half of the rule:

  1. Values are a permutation of 0..len — checked at compile time, because a
    collision otherwise silently remaps one arm onto another.
  2. Every combination of dials must be legal, not just the reachable ones. A
    shape a dial implies has to come from whoever knows all the dials, rather than
    being written as a literal where one dial can see it and the others cannot.

Runs

On 6babbfa (post-rebase): build pass, regcount pass,
cargo test, cargo clippy --all-targets, scripts/fmt pass. examples and
bench --case sol-ablate did not run — the Modal workspace hit its spend limit
(bench exit 2, examples exit 1 workspace is disabled), which is
infrastructure and not the diff.

On a7c26f7 (pre-rebase): build, regcount, examples and
bench --case sol-ablate all pass, and that is where every timing above and the
exactness bar come from.

What this does not separate

  • The stmatrix scatter's transaction rate from its byte rate. The end of the
    chain, and it wants a counter this container does not have.
  • Whether two requesters per sub-partition is queueing or serialization. The
    split between the two shapes is consistent with contention a longer K loop
    absorbs, but this PR does not establish that.
  • Why the split reads slightly differently at the two shapes. Both are
    reproduced twice; the difference is reported, not explained.

@feitreim
feitreim changed the base branch from gemm-sol to main July 30, 2026 02:00
@feitreim
feitreim force-pushed the epilogue-warpgroup-split branch from a7c26f7 to 6babbfa Compare July 30, 2026 02:36
…ster: the axis that is free is not the axis the hardware parallelizes

The drain is ~12 points of the launch at 8192^3 and ~20 at 4096^3, E > D says it
interferes rather than failing to overlap, and LDTM waits, the convert and store
width all measure zero. That left adding parallelism, and lane ownership forbids a
fifth warp per warpgroup -- but warp 4 is warpgroup 1's warp 0 and owns the same
rows, so eight warps can split the accumulator's COLUMNS.

Built, exact, and it does not pay: -1.4/-1.8% at 4096^3 and +0.3/+0.4% at 8192^3
over two round-robin passes, against a `no drain` control at its own 320 threads
that matches the 192-thread one to a tenth of a percent. So the two extra warps
are free when idle and the drain is slower once split -- -9% of the drain at
4096^3, +3% at 8192^3, for twice the warps at the same work.

The mechanism is the resource that fixed the row axis in the first place: 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 more. There is no third
axis. Kept as a rung, exact at both entries over 1 048 576 BF16 outputs, which is
what says the null is about the hardware and not the code.
@feitreim
feitreim force-pushed the epilogue-warpgroup-split branch from 6babbfa to 66e77a3 Compare July 30, 2026 13:08
@feitreim

Copy link
Copy Markdown
Owner Author

The block is cleared. Re-run on 66e77a3 — this branch rebased onto main at 3419920, i.e. the tree that ships — after the Modal workspace was re-enabled.

The exactness bar passes on this tree. M256xN256 two warpgroups exact over 1048576 outputs and M512xN256 two warpgroups exact over 1048576 outputs, alongside paired, per issue and wide. That was the one gate this PR genuinely could not land without, since the split censuses identically to the shipped kernel and the exact outputs are the only evidence both that the split happened and that warp 4 owns warp 0's TMEM lanes.

The tables, re-measured on 66e77a3, two passes per shape:

shape one wg (192 thr) two wg (320 thr) epilogue, one → two of one wg
4096³ pass 1 0.1031 ms 0.1050 ms 5.08 → 5.52 µs 0.983
4096³ pass 2 0.1031 ms 0.1052 ms 5.01 → 5.59 µs 0.981
8192³ pass 1 0.5810 ms 0.5799 ms 9.24 → 9.07 µs 1.002
8192³ pass 2 0.5805 ms 0.5798 ms 9.26 → 9.06 µs 1.001

The control still holds, which is what makes this a finding rather than a wash. no drain at 192 threads and at 320 threads agree to within 0.06% at both shapes — 0.0828/0.0831 against 0.0829/0.0828, and 0.5163/0.5157 against 0.5164/0.5164. The two extra warps are free when idle; the loss is the drain itself, ~10% slower once split at the small entry.

The conclusion reproduces across the pin bump, the rebase and the container: −1.7/−1.9% at 4096³ and +0.1/+0.2% at 8192³, against −1.4/−1.8% and +0.3/+0.4% pre-rebase. Same sign, same verdict, and it is not shipped.

Also green on this head: build, device-surface, regcount. regcount confirms the census bar — the split is opcode-identical to the shipped kernel, and ldtm.wait at 1 remains the only column this branch moves in a shipped kernel.

@feitreim
feitreim merged commit 257a385 into main Jul 30, 2026
4 checks passed
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