Repository navigation
The SFU exp2 wins on softmax and loses on flash_forward, and the two-CTA shared step is a kilobyte under half the SM (#81) - #208
Merged
Conversation
feitreim
force-pushed
the
flash-harness-exp2
branch
from
August 6, 2026 20:54
9f0184b to
eb2bfb0
Compare
…CTA shared step is a kilobyte under half the SM (#81) `flash_forward` is on a clock now — a `flash` case in `experiments/`, checked against the f64 reference at every size it times — and the two things that needed measuring came out against the guess. `exp2_hw` in the inner loop is 3.9% slower at 2048 queries x 16 heads, where that shape repeats to 0.3% across two runs of the same arm, so the kernel keeps the FMA polynomial and the swap is recorded rather than shipped. The register column is byte-identical between the arms, which is #81's own point. Four census rungs 1 KiB apart put the two-CTAs-an-SM shared step in [115712, 116736): at exactly half the SM a second CTA is not admitted, so #85's arithmetic is a kilobyte too generous and the ring has to give up 31824 B. And the housekeeping #85 asks for: a CTA is not charged the SM's whole tensor memory, 256 columns admit two CTAs, and the 1 CTA/SM is the shared plan.
feitreim
force-pushed
the
flash-harness-exp2
branch
from
August 6, 2026 21:06
594e301 to
8cd6e5a
Compare
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 #81, refs #85.
#81 asked for the
exp2question to be settled onflash_forwardrather thanasserted, and #85's prerequisite — a launcher and a CPU reference — landed in
#182. What was still missing was a clock on that kernel, and a counted
value for the shared-memory step #85 does by arithmetic. Both exist now, and
both answers are not the expected ones.
The SFU
exp2does not win onflash_forwardsoftmaxis 2.7× faster forexp2_hw(#76), and flash exponentiates everyelement of every key block, so it looked like the place the polynomial would
cost the most. Timed through the new
bench --case flash, each arm checkedagainst the f64 reference before it was timed, and the polynomial run twice
so the difference carries its arms' own repeatability (#122):
exp2exp2againexp2_hwThe last row is the one with a denominator: 256 CTAs is the first size past a
full wave, it repeats to 0.3% across two runs of the same arm, and the SFU
is 3.9% slower there. The other two rows are 16 and 64 CTAs on 148 SMs and
repeat to 2.7%, so they say only that nothing large happened.
So the kernel keeps the polynomial and the swap is recorded rather than
shipped. Exactness was checked on the SFU arm before the clock was believed:
worst relative error 1.73e-3 against the polynomial's 1.66e-3, tolerance
2⁻⁸ = 3.91e-3 — neither spelling is what the tolerance is made of.
Registers say nothing either way. Two
regcountruns, one per arm:examplesregsexperimentsregs.localst/ldexp2(ships)exp2_hwByte for byte identical — which is #81's own point from the other side: the
column the original claim was made on cannot see this difference in either
direction. (The 168/255 gap is crate composition, not the exp2 spelling: same
source file, two crates, both arms.
groupnorm_tile's 168 → 236 across the samesplit is the precedent, and it is recorded in
docs/kernels/flash_forward.md.)src/reg.rs's header says all of this now: which spelling to call is ameasurement each kernel takes,
exp2stays the polynomial becauseex2.approx.f32is device-only and panics on a host build — so it is the onlyone a CPU reference, host test or doctest can evaluate — and the
ex2.approxserialization claim the header used to carry is gone, with a note that settling
it needs a warp-count probe of its own rather than either of these kernels.
The shared-plan step, counted: [115712, 116736)
#85 puts it at 116736 B, half the SM's 233472. Four rungs on
device-tests'tmem residency census, 1 KiB apart, no allocator so only shared memory binds:At exactly half the SM a second CTA is not admitted — the arithmetic is a
kilobyte too generous.
2 × (115712 + 1024) = 233472exactly, which points atthe per-CTA slice the driver keeps (
RESERVED_SHARED_MEMORY_PER_BLOCK); thatreading is not proven by these rungs and locating the step inside that kilobyte
would need another ladder, which would change nothing for this kernel. So
flash_forward's plan has to give up 31824 B, not 30800 — one stage offboth K/V rings is 32768 B and still clears it, with 944 B to spare.
These rungs are the one place in that file where a count is reported rather
than asserted (
Measured::budgetisNonefor them): what they measure is thenumber #85 designs against, so a step that is not where the arithmetic puts it
is the finding, not a failure. The census's verdict string prints the interval.
#85's housekeeping
flash_forward.rsanddocs/kernels/flash_forward.mdsaid the allocation couldnot be shrunk because a CTA is charged the SM's whole tensor memory. The advice
was right and the reason was wrong: #84 counts
512 / columnsCTAs holding atonce, so 256 columns admit two, and the 1 CTA/SM is the shared plan,
which is the resource #70 ruled out on four occupancy queries that were all
pinned at 1 by the allocator. Corrected in both, with the doc's "shrinking the
rings buys nothing" replaced by what it now is: the only lever this kernel has.
examples/src/main.rs's occupancy table needed no number changed — it asks thedriver — but its
clustercell implied the question was unanswerable. It isanswerable with
cuOccupancyMaxActiveClusters; the comment now says so and sayswhat is missing here (a grid), rather than implying no such query exists.
This PR does not shrink the ring. That is #85's follow-up, and it is what
this enables: a reference, a clock at three shapes, and a counted threshold to
aim at.
Also
flash_forwardgets abenchcase inexperiments/, which empties that file'sSKIPPEDlist. The denominator it owed is the flops it issues — both MMAs runover every key block of every query block, so
4 · sequence² · HEADa head; thekernel does not skip fully-masked key blocks, so a causal-optimal kernel would
do a little under half of that, and the table quotes what is on the clock. Sizes
are bounded by the host: the f64 reference is
heads · sequence² · HEADmultiply-adds.
Gates — all run by hand (GitHub Actions is out today)
scripts/fmt --checkcargo test(library, 4 manifests' worth of doctests)scripts/modal-run buildscripts/modal-run regcountscripts/modal-run device_testsscripts/modal-run examplesflash_forward 2x256x128 rows attended, worst relative error 1.66e-3scripts/modal-run bench --case flashRebased onto 817d852 part-way through (#206 and #207 landed while this was
measuring); the only conflict was a section heading in
docs/kernels/softmax.md, andbuildandexampleswere re-run on therebased tree — the numbers above are from the pre-rebase runs of
regcount,device_testsandbench, whose subject matter neither of those PRs touches.Pre-existing and not from this branch:
cargo clippy -D warningsondevice-testsandexamplesis red on the pinned toolchain for four lints infiles this branch does not touch (
device-tests/src/main.rs:1304/1324duplicated
#[inline(always)],tmem_rescale.rs:297,tmem_warpgroup.rs:495empty format strings). Tier 1 only lints the library, and
modal_app.py::buildruns clippy without
-D warnings, so nothing gates on them today.