Repository navigation
Description
global moves a staged tile to memory and has no way to fold it into memory. There is
store_shared_rows (16-byte accesses out of a shared tile, the epilogue #116/#117 built and #123
kept) and store_rows (the register route), and no += twin of either. A kernel computing
C += A·Bᵀ — which is every backward pass and every gradient accumulation — therefore drops off
the access ladder entirely and read-modify-writes C by hand.
What that costs, measured
feitreim/oxide-train's tcgen05 GEMM has store and accumulate entry points over one compute
pipeline, so the accumulate is the store plus the fold and nothing else. B200, 4096³, bf16
operands, min of 10 launches after 3 warm-ups:
| entry point | ms | TFLOP/s |
|---|---|---|
gemm_tcgen05_bf16_optimized store |
0.123 | 1113.8 |
gemm_tcgen05_bf16_optimized accumulate |
0.256 | 536.2 |
gemm_tcgen05_f32_optimized store |
0.144 | 956.2 |
gemm_tcgen05_f32_optimized accumulate |
0.275 | 500.1 |
The fold costs more than the entire rest of the kernel. It is not bandwidth: re-reading C at
4096² bf16 is 33.5 MB, about 4 µs of HBM against the 133 µs the fold adds. It is the shape — the
hand-rolled path is a 4-byte ld.global + 4-byte st.global per packed word, which is exactly the
128-scattered-4-byte-stores shape #116 measured off the register drain and replaced with 32
contiguous 16-byte ones. There is no library route that keeps the 16-byte accesses and adds.
Proposed
global::accumulate_shared_rows, store_shared_rows' signature exactly, descending the same
access_width ladder, with the copy replaced by load-both/add/store:
pub unsafe fn accumulate_shared_rows<E: Element, const R: usize, const C: usize, S: Swizzle, const THREADS: u32>(
dest: GlobalRows<E>, row: u32, column: u32, thread: u32, tile: SharedTile<E, R, C, S>,
);
The addition is the element's, not the caller's: a bf16 C += x has to widen both sides, add in
fp32 and round once, and that rounding belongs beside Element::pack rather than in every
epilogue. So this also wants one required method on Element —
fn add_packed(current: u32, update: u32) -> u32 — which is three two-line impls (Bf16, F16,
F32) and makes the trait describe how packed words fold as well as how they pack.
Not in scope here
- The register route's twin (
accumulate_rows). It is already expressible without new API —
load_rows+bin_map_assign::<Add>+store_rows— becauseload_rowsexists and reads the
same addressesstore_rowswrites. Worth having for symmetry; not a gap. - An fp32 staged drain.
store_shared_rowsis generic overEand would take anF32tile
happily, but nothing can fill one:ldst::store_tile/store_tile_x4bound
E: Element<Unpacked = [f32; 2]>because they arestmatrix, so an fp32 accumulator band has no
path into shared memory and an fp32 epilogue is stuck on the register route. Separate gap, worth
its own issue — noting it here because it is why the fp32 rows above are slower than the bf16
ones even before the fold.
While nearby: GAPS.md §1.2 is stale
It reads "Bf16 is still the only operand impl". F16 has been a second MmaElement since it
landed (src/shared.rs:212, MMA_KIND = 0, Tcgen05ElementType::F16). tf32 (KIND = 1) and fp8
are still genuinely absent, which is the entry's real content.
Activity
A staged tile can be folded into memory, not only written over it (#169…