Skip to content

The two pair tiles cross over between 1536 and 2048 cubed, and the host picks from the shape (#105) - #209

Merged
feitreim merged 1 commit into
mainfrom
feat/tile-chooser
Aug 6, 2026
Merged

feitreim merged 1 commit into
mainfrom
feat/tile-chooser

Conversation

@feitreim

@feitreim feitreim commented Aug 6, 2026

Copy link
Copy Markdown
Owner

Closes #105.

#104 promoted the pair tile to [256, 256] @ STAGES = 3 and stated its two
costs rather than burying them. 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 instrument

bench --case crossover — four rungs across eight shapes, the sizes --case tile does not visit. Its own case rather than a fifth table there, because
tile is 8192³ and 16384³ dozens of times over and costs most of an hour: a
measurement the next tile change has to re-take should cost a minute.
This
one runs in 47-72 s.

Two of the four arms are instruments rather than candidates:

arm what it is
[256,128] k64 s3 the kernel this file shipped through #102 — the denominator, and what the acceptance is about
[256,128] k64 s4 that tile at the wide rung's residency, at unchanged tile count and waves — prices the occupancy step alone
[256,256] k64 s3 the tile moved at a fixed epilogue — #104's own arm
[256,256] k64 s3 staged84 what actually launches

The timing table

Run 3, in full, losing rows kept. B200, driver 580.95.05, one container,
--features cublas, every row checked element by element against the CPU
reference before it was timed.

shape rung tiles SMs wave eff CTA/SM reached min ms TFLOP/s vs #102
512³ [256,128] s3 8 16 3.6% 3 1 0.0119 22.6 —
512³ [256,128] s4 8 16 5.4% 2 1 0.0123 21.8 −3.1%
512³ [256,256] s3 4 8 2.7% 2 1 0.0136 19.7 −12.7%
512³ [256,256] s3 staged84 4 8 2.7% 2 1 0.0138 19.5 −13.5%
1024³ [256,128] s3 32 64 14.4% 3 1 0.0151 142.5 —
1024³ [256,128] s4 32 64 21.6% 2 1 0.0151 142.5 +0.0%
1024³ [256,256] s3 16 32 10.8% 2 1 0.0162 132.6 −6.9%
1024³ [256,256] s3 staged84 16 32 10.8% 2 1 0.0164 130.6 −8.4%
1024x1152x1024 [256,128] s3 36 72 16.2% 3 1 0.0156 154.7 —
1024x1152x1024 [256,128] s4 36 72 24.3% 2 1 0.0156 155.0 +0.2%
1024x1152x1024 [256,256] s3 — — — — — — — n % 256 != 0
1536³ [256,128] s3 72 144 32.4% 3 1 0.0191 379.4 —
1536³ [256,128] s4 72 144 48.6% 2 1 0.0186 389.8 +2.8%
1536³ [256,256] s3 36 72 24.3% 2 1 0.0202 358.4 −5.5%
1536³ [256,256] s3 staged84 36 72 24.3% 2 1 0.0193 375.6 −1.0%
2048³ [256,128] s3 128 148 57.7% 3 2 0.0236 729.4 —
2048³ [256,128] s4 128 148 86.5% 2 2 0.0237 725.5 −0.5%
2048³ [256,256] s3 64 128 43.2% 2 1 0.0225 763.7 +4.7%
2048³ [256,256] s3 staged84 64 128 43.2% 2 1 0.0228 754.0 +3.4%
3072³ [256,128] s3 288 148 64.9% 3 3 0.0561 1034.2 —
3072³ [256,128] s4 288 148 97.3% 2 2 0.0519 1117.8 +8.1%
3072³ [256,256] s3 144 148 97.3% 2 2 0.0440 1317.8 +27.4%
3072³ [256,256] s3 staged84 144 148 97.3% 2 2 0.0422 1373.7 +32.8%
4096³ [256,128] s3 512 148 76.9% 3 3 0.1087 1264.0 —
4096³ [256,128] s4 512 148 86.5% 2 2 0.1128 1218.4 −3.6%
4096³ [256,256] s3 256 148 86.5% 2 2 0.0977 1407.3 +11.3%
4096³ [256,256] s3 staged84 256 148 86.5% 2 2 0.0953 1442.2 +14.1%
4096x4224x4096 [256,128] s3 528 148 79.3% 3 3 0.1115 1271.7 —
4096x4224x4096 [256,128] s4 528 148 89.2% 2 2 0.1163 1219.2 −4.1%
4096x4224x4096 [256,256] s3 — — — — — — — n % 256 != 0

SMs is min(2·tiles, 148) — SMs the launch puts a CTA on at all. reached
is ceil(CTAs / 148), the CTAs an SM must hold for the grid to be placed,
against the CTA/SM the rung is admitted for.

The percentages do not reproduce; the routing does

Three runs in three containers. Those rows are 12-23 µs launches and #98's 2.9%
of drift is 10-12% down there:

shape shipped vs #102, run 1 run 2 run 3
512³ — −15.3% −13.5%
1024³ −11.9% −10.6% −8.4%
1536³ +0.5% −8.7% −1.0%
2048³ +5.2% +0.5% +3.4%
3072³ +29.4% +29.8% +32.8%
4096³ +14.6% +12.3% +14.1%

(Run 1 predates the paid column's correction and lost its 512³ rows to a
truncated capture; every other cell is one container each.)

512³ and 1024³ lose on every run, 2048³ and above win on every run, 1536³
straddles zero. The crossover is between 36 and 64 output tiles of the wide
rung
, and that is the whole of what these runs establish. Anyone quoting
"−8.4% at 1024³" is quoting one container.

Which mechanism: parallelism, and the step is not even reachable

The [256,128] s3 against s4 arm — same tile, same tile count, same waves,
same intensity, 3 CTAs an SM against 2:

shape reached run 1 run 2 run 3
512³ 1 — −11.5% −3.1%
1024³ 1 −2.0% +11.1% +0.0%
1024x1152x1024 1 −1.6% +4.8% +0.2%
1536³ 1 +0.2% −7.5% +2.8%
2048³ 2 −3.4% −7.8% −0.5%
3072³ 2 (from 3) +8.8% +6.9% +8.1%
4096³ 2 (from 3) −3.3% −3.7% −3.6%
4096x4224x4096 2 (from 3) −5.1% −6.4% −4.1%

Below 2048³ the occupancy step does not have a sign — −2.0%, +11.1%, +0.0%
at 1024³ is no effect, not a small one, 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 one admitted for 2 run the identical schedule.
#101's 14-16% is a price on a resource the small end is not spending.

So the small-size loss is quantization, and all of it: at 1024³ the wide
tile puts 32 SMs to work where the narrow one puts 64 and loses 8.4-11.9%; at
512³ it is 8 against 16 and 13.5-15.3%. The loss tracks the SMs column, and
the arm built to price CTA/SM returns noise.

Where the step is reachable it is −3.6 to −6.4% at 4096³ and above, and at
3072³ it is +8.1%: losing a CTA an SM shortens the grid from 222 clusters to
148, and 288 tiles divide into that at 97.3% wave efficiency against 64.9%. An
occupancy step whose sign is set by wave quantization is not a 14-16% constant,
and #101's figure should not be carried to sizes it was not taken at.

The rule as shipped

pub fn plan_for(m: usize, n: usize) -> Plan {
    let wide = n.is_multiple_of(SHIPPED.block_n)
        && tiles(m, n, SHIPPED.block_n) >= CROSSOVER_TILES;
    ...
}

CROSSOVER_TILES is 64 — the upper end of the measured bracket, because
everything between 36 and 64 is unmeasured and a rule that has to guess should
guess toward the rung that was already shipping. Tiles, not n: the
mechanism is tile count against SM count, and a threshold on n would send
16384x512 — 32 wide tile-rows and a full grid — to the narrow rung.

It picks an epilogue with the tile because it has to: staged84 is built on the
wide rung only, so the narrow route gives up #119's epilogue, and that cost is
inside the numbers above rather than beside them. bench_with does not
consult it — a control whose rung moved with the shape would not be one — so
gemm_ws' control arm and every A/B in gemm.rs still read the rung they name.
grid and wave_efficiency do consult it, because bench launches it.

The chooser's own row, run 3, against the better of the two arms it was choosing
between (the two controls are excluded — scoring a rule against a rung it may
not pick measures nothing):

shape chose chosen ms best ms paid
512³ [256,128] s3 0.0119 0.0119 0.0%
1024³ [256,128] s3 0.0151 0.0151 0.0%
1024x1152x1024 [256,128] s3 0.0156 0.0156 0.0%
1536³ [256,128] s3 0.0191 0.0191 0.0%
2048³ [256,256] s3 staged84 0.0228 0.0228 0.0%
3072³ [256,256] s3 staged84 0.0422 0.0422 0.0%
4096³ [256,256] s3 staged84 0.0953 0.0953 0.0%
4096x4224x4096 [256,128] s3 0.1115 0.1115 0.0%

Run 1's threshold left 0.5% at 1536³ and run 2's left none; the column is zero
or inside the drift at every row of every run.

Acceptance

No rung is deleted. "No shape that worked before #104 is slower after this"
holds by construction below the threshold: the fallback is gemm_256x128_s3,
which is not a reconstruction of the pre-#104 kernel but the entry point itself,
kept launchable by #104 as its control. Below 64 wide tiles, and at every n
the wide tile cannot divide, the launch is byte for byte the one that shipped.
Above the threshold it is faster, on three runs.

And the constraint the issue opens on is gone from the call site: n = 1152 is
a kernel rather than an error, 4096x4224x4096 runs at 1271.7 TFLOP/s and 0.769
of cuBLASLt, and GEMM_SIZES' 256x128x256 row — the one-cluster-one-item
floor #87 had to delete — is back.

gemm::check grows the one shape class that was on no gate at all: every check
size in the file divides both tiles, so the 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.

The denominator

cuBLASLt in the same container, run 3. Not a flattering table and the one worth
keeping: below 2048³ this kernel is 0.59-0.68 of a vendor GEMM whichever tile it
picks. The chooser stops #104 widening that gap; it recovers none of it.

shape cuBLASLt ms theirs TF/s #102/theirs chosen/theirs
512³ 0.0081 33.3 0.677 0.677
1024³ 0.0099 216.5 0.658 0.658
1024x1152x1024 0.0092 263.1 0.588 0.588
1536³ 0.0118 613.8 0.618 0.618
2048³ 0.0188 913.0 0.799 0.826
3072³ 0.0388 1493.8 0.692 0.920
4096³ 0.0837 1641.8 0.770 0.878
4096x4224x4096 0.0857 1654.5 0.769 0.769

Gates

GitHub Actions is in an outage; run by hand on this branch's head, rebased onto
origin/main at 2703360 (#206).

gate result
scripts/fmt --check clean
cargo test (library) 84 passed
scripts/modal-run build green — clippy on four crates, host tests 127 + 90, cargo doc --features host, sm_100a codegen of all three kernel crates, plus the --features cublas build
scripts/modal-run regcount green — "every gated kernel is inside its step"; gemm_cg2_staged_x8x4 at 80 registers and gemm_256x128_s3 at 168/0/0, both unchanged, since no kernel source moved
scripts/modal-run examples green — 10 pass, 0 fail, including 512x384x256 exact on [256,128] k64 s3 (n % 256 != 0, so the chooser has no other rung)
scripts/modal-run bench --case crossover ×3, the measurement above

device_tests was not run: no src/ or device-tests/ file is touched and the
diff is host-side dispatch and documentation.

What the next tile change has to re-measure

CROSSOVER_TILES is a property of this pair of rungs on this device. Move
either tile, move SHIPPED_EPILOGUE, or change MAX_CLUSTERS and the bracket
moves. The instrument is bench --case crossover, it costs a minute, and the
thing to read off it is which choosable arm wins at each size — not the
percentage, which below 2048³ does not survive a change of container.

…st picks from the shape (#105)

#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.
@feitreim
feitreim merged commit c251d72 into main Aug 6, 2026
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.

The [256,256] tile costs 18% at 1024 cubed and n % 256, and nothing picks between the two tiles

1 participant