Commit e968b0b
committed
[cute] Leaner masked store for single padded-M tcgen05 tile
The padded-M tcgen05 fp8 path (block_m > static_m, added in the parent
commit) ran the epilogue store through the SIMT R2G hybrid's scalar masked
loop, leaving the memory pipe under-fed. For a single padded tile this is
pure overhead: the kernel issued a Python-unrolled per-element loop that
recomputed a 2-D `cute.elem_less(coord, (m_size, n_size))` predicate and a
scalar `if`-guarded store for every element of every subtile.
Root of the waste: when `block_m > m_size` (e.g. M=16 on a bm=64 tile),
`m_size % bm != 0` marks the output tile non-static-full, so the store
dispatches `if tcgen05_full_tile: <vector copy> else: <scalar masked loop>`.
The full-tile predicate `m_offset + bm <= m_size` (0+64 <= 16) is statically
false, so the vector branch is dead and every store takes the scalar path.
NCU showed this capping DRAM throughput well below the equivalent full tile.
Fix (single padded tile only, gated by
`tcgen05_flat_m_edge_single_tile = tcgen05_flat_m_edge_tma and m_size <= bm`,
threaded via a new `CuteTcgen05StoreValue.flat_m_edge` field):
- Drop the dead `if full_tile` branch.
- Emit a single vectorized `cute.copy(..., pred=mask)` (the same
`logical_divide` predicated-copy path already used by `simt_edge_only`)
instead of the scalar per-element loop.
- Use an M-only predicate `_coord[0] < m_size` instead of the 2-D
`elem_less`, since this fast path already requires N % bn == 0 so every
in-bounds column is valid — fewer scalar ops on the epilogue warps.
The gate is deliberately narrowed to `m_size <= bm` (a single M tile). For
multi-M-tile edges (m_size > bm, e.g. M=80 with bm=64) the first tile is a
genuine full tile and keeps its unpredicated vector store; only the original
load-side TMA relaxation (`tcgen05_flat_m_edge_tma`) applies there.
Measured (B200, M=16 K=4096 N=14336, fp8 e4m3, do_bench_wrapper, cudagraph,
A/B against the parent commit in one session):
- warm-L2: 18.36 us / 3.23 TB/s -> 16.07 us / 3.69 TB/s (1.14x)
- cache-clear: 26.67 us / 2.22 TB/s -> 24.45 us / 2.42 TB/s
- DRAM %peak (NCU): 38.4% -> 42.9% (closes ~57% of the gap to the 46.6%
full-tile ceiling).
Correctness: output shape is the true (M, N); relerr vs a float32 matmul is
at the fp8-rounding floor (~1.7e-3) for the real rows; generated code still
contains `cute.nvgpu.tcgen05`. Verified across static_m in {16,32,48,64,80}
x block_m in {64,128} (the M=80 multi-tile case confirms the full-tile fast
branch is retained). Regression test
`test_matmul_mma_fp8_small_static_m_padded_tile` passes; full
`test_cute_backend.py` passes (114 + 6 subtests).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
stack-info: PR: #2844, branch: yushangdi/stack/611 parent 014fbfb commit e968b0b
3 files changed
Lines changed: 52 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2040 | 2040 | | |
2041 | 2041 | | |
2042 | 2042 | | |
| 2043 | + | |
| 2044 | + | |
| 2045 | + | |
| 2046 | + | |
| 2047 | + | |
| 2048 | + | |
| 2049 | + | |
| 2050 | + | |
2043 | 2051 | | |
2044 | 2052 | | |
2045 | 2053 | | |
| |||
5117 | 5125 | | |
5118 | 5126 | | |
5119 | 5127 | | |
| 5128 | + | |
5120 | 5129 | | |
5121 | 5130 | | |
5122 | 5131 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
48 | 63 | | |
49 | 64 | | |
50 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3297 | 3297 | | |
3298 | 3298 | | |
3299 | 3299 | | |
| 3300 | + | |
3300 | 3301 | | |
3301 | 3302 | | |
3302 | 3303 | | |
3303 | 3304 | | |
| 3305 | + | |
| 3306 | + | |
| 3307 | + | |
| 3308 | + | |
| 3309 | + | |
| 3310 | + | |
3304 | 3311 | | |
3305 | 3312 | | |
3306 | 3313 | | |
3307 | 3314 | | |
3308 | 3315 | | |
| 3316 | + | |
| 3317 | + | |
| 3318 | + | |
| 3319 | + | |
| 3320 | + | |
3309 | 3321 | | |
3310 | 3322 | | |
3311 | 3323 | | |
| |||
3314 | 3326 | | |
3315 | 3327 | | |
3316 | 3328 | | |
3317 | | - | |
| 3329 | + | |
3318 | 3330 | | |
3319 | 3331 | | |
3320 | 3332 | | |
| |||
4083 | 4095 | | |
4084 | 4096 | | |
4085 | 4097 | | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
| 4101 | + | |
| 4102 | + | |
| 4103 | + | |
| 4104 | + | |
| 4105 | + | |
| 4106 | + | |
| 4107 | + | |
| 4108 | + | |
| 4109 | + | |
| 4110 | + | |
| 4111 | + | |
| 4112 | + | |
4086 | 4113 | | |
4087 | 4114 | | |
4088 | 4115 | | |
| |||
0 commit comments