Repository navigation
[HIP] [FlyDSL] [gfx1250] Optimize native MXFP8 GEMM across M regimes - #8273
XiaobingSuper wants to merge 16 commits into
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
WAITING ON AUTHORPR Self-ReviewRevision Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision. Questions to answer in the PR description
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
The stack carried #8273 at 3c157e3. This is its increment to cd6820a: the narrow-N MXFP8 path (cd6820a), the MiniMax-M3.1 indexer MXFP8 config rows (e83d633), and the removal of the small-M 1x32 kernel that did not win (c6fb8a3). Co-authored-by: XiaobingSuper <[email protected]> Co-Authored-By: Claude Fable 5.2 <[email protected]>
…68-token fallback rows The MiniMax-M3.1 TP4 routed MoE (E128 top-4, hidden 6144, inter 768, MXFP4) rows at token 16384 and 32768 now take the E129 M=32768 cluster config: 256x256x256 tiles, 2x2 waves for both stages, 3 + 3 buffers, clusters 2x2 (GEMM1) and 4x4 (GEMM2), next-stage prefetch and LDS SoA interleave on, no activation preshuffle. These rows serve the two largest prefill token buckets; all other rows are unchanged. The `us` column holds each row's own tuning-session value, so the old and new values are not a like-for-like comparison. The A/B is in-model on 4x MI455X: output bitwise identical to the previous rows standalone; greedy outputs identical on 3 long prompts; part of a 7.4 ms reduction of a 14336-token prefill on a 99968-token cached prefix (with the QKV MXFP8 rows of ROCm#8273). Not adopted: the E129 M=8192 config with activation preshuffle measured about 1 ms more saving but changes greedy outputs in-model; it is left out pending investigation. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…'s decode GEMM (opt-in) ATOM_M3_FAST_OPROJ=1 (default off, needs ATOM_MINIMAX_M3_PA_MXFP8_OUT). The sparse layers run o_proj on the paged attention's MXFP8 output (E4M3 + E8M0 per 32) through aiter's gfx1250 mxfp8_decode_gemm (ROCm/aiter#8273), for the token counts mxfp8_decode_gemm_supported serves (N 6144, K 2048, M <= 128). Every other count keeps the linear's tuned GEMM. - The call goes through a custom op, minimax_m3_o_proj_mxfp8, which looks the linear up by name. It is opaque to torch.compile, so the kernel is chosen per call, by token count, and a CUDA graph keeps the capture's choice. - The weight conditions are checked at the op's first call and logged once: preshuffled E4M3, native 1x32 scales in [N, K/32], no bias, no own all-reduce. The weight's layout is settled by process_weights_after_loading, after construction. - Same bytes up to the GEMM's FP32 K order. aiter#8273 reports at least 99.98% of outputs bit-identical to gemm_a8w8_blockscale, and rel-L2 vs fp64 the same. tests/test_minimax_m3_pa_mxfp8_out.py: the forward routes through the op; decode rows take the GEMM and larger ones the linear; the weight is judged at the first call; without a shuffled weight the linear is kept; the op and its fake look the linear up by name. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Superseded in part (see the next comment): only the Update: pushed 15b5803, a bugfix: the MXFP8 GEMM's C tile now leaves LDS through a Scope.
Why. It fixes the stray token-0 bug in MiniMax-M3.1 TP4 decode on 4x MI455X.
Evidence. Measured together with the same change in the grouped MXFP4 MoE GEMMs (#8466):
Hardware / compiler note. On gfx1250, the LDS read of
Re-checked after the rebase. The two files are byte-identical to the validated stack's versions. FlyDSL compile-only for gfx1250 (GPU-less container), through the real dispatchers: all 60 non-fused-split-K MiniMax-M3 mx32 kernelNames of the tuned CSV compile ( |
|
Update: pushed fdc7d49, which narrows the bugfix to Why narrowed. The 256x256 and grouped-MoE read-backs cost about 4% of prefill time (uncached prefill TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283). No failure was ever observed in those kernels: all located events were in Re-checked. The |
…e2e9) Scope decision for the stray token-0 fix: only the read-back in gemm_a8w8_gfx1250 ships (ROCm#8273); the grouped MoE PR (ROCm#8466) is closed. This reverts both commits that brought it here: - f3c9c30, the `cq_lds_store` wiring for launch_gemm_a8w4_tdm_tpg; - the merge 77be2e9 of the grouped GEMM1 / GEMM2 read-back (`_c_lds_store`, `cq_lds_store`). The grouped MoE read-back cost about 4% of prefill time (uncached prefill TTFT +3.7-4.5%, C64 P90 274.7 vs 281-283), and no failure was ever observed in these kernels. They keep the TDM store, a latent risk recorded in ROCm#8273's hardware / compiler note. This branch's tree is again that of 9baf599. Co-Authored-By: Claude Opus 5.5 <[email protected]>
MiniMax M3 1x32 gfx1250 table retunePushed two commits on top of
Result (
The 356 sampled M values inside the served ranges give +16.1% cold and +5.5% hot. The 67 changed rows give +29.9% cold and +9.3% hot. Best single points: 6144×768 M=256 +93% (6.5 → 3.4 µs), 2304×6144 M=1024 +88% (24.9 → 13.3 µs). The gain comes from cluster variants of the generic kernel (28 rows) and fused split-K tile and Checks: dense functional matrix 6312/6312 (full output written, finite, bitwise repeatable, max nRMSE 1.7e-3); Unrelated to the table
|
…'s decode GEMM When the NVFP4 sparse layers' paged attention writes o_proj's MXFP8 input (ATOM_MINIMAX_M3_PA_MXFP8_OUT) and aiter has mxfp8_decode_gemm (ROCm/aiter#8273), o_proj runs through a custom op that takes aiter's gfx1250 decode GEMM for the token counts mxfp8_decode_gemm_supported serves (N 6144, K 2048, M <= 128) and keeps the linear's tuned GEMM otherwise. - The op is opaque to torch.compile, so the kernel is chosen per call by token count; a CUDA graph keeps the capture's choice. - The weight conditions (gfx1250 and (N, K) served, preshuffled E4M3, native 1x32 scales in [N, K/32], no bias, no own all-reduce) are checked at the op's first call, after process_weights_after_loading, and logged once. - Same bytes up to the GEMM's FP32 K order: at least 99.98% of outputs are bit-identical to gemm_a8w8_blockscale, rel-L2 vs fp64 the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
36a3368 to
6d28766
Compare
6d28766 to
ff556f4
Compare
|
Rebased onto main (
Since the last description: the eight-wave Reproducing the timings in the description. The script below times the gfx1250 1x32 rows of the two tables through the production entries as the description's A/B did (CUDA graph, every call on its own weight copy, about 1.2 GB of weight in all, activation and output hot, 1 s idle, median of 3 replays). For an A/B, run it alternately from the two trees on one GPU, swapping the order every round, and compare per-row medians (usage in the docstring).
|
…full-M ks 3 clusters Brings the three B = 1 kernels of #8273 (head 6d28766, pre-AOT launchers of f436c5d) to this branch so tuned 1x32 rows can name them: - kernels/mxfp8_skdec_gemm_gfx1250.py, kernels/mxfp8_fullm_gemm_gfx1250.py (new) and kernels/mxfp8_decode_gemm_gfx1250.py (#8273's, a superset: kint, relaxed TDM chunk rule); - mxfp8_decode_gemm_gfx1250.py: #8273's name / parse / launchable / candidate / run helpers for the three kernels; the fixed-table mxfp8_decode_gemm entry that ATOM's MiniMax-M3 TP4 o_proj calls (ATOM_M3_FAST_OPROJ) stays as it was; - batched_gemm_a8w8_gfx1250.py: the B = 1 runner launches a decode, skdec or full-M kernelName the way it launches the streaming kernel. Full-M also takes a 3-rank K split, (cn 1, ks 3), and wave splits (2, 1), (4, 1), (4, 2): on MI455X they fill 231 of 256 CUs for N 9856 (77 slices x 3), where ks 2 leaves 176 busy. The split-K reduce gives rank r the float4s from r * TILE_F // ks on, so shares stay balanced when ks does not divide the tile; for ks 1, 2 and 4 that is the old split, and the generated code of existing configs is unchanged. The tuner's full-M candidates gain the ks 3 shapes. op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: #8273's per-candidate check of the decode / skdec / full-M kernels against the fp32 reference (rows past M untouched), with the DP-attention o_proj (6144 x 8192) and QKV (9856 x 6144) shapes at 96 and 128 rows, which run the ks 3 split; and every MiniMax-M3 blockscale row naming one of these kernels must launch at its M. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… options The gfx1250 FlyDSL work for the native E4M3 / E8M0 1x32 MXFP8 GEMM that the following commits build on (tables come last): * Tuner (gemm_a8w8_mxfp8_bpreshuffle_tune.py): gfx1250 1x32 shapes over every legal direct, B = 1 batched, weight-streaming and decode kernel, timed in a CUDA graph over rotating weight copies (weights not cache-resident, as in a model); a candidate replaces the current row only if it wins every paired round and the median by --min-gain-pct (2%). The launch check and the tuner accept every tuned kernel that can launch at the real M. * Compute kernel: 192-wide tiles, early A / B TDM merge, a 256x128 tile with M-only clusters for narrow N, a ragged last N tile (cluster_m 1, split-K 1), wider A-scale panels for four-slot K loops, and an optional L2 prefetch of the next-but-one K step, deduplicated within the cluster (_pf1 / _pf2). * Direct kernel: cluster-fused split-K for 2-D mxfp8_32, summed in split order, with a per-stream graph-safe workspace; optionally issues its LDS reads two K steps ahead (_pd2), same WMMA order. * Weight-streaming kernel for M <= 16: the preshuffled weight goes straight into VGPRs; wave partials are summed in wave order. Streaming and decode kernels can interleave K steps across K-waves (_ki). * Decode kernel for M <= 128: weights straight into VGPRs, the activation in LDS by TDM, K split over up to 16 K-waves summed in wave order. * Dispatch: tuned rows naming a batched, streaming or decode kernel run through the B = 1 batched runner, in gemm_a8w8_blockscale(isBpreshuffled= True) (kernelId bmm) and gemm_a8w8_mxfp8_bpreshuffle; the 1x32 lookup of the latter skips a row whose kernel cannot launch at the real M. * Fix: the per-token gfx1250 GEMM passes the new arg_out runtime argument like the other callers. * Op tests: a repeat check on two per-token shapes, a mocked B = 1 dispatch check, every decode candidate of five shapes against fp32, and the fused split-K workspace in the private-graph-pool check. The direct, compute and split-K reduce launches go through main's AOT launcher factories (gemm_a8w8_launcher, _gemm_a8w8_compute_bound_launcher, splitk_reduce_launcher); the streaming and decode kernels launch on the JIT path, as the other kernels no replay prebuilds. The direct kernel's cache (aiter/aot/flydsl/sources.py) now declares the fused split-K epilogue it imports. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A steady refill used one fence per slot boundary: each wave waited for its TDM load of the next slot, then the barrier, then issued the refill of the freed slot. A two-slot pipeline so kept one load in flight per wave, and 30-38% of the steady loop sat in s_wait_tensorcnt on cold weights. _sf splits the fence: a first barrier only frees the slot, the refill is issued, then each wave waits for its next-slot load and a second barrier publishes it. Two loads are in flight: the TDM wait share drops to 16% and the steady loop from 15.1 to 12.3 cycles per WMMA on 8192x6144x12288. The WMMA order and the outputs are unchanged. The extra barrier does not pay on four-slot or L2-prefetch kernels (0.5-4% slower), so _sf is a tuner option of the two-slot compute profiles, after every existing kernel ID, and never the untuned fallback. Co-Authored-By: Claude Code <[email protected]>
A launch whose grid reads every weight byte once marks those loads non-temporal (th=1), as the decode kernel already does: * direct / B=1 batched kernel: the B tile's TDM load, when one M tile (or one cluster of M tiles sharing B by multicast) covers M; not with the clustered split-K epilogue (_fsk), where it measured 3-10% slower; * streaming kernel: the weight buffer loads, when one 16-row tile covers M; * split-K reduce kernel: the partial loads (each is read exactly once). It is a compile-time flag picked per launch from M; kernel names, the tuner's candidates and the outputs are unchanged. Only mxfp8_32 launches of the direct kernel change. MI455X, production entry in a CUDA graph, weights not cache-resident, old and new alternating, median of 6 rounds: the 81 affected rows 564.3 -> 554.5 us (1.018, 0.96-1.11 per row); N=24576 rows 1.03-1.06, t128x128x256 split-K rows 1.04-1.10. Co-Authored-By: Claude Code <[email protected]>
Each of the four waves keeps 96 fp32 accumulators (768 VGPRs) and the eight A fragments of a K-tile, and streams B in pairs: pass p runs (i, 2p) and (i, 2p + 1) for the eight A fragments while B pair p + 1 loads into the registers pair p - 1 left. Every fragment is read from LDS once per K-tile, so a WMMA reads 427 LDS bytes instead of 512, the TDM writes 213 bytes per WMMA instead of 256, and a grid has one third fewer tiles. Three slots of one K-tile (271.5 KB of LDS). The previous K-tile seeds A 0-5, B pair 0 and the scales; A 6-7 load at the start of the K-tile, and in the last pass the next K-tile's A i loads three WMMAs after A i's last read. Per output element the WMMA order is that of the 256x256 kernel, so results are bit-identical. 1024 VGPRs, no spills. N may end on a partial tile as for the other compute profiles. The tuner appends the 24 variants (six clusters, four early-merge choices) after every existing kernel ID, for mxfp8_32 tuned rows only: kernel_fits_shape accepts the profile only with allow_wide, which the mxfp8_32 check passes and the untuned fallback and mxfp8_128 do not. Co-Authored-By: Claude Code <[email protected]>
…ters (_nm) The compute kernel's waves alternate between two quadrant orders by wave parity. _wo1 / _wo2 run every wave in the even or the odd order; on 128x256 and 192x256 tiles the odd waves finish a K step later and the barrier waits for them. _nm numbers whole clusters N-first, so the clusters that read the same B strip start apart in the dispatch window. Every accumulator sees the same K order either way, so outputs are bit-identical to the base kernel. The tuner derives both for split-K-1, non-persistent compute candidates (kernelId 8_000_000 + 8 * catalog id + variant: _wo1, _wo2, _nm, _wo1_nm, _wo2_nm); default launches compile as before. The 256x384 kernel runs one schedule on every wave, so it takes only _nm. Co-Authored-By: Claude Code <[email protected]>
Many M 256-2048 shapes leave CUs idle on the 256-wide tiles: 1024x6144 is 192 128x256 tiles on 256 CUs, but 256 128x192 ones; 1536x6144 is 192 192x256 tiles, but 256 192x192 ones. A grid that covers every CU also spreads the load evenly; with a quarter of the CUs idle a single cluster often runs 1.4x slower than the rest and sets the kernel time. New compute profiles: 128x192 and 192x192 with three slots of two K-tiles, 256x192 with four slots of one K-tile (as 256-wide four-slot tiles). Three 192-row slots take two-step A-scale panels; four-step ones overflow LDS by 1.8 KB. The tuner catalog appends their 72 kernels (six clusters, four early-merge choices, split_k 1) after every existing ID. The K order of every accumulator is unchanged, so outputs match the 256-wide kernels bit for bit; existing kernels compile to the same ISA. Co-Authored-By: Claude Code <[email protected]>
A decode-shaped kernel that keeps the weight stream on the vector memory
path alone and moves the rest off it:
* the activation tile, its scales and the workgroup's weight scales go to
LDS by TDM (optionally shared across a cluster by multicast, "_mc"); the
decode kernel loads a weight scale with a vector load every K step;
* the W waves of a workgroup take interleaved K steps of one 16-column block
at a time with D steps of weight loads in flight a wave (fewer, deeper
waves stream best: W 4-8, D 6-12);
* a cluster of C workgroups splits its Q blocks into C equal runs of K steps
in address order (stream-K); a head piece is streamed first and its FP32
partial published, the matching tail piece is streamed last and adds it,
so the exchange is off the critical path;
* finished blocks are reduced over the waves through LDS and kept in VGPRs;
all outputs are stored after the last weight load (a store between weight
loads makes its wave wait for the whole load queue: 1.5 us on 4x24576x6144).
Name flydsl_mxfp8_32_bpreshuffle_skdec_t{tile}_c{C}_q{Q}_w{W}_d{D}[_mc], run
through the B=1 batched runner like the decode kernel (bf16 only). The tuner
offers it per shape (ids 3_980_000+): tile 16 up to M 16, else 32 (one
workgroup set per 32 rows), C 1/2/4/8, the largest grid per C, W/D 16/3,
8/6, 8/8, 4/12, with and without multicast. The config check keeps to what
ran on MI455X: clusters of at most 8 (a sweep with 16-workgroup clusters,
2-wave and 16/24-deep variants never finished), 4..32 waves, depth <= 12.
FP32 sums run in a fixed order (bit-identical across runs); the K order
differs from the other kernels'. The op test runs every offered kernel of
its decode shapes against the fp32 reference.
Co-Authored-By: Claude Code <[email protected]>
The gfx1250 1x32 candidates were timed off a torch.profiler trace of the CUDA Graph replay, with every input rotated. Kernel tracing slows some kernels more than others (the 192-wide tiles by 6-7%, older ones by about 1%), and rotating the activation and the output makes them cold too, which a model forward does not do. Both biased picks against kernels that win in the production entry. A small timer in the tuner now captures the graph itself: each launch reads its own copy of the weight and its scales (about 1.2 GB of weight, as before), the activation and the output stay one buffer each, and run_perftest times whole replays with events (use_cuda_event), no profiler; the tuner divides by the launches per replay. Tuning and --run_config both use it. run_perftest and other tuners are unchanged. Co-Authored-By: Claude Code <[email protected]>
M 256-768 x N 6144 grids leave a quarter to two thirds of the CUs idle on 128x128 / 128x256 tiles; 192-wide tiles reach 256 workgroups only with K splits (256 x 6144 is 64 128x192 tiles, 256 with four splits; 768 x 6144 is 128 192x192 tiles), and the cluster-local split-K epilogue took only power-of-two tile_m and rows of 128 // (tile_n / 4) vectors. - The reduction takes a 192-column row (48 vectors, 128 threads) in 64-column chunks and issues every chunk's peer loads before the first sum; the batch is the largest row count that divides the stripe. A 192-row tile rotates its stripe with a compare instead of a mask. - The compute kernel reads the peer stripes non-temporally: the scratch lines are not kept, and the next launch's peer TDM store no longer waits on them (512x6144x6144 128x192 sk2: peer store 2.3 -> 1.15 us, kernel 14.9 -> 13.7 us; 256x6144x8192 128x128 sk2, a tuned row: 13.0 -> 12.5 us). - Catalog: fused split-K 2/4/8 on the 128x192 nb3, 192x192 nb3 and 256x192 nb4 profiles with each existing cluster that fits 16 workgroups (27 kernels), appended after every existing ID. The 192x256 / 192x192 nb2 fused IDs already in the catalog now launch as well. The sum stays FP32 in split order, so outputs match the unfused kernels of the same split bit for bit. Kernels without a compute fused split-K epilogue compile to the same ISA; compute fused split-K kernels differ only in the cache policy of the peer loads. Co-Authored-By: Claude Code <[email protected]>
At M 48-128 the GEMM is bound by the weight stream, and the tile kernels in
the tables reach 35-60% of a pure weight scan: every M tile reads all of the
weights through LDS, and A is re-read per N tile. The new kernel holds every
row in one workgroup (tile_m = M rounded up to 16):
* weights go straight into VGPRs with non-temporal vector loads, each byte
read once; 2-3 K steps in flight a wave (deeper queues flood the vector
path and delay the activation);
* the activation is the remaining traffic, A[tile_m, the rank's K range] per
workgroup. A cluster of ks x cn workgroups keeps it small: the ks ranks
split K, and the cn ranks of a K range share their slice by TDM multicast.
The slice goes to LDS in 512-byte K chunks (a ring of 3+ slots, refilled
after a cluster barrier, when it does not fit);
* the ks FP32 partials meet in a global slab after a cluster barrier. With
equal runs each rank sums a 1/ks share in rank order (reduce-scatter). With
"_u" (ks 2) the reducer rank takes 4u more K steps; the publisher writes
its whole partial and finishes first, so the exchange costs the reducer one
read instead of four global round trips (about 2.3 us measured);
* the wk K-wave partials of a workgroup are summed in LDS in wave order, so
results are bit-identical across runs.
Name flydsl_mxfp8_32_bpreshuffle_fullm_t{tile}_ks{ks}_cn{cn}_nb{nb}_wn{wn}
_wk{wk}_d{D}[_u{u}], run through the B=1 batched runner like the decode
kernels (bf16 only). The tuner offers it for M 48-128 (ids 3_990_000+: inside
the B=1 window below 4_000_000, so MiniMax rows keep kernelId "bmm", and above
skdec's ids). The config check, used by the launcher and by
launchable/candidates, keeps to what ran on MI455X: cluster shapes cn x ks of
1x1, 2x1, 1x2, 2x2, 4x1, 1x4, 4x2, 2x4 (all used by other kernels of this
GEMM), wave splits 1x4, 2x2, 2x4, 3x2, 3x4, depth <= 6, u <= 2, tile_m
48-128, LDS <= 320 KB, an estimated VGPR budget. Synchronization is the
workgroup barrier and the hardware cluster barrier, each workgroup signalling
and waiting the same number of times; there is no spin wait.
The op test runs every offered kernel of its decode shapes (now with
72x6144x6144) against the fp32 reference, rows past M unwritten.
Co-Authored-By: Claude Code <[email protected]>
The three-slot ring and the four-step A-scale panel left mod 3 / mod 4 arithmetic and per-wave selects for every refill descriptor, hoisted to the K-loop head (137 SALU per three K-steps). The three panels now sit side by side in one padded LDS row, so K-step s reads column s % 12 and a panel always refills into the slot column of the K-step that frees it. Each steady rev computes the A-scale state once, and the refill descriptors take per-wave constants instead of selects: 55 SALU per rev, 1080 -> 1049 cycles per K-step at 16384x6144x12288. Sums are bit-identical. Co-Authored-By: Claude Code <[email protected]>
minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csv gains 315 gfx1250 1x32 rows (kernelId bmm on the rows that run the B = 1 runner); 31 of the 36 gfx1250 rows of dsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv change. No gfx950 row changes. Each kernel was picked by the tuner (paired rounds, weights not cache-resident, at least 2% on the median and every round won) and kept only when the production entry confirmed it: CUDA graph, old and new processes alternating on one GPU, 6 rounds (4 for M >= 4096). A row that won the median but lost one or two rounds was run again and kept at 10 of 12 rounds (7 of 8 for M >= 4096). us is the production-entry median. Against the previous revision of these tables, production entry, 4 alternating rounds (total us before -> after, speedup of the total, geomean): M <= 16 77 rows 405.7 -> 366.6 1.107 1.104 M 17-47 27 rows 190.1 -> 168.8 1.126 1.129 M 48-128 56 rows 423.6 -> 375.8 1.127 1.121 M 160-192 14 rows 184.8 -> 178.8 1.034 1.043 M 256-2048 109 rows 2644.1 -> 2486.2 1.063 1.053 M >= 4096 68 rows 18577.2 -> 17028.9 1.091 1.134 all 351 rows 22425.5 -> 20605.0 1.088 1.095 Co-authored-by: lirui927 <[email protected]> Co-authored-by: aoli26 <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…cales on 256x384 kernel_fits_shape took the 192-wide fill profiles (128x192 / 192x192 nb3, 256x192 nb4) without allow_wide, so the untuned fallback and the mxfp8_128 candidates could pick them; a static replay of the fallback over 1190 shapes picked another kernel than the previous revision for 275 of them. They now need allow_wide like the 256x384 profile: the fallback is back to the previous revision's picks on all 1190, and the mxfp8_32 tuned rows and candidates (allow_wide=True) are unchanged. gemm_a8w8_mxfp8_bpreshuffle(a_scale_preshuffled=True) appended _aspre to a tuned 256x384 name, a kernel that reads row-major A scales only (a trace-time assert); such a row now takes the direct fallback, as a B=1 row with preshuffled A scales already does. The op test's mocked dispatch check covers a 256x384 row with preshuffled A scales, and on gfx1250 the test checks every 1x32 row of the two tuned tables with the launch check the mxfp8 entry uses (the blockscale entry runs a row without it). Co-Authored-By: Claude Opus 5.5 <[email protected]>
bmm_mx32_kernel_launchable is a runtime check (tuned-row lookup and the tuner), so it reads the LDS capacity of get_gfx_runtime(), not of get_gfx(), which follows GPU_ARCHS and can name another target on a multi-target build. Same answer on a single-target build or on gfx1250. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…e AOT cache The mxfp8_32 B = 1 kernels the tuned rows select (weight streaming, decode, balanced decode, full M) still launched on the JIT path: the gfx1250 replay compiled them but wrote no entry, and every process traced them on their first call. Each launcher now has an aot_factory with no argument that imports its kernel module, as the a8w8 launchers of ROCm#8678 do, and the launch uses factory.lazy(). Every constexpr was already in specialization_key, with one type. The specialization keys held the device index. They hold the torch.device now: in memory it keeps one launcher per device, as the JIT path needs, and on disk only its type, so one entry serves every GPU. The four caches and their sources are declared in aiter/aot/flydsl/sources.py. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The balanced decode and full-M kernels each defined the same tdm_2d closure; it is now tdm_load_2d in the balanced decode module, taking the LDS base as an argument, and the full-M kernel imports it. The full-M AOT cache declares that module as a source. The decode, balanced decode and full-M runners repeated the same operand check; _check_operands takes the runner's label for the message. No kernel change: the compiled code is the same. Co-Authored-By: Claude Opus 5.5 <[email protected]>
ff556f4 to
0f3007c
Compare
|
Rebased onto main Conflicts. Both were in the first commit, and in both main and this PR had each added a block at the same spot, so both blocks are kept:
Other changes. CPU checks. All 19 changed Python files compile, and black is clean. CI's GPU, partial (4x MI455X, FlyDSL 0.5.5 as main now pins it).
The torch profiler's drain also hung at exit on that stack. I will rerun with those fixed when a gfx1250 node is free. |
What
gfx1250 FlyDSL kernels for the native E4M3 / E8M0 1x32 MXFP8 GEMM, a tuner that picks one per shape, and the tuned rows. A tuned row names its kernel; shapes without a row keep main's heuristic.
gemm_a8w8_mx32_stream_gfx1250.pymxfp8_decode_gemm_gfx1250.pyskdec)mxfp8_skdec_gemm_gfx1250.pyfullm)mxfp8_fullm_gemm_gfx1250.pygemm_a8w8_gfx1250.py_pd2); non-temporal weight loads when one M tile covers Mgemm_a8w8_256x256_gfx1250.py_pf)Compute-kernel options, each a tuner candidate with the default kernel unchanged: split pipeline fence (
_sf, two TDM loads in flight on two-slot pipelines), one wave order (_wo1/_wo2), N-major cluster numbering (_nm).gemm_a8w8_mxfp8_bpreshuffle_tune.py): times every legal kernel of a shape in a CUDA graph with events; each launch reads its own weight copy (about 1.2 GB in total, so weights are not cache-resident, as in a model) while the activation and the output stay hot. A candidate replaces the current row only if it wins every paired round and the median by--min-gain-pct(2%).run_perftestis unchanged.skdecorfullmkernel run through the B = 1 batched runner, in bothgemm_a8w8_blockscale(isBpreshuffled=True)(kernelId=bmm) andgemm_a8w8_mxfp8_bpreshuffle. The 1x32 lookup skips a row whose kernel cannot launch at the real M.minimax_m3_a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm.csvand 36 indsv4_a8w8_mxfp8_bpreshuffle_tuned_gemm.csv; no gfx950 row changes.skdecandfullmlaunches through four newaot_factorycaches (keyed on thetorch.device, so one entry serves every GPU).aiter/aot/flydsl/sources.pydeclares their sources, including the fused split-K epilogue the direct kernel imports.arg_outruntime argument like the other callers.The C-tile LDS read-back is not here; #8486 carries it.
Results
MI455X, ROCm 10.3.0, torch 2.13, FlyDSL 0.5.3, production entry with 1x32 scales, us per call in a CUDA graph, weights not cache-resident.
This revision's kernels and tables against the previous revision (f3767ec), all 351 gfx1250 rows, old and new processes alternating, 4 rounds (measured before the rebase onto main, which changes no kernel; since then 3 MiniMax rows that used an eight-wave option, dropped as too narrow, were retuned, 0.9-5.1% slower each, +0.5 us in total):
250 rows name another kernel (1.096 total, 1.132 geomean); the other 101 are unchanged (1.007). Outputs are bit-identical to the previous revision on 232 rows; the 119 others changed kernel and differ by at most 1.7e-3 relative. The previous revision was 1.046 (total) over the first one.
After the rebase onto main (AOT launch path of #8678), 41 rows across all M segments against the pre-rebase head, 2 rounds: 1.000 total, 0.996 geomean; two small-M direct rows (10x9856x6144, 20x24576x6144) measured 3-6% slower. Their kernel binaries, launch arguments, allocations and outputs are identical; the same kernel runs at one of two discrete speeds set by host-side process history unrelated to the GEMM (replaying the graph on another stream, importing another module first or a single hardware queue flips it either way), and the new launch path, which imports only the kernel module it launches, lands on the slow one more often in this harness.
Against main, measured at the first revision (5b674a1) and not re-measured since; main has no gfx1250 rows for these shapes:
Reviewed revision
ff556f4
Behavior and intent
On gfx1250, a 1x32 MXFP8 shape with a tuned row runs the kernel the row names; shapes without a row keep main's heuristic. gfx950 and 128x128 paths are unchanged. There is no separate entry point for the small-M kernels: they run exactly where a tuned row selects them. Split-K, K-wave and cluster partials are summed in a fixed order, so repeated calls give the same bytes.
Validation and unverified scope
One MI455X (ROCm 10.3.0, FlyDSL 0.5.3), on this revision's code (the rebase onto the latest main changed none of this PR's files):
gemm_a8w8_blockscale(isBpreshuffled=True)for MiniMax-M3,gemm_a8w8_mxfp8_bpreshufflefor DSV4), twice each: all pass (finite, repeats bit-identical, within the fp32-reference tolerance, dispatched kernel == row's kernel); outputs identical to the previously validated revision except the 3 retuned rows, also when served from the AOT cache;python op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: exit 0, no mismatch, including the new checks;AITER_GEMM_TEST_ITERS=1 python op_tests/test_gemm_a8w8.py: exit 0. One earlier run reported a catastrophic delta on ptpc 32768x7168x16384, a row ofa8w8_bpreshuffle_tuned_gemm.csvthis PR does not touch; it did not recur in a rerun or in 30 repeats on this branch or on main;pytest op_tests/test_graph_alloc.py: 4 passed, 3 skipped;pytest tests/test_flydsl_aot_launch.py tests/test_flydsl_aot_cache.py tests/test_flydsl_aot_replay.py: 88 passed, 6 failed, 5 skipped, the same 6 failures on main in the same container;GPU_ARCHS=gfx1250 python -m aiter.aot.flydsl.gemm --csv <the two tables>: 351 jobs ok, 0 failed, 0 refused (104 scanned in-range M), 250 entries, a second run builds nothing,--checkpasses; a production call of every kernel family (streaming, decode,skdec,fullm, compute, direct, B = 1 batched, untuned M) then loads its AOT entry with no JIT trace, andAITER_FLYDSL_AOT_CACHE=0gives the same bytes;Unverified: the commits one by one (only the final tree ran); the table against main was not re-measured;
op_tests/test_gemm_group32_interface.pywas not re-run; other GPUs, multi-GPU or model runs; FlyDSL other than 0.5.3.PR-specific question
Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
Only gfx1250, E4M3 operands, E8M0 1x32 scales and a (16, 16)-preshuffled weight, through a tuned row. The 1x32 lookup of
gemm_a8w8_mxfp8_bpreshufflechecks each row's launch condition at the real M (tile and cluster fit, M >= tile_m for compute kernels, ragged N only whereragged_n_okallows, each small-M kernel's own config check) and otherwise falls to the next padded row or main's heuristic; the blockscale table keeps main's rule. A row naming a decode,skdecorfullmkernel takes the direct kernel when the output is not bf16 or the A scales are preshuffled, and so does a 256x384 row with preshuffled A scales. The 256x384 and 192-wide fill compute profiles are accepted only for mxfp8_32 tuned rows (allow_wide), never by the untuned fallback. Launchers raise on unsupported configurations; theskdecandfullmchecks admit only cluster shapes, wave splits and depths that ran on MI455X, and their workgroups synchronize only through the workgroup and cluster barriers (no spin wait).Changed op tests
op_tests/test_gemm_a8w8.py: two per-token shapes sharing one tuned gfx1250 kernel, each run twice; repeats must match the first launch bit for bit.op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: a CPU, mocked check that batched, streaming, decode,skdecandfullmrows run the B = 1 batched runner and that preshuffled A scales (also on a 256x384 row) or fp16 output take the direct kernel; on gfx1250, every decode,skdecandfullmkernel the tuner offers for seven shapes against the fp32 reference, with rows past M left unwritten; and, on gfx1250, every 1x32 row of the two tuned tables must name a kernel that launches at its M (the blockscale entry runs rows without that check).op_tests/test_graph_alloc.py: adds the fused split-K workspace to the private-graph-pool check.🤖 Generated with Claude Code