Skip to content

The item boundary is roughly a third of 8192 cubed, and the curve stops where the waves said (#86) - #90

Merged
feitreim merged 2 commits into
mainfrom
bind-gemm-86
Jul 28, 2026
Merged

feitreim merged 2 commits into
mainfrom
bind-gemm-86

Conversation

@feitreim

@feitreim feitreim commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Closes #86.

Revised after review. The first version of this PR reported the boundary
cost as 1508 TFLOP/s / 0.2948 ms / 28.8% without saying that the fit used
only K=8192 and K=32768
, which is precision the data does not carry and a
point selection a reader could not check. No measurement changed and no GPU
gate was re-run — only the stated precision, plus one explanation that turned
out to be wrong and is now removed. Details in §2.

The answer, in one line

The largest single term is the item boundary, not bandwidth. It costs
28–37 µs per output tile — 27–36% of the 8192³ launch — and with it
amortized the same kernel, no constant changed, measures 1369.9 TFLOP/s
(60.9% of dense peak)
against 1069.6 at 8192³. #86 asked which of HBM and L2
to attack; the biggest thing in the way is neither.

1. 16384³: it lands on the prediction, and I would not read one digit off it

Wave efficiency is tiles / (222 · waves); the last column is what the
prediction claims is constant.

shape tiles waves wave eff. min ms TFLOP/s ÷ efficiency
2048³ 128 1 57.7% 0.0472 363.7 631
4096³ 512 3 76.9% 0.1975 695.9 905
8192³ 2048 10 92.3% 1.0280 1069.6 1159
16384³ 8192 37 99.7% 7.4638 1178.5 1182

1182 against a predicted 1171 is inside the noise, and the climb — 631, 905,
1159 — stops. Confirmed, not refuted.

The caveat is real and I am not burying it. 16384³ is the least reproducible row
in the file: a second full run of this tree gives 7.8727 ms and 1117.3
TFLOP/s
, 5.5% away, where 8192³ repeats to 0.02% (1069.8 against 1069.6)
and every aspect-ratio row below to under 1%. Its median-to-minimum gap is 11%
against ~1% everywhere else. So the honest figure is 1117–1179 across two
runs, straddling 1171
. I ran the sweep twice for exactly this reason; on the
first run alone I would have reported "lower than predicted", and been wrong.

It fits: 3 × 512 MiB of bf16 operands plus a 1 GiB fp32 C is 2.1 GiB against
183 GiB. The size is bounded by host staging, which is why bench's Modal
timeout goes to 5400 s.

What this does not settle is what the kernel could do. Ragged waves were
the story from 2048³ to 8192³ — 42% of 2048³ is empty cluster slots — and by
8192³ only 7.7% is left, which is why 4× the work buys ~5–10%. It does not
follow that 1171 is a ceiling, and the next table refutes that directly.

2. It is not a ceiling: hold everything but K

M and N are 8192 in all four rows, so each has the same 2048 tiles, 10
waves, 92.3% efficiency, grid of 444, and 268 MB of C written — and the same
operand bytes per flop, since arithmetic intensity is a property of the
[256, 128] pair tile and not of the shape. Only the arithmetic between one
item boundary and the next moves.

K K blocks per item min ms TFLOP/s % of peak
512 8 0.4497 152.8 6.8%
2048 32 0.5404 508.6 22.6%
8192 128 1.0237 1074.0 47.7%
32768 512 3.2105 1369.9 60.9%

The fit, with its point selection stated

Milliseconds against K is a line whose intercept is a cost that does not scale
with the arithmetic. Dividing by 10 — the items on the critical path, since 50
clusters walk 10 and 172 walk 9 — gives a cost per output tile. Which points
the fit uses moves the answer, so here are all of them
, refitted by least
squares on the raw minimum milliseconds rather than on the rounded rates:

points steady state fixed per tile share at K=8192
K = 8192, 32768 1508 0.2948 ms 29.5 µs 28.8%
K = 2048, 8192, 32768 1534 0.3370 ms 33.7 µs 32.9%
all four 1552 0.3654 ms 36.5 µs 35.7%

That reproduces the review's reconstruction to the last digit, so the rounding
in the rates cost nothing. The other session runs 2–4% under all nine figures.
Across both sessions and every selection:

the boundary is 28–37 µs per output tile and 27–36% of the 8192³ launch, on
a steady state of 1480–1550 TFLOP/s.

Note the per-tile figures depend on the divisor: I use 10, the critical-path
item count. Dividing by the mean 9.23 instead gives 32–40 µs. The intercept also
folds in whatever is per-launch rather than per-item, so it is an upper bound
on the per-tile cost either way.

Why the two deepest points, and why the obvious defence is wrong

A two-point fit has no residuals, so it checks nothing. The defence that first
suggests itself — K = 512 is 8 blocks against STAGES = 3, so the pipeline
barely fills — is wrong, and the residuals say so. Under the four-point fit
they run +40.0, −2.1, −50.0, +12.0 µs, and the marginal cost of a K block
between adjacent rows is 0.378, 0.503, 0.569 µs — reproduced as
+34.1, −1.1, −43.3, +10.4 and 0.419, 0.522, 0.580 in the other session. A
pipeline that fails to fill makes shallow loops dear per block. These get
dearer as they deepen.

What is actually convex about it is a variable this sweep does not hold fixed,
and that is a limitation of my experiment rather than a subtlety.
K sets the
operand footprint: A and B are 8 MiB each at K = 512 and 512 MiB each at
K = 32768
, so the sweep crosses L2 between the second row and the third. The
shallow rows are cheap per K block partly because the whole of both operands is
L2-resident for the entire launch, which the deep rows cannot be.

So the deepest two are preferred because K = 8192 is the regime in question
and they straddle it in the same cache regime — not because the shallow rows
fill badly. A line through convex data has an intercept above the deep-end
tangent, which is exactly the ordering in the table, and it is why the preferred
selection is also the most conservative: it gives the smallest fixed cost of
any subset, so if anything it understates the finding.

The part that needs no fit at all is the measured 1369.9, sitting 28%
above 8192³ and 17% above the 1171
offered as where the curve would stop.

The measurement that would have moved if it were something else. Every
alternative is held fixed across those four rows: ragged waves (92.3% in all
four), occupancy (3 CTAs/SM per #83 and #84 — K does not touch the shared
plan), C traffic (268 MB in all four), operand intensity (85.3 FLOP/byte in
all four), grid (444 in all four). And it is not launch overhead — #67 settled
that, and layernorm reaches 9.2 µs on this harness in this same run.

What the boundary is, structurally. done.wait, sync_threads, LDTM of a
[32, 128] fp32 band into 128 registers a thread, then store_rows — one
st.global.f32 per owned value, 128 a thread. Under BaseLdtm a single one of
those stores has the warp's 32 lanes writing eight different rows of C,
four four-byte words each: 8 sector transactions for 128 useful bytes. Only then
does pipeline::run re-arm the barriers, and only then, a full memory latency
later, can the next tile's MMA start. Nothing in that chain overlaps. That is
the shape #15's lcsf changes; the scattered fp32 store is a second, separable
thing, and neither is in this issue's scope.

3. The small-size floor is one item boundary

256x128x256 is a single cluster running exactly one item: 23.4 µs, against
layernorm's 9.2 µs on the same harness in the same run. 512x256x256 is four
clusters at one item each: 23.3 µs. It is the same ~30 µs the depth sweep
priced, at 1/222 of the contention — not a launch cost, and not a floor peculiar
to small problems, but the per-tile cost showing up undivided because there is
only one tile to divide it by.

The check that makes this more than a coincidence of magnitudes: 2048³ is 128
clusters at one item each with K = 2048 and costs 47.2 µs, against the
depth sweep's 54.0 µs per item at the same K with 222 clusters contending.
Two shapes sharing nothing but their reduction depth land within 13% per item.

4. The traversal is worth 23%, and the issue's L2 arithmetic is optimistic

#86 reads 12.7 TB/s of operand traffic as "~48× reuse over 268 MB of unique
input". That is the aggregate ratio over a whole launch. What L2 can capture is
the reuse available inside one wave, and that is a property of the aspect
ratio: the 222 clusters of a wave sit on ceil(222 / tiles_n) rows of tiles,
span min(222·128, N) columns, and march through K together, so at one K
block they collectively touch (rows_of_A + columns_of_B) · 128 bytes.

Five shapes — each 2048 tiles, 10 waves, 92.3% efficiency, 444 blocks, 1.1
TFLOP, 12.9 GB of operands requested and 268 MB of C written. Identical
runs but for M : N:

shape tiles_n distinct per K block reuse min ms TFLOP/s
32768 x 2048 x 8192 16 0.72 MB 15.1× 0.9785 1123.7
16384 x 4096 x 8192 32 0.75 MB 14.5× 1.0005 1099.0
8192 x 8192 x 8192 64 1.18 MB 9.2× 1.0246 1073.1
4096 x 16384 x 8192 128 2.16 MB 5.0× 1.0710 1026.6
2048 x 32768 x 8192 256 3.67 MB 3.0× 1.2007 915.7

23%, monotone, on nothing but the walk — and reproduced row for row in the
other session (1112.6 / 1093.4 / 1066.4 / 1014.4 / 910.4, every row within 1%).
This one is measured end to end and involves no fit at all. The first and last
rows are transposes of each other with identical 570 MB total footprints, so
this is not about how much data there is; it is about which operand a row-major
item map re-reads. The reuse the map leaves L2 is 3× to 15×, never the 48× the
aggregate suggests
. That is #89, and this is the number it is worth.

Not HBM saturation. layernorm moves 5497 GB/s of real streaming traffic on
this device in this same run, and the worst row above is inferred to pull
~3.8 TB/s against that. Nor is the response a cliff, which is what saturation
looks like; it is proportional, which is what an exposed miss latency looks like
against a pipeline STAGES = 3 deep.

Subtracting the boundary gives the steady-state rate per shape

Over the range of intercepts the point selections give, and both sessions:

shape steady TFLOP/s
32768 x 2048 x 8192 1540 – 1790
8192 x 8192 x 8192 1500 – 1670
2048 x 32768 x 8192 1210 – 1320

So this tile shape, boundary overlapped and walk L2-aware, is worth roughly
1550–1800 TFLOP/s — 69% to 80% of dense bf16 peak — with no change to the tile,
the stages or the traversal granularity.
The range is wide because the two
uncertainties compound in the same direction: a larger fixed cost implies a
larger recovered rate.

It is a derivation, not a measurement, and it stacks two assumptions — that
the line is the right model, which its own residuals say it is only roughly, and
that the intercept is shape-independent, which it should be since all three rows
write the same C over the same item count. Nothing has run at any of these
rates.
The fastest this kernel has been measured at is 1369.9 TFLOP/s, and
that is the number to hold anyone to. What the derivation is for is ordering the
levers.

What I could not measure, and it matters which

The distinct per K block and reuse columns are arithmetic on the item
map
, not counters. There is no measured L2 hit rate or DRAM byte count in this
PR, and here is why.

Nsight Compute 2025.3.0 is already in the image at /usr/local/cuda/bin/ncu,
it lists gb100 among the chips it knows, libnvperf_target.so is in the
install, and /proc/driver/nvidia/params reports RmProfilingAdminOnly: 0. It
still refuses:

Failed to initialize the profiler: LibraryNotLoaded.
Check that a compatible driver library is loaded.

The injected driver set under /usr/lib/x86_64-linux-gnu carries
libnvidia-ml, -nvvm, -ptxjitcompiler, -allocator, -gpucomp and the
graphics libraries, and no libnvidia-pcc.so — the performance-counter
library the container runtime does not mount for the compute capability set. I
tried fetching it out of the matching 580.95.05 .run package; it is not in
there either. modal_app.py::profile is checked in with all of that in its
docstring, so it is one command whenever the library appears.

The substitute is not strictly weaker. A counter attributes; an intervention
that holds nine things fixed and moves one establishes cause. All three tables
above are interventions, and each has a stated quantity that would have moved
if the answer were something else. §2 is also honest that the depth sweep holds
nine things fixed and not the tenth.

What binds it at 8192³, in order

The order is the finding: #87's tile sweep should stay queued behind #15 and
#89, not just behind this issue.
Committing to a shape before the boundary is
overlapped would tune against a term that is around a third of the time.

Scope

No kernel constant moved. BLOCK_M, BLOCK_N, BLOCK_K, STAGES,
CTAS_PER_SM, MAX_CLUSTERS, the traversal and the shared plan are byte for
byte what they were. What changed:

  • examples/src/bench.rs: 16384³ in GEMM_SIZES; two new diagnostic cases,
    gemm-footprint and gemm-depth; bench <case> [<m> <n> <k>] to narrow the
    sweep to one table or one row.
  • examples/src/gemm.rs: documentation only — the boundary result in the
    module header, and one stale sentence corrected. The exactness argument said
    "the benchmark's largest K of 8192", which the new sizes make 32768; the
    partial-sum bound goes to 983,040 against fp32's exact integer range of
    16,777,216, so every size here is still compared with ==.
  • examples/README.md §7: the four tables and the argument.
  • modal_app.py: bench takes --case/--m/--n/--k and 5400 s; the profile
    entry point and its note.

Every timed figure went through bench.rs's checked path. No new route prints a
throughput for a launch it did not verify — the single-size selection narrows
which Case runs and changes nothing about the order of check and clock.

Verification

  • modal run modal_app.py::build — exit 0, all seven steps including
    RUSTDOCFLAGS=-D warnings cargo doc --features host and a real
    cargo oxide build --arch sm_100a of both crates.
  • modal run modal_app.py::examples — pass gemm 512x256x256 exact (4 tiles over 4 clusters), 4096x4096x256 exact (512 tiles over 222 clusters),
    pass softmax, pass layernorm.
  • modal run modal_app.py::bench — the full sweep twice, plus dedicated runs of
    --case gemm-footprint and --case gemm-depth. Every table above is from one
    full-sweep session; the reproduction figures are from the others.
  • Locally: cargo fmt --check (both crates), cargo clippy --all-targets -D warnings, cargo test (76 + 1).

B200, driver 580.95.05, 1965 MHz max SM clock, 148 SMs, 183359 MiB.

The revision above is text and arithmetic on measurements already taken; the
device gates were not re-run for it, and no number they produced has changed.

feitreim added 2 commits July 28, 2026 15:23
…he waves said (#86)

Three sweeps in `bench.rs`, no kernel constant touched.

- 16384^3 measures 1178.5 and 1117.3 TFLOP/s over two full runs, straddling
  #86's ~1171 prediction. The climb stops: normalized by wave efficiency the
  column goes 631, 905, 1159, 1182.
- `GEMM_DEPTH_SIZES` holds M, N, tiles, waves, grid and C traffic fixed and
  sweeps K. 152.8 / 508.6 / 1074.0 / 1369.9 TFLOP/s at K of 512 / 2048 / 8192 /
  32768 -- so 1171 is not the ceiling. The fit is a 1508 TFLOP/s slope on a
  0.2948 ms intercept: ~30 us per output tile, 28.8% of the 8192^3 launch, and
  the same ~30 us as the flat floor at the small end.
- `GEMM_FOOTPRINT_SIZES` holds every one of those fixed *and* the operand bytes
  requested, and sweeps the aspect ratio. 1123.7 down to 915.7 TFLOP/s, 23%,
  monotone in the reuse the row-major walk leaves L2 -- 3x to 15x, not the 48x
  the aggregate suggests.

Subtracting the boundary puts the steady state at ~1600 TFLOP/s, 71% of dense
peak, for this tile unchanged.

`bench <case> [<m> <n> <k>]` narrows the sweep to one table or one row, and
`modal_app.py::profile` records why Nsight Compute cannot answer this on Modal:
`libnvidia-pcc.so` is not in the injected driver set.
…ange (#86)

The first version reported 1508 TFLOP/s / 0.2948 ms / 28.8% without saying the
fit used only K=8192 and K=32768. No measurement changed; the stated precision
did, and one explanation came out.

- Refit by least squares on the raw min-ms over three point selections. Fixed
  cost 0.2948 / 0.3370 / 0.3654 ms, steady state 1508 / 1534 / 1552 TFLOP/s;
  the other session runs 2-4% under all nine. Reported as 28-37 us per tile,
  27-36% of the 8192^3 launch, 1480-1550 TFLOP/s steady.
- The two deepest points stay preferred, but NOT for the pipeline-fill reason:
  the residuals (+40.0, -2.1, -50.0, +12.0 us) and the marginal cost of a K
  block (0.378, 0.503, 0.569 us) both go the other way, reproduced in both
  sessions. The curve is convex because the sweep does not hold the operand
  footprint fixed -- A and B are 8 MiB each at K=512 and 512 MiB each at
  K=32768, crossing L2 between the second row and the third. That limitation
  now sits in `GEMM_DEPTH_SIZES`' own doc.
- The recovered steady state becomes ~1550-1800 TFLOP/s, labelled a derivation
  stacking two assumptions, against a fastest measured 1369.9.
@feitreim feitreim changed the title The item boundary is 29% of 8192 cubed, and the curve stops where the waves said (#86) The item boundary is roughly a third of 8192 cubed, and the curve stops where the waves said (#86) Jul 28, 2026
@feitreim
feitreim merged commit 9d9a47b into main Jul 28, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 28, 2026
…are at 0.69 of it (#92) (#96)

* cuBLASLt beside the GEMM, in-process and checked first (#92)

* The measured ratio, both runs, and what cuBLASLt's 1791-1947 says about #90's derivation (#92)

* Re-measure both columns on one tree after #94: 0.69 where the ratio is stable, and cuBLASLt prices the target (#92)
feitreim added a commit that referenced this pull request Aug 6, 2026
…ints stop remembering it (#132) (#200)

* The drain a deferred job owes is `Job::finish`, and thirteen entry points stop remembering it (#132)

A job that defers its last item's store owed one drain after the item loop, and
the trait provided nowhere to put it: both deferred jobs invented a `pending`
field with a `u32::MAX` sentinel and a `finish()` the *entry point* had to call.
`gemm_ws` has nine entry points and so had nine chances to forget it, and
forgetting it is a whole output tile computed by nobody.

`Job::finish` is that place — empty default, so it costs nothing for a job that
does not defer, and called by both `run` and `run_stealing` after their loops.
It runs after the loop's last `inval` and before the caller's `dealloc_*`, which
is exactly where all thirteen hand-rolled calls already sat, so no launch's
instruction stream moves.

The call sites removed: `gemm_cg2_lcsf`'s `job.finish()`, the nine in
`gemm_ws`, and the three `job.ring.drain()` the `StoreRing` entry points carried
— the same shape of obligation, named by #132 as such.

Also written down in `pipeline.rs`, where #132 asks for it: a
warp-asynchronous item stream is out of scope for this trait, why it is a
decision rather than an omission, and what the decision costs — #90 and #94 put
the item boundary it buys at a fifth to a third of the launch. That argument
lived only in `experiments/src/gemm_ws.rs`, which is being restructured.

* The empty default is about a job that defers nothing, not about an empty cluster

* The drain a job owes is the hook's, and docs/library/pipeline.md says so too (#132)
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.

What binds the GEMM at 1081 TFLOP/s, and does the curve flatten at 16384 cubed

1 participant