Skip to content

The cap was the whole story: gemm adopts pipeline::run at a dead heat (#51) - #83

Merged
feitreim merged 1 commit into
mainfrom
gemm-adopts-pipeline-run
Jul 28, 2026
Merged

feitreim merged 1 commit into
mainfrom
gemm-adopts-pipeline-run

Conversation

@feitreim

@feitreim feitreim commented Jul 28, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #80, which landed the scaffold and concluded the GEMM should not
adopt it. That conclusion was wrong, and #80 said exactly which measurement
would decide it.

#80's own words:

Cap 222 — 3 CTAs/SM, the value 228 KiB / 72 KiB of shared memory admits and
the value the throughput curve points at — was never run.
The Modal
workspace hit its spend limit mid-investigation. […] the conclusion "the GEMM
should not adopt this" is provisional on that one point.

The spend limit lifted. I ran the point. It draws level, so gemm.rs adopts the
scaffold and pipeline::run has its first caller.

The number

Min ms over 30 timed launches, B200, 148 SMs. Cap is in clusters; a cluster is 2
CTAs. Rows marked = have fewer tiles than the cap, so the grid is identical
to the launch-per-tile grid and each cluster runs one item — a free control.

Two launch-per-tile runs, because the cross-run spread is a few percent and the
conclusion has to survive it; run 4 was taken adjacent to the cap-222 run for
exactly that reason.

shape per tile (1) per tile (4) cap 74 cap 148 cap 222
256x128x256 0.0224 0.0239 = 0.0223 = 0.0234 = 0.0231
512x256x256 0.0225 0.0239 = 0.0225 = 0.0251 = 0.0258
1024x1024x1024 0.0283 0.0285 = 0.0268 = 0.0284 = 0.0292
2048x2048x2048 0.0451 0.0481 0.0593 = 0.0478 = 0.0492
4096x4096x4096 0.1891 0.1900 0.2808 0.2059 0.1944
8192x8192x8192 1.0169 1.0204 2.1036 1.2130 1.0217

TFLOP/s at 8192³: 1081 / 1077 launch per tile, 523 at cap 74, 906 at cap
148, 1076 at cap 222.

It is a dead heat, not a win. 0.13% at 8192³ against the adjacent baseline;
4096³'s 2.3% is exactly the offset that run's own = control rows carry. I am
not dressing parity up as a speedup — lcf folds the epilogue into the item, so
the boundary hands back at the drain what persistence saves on launches, and a
dead heat is the ceiling for this shape. #15's lcsf is what would let the
epilogue and the next tile's first K loads cross.

What adopting it buys is that the scaffold has a caller and therefore a
regression test
. pipeline::run was exercised by nothing at all before —
including in #80, which is a poor place for a load-bearing scaffold to sit.

Why this is worth landing even at parity, stated plainly

If you would rather not carry the constant for parity, the honest alternative is
to revert this and leave the scaffold uncalled; I think the regression test is
worth more, but the numbers above are the whole basis for that and they are a
tie.

The residency, which is #78's step one

Picking the cap needs to know how many CTAs of this kernel an SM holds, and the
repo cannot ask: cuOccupancyMaxActiveBlocksPerMultiprocessor takes a block
shape and no cluster, which is why main.rs prints cluster in the GEMM's
occupancy row. So it came off the clock by bisection, and the answer is 3 CTAs
per SM
— what 228 KiB / 72 KiB of shared memory admits.

The GEMM is not pinned at 1 CTA/SM like flash_forward, by a factor of
three.
The method may be worth as much as the number: for a
#[cluster_launch] kernel, a timing sweep over a persistent grid's cap is a
residency probe, and right now it is the only one available. Recorded for #78; I
have not gone further into it.

Verification, on this tree, against current main

  • modal run modal_app.py::examples — pass gemm 512x256x256 exact (4 tiles over 4 clusters), 4096x4096x256 exact (512 tiles over 222 clusters). The
    second size is there because the first is 4 tiles over a grid holding 222 and
    never enters the loop twice, so it would pass identically against the
    non-persistent kernel — a check that cannot fail against the code you replaced
    is not a check. pass softmax and pass layernorm beside it, unchanged.
  • 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::bench — four sweeps, above. bench.rs checks every
    size against the CPU reference before timing it, so all six sizes up to 8192³
    are exactness runs too.
  • Locally: cargo fmt --check (both crates), cargo clippy --all-targets -D warnings, cargo test (74 + 1).

Rebased on d213161; #79's softmax work in examples/README.md is untouched
— this changes §7 and one sentence above it, and nothing else in that file.

One note on the timings and #82

Rebased onto #82 (#29's charge rework), which lands in this kernel's producer
loop: tma_load_2d_arriving_at now hands back its own charge and the leader
scales it with across_ranks(RANKS). The merge keeps that — the persistent
Tile::work carries #29's form, not the hand-written total.

Every timing above was taken before #82, on both sides of the comparison.
The launch-per-tile baselines and the three capped runs were all built from the
same pre-#82 tree, so the comparison is internally valid and the dead heat
stands. What is not re-measured is the absolute figures against post-#82 code; I
would not expect a charge that is computed rather than written down to move
them, but that is a prediction and it is stated as one rather than checked.
::build and ::examples are re-run post-rebase, so correctness is not
resting on the same assumption.

The GEMM as a `Tile: Job` driven by `pipeline::run`: one output tile per work
item, one item per cluster, `RANKS = 2`, TMEM allocated once outside the loop
because `alloc_cluster` is a whole-cluster collective whose address never
changes. This is the scaffold's first caller, which is most of what it buys —
`pipeline::run` was exercised by nothing before and is now on the `::examples`
gate.

`check` gains a second size, 4096x4096x256 at 512 tiles, because the existing
512x256x256 is four tiles over a grid that holds 222 and so never enters the
loop twice. It would pass identically against the kernel this replaces, and a
check that cannot fail against the code you replaced is not a check.

It is a dead heat and not a win: 1.0217 ms at 8192³ against the launch-per-tile
grid's 1.0204, 1076 TFLOP/s against 1077. Reported that way in README §7 rather
than dressed up, since `lcf` folds the epilogue into the item and hands back at
the boundary what persistence saves on launches. #15's `lcsf` is what would let
those cross.

The route to that dead heat is the part worth keeping. The grid's cap is the
only thing this port changes, and two guesses at it were wrong by a lot — 2.07×
slower at one CTA/SM and 1.19× at two, before three drew level. Picking it needs
a residency `cuOccupancyMaxActiveBlocksPerMultiprocessor` will not give for a
`#[cluster_launch]` kernel, so `CTAS_PER_SM` is a bisection on a clock rather
than a derivation, and it says three — refuting the extrapolation of #77's
1 CTA/SM to this kernel by a factor of three, which is #78's step one.
@feitreim
feitreim force-pushed the gemm-adopts-pipeline-run branch from 61d6f77 to 91f5c8e Compare July 28, 2026 17:48
@feitreim
feitreim merged commit e913940 into main Jul 28, 2026
3 checks passed
feitreim added a commit that referenced this pull request Jul 28, 2026
Two doc sites said the occupancy question was unanswerable for a
`#[cluster_launch]` kernel. Both are accurate about the function they name and
misleading about the situation, one commit after the census showed
`cuOccupancyMaxActiveClusters` does describe such a kernel and agrees with a
counted census on the cluster control.

- `main.rs`'s `entry` field: `None` now marks a query nobody wired into that
  table rather than a residency nothing can reach.
- `gemm.rs`'s `CTAS_PER_SM`: #83's clock-bisected 3 stays as the measured
  figure and so does the route to it. Added that #78's census counts 3 at the
  same envelope from `%smid` and `%globaltimer` — two methods sharing nothing
  agreeing on one integer — and that it names the resource the bisection could
  not: 128 columns admit 4, the 73792 B shared plan admits 3, so shared memory
  caps this kernel and tcgen05 does not.

No constant re-tuned, no kernel touched.
feitreim added a commit that referenced this pull request Jul 28, 2026
…he other reason (#78) (#84)

* Count the CTAs instead of asking, and flash_forward's 1 is real for the other reason (#78)

`cuOccupancyMaxActiveBlocksPerMultiprocessor` returns 1 for any kernel
containing a `tcgen05.alloc` (#77). #51 then measured `gemm` losing 2.07x to a
one-CTA-per-SM grid cap, which is impossible if 1 were the ceiling, so the query
had been shown once not to predict residency and flash_forward's 1 stopped being
established.

Rather than infer residency from where a throughput curve flattens, count it.
`%smid` names the SM a CTA is running on and `%globaltimer` is a device-wide
nanosecond clock, so each census CTA records where it ran and timestamps both
ends of its TMEM allocation; the host sweeps those intervals per SM for the most
ever open at once. Two intervals are kept, and the pair is the point: a CTA
parked inside a blocking `tcgen05.alloc` is resident and making no progress,
which no grid-cap sweep can distinguish from absence.

Residency is `min(512 / columns, shared per SM / plan)`, exactly, at all
fourteen rungs. So:

- flash_forward's 1 CTA/SM is REAL, and tcgen05 is not the cause. Its 256
  columns admit 2; its 147536 B shared plan admits 1 with no allocator in the
  kernel at all. Shared memory is the only thing capping it — the resource #70
  tried to rule out and could not, because the query it asked was pinned by the
  allocator in all four of its readings.
- gemm's envelope counts 3, reproducing #83's clock-bisected 3 on an instrument
  with nothing in common with a throughput curve.
- alloc_cluster is charged identically to alloc_block at equal columns, so the
  pair does not split the SM's tensor memory. #78's leading hypothesis for why
  the two kernels differ is refuted; what differs is their shared plans.
- The query reacts to the instruction, not to a held resource: a kernel that
  allocates 512 columns and releases them before doing anything runs 25 CTAs an
  SM while the query still answers 1.

`cuOccupancyMaxActiveClusters` does describe a `#[cluster_launch]` kernel, and
matches the census on the cluster control. The docs saying it could not predate
anyone calling it.

* Say which query cannot answer a cluster launch, and which one can (#78)

Two doc sites said the occupancy question was unanswerable for a
`#[cluster_launch]` kernel. Both are accurate about the function they name and
misleading about the situation, one commit after the census showed
`cuOccupancyMaxActiveClusters` does describe such a kernel and agrees with a
counted census on the cluster control.

- `main.rs`'s `entry` field: `None` now marks a query nobody wired into that
  table rather than a residency nothing can reach.
- `gemm.rs`'s `CTAS_PER_SM`: #83's clock-bisected 3 stays as the measured
  figure and so does the route to it. Added that #78's census counts 3 at the
  same envelope from `%smid` and `%globaltimer` — two methods sharing nothing
  agreeing on one integer — and that it names the resource the bisection could
  not: 128 columns admit 4, the 73792 B shared plan admits 3, so shared memory
  caps this kernel and tcgen05 does not.

No constant re-tuned, no kernel touched.
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
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.

1 participant