Repository navigation
A staged tile can be folded into memory, not only written over it (#169) - #171
Merged
Merged
Conversation
`global` had `store_shared_rows` and no `+=` twin, so `C += A·Bᵀ` — every backward pass — had no library route and every caller hand-rolled a read-modify-write. That drops off the access ladder: `oxide-train`'s tcgen05 GEMM measures 1113.8 TFLOP/s storing and 536.2 accumulating at 4096³ on one compute pipeline, so the fold costs more than the whole rest of the kernel. It is not bandwidth — re-reading a 4096² bf16 `C` is 33.5 MB against a 133 µs difference — it is the shape, which is #116's finding one level up: 4-byte scattered accesses where the store path issues 16-byte contiguous ones. `accumulate_shared_rows` is `store_shared_rows` with the copy replaced by a load of both sides, an `Element::add_packed` and a store: same signature, same chunk split, same `access_width` ladder, so the fold costs the read and nothing else. The addition is the element's. A bf16 `C += x` has to widen both sides, add in fp32 and round the sum **once** — the addend arrived already rounded, and rounding again after the add is an error the accumulator did not have to carry. That belongs beside `Element::pack`, so it is a required trait method rather than a snippet at each epilogue: three impls, each `unpack`, `+`, `pack`. Held by `shared accumulate` and `shared accumulate wide` on a B200 — the two `shared drain` cases with the rectangle seeded with its own identities instead of poison, so the answer is every identity doubled. Doubling a bf16 moves the exponent and leaves the mantissa alone, so the comparison stays on bit patterns with no tolerance: a fold that rounded twice, or dropped the read, lands on a different pattern rather than a nearby one. The margins are still poison and still checked, so the geometry the store cases prove is proved again here. GAPS.md §2.6 records it, and two entries beside it that this work falsified or found: - §1.2 read "`Bf16` is still the only *operand* impl", and had not been true since `F16` landed eight lines above `impl MmaElement for Bf16` in the same file. The section's usual failure and not a slow rot. tf32 and fp8 are the genuinely absent ones — and `oxide-train` #67 was filed believing its fp32 GEMM needed tf32, when that kernel's operands are bf16 and only its `C` is fp32. - §2.6 now names the reason an **fp32** epilogue is still on the register route: `store_shared_rows` would take an `F32` tile, but nothing can fill one, since `ldst::store_tile*` are `stmatrix` and bound `Unpacked = [f32; 2]`. So an fp32 `C` pays the 20.43 µs/tile scattered drain against the staged route's 6.68. Filed nowhere; a plain non-`stmatrix` `store_tile` over `SwizzledChunks` is what it wants.
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 #169.
What
global::accumulate_shared_rows—store_shared_rows'+=twin. Samesignature, same chunk split, same
access_widthladder, withcopy_bytesreplaced by
add_bytes: oneld.shared.vN, oneld.global.vN,Element::add_packedper word, onest.global.vN.Plus one required method on
Element:fn add_packed(current: u32, update: u32) -> u32.Three impls (
Bf16,F16,F32), eachunpack,+,pack. It is a traitmethod rather than a call-site snippet because a narrow element's
C += xhasto widen both sides, add in fp32 and round the sum once — the addend arrived
already rounded, and the second rounding is an error the accumulator did not
have to carry. That rounding belongs beside
Element::pack.Why
C += A·Bᵀis every backward pass and had no library route at all, socallers hand-rolled a read-modify-write and dropped off the ladder to 4-byte
accesses. On
feitreim/oxide-train's tcgen05 GEMM, where store and accumulateare the same compute pipeline and differ only in the epilogue (B200, 4096³,
minof 10 after 3 warm-ups):The fold costs more than the whole rest of the kernel. Not bandwidth —
re-reading a 4096² bf16
Cis 33.5 MB, ~4 µs of HBM against a 133 µsdifference. It is the shape, which is #116's finding one level up.
Held by
shared accumulate/shared accumulate wide(device-tests, B200): the twoshared draincases with the rectangle seeded with its own identities insteadof poison, so the answer is every identity doubled. Doubling a bf16 moves the
exponent and leaves the mantissa alone, so the comparison stays on bit
patterns with no tolerance — a fold that rounded twice, accumulated at bf16,
or dropped the read lands on a different pattern, not a nearby one. Margins
stay poison and stay checked, so all of
check_shared_drain's geometryfailures are named here too.
f32_add_packed_is_the_fp32_addition_itselfandbf16_add_packed_pairs_the_halves_lane_wise(host).Bf16::packiscvt.rn.bf16x2.f32with no host body, so the host half can only pin thelane-wise pairing; the rounding is the device cases'.
tests/gaps.rs::a_staged_tile_can_be_folded_into_memory. Separate froma_staged_drain_is_two_callsbecause the two can rot apart, and unbounded inEwhere that one boundsUnpacked = [f32; 2]— which is the claim that thefold is not an
stmatrixpath and takes an fp32 destination.GAPS.md
§2.6 records the addition, and two entries beside it that this work moved:
Bf16is still the only operand impl", and hadnot been true since
F16landed —impl MmaElement for F16sits eight linesabove
impl MmaElement for Bf16in the same file, andexperiments'gemm_solis benchmarked against a cuBLASLt FP16 baseline because of it. The section's
own failure mode again. tf32 (
KIND = 1) and fp8 are the genuinely absentones — and
feitreim/oxide-trainlayernorm_rows sits at 255 registers with spills and gets 2 blocks/SM where softmax gets 6 #67 was filed believing its "f32" GEMMneeded tf32, when that kernel's operands are bf16 and only its
Cis fp32.store_shared_rows/accumulate_shared_rowsare generic overEand wouldtake an
SharedTile<F32, …>, but nothing can fill one:ldst::store_tile/store_tile_x4boundE: Element<Unpacked = [f32; 2]>because they are
stmatrix. So an fp32Cpaysstore_rows' scatteredper-value stores — The epilogue's stores were the wrong shape, and stmatrix fixes 20% of them (#15) #116's 20.43 µs/tile against the staged route's 6.68. Filed
nowhere; what it wants is a plain non-
stmatrixstore_tileoverSwizzledChunks, generic inE.Checked
scripts/fmt --check,cargo clippy --all-targets -- -D warnings,cargo test(105 + 1 + 75),
cargo doc --no-depswithRUSTDOCFLAGS=-D warnings, and theintra-doc link pass with the
cfg_attrcommented out (only the knownGlobalLayouthost-gated dangles remain). Tier 2 and 3 are CI's — thedevice-tests cases have not been run on a B200 from here.
Downstream:
feitreim/oxide-train#67 pinskittensto this branch's rev andwill move back to ferro
mainonce this merges.