Repository navigation
The pair tile was the lever, and the mechanism is not the one that looked stronger (#87) - #104
Merged
Merged
Conversation
…oked stronger (#87) `gemm_cg2`'s pair tile is `[256, 256]` at three stages, not `[256, 128]`: **+11.6% at 8192³ and +21.6% at 16384³**, which is 1457.1 and **1622.5 TFLOP/s** — the fastest this kernel has been measured at — and **0.826 and 0.886 of cuBLASLt** against 0.740 and 0.728. The pair tile and the pipeline depth are const parameters of `Tile` now, and `bench --case tile` is the sweep, with all four losing rungs kept. ## The re-fit first, because #102 invalidated the fit that ranked this `gemm-depth` re-run on `7ef5685`, point selections all stated: | points | fixed ms | per tile | steady TFLOP/s | share of 8192³ | | --- | ---: | ---: | ---: | ---: | | K = 8192, 32768 | 0.0865 | 8.6 µs | 1480 | 10.4% | | K = 2048, 8192, 32768 | 0.1516 | 15.2 µs | 1518 | 18.3% | | all four | 0.1835 | 18.3 µs | 1538 | 22.1% | The steady state did not move (1480–1538 against #91's 1515–1527), the ceiling suspicion got *stronger* — four numbers by three routes in 1437–1480, with the deepest measured row 2.9% under the asymptote where it used to be 10.6% under — and the fit got **worse** as an instrument for the item boundary, because #102 put a K-dependent term into the intercept and the answer now moves 10.4% → 22.1% on point selection. ## And the ceiling was a property of the tile `[256, 256]` measures **1718.5 TFLOP/s** at `K = 32768`, straight through that band. Three shapes agreeing meant one shared term bound them; every one of the three had the same tile. ## The sweep, and the control that separates the mechanisms Min ms over 30, static, `GROUP = 8`, every row checked against the CPU reference before timing. `vs #102` is against `[256, 128] s3`. | rung | shared B | CTA/SM | 8192³ TFLOP/s | vs #102 | 16384³ TFLOP/s | vs #102 | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | [256,128] s2 | 49224 | 4 | 844.6 | −35.3% | 934.2 | −30.0% | | [256,128] s3 | 73816 | 3 | 1305.9 | — | 1333.8 | — | | [256,128] s4 | 98408 | 2 | 1206.0 | −7.7% | 1361.5 | +2.1% | | [256,256] s2 | 65608 | 2 | 1285.2 | −1.6% | 1503.8 | +12.7% | | **[256,256] s3** | 98392 | 2 | **1457.1** | **+11.6%** | **1622.5** | **+21.6%** | `[256, 128] @ STAGES = 4` is the row #87's table does not have and the reason the rest is readable: same shared plan and same residency as the winner, at unchanged tile. It prices the occupancy step alone at −7.7% / +2.1%, leaving the tile worth **+20.8% / +19.2%** net. Two things fall out that are not #87's argument. A **fourth pipeline stage nearly pays for the CTA it costs** — #98 priced that step at 13.6–16.1% on dead bytes, and with a live stage it is 7.7% and −2.1%. And the reverse trade is a disaster: `[256, 128] @ STAGES = 2` steps residency *up* to four CTAs an SM, with the best wave efficiency and the best reuse in the table, and loses 35%. ## Which mechanism: intensity, and boundary count has the wrong sign The two scale differently with `K`, so `gemm-depth` was re-run on the new tile: | points | steady TFLOP/s | fixed ms | per tile | | --- | ---: | ---: | ---: | | K = 8192, 32768 | 1480 → **1826** | 0.0865 → 0.1504 | 8.6 → 21.5 µs | | all four | 1538 → **1862** | 0.1835 → 0.1903 | 18.3 → 27.2 µs | **The slope moved 21–23% and the intercept rose 74%.** Arithmetic intensity is the whole win, agreeing with the control's +19–21% from different arithmetic. Boundary count is not a mechanism: halving the tiles does not halve the boundaries on the critical path, because the occupancy step halves the clusters too — items per cluster fall 10 → 7 while a boundary draining twice the columns costs more than twice as much. This was **pre-registered as the opposite** — that boundary count was the stronger mechanism and intensity would be worth nothing against a ceiling — and it was wrong on both halves, in opposite directions. ## Counted, not predicted `tmem residency census` at all four envelopes, `shared per SM` queried: | rung | columns | shared B | budget | resident | holding | wait µs | | --- | ---: | ---: | ---: | ---: | ---: | ---: | | [256,128] s2 | 128 | 49224 | 4 | 4 | 4 | 0.9 | | [256,128] s4 | 128 | 98408 | 2 | 2 | 2 | 0.9 | | **[256,256] s2** | 256 | 65608 | 2 | **3** | **2** | **100.0** | | [256,256] s3 | 256 | 98392 | 2 | 2 | 2 | 0.9 | Predicted and counted agree at all four. The third row is the **first rung in this repo where the `512 / columns` half of the residency formula binds**, and the first where `resident` and `holding` differ: a CTA admitted and parked inside a blocking `tcgen05.alloc`, with the wait column as direct evidence. ## Cost **168 registers, 0 spill, 528 B frame on every entry point** — unchanged. Not automatic: a `RegTile<32, 256>` band is 256 fp32 a thread, so the epilogue drains in two 128-column bands (`DRAIN_N`), which the ladder in the same run says was necessary. The step also bought **87 registers of headroom**, since the 2-CTA ceiling is 255 rather than 168. What it did cost is **generality and the small end**: `n % 256 == 0` where 128 used to do, and 1024³ regresses 18% (98.0 → 79.9 TFLOP/s). Above 2048³ every row improves. Both are in §7 rather than left to be found.
`cargo fmt` at the root formats the library only — `examples/` and `device-tests/` are separate manifests, and tier 1 checks all three.
This was referenced Jul 28, 2026
The [256,256] tile costs 18% at 1024 cubed and n % 256, and nothing picks between the two tiles
#105
Closed
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
Tier 1 checks the library, device-tests and examples. A root `cargo fmt` reaches only the first -- the other two are separate workspaces -- so a change can be clean locally and red in CI on whitespace alone. That has happened three times (#97, #104, #109), each costing a review round trip on a gate that runs in twenty seconds.
feitreim
added a commit
that referenced
this pull request
Jul 29, 2026
… says scope four ways (#133) * Audit the library whole: three doc claims were wrong, and the surface says scope four ways `src/` is 10 156 lines and nobody had read it whole since it grew. This is that read, against Finn's three areas: API coherence, missing coverage, docs vs reality. No API changes -- findings are issues, and the only edits here are documentation corrections, where a stale doc is the finding and the fix. Corrected in `src/`: - `reg.rs`'s module header said "the measurement does not favour" the SFU `exp2`, on a register count. Timed on `softmax`, it is 2.7x the other way (#76/#81). The "ex2.approx serializes" claim had no probe and is removed, not restated. The default does not move: that is #81's call and `flash_forward` has no reference to check one against. - `tmem.rs`'s occupancy table said `gemm` allocates 128 columns and is capped by shared memory at 3 CTAs. Since #104 it asks for `BLOCK_N = 256` and tensor memory is the resource that binds it. - `ldst.rs`'s store contracts required "all 32 lanes of the warp owning TMEM rows row..row+16". Nothing in `ldst` touches tensor memory; the clause was `tmem.rs`'s, where it is correct, and the load side never had it. - Two dangling `#56` citations in `reg.rs`, predating this repo's issue #56 by a day and unresolvable against it. `GAPS.md` gains a section 7 -- the coherence of the surface itself, which no comparison against ThunderKittens finds -- and loses two entries that had gone stale inside a day: 2.2 said `GlobalRows` was fp32-only after #108 gave it an element, and 4 said the pipeline scaffold had no caller after `gemm` had been running on it since #83. Both are now named in `tests/gaps.rs`, along with the `.x8` drain, the `.x4` store, the store ring's `Scope`, the cluster charge and the operand-order square. Nine issues filed (#124-#132) and two comments on #14 and #42. * reg.rs: state the correction, let #81 carry its history * GAPS 7.4: the drain loop is shared, the preambles are not
feitreim
added a commit
that referenced
this pull request
Aug 6, 2026
…st picks from the shape (#105) (#209) #104 promoted the pair tile to `[256, 256] @ STAGES = 3` and stated its two costs rather than burying them: `n % 256 == 0` where 128 used to do, and 18% at 1024 cubed. Both rungs stayed launchable, so the material for a fix was already in the file. What did not exist was anything choosing between them, or any measurement to choose by — the sweep had both tiles at 8192 cubed and 16384 cubed and the crossover is somewhere below 2048 cubed, which nothing had timed. `bench --case crossover` is that measurement. Four rungs across eight shapes: the pre-#104 kernel as the denominator, `[256, 128] @ s4` to price the occupancy step at a fixed tile, `[256, 256]` fused to price the tile at a fixed epilogue, and `[256, 256]` on `staged84` because that is what actually launches. Its own case rather than a fifth table on `tile`, which costs most of an hour where this costs a minute — a measurement the next tile change has to re-take should be cheap to re-take. It was run three times, and the reason is in the answer: those rows are 12-23 microsecond launches and #98's 2.9% of drift between containers is 10-12% down there. What reproduces is the sign. 512 and 1024 cubed lose on every run, 2048 cubed and above win on every run, and 1536 cubed straddles zero — so the crossover is bracketed at 36 < T <= 64 output tiles of the wide rung. Which mechanism it is, since the issue asks rather than assumes: **the tile's parallelism, and the occupancy step is not reachable at all down there.** The same-tile arm reads -2.0%, +11.1% and +0.0% at 1024 cubed across the three runs — not a small effect measured imprecisely, no effect — and the `reached` column says why before the clock does: at 32 clusters on 148 SMs no SM is asked to hold a second CTA, so a rung admitted for 3 and a rung admitted for 2 run the identical schedule. #101's 14-16% is a price on a resource the small end is not spending. The loss tracks the SM column instead: at 1024 cubed the wide tile puts 32 SMs to work where the narrow one puts 64, and loses 8.4-11.9%. `gemm::plan_for` is the chooser, host-side beside the grid arithmetic. It thresholds on the wide rung's tile count and not on `n`, because tile count against SM count is the quantity the mechanism is about — a threshold on `n` would send 16384x512 to the narrow rung and that shape has a full grid. It picks an epilogue with the tile because it has to: `staged84` is built on the wide rung only. `bench_with` does not consult it, so every A/B's control arm still reads the rung it names. No rung is deleted. The acceptance holds by construction below the threshold — the fallback is `gemm_256x128_s3`, the pre-#104 entry point itself and not a reconstruction of it — and by measurement above it. `n = 1152` is a kernel rather than an error, `4096x4224x4096` runs at 1271.7 TFLOP/s, and `GEMM_SIZES`' `256x128x256` row is back. `check` grows the one shape class that was on no gate at all: every check size in this file divides both tiles, so the chooser's fallback route had never been computed by anything. It takes its plan from `plan_for`, so it tests the rule and not only the rung it happens to pick.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The pair tile was the lever, and the mechanism is not the one that looked stronger (#87)
gemm_cg2's pair tile is[256, 256]at three stages, not[256, 128]:+11.6% at 8192³ and +21.6% at 16384³, which is 1457.1 and 1622.5
TFLOP/s — the fastest this kernel has been measured at — and 0.826 and
0.886 of cuBLASLt against 0.740 and 0.728.
The pair tile and the pipeline depth are const parameters of
Tilenow, andbench --case tileis the sweep, with all four losing rungs kept.The re-fit first, because #102 invalidated the fit that ranked this
gemm-depthre-run on7ef5685, point selections all stated:The steady state did not move (1480–1538 against #91's 1515–1527), the ceiling
suspicion got stronger — four numbers by three routes in 1437–1480, with the
deepest measured row 2.9% under the asymptote where it used to be 10.6% under —
and the fit got worse as an instrument for the item boundary, because #102
put a K-dependent term into the intercept and the answer now moves 10.4% →
22.1% on point selection.
And the ceiling was a property of the tile
[256, 256]measures 1718.5 TFLOP/s atK = 32768, straight through thatband. Three shapes agreeing meant one shared term bound them; every one of the
three had the same tile.
The sweep, and the control that separates the mechanisms
Min ms over 30, static,
GROUP = 8, every row checked against the CPUreference before timing.
vs #102is against[256, 128] s3.[256, 128] @ STAGES = 4is the row #87's table does not have and the reasonthe rest is readable: same shared plan and same residency as the winner, at
unchanged tile. It prices the occupancy step alone at −7.7% / +2.1%, leaving
the tile worth +20.8% / +19.2% net.
Two things fall out that are not #87's argument. A fourth pipeline stage
nearly pays for the CTA it costs — #98 priced that step at 13.6–16.1% on dead
bytes, and with a live stage it is 7.7% and −2.1%. And the reverse trade is a
disaster:
[256, 128] @ STAGES = 2steps residency up to four CTAs an SM,with the best wave efficiency and the best reuse in the table, and loses 35%.
Which mechanism: intensity, and boundary count has the wrong sign
The two scale differently with
K, sogemm-depthwas re-run on the new tile:The slope moved 21–23% and the intercept rose 74%. Arithmetic intensity is
the whole win, agreeing with the control's +19–21% from different arithmetic.
Boundary count is not a mechanism: halving the tiles does not halve the
boundaries on the critical path, because the occupancy step halves the clusters
too — items per cluster fall 10 → 7 while a boundary draining twice the columns
costs more than twice as much.
This was pre-registered as the opposite — that boundary count was the
stronger mechanism and intensity would be worth nothing against a ceiling — and
it was wrong on both halves, in opposite directions.
Counted, not predicted
tmem residency censusat all four envelopes,shared per SMqueried:Predicted and counted agree at all four. The third row is the first rung in
this repo where the
512 / columnshalf of the residency formula binds, andthe first where
residentandholdingdiffer: a CTA admitted and parkedinside a blocking
tcgen05.alloc, with the wait column as direct evidence.Cost
168 registers, 0 spill, 528 B frame on every entry point — unchanged. Not
automatic: a
RegTile<32, 256>band is 256 fp32 a thread, so the epiloguedrains in two 128-column bands (
DRAIN_N), which the ladder in the same runsays was necessary. The step also bought 87 registers of headroom, since
the 2-CTA ceiling is 255 rather than 168.
What it did cost is generality and the small end:
n % 256 == 0where 128used to do, and 1024³ regresses 18% (98.0 → 79.9 TFLOP/s). Above 2048³ every
row improves. Both are in §7 rather than left to be found.