Repository navigation
The item map walks in groups, and the 23% the aspect ratio cost is recovered (#89) - #102
Merged
Merged
Conversation
…43.9/1466.3 coincidence without claiming it
feitreim
force-pushed
the
l2-aware-traversal
branch
from
July 28, 2026 22:19
293f25c to
73973a0
Compare
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
…oked stronger (#87) (#104) * 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 `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. * rustfmt the examples crate against its own manifest `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
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.
Closes #89.
pipeline::groupedreplaces the GEMM's row-major item map with one that walksGROUPtile-rows down a column before moving right. It is one line inJob::work, the width is a launch parameter with a sweep behind it, andGROUP = 1is the row-major map — so the control in every table below is aparameter value and not a second code path.
8192³ goes from 0.684 to 0.742 of cuBLASLt, and 16384³ from 0.685 to 0.793.
Two corrections to the issue text, carried into the work
#89's traffic arithmetic is wrong and is not repeated here. It argues from
"roughly 48× reuse", which is the aggregate over a whole launch. What L2 can
capture is the reuse inside one wave, which is 3×–15×. The 48× appears nowhere
in this PR.
Its sequencing says to wait for #86 to establish the bound. That was met by
something better. #90 ran five shapes identical in flops, tiles, waves, grid,
Cbytes, operand bytes and arithmetic intensity, differing only inM : N.Throughput moved 1123.7 → 915.7 TFLOP/s, best and worst rows exact
transposes. A 23% swing nothing but access order can explain is a direct
measurement of the thing this PR exploits, and it is what I started from.
Predictions, stated before the run
256r + 128csubjectto
r · c = 222givesr ≈ 10.5.2048x32768gains most and32768x2048,already walking a near-square wave, regresses.
largest
K.Four were right. The fifth was wrong, and it is the most useful row in the PR.
1. The width, at 8192³, both schedulers — losers kept
Min ms over 30 timed launches, every row checked against the CPU reference first.
reuseis arithmetic on the item map; it reproduces #90's published column forgroup 1at all five aspect ratios to the printed digit.The curve turns over — 32 is back where 1 was — which is what says the
mechanism is the wave's shape rather than "more grouping is better".
group 2is the sharpest row: same 4 x 64 wave, same 9.2×, because at
tiles_n = 64twotile-rows still take 128 items and 222 clusters spill into the next group either
way. It measures within 1.3% of row-major, which is this benchmark's own spread.
A width that does not move the reuse does not move the clock.
GROUP = 8is set from this table, at this tile shape. #87 moves the tile,which moves this — hence a parameter and a sweep rather than a written-in
swizzle.
2. The mechanism, and the prediction I got backwards
MandNare 8192 throughout, so tiles, waves, grid,Cbytes and the wave'sworking set are identical and only the operand footprint moves. Static,
min ms / TFLOP/s:The gain is a band, not a ramp. The shallow end was predicted and arrives,
and it is the control the aspect table cannot supply: at
K = 512the traversalis worth nothing, so the 8.4% is not some fixed cost the change happens to
remove — the same change against the same tiles, waves and grid does nothing when
the operand stream is trivial.
The deep end was predicted backwards.
K = 32768was supposed to gain mostand loses 2.2%.
The hypothesis, stated as one: the traversal only pays where operand delivery
is on the critical path, and neither end of this sweep is there. At
K = 512the launch is the item boundary (0.271 ms for ten items, against #90's 18–30 µs
per tile) and the operand stream is 348 GB/s where
layernormreaches 5497. AtK = 32768the kernel is at 1443.9 TFLOP/s — inside #90's derived steady stateof 1480–1550 — so it is pipeline-bound, the traffic the swizzle removes was not
being waited on, and what is left is its cost. That cost is real and this is
where it shows: a grouped walk makes consecutive items write
Cdown a columnrather than across a row, which is worse locality on the one stream the traversal
does not help.
So the L2-residency framing gets
K = 512right for roughly the wrong reason —it is not that 16 MiB fits L2, it is that 16 MiB is not enough traffic to wait
on — and gets
K = 32768wrong outright. I think #89 overclaims here, and Iwould state the generalization more narrowly than it does: a traversal change
is worth something in the regime where operands bind, and this kernel is in that
regime at its benchmark sizes and out of it at
Kfar past them.#101 is independent evidence for that reading, taken for an unrelated reason.
It measures a lone CTA at a flat ~585–640 TFLOP/s across 4096³, 8192³ and
16384³ — so more than half of what this kernel achieves at any size is one
CTA's stall covered by another's work, and overlap between CTAs is the dominant
mechanism everywhere. A row already at 1443.9 TFLOP/s has that resource close to
spent, and there is little uncovered stall left for cheaper operand delivery to
remove. Two measurements pointing the same way beats a better argument for one.
3. The aspect ratio — #89's falsifiable prediction, tested
Confirmed, including its sign on the row that was supposed to lose. Row-major
spans 1041.1 → 1306.5 TFLOP/s, a 25.5% spread; grouped spans 1293.0 → 1328.4, a
2.7% spread. Every gain is ordered by the reuse recovered, and
32768 x 2048— the one shape already near-optimal, whose reuse the swizzlelowers — is the one row that gets worse. A prediction that only says "faster"
is not falsifiable; this one named the row that would regress.
#89 predicted "up to 23% at the worst aspect ratio against 6–7% square". Measured:
27.6% and 8.4%. Conservative in both places.
(The
group 1numbers are all above #90's — 1306.5 against 1123.7 and so on —because #91's paired fp32 store landed in between. The spread is the comparable
quantity: 22.7% there, 25.5% here.)
4. Before and after, both schedulers, with the denominator
The two
group 1ratios reproduce #96's 0.689 and 0.694 within this file'sspread, which is what says the control is the kernel that was already there.
1466.3 TFLOP/s is the fastest this kernel has measured, past #90's 1369.9,
and 65% of dense bf16 peak.
16384³ gains more than 8192³ — 13.6% against 8.4% — and it is not noise. A
square
M : Nis not a square wave. 16384³ has a 64 x 128 tile grid, so 222clusters walked row-major span two tile-rows and all 128 columns: a 2 x 128 wave
at 5.0× reuse — exactly the
4096 x 16384row above, which gained 15.5%. Thetwo agree. 16384³ is still the least reproducible row in this repo, but a gain
measured against its own control in the same run, landing where a shape with the
same reuse independently landed, is outside the 5.5% cross-run spread that caveat
is about.
It composes with CLC rather than replacing it. The swizzle applies to the
item; both item sources hand out a permutation of
0..tiles, andgroupedbeing a bijection makes it correct under either by construction. Both schedulers
pick the same width, both gain, by the same amount (8.4% static, 7.7% CLC at
8192³).
And most of what CLC was winning, the swizzle was already winning. At 16384³
CLC was 4.2% ahead of the static stride row-major (6.9461 → 6.6635) and is
0.1% ahead of it grouped (5.9990 → 5.9933). At 8192³ the same collapse, 1.4%
→ 0.7%. #97 argued CLC's case was portability rather than throughput and had one
measurement for it; this is a second, from a different direction — the throughput
CLC was recovering was a traversal problem, and once the traversal is fixed there
is close to nothing left for the dynamic schedule to win. The portability case
is unaffected and is now the whole case.
Cost: none
ptxas -v -arch=sm_100a, samemodal_app.py::regcounton this tree and onc802627:gemm_cg2before / aftergemm_cg2_clcbefore / afterThe cliff at 170 was not approached and residency is the same 3 CTAs/SM. Two
integer divides per output tile against a 20–30 µs item boundary is not something
this harness can see. #100's occupancy-step gate passes — the shared plan is
byte-identical, so the kernel sits on the same side of the step it did before.
(Note the brief said 167; the current tooling reports 168 for
c802627as well,so the delta is 0 either way.)
#101 is what makes this more than a null result. It priced one CTA an SM at
14–16%, with a 25–44% cliff behind it. This traversal spends no shared
memory, no registers and no TMEM, so it pays none of that: the 8.4% and 27.6%
above are not net of an occupancy step. It is currently the only lever this
repo has measured that is free of the resource cliff, and both levers still on
the table have to buy their gains out of a budget it did not touch —
lcsf(#15)must hide most of the item boundary to clear one step, and #87's tile change can
afford the first step and must not take the second. A free lever and a lever with
a 14–16% entry fee should not be ranked as though equal nominal size meant equal
value.
Exactness, and where this map can be silently wrong
A wrong item map is a tile computed twice and a tile computed by nobody — the
same failure from either end, both silent on the device, both reaching the host
only as a wrong
C. Held two ways:src/pipeline.rsassertsgroupedis a bijection over every tile gridup to 17 x 17 at every width up to 19. That is what covers the short last group
a width not dividing
tiles_mleaves, which is the one branch in the map.modal run modal_app.py::examplesruns the GEMM at widths[1, 3, 6]under both schedulers at both correctness sizes — not powers of two,
deliberately: every
Mthis project runs is one, so a swept width of 8 or 16always divides
tiles_mand the short-group branch would never execute. At4096x4096's 16 tile-rows, 3 leaves a final group of one row and 6 leaves four;
at 512x256's two tile-rows both saturate.
All twelve pass, and every timed row above is checked before it is timed by the
same entry point (
bench's rule 1 has no exception here).What I could not establish: the L2 hit rate
#89's acceptance asks for it either side and it is the right demand — a
throughput win with an unchanged hit rate would mean the cause was something
else. Saying so plainly rather than dropping it:
There is no L2 hit rate available on this harness. Nsight Compute is in the
image and cannot start — the injected driver set has no
libnvidia-pcc.so, whichis not in the 580.95.05 package either — and
modal_app.py::profileis checkedin documenting exactly this. Same wall #86 and #90 hit; nothing here moved it. I
did not spend a B200 container re-confirming a negative that is already written
down in the repo.
What stands in for it, and why I think it is not much weaker:
reusecolumn is arithmetic on the item map, calibrated by reproducingThe item boundary is roughly a third of 8192 cubed, and the curve stops where the waves said (#86) #90's published column exactly at all five aspect ratios.
where the effect vanishes when the operand stream is not the bottleneck, and
table 3, where the effect tracks predicted reuse across five shapes holding
nine other things fixed. A counter attributes; an intervention that moves one
variable establishes cause.
It remains true that a hit rate would have been worth having, and that this PR
cannot fully separate "fewer L2 misses" from "fewer DRAM reads".
Shape of the change
src/pipeline.rs—pub fn grouped(item, rows, columns, group), itsmodule-doc section, three host tests. It lives in the scaffold because it
composes with the item source instead of replacing it.
examples/src/gemm.rs— one line inJob::work;tiles_mandgroupaslaunch parameters;
Plan { scheduler, group };wave_reuse; theswizzlesweep. The redundant
tilesargument is gone —tiles_m * tiles_nis theitem count now that the map needs
tiles_manyway, so the launcher no longerpasses a total it had already told the kernel twice over.
examples/src/bench.rs—bench swizzledispatch, and three items madepubfor it.modal_app.pyis untouched. The sweep is reachable asscripts/modal-run bench --case swizzle, which rides the existing--casepass-through and already turns on
--features cublas— hence the cuBLASLt columnabove from the same container. That was deliberate: two changes to that file were
in flight, and both (#99's watchdog, #100's occupancy gate) have since landed
without touching this branch.
What this invalidates, which reviewers should know before merging
This PR moves the kernel that #90's K-depth sweep was fitted on, so the fit
that ranks everything queued behind it no longer describes the kernel. That fit
gives the item boundary as 20–22% of the launch (the intercept) and a steady
state of 1521 TFLOP/s (the slope), and both were measured row-major. Grouped
16384³ is 1466.3, close enough to the old slope that the fit is now
describing something that does not exist.
So "there is 20–22% of item boundary left to win" is what was true pre-#102 and
is not currently a supported claim.
gemm-depthneeds re-running on this treebefore #15 or #87 is ranked off it. I have not done that here — it is a separate
B200 sweep and the natural first act of whoever picks up #87 — but I have said so
in §7 rather than leaving the stale number standing unqualified.
A coincidence in my own data points the same way, and I am not claiming it.
K = 32768regressed under grouping at 1443.9 TFLOP/s; grouped 16384³ is1466.3. Two shapes with almost nothing in common landing within 2% is
consistent with a ceiling that is not operand traffic — which would matter far
more than this PR, since it would mean neither a bigger tile nor a store stage
touches what actually binds. Two points measured once each is not a ceiling.
What would test it is the re-fit above plus a third shape reaching the same
number by a third route; a
gemm-depthsteady state re-fitting near 1470 ratherthan 1521 would be the same suspicion from a fourth direction.
Rebase note
Rebased
c802627→99e5698. #100 and #101 changed.github/,CI.md,README.md,device-tests/,examples/README.md,modal_app.pyandscripts/— and nothing undersrc/orexamples/src/. So every kernel andharness byte behind the numbers above is unchanged by the rebase and no B200 was
re-booked for it. The one conflict was
examples/README.md, where #101's sectionand this one both attach after the CLC section; resolved by placing them in
order rather than by either winning, and they now cross-reference each other in
both directions.
::buildre-ran green on the rebased tree.::regcountI started by hand andthen killed — #100 made it a tier-2 CI job, so it runs on this PR
automatically and a local cold
sm_100abuild was duplicating it. The number itis expected to report is unchanged from the table above, since the shared plan
and the register count are both untouched; CI is the authority on it.
One note against the brief
gemm::compare(theclctable) now runs atGROUP = 8, so its absolutemilliseconds are no longer comparable to #97's. The difference between its two
columns still is, which is what that table is for, and its docstring now says so.