Repository navigation
The item boundary is roughly a third of 8192 cubed, and the curve stops where the waves said (#86) - #90
Merged
Conversation
…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.
This was referenced Jul 28, 2026
feitreim
added a commit
that referenced
this pull request
Jul 28, 2026
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)
This was referenced Jul 28, 2026
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)
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 #86.
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 theprediction claims is constant.
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
Cis 2.1 GiB against183 GiB. The size is bounded by host staging, which is why
bench's Modaltimeout 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
MandNare 8192 in all four rows, so each has the same 2048 tiles, 10waves, 92.3% efficiency, grid of 444, and 268 MB of
Cwritten — and the sameoperand bytes per flop, since arithmetic intensity is a property of the
[256, 128]pair tile and not of the shape. Only the arithmetic between oneitem boundary and the next moves.
The fit, with its point selection stated
Milliseconds against
Kis a line whose intercept is a cost that does not scalewith 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:
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:
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 = 512is 8 blocks againstSTAGES = 3, so the pipelinebarely 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 blockbetween adjacent rows is 0.378, 0.503, 0.569 µs — reproduced as
+34.1, −1.1, −43.3, +10.4and0.419, 0.522, 0.580in the other session. Apipeline 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.
Ksets theoperand footprint:
AandBare 8 MiB each atK = 512and 512 MiB each atK = 32768, so the sweep crosses L2 between the second row and the third. Theshallow 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 = 8192is the regime in questionand 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 —
Kdoes not touch the sharedplan),
Ctraffic (268 MB in all four), operand intensity (85.3 FLOP/byte inall four), grid (444 in all four). And it is not launch overhead — #67 settled
that, and
layernormreaches 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, thenstore_rows— onest.global.f32per owned value, 128 a thread. UnderBaseLdtma single one ofthose 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::runre-arm the barriers, and only then, a full memory latencylater, can the next tile's MMA start. Nothing in that chain overlaps. That is
the shape #15's
lcsfchanges; the scattered fp32 store is a second, separablething, 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 fourclusters 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 = 2048and costs 47.2 µs, against thedepth sweep's 54.0 µs per item at the same
Kwith 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 throughKtogether, so at one Kblock they collectively touch
(rows_of_A + columns_of_B) · 128bytes.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
Cwritten. Identicalruns but for
M : N: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.
layernormmoves 5497 GB/s of real streaming traffic onthis 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 = 3deep.Subtracting the boundary gives the steady-state rate per shape
Over the range of intercepts the point selections give, and both sessions:
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
Cover the same item count. Nothing has run at any of theserates. 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 blockandreusecolumns are arithmetic on the itemmap, 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
gb100among the chips it knows,libnvperf_target.sois in theinstall, and
/proc/driver/nvidia/paramsreportsRmProfilingAdminOnly: 0. Itstill refuses:
The injected driver set under
/usr/lib/x86_64-linux-gnucarrieslibnvidia-ml,-nvvm,-ptxjitcompiler,-allocator,-gpucompand thegraphics libraries, and no
libnvidia-pcc.so— the performance-counterlibrary the container runtime does not mount for the compute capability set. I
tried fetching it out of the matching 580.95.05
.runpackage; it is not inthere either.
modal_app.py::profileis checked in with all of that in itsdocstring, 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
lcsfis what lets the epilogue and thenext tile's first loads cross.
not leave in L2. 23% at the worst aspect ratio, and that one is measured end
to end rather than fitted. The item to tile map is row-major, and the GEMM already lives in L2 #89.
85.3 FLOP/byte. The only lever on that number is the tile, which is Sweep the GEMM's pair tile and pipeline depth: [256,256] at three stages should dominate on paper #87.
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 forbyte what they were. What changed:
examples/src/bench.rs:16384³inGEMM_SIZES; two new diagnostic cases,gemm-footprintandgemm-depth;bench <case> [<m> <n> <k>]to narrow thesweep to one table or one row.
examples/src/gemm.rs: documentation only — the boundary result in themodule header, and one stale sentence corrected. The exactness argument said
"the benchmark's largest
Kof 8192", which the new sizes make 32768; thepartial-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:benchtakes--case/--m/--n/--kand 5400 s; theprofileentry point and its note.
Every timed figure went through
bench.rs's checked path. No new route prints athroughput for a launch it did not verify — the single-size selection narrows
which
Caseruns and changes nothing about the order of check and clock.Verification
modal run modal_app.py::build— exit 0, all seven steps includingRUSTDOCFLAGS=-D warnings cargo doc --features hostand a realcargo oxide build --arch sm_100aof 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-footprintand--case gemm-depth. Every table above is from onefull-sweep session; the reproduction figures are from the others.
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.