Repository navigation
[FlyDSL] [Bugfix] gfx950 A16W16: reduce split-K and slice-K partials in fp32, deterministically - #7053
[FlyDSL] [Bugfix] gfx950 A16W16: reduce split-K and slice-K partials in fp32, deterministically#7053AndreasKaratzas wants to merge 24 commits into
Conversation
…in fp32, deterministically The gfx950 FlyDSL HGEMM rounded every split-K partial to the output dtype and added it to C with packed bf16/fp16 atomics, and summed slice-K wave partials from an LDS tile typed as the output dtype. With bf16 output each partial is rounded to 8 bits and every add rounds again, instead of one rounding of the fp32 sum, and the atomics make the result depend on arrival order (fp32 output used fp32 atomics: order-dependent too). Issue ROCm#5976. - Slice-K: k-waves hand their fp32 accumulators to k-wave 0 through LDS, one k-wave at a time; C is rounded once. Same LDS for k_waves=2. - Split-K: every split stores its fp32 partial to a workspace (sc1, agent coherent); the tile's last split to start waits until the others have counted themselves done and adds all partials in split order, then writes C once. No zero-init of C, no atomics on C, no cache-wide fence. The semaphore holds a ticket and a done word per tile, both monotonic. - split_k is now a constexpr of the param (unrolled reduction); kernel names gain "f32" so stale disk-cache binaries are not reused. - op_tests/test_flydsl_hgemm.py: small-integer inputs keep every fp32 partial exact, so split-K/slice-K outputs must equal the exact product rounded once, and Gaussian inputs must be bitwise reproducible. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
The fp32 split-K reduction made small-M split-K rows 1.5-2.3 us slower
(+7..+40%): the tile's last split to start spin-waited on a done counter
until the other splits had stored their partials. This gets that time back
and retunes the affected rows. Outputs stay exact and bitwise
deterministic.
- Reduction: every split stores its fp32 partial, waits for its own sc1
stores, then increments the tile's counter (atomic inc with wrap at
split_k - 1, so the last arrival also resets it). The split that reads
split_k - 1 is the last to arrive: it adds all partials in split order
and writes C once. No workgroup waits for another.
- Each tile's counter sits on its own 128-byte line. Packed counters put
every split of every tile on one or two lines, where the agent-scope
atomics serialized. One int32 counter per tile replaces the int64
ticket/done pair, so get_split_k_buffers() drops its split_k argument
(op_tests/test_graph_alloc.py already calls it that way). Kernel names
use "_ksNfp32" so binaries of the previous protocol are not reused from
the disk cache.
- split_k no longer has to divide K: each split takes whole block_k tiles
and the last split takes the remainder. Configs that were valid before
get the same partition. The gfx950 tuner tries split_k 1..16; its pruner
no longer counts per-split K padding and allows 3 grid rounds.
- Tables: the 824 gfx950 rows with M <= 128 that use split-K or slice-K
were re-searched under this kernel; 587 rows change (new picks: 535
FlyDSL, 43 torch, 8 triton, 1 skinny). A row changes only
if the new config is exact on integer inputs, bitwise deterministic and
faster in three separate runs.
- op_tests/test_flydsl_hgemm.py gains an uneven split (4x1536x7168 ks5).
Through aiter.tuned_gemm, HIP-graph replay, weights rotated past the LLC,
median of 7 interleaved rounds, MI350X, 824 rows, vs the kernel and tables
before the fp32 fix:
geomean rows <= before summed us
fp32 fix alone 1.215 52 15727
with this change 0.968 490 13454
Signed-off-by: Andreas Karatzas <[email protected]>
Co-Authored-By: Claude <[email protected]>
Conflicts: SPLIT_K_SEMAPHORE_MAX_LEN takes main's 2048 next to the per-tile counter stride. Tuned CSVs merged row by row: main's rows win where only main changed them or where main moved a row off split-K; this branch's exactness- gated retunes win where both changed a split-K/slice-K row. Co-Authored-By: Claude <[email protected]> Signed-off-by: root <[email protected]>
…duction, retune The exact fp32 split-K reduction left 237 of the 824 gfx950 M <= 128 rows slower than the bf16-atomic kernel. Its tail (store the partial, wait for it, count in, reload every partial) costs about 1 us more than the old fire-and-forget atomics, and big tiles with many splits move S x tile x 4 bytes of partials at the end. Outputs stay bitwise identical to the previous commit. - Load every kernel argument the kernels use (A, B, C, semaphore, workspace and bias base addresses, M, N, K, working K) through one empty asm at entry, so the scalar loads share one wait instead of two serialized round trips before the first weight load, and the tail no longer reloads the semaphore pointer. - With group_m == 0, launch a (n tiles, m tiles, splits) grid: same dispatch order as the linear tile id, without dividing it by num_pid_n. - Split-K tiles of at least 1024 elements: the reducer adds its own partial from registers (one copy of the sum per split index, chosen by a scalar branch), and partial stores and loads skip groups entirely past M by pointing them past the bounds-checked workspace. - Tables: 222 gfx950 bf16 rows re-picked among FlyDSL configs near the current and pre-fp32 picks, timed with HIP-graph replay and weights rotated past the LLC. A row changes only if the new config is faster by >= 1% and >= 0.05 us in at least 4 of 5 interleaved rounds (3 of 3 for 16 rows), and it is exact on integer inputs and bitwise deterministic. Rows retuned on main keep main's pick. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude <[email protected]>
NOT READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
…slice-K combine The fp32 split-K reduction is slowest where the last split of a tile has to read every split's partial alone. Spread that work over the splits where the whole grid is resident, and keep the fragment-store reduction everywhere else. - Shared reduction: every split arrives on the tile's word with a promise to reduce one range of the tile, polls (at most 64 times) until every split has arrived, then adds bias + every split's share of its range in split order and writes that part of C. A split whose polls run out stores its range and withdraws the promise with a CAS, which fails once the last split has arrived; the last arrival reduces every range whose promise is missing. Every wait is bounded. - The host picks the reduction per launch: shared only when num_pid_m * num_pid_n * split_k <= CUs, the tile has at least 4096 elements and, for k_waves=1, split_k * tile >= 16384. Otherwise k_waves=1 stores partials straight from the MMA fragments (row-masked only when M is not a multiple of block_m, so full tiles compile to the previous ISA) and k_waves>1 uses the last-arrival reduction through LDS. - One-pass slice-K combine: every k-wave writes its fp32 tile to LDS once and the whole workgroup adds the k-waves in order while storing C or the split's row-major partial. - The tuner catalog adds k_waves 4 and 8 and split_k 20, 24, 28 and 32. - Kernel names gain "c" (one-pass combine), "s" (shared reduction) and "m" (row-masked partials), so older binaries are not reused from the disk cache. - Retuned the 824 small-M (M <= 128) gfx950 rows. A row only changes if the new config is exact on small-integer inputs, bitwise repeatable and faster in separate processes and in lockstep runs against the previous tables. Every per-element sum keeps its order (bias, then splits 0..S-1, k-waves in order), so outputs are bitwise identical to the previous kernel on all 42 compared configs. The 663 tuned configs of the original tables, the 552 of the previous tables and the 620 of these run exact and deterministic on this kernel. All 824 rows through aiter.tuned_gemm on MI355X, HIP-graph replay over weights rotated past the LLC, 7 lockstep rounds, against main: geomean 0.948 (previous tables 0.969), 631 rows at or below main, 31 more than 5% slower; summed 13183 us vs 14153 us. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude <[email protected]>
Conflict: op_tests/test_flydsl_hgemm.py keeps both main's HTI concurrent-copy test (ROCm#7042) and this branch's partial-sum exactness test. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
…tza_hgemm_fp32_partials Combines the PR branch's f301498 with the shared split-K reduction and the one-pass slice-K combine of this branch. Kernel: - Taken from f301498: the kernarg loads through one empty asm at entry in both kernels, the (n tiles, m tiles, splits) grid for group_m == 0 (the split-K counters and partial slots follow its tile index), the bounds-checked workspace for every split-K path, and the fragment-partial reducer adding its own partial from registers for tiles of at least 1024 elements. - Fragment partials skip groups past M through an offset beyond the workspace (f301498's mechanism) instead of a branch and a reload of group 0, but only when the tiles cross M (this branch's host flag) and the tile has at least 1024 elements: on 16x16 tiles the mask cost 2-3% and saved nothing. - The shared reduction no longer loads another split's slot in place of its own; the own split's load reads past the workspace. - Tried and dropped: the last-arrival LDS reduction adding its own partial from registers (per-split selects made split_k >= 20 tiles up to 14% slower). Tables: rows changed on both sides (162) take whichever of this branch's, f301498's or an earlier pick of the PR is fastest on the combined kernel (101 this branch, 57 f301498, 4 earlier picks); rows changed on one side keep that side's pick unless another one is faster by > 1% in >= 5 of 7 lockstep rounds (23 of 303 switched). Three rows (16x24x2560, 80x512x2560, 32x2560x2880 with bias) then take f301498's config, which was faster by > 1% in >= 14 of 21 rounds. Every config is exact on small-integer inputs and bitwise repeatable on the combined kernel. 824 gfx950 M <= 128 rows through aiter.tuned_gemm, HIP-graph replay, weights rotated past the LLC, 7 lockstep rounds against the original tables: geomean 0.922 (this branch 0.948, f301498 0.941), 694 rows at or below, 15 more than 5% slower; vs the faster of the two parents per row 0.993. Co-Authored-By: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Conflicts: - gemm_a16w16_gfx950.py: keep the fp32 split-K workspace, the one-counter get_split_k_buffers(stream, device) and the up-front kernarg loads; take main's capture_scoped_cache, kernarg preload hints, k_stagger and b_non_temporal. - aot/flydsl/gemm.py: take main's replay-based AOT build (ROCm#6956), which launches through the runtime and so needs no HGEMM-specific arguments. - glm5/kimik3/minimax_m3_eagle tables: rows are merged one by one. Where both sides changed a row, main's row is kept: glm5 2624x6144 M=1/2/4/6/8 use the skinny kernel (ROCm#6427), and kimik3 64x20480x7168 uses the band-stream kernel (ROCm#7546). Neither uses split-K; both are exact and repeatable. - test_graph_alloc.py: call get_split_k_buffers(s, dev), which no longer takes split_k. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
… reduction The exact fp32 reduction made some M > 128 split-K and slice-K rows slower than main, because these rows were tuned for the bf16 atomic reduction. Retune them with the gfx950 tuner (csrc/gemm_a16w16/gemm_a16w16_tune.py, flydsl/torch/triton candidates). Keep a new row only when it is faster than the merged row in interleaved runs with weights rotated past the LLC. - 119 rows in 14 tables change (107 FlyDSL to FlyDSL, 12 FlyDSL to torch). - glm5 2624x6144: M=256 moves to t128x128x64x3 ks6 kw2, and a new M=192 row uses t128x128x64x3 ks6. - No row with M <= 128 changes. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
89 gfx950 rows with M <= 128 were more than 2% slower than main with the exact fp32 split-K reduction. This retunes them with a wider search. - FlyDSL: every config of the tuner catalog for the 6 GLM-5 2624x6144 rows (8.7k-14.7k per row), and for the other 83 rows the configs with the row's tile and split_k +-3 plus 600 random configs. Then the k_stagger and b_non_temporal variants of the best configs. - hipBLASLt: every solution was timed. It was not faster on GLM-5. - A row changes only if the new config is exact on integer inputs, gives bitwise identical outputs in 20 runs, and is more than 1% faster than the current row in interleaved runs through aiter.tuned_gemm, with and without torch.cuda.empty_cache() between rows. 58 rows in 12 tables change, all to other FlyDSL configs. On the 89 rows, the geomean vs main goes from 1.048 to 1.003 with empty_cache and from 1.038 to 0.990 without it (7 rounds on each of 2 GPUs per mode). The `us` column of the changed rows is the median kernel time from the interleaved selection runs (HIP-graph replay, weights rotated past the LLC). It is not the tuner's time, so it does not compare directly with the `us` of the old rows. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
…6144 hipBLASLt solution 17403 is exact on integer inputs, bitwise repeatable and 5-12% faster than the FlyDSL split-K row through aiter.tuned_gemm (15 interleaved rounds on 2 GPUs, with and without empty_cache). The index is valid for hipBLASLt 1.4.1 (ROCm 10.0.0). Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Resolve aiter/configs/model_configs/dsv41_bf16_tuned_gemm.csv after ROCm#7624. The gfx950 128x384x5120 row changed on both sides. Take the row from main. With the fp32 partial reduction of this branch, its tile is exact and deterministic, and it is faster than the row of this branch. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
|
I measured this PR on gfx950 (MI355X) with split-K bf16 rows we tune for GLM-5.3-Flash and Qwen3.8-Flash-Next, and with this PR's own retuned rows for those two models. Setup:
Error and reproducibility come from a separate run, in which the lookup also missed 4 more Qwen keys (not reproduced since); they are left out here:
Not measured: a main build, end-to-end serving, other GPUs. The semaphore comes from |
|
@eppaneamd thanks for measuring this. Yes, a cached per-stream workspace works with the protocol, and I'll switch to one. Why it is safe: the workspace needs no initial value. Each split writes its own fp32 slots before it takes its ticket, and the reducer reads them only after the counter shows every split has arrived. The counter (from Two constraints decide the shape of the change:
Sketch (cached with @capture_scoped_cache
def _split_k_workspace(device, stream_handle, numel):
with persistent_alloc(device):
ws = torch.empty((numel,), dtype=torch.float32, device=device)
return ws, _dynamic_tensor_arg(ws, 0)
# in gemm_a16w16, split_k > 1:
needed = split_k * tiles * param.block_m * param.block_n
bucket = 1 << (needed - 1).bit_length()
if bucket * 4 > 2**30: # keep the SKIP offset outside the buffer
bucket = needed
_, workspace_arg = _split_k_workspace(device, stream.cuda_stream, bucket)I cache the wrapped Cost: one bucket per (device, stream, size) is kept for the life of the process. With the tables in this PR, the largest single workspace is 56 MiB (llama70B 256x8192x28672, t128x256 ks7). Every other table needs at most 48 MiB, and most need 8-16 MiB. Power-of-two buckets cap the total per stream at about twice the largest bucket. A cached buffer first allocated after vLLM's memory profiling (for example during graph capture at a larger M) isn't counted in the profile. Today the per-call I'll add a test that two eager calls on one stream reuse the same workspace, that two streams get different ones, and that the exact-and-deterministic cases still pass under graph replay. I'll also rerun your host-time comparison. |
Conflicts: - gemm_a16w16_gfx950.py: keep this branch's whole-tile split partition (last split takes the remainder) and its validator. Drop main's FT balanced-split branch in the kernel body, because the host now always passes a block_k-aligned working_k, so that branch cannot run. Keep this branch's kernel names (they already differ from main's _kst4/_kst5 names). Keep main's bpreshuffle shape check. - gemm_a16w16_policy.py: keep both the whole_tile_splits field and main's tdm/b_k_contiguous fields. Keep this branch's split_k candidates, which are a superset of main's 1..9 for K >= 9. - kimik3, qwen38_flash_next, qwen3_5_397b tables: key-based 3-way merge. Take main's change where this branch did not touch a row (incl. the hipBLASLt row removal from ROCm#8490). For the five gfx950 kimik3 896x3584 rows (M 8-64) that both sides retuned, keep this branch's exact fp32-partial rows. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Conflicts: - gemm_a16w16_gfx950.py: take main's AOT-cache launch (ROCm#8565, ROCm#8600): bind_aot, _PARAM_ITEMS and _run_compiled with the sorted param items and the device as the specialization key. Keep this branch's fp32 workspace argument, its one-counter get_split_k_buffers(stream, device) and its get_cu_num/buf_base_i64 imports. The param items now include this branch's split_k_resident and m_tail, so the AOT key covers the per-launch reduction choice. - llama70B, minimax_m3_eagle tables: key-based 3-way merge. Take main's change where this branch did not touch a row. For minimax_m3_eagle 128x50016x6144, which both sides changed, keep main's row (ROCm#8598, FlyDSL t128x256x64x3 ks1 w4x4x1, 119.9 us vs this branch's torch row at 135.0 us). It has no split-K and no slice-K, so this PR's reduction does not apply and it is exact. This follows the earlier merges, which kept main's row where main's non-split-K pick is faster. Signed-off-by: Andreas Karatzas <[email protected]> Co-authored-by: Claude <[email protected]>
Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
…28x12288x6144 Main removed every shipped hipBLASLt BF16 row in ROCm#8490, because a saved solution index can map to another kernel with a different hipBLASLt build (ROCm#8406). This row goes back to the exact FlyDSL config from aca9344 (t128x96x64x5 ks2 w4x1x1 stg3 bnt, 41.81 us). Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
…tream Eager launches reuse one fp32 workspace per (stream, device, power-of-two size) instead of a torch.empty and a from_dlpack per call: on MI355X the host time of a split-K call goes from +8.0 us to +2.0 us against main. A launch on a capturing stream that has no eager buffer still takes its workspace from the graph's pool, so captures keep no extra memory. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…tic kernels The asm split-K kernels return different bits from run to run with 3 or more splits. 39 gfx950 bf16 rows move to FlyDSL (37), torch (1) and Triton (1) configs that are repeatable and 1.4% to 33% faster with cold activations on MI355X; 29 bf16 rows stay on the asm kernel. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…eduction 123 gfx950 bf16 rows in 16 tables (11 of them in the Gemma-4-26B-A4B table, which was never retuned) move to exact configs: 111 FlyDSL, 12 torch. Each is 1.0% to 35.5% (median 5.7%) faster than the row it replaces with cold and with warm activations on MI355X. 107 of the rows were more than 2% slower than main; 73 of those are now within 2%. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
|
I timed every affected gfx950 row on MI355X against main, with cold and with warm activations, and pushed three follow-up commits. Short version: they take about 70 rows out of the "more than 2% slower than main" set (472 before, 401 after) and make 39 asm split-K rows repeatable. 401 of 1733 rows are still more than 2% slower than main (165 above 5%, 37 above 10%), and I did not find a way to close those with the fp32 reduction. Commits
Every FlyDSL split-K and slice-K row keeps the fp32 reduction. I also built a two-split policy that keeps main's packed atomics (two additions onto zero commute, so it is repeatable): it brings 26 more rows within 2% of main, at main's accuracy on 38 rows (12.9% of outputs more than 1 ulp off instead of 0.01%). It is not in this push, because it gives up the accuracy this PR is about and #8031 has just removed the same reduction on gfx1250. I can open it as a separate PR if that trade is wanted. Timing
A row counts as slower only when the median of its per-round ratios is above the threshold against both main workers. The control differs from main by 0.29% (median) and 1.40% (90th percentile). Counting a row when the geometric mean of the two ratios is above 2% gives 429 rows instead of 401. Rows: every 256-CU gfx950 bf16 row that uses split-K or slice-K on either side or whose pick this PR changes, 1733 rows. "Before" is 1f8a4e5 with commits 1 and 2; "after" is all three commits. Each cell with three numbers is cold / warm / either mode.
Per table
"Before" was measured earlier the same day with the same harness. On the 1610 rows that commit 3 does not change, 356 were above 2% then and 362 are now (325 in both runs). Of the 123 changed rows, 116 were above 2% before and 39 are after. 699 rows are more than 2% faster than main in both modes. Summed over the 1733 rows, the cold time is 4.1% below main (3.4% before). In 8 identical calls per row, 0 of the 1733 rows return different bits; on main 1213 do. How far the count moves between runs: on the 1695 rows that a second full run a few hours earlier shares with this one, it gave 363 rows above 2% and this one 374; 346 rows are above 2% in both and 391 in at least one. One row can sit 6% apart between two runs with the same kernel (Llama 405B 256x9216x16384: +6.3% here, -0.7% there), so single rows near the threshold do not carry signal; the count does. Why the remaining rows are slower369 of the 401 use 3 or more splits on main (146 with 4, 103 with 8, 65 with 7); 30 use 2. Their K loop is as fast as on main; the reduction is not. Kernel time (cold, us) with parts of the reduction switched off:
The packed atomics cost 0.8 to 2.6 us on these rows and the fp32 reduction 1.6 to 6.5 us. The partial stores are cheaper than the atomics. The cost is in what follows: the last split has to learn that every other split has stored (wait for its own stores, a barrier, one atomic that returns a value: 0.8 to 1.6 us) and then read the partials back (0.5 to 2.5 us). Those are two more memory round trips after the K loop, on kernels of 6 to 12 us. What I tried on these rows:
Ways forward for these rows: a tuner run over the full catalog (the second screening pass, 15,507 new pairs on the 120 slowest rows, still gave 34 of the 123 changes, so the catalog is not exhausted); a cheaper ordered reduction in the kernel; or accepting them. A per-row switch back to the atomics for 3 or more splits would make them as fast as main and non-repeatable again. I have not added one. Checks on MI355X
Merge with main1f8a4e5 and the three commits merge cleanly into main (9da5928). On the merged tree the four tuning test files give 80 passed and 0 failed, AI assistance (Claude Code) was used for the measurements and for these commits. |
…talog screen 319 gfx950 bf16 rows in 17 tables move to other repeatable configs: 246 FlyDSL to FlyDSL, 65 to the FlyDSL skinny kernel (M <= 128), 4 to torch, 3 to Triton, 1 torch to FlyDSL. The configs come from a screen of the tuner catalog for the 1733 rows this PR affects: the (tile, block_k, split_k, waves) classes with up to 8 splits, then every stage count and the k_stagger / b_non_temporal variants of the best classes, 3.0 M (row, config) pairs timed with HIP-graph replay over cold weights. A row changes only if the new config is repeatable in 8 calls, as accurate as the current one, and not more than 1% slower than the current row with cold or with warm activations in separate runs. On MI355X against main (dd6beb9 rows and kernels), two interleaved passes over the 1733 rows: rows more than 2% slower than main go from 381 to 255 and above 5% from 148 to 108 in these passes; geomean vs main from -3.4% / -4.1% (cold / warm activations) to -4.9% / -5.7%. 288x2272x7168, the slowest row, moves from t96x96x64x5 ks7 to t96x96x128x3 ks3 with two k-waves and is within 2% of main. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
…onfig Three reruns on the committed tables (two interleaved passes over the 1733 affected rows with 9 rounds each, and a 15-round run of the rows in question) found no gain on two of the 319 rows of the previous commit: - dsv4 1920x64x4096: t32x64x128x4 ks4 with waves 2x4x1 reads 1.2% to 2.1% slower with warm activations than with waves 2x2x1, and within 0.7% with cold ones. - qwen32B 16x5120x25600: t16x128x128x4 ks5 with waves 1x2x1 reads 0.6% to 0.9% slower than with waves 1x4x1 in both modes. Its stored time (56.6 us) does not reproduce; the kernel takes 46.7 us. Two workers that run the same kernel differ by up to 0.8% on these rows, so the first is a small loss at most and the second is no change. Neither is a gain, so both rows go back to their b155ae8 line and the retune covers 317 rows. The same reruns against main (dd6beb9 rows and kernels) with these tables: rows more than 2% slower than main go from 377 at b155ae8 to 257, above 5% from 142 to 102, above 10% from 30 to 14, none above 15%; geomean vs main from -3.4% / -4.1% (cold / warm activations) to -5.0% / -5.7%. The screen behind the previous commit timed 3.0 M of the 34.1 M (row, config) pairs in the tuner catalog of these rows; it is not an exhaustive run. Signed-off-by: Andreas Karatzas <[email protected]> Co-Authored-By: Claude Code <[email protected]>
|
I screened the tuner catalog for all 1733 affected gfx950 rows and pushed two more commits with the result. Short version: it helps, and it does not bring every row within 2% of main.
Commits
Together: 317 rows in 17 tables. 244 go from one FlyDSL config to another, 65 to the FlyDSL skinny kernel (rows with M from 1 to 48), 4 to torch, 3 to Triton, 1 from torch to FlyDSL. Every new FlyDSL name is in the tuner's default catalog for its shape, at the TimingSame harness and statistic as in my last comment: The table combines two passes over all 1733 rows on the committed tables, each with fresh processes: one on a single GPU, one split over two other GPUs. A row's ratio is the geometric mean of the two passes. The two rows that the second commit put back carry the numbers of the b155ae8 worker. How much the counts move:
Per table
Of the 317 changed rows, 195 were above 2% before and 70 are after. Against the row it replaces, a changed row is 5.0% faster at the median (worse of the two modes) and 19% at the 10th percentile. Two changed rows read more than 1% slower than their old row in one mode and are faster in the other: 336x384x7168 (+1.4% warm, -0.6% cold) and 32x4x10240 (+1.0% cold, -3.4% warm). None reads more than 2% slower. 838 rows are more than 2% faster than main in both modes (741 before). Summed over the 1733 rows, the cold time is 5.9% below main (4.2% before). Of 90 control rows this PR does not touch, two are above 2% (worst +4.5%); they run the same kernels as main, so that is the noise of a single row. How the screen was done
What it found
The 257 rows that stay slower
Where the time goes on these rowsKernel time (cold, us) of 11 of these rows with their tuned config and parts of the reduction switched off:
The K loop alone is 0.9 to 1.6 us faster than main's whole kernel, which puts the cost of main's atomics at about 0.9 to 1.6 us (on 9 of the 11 rows the tuned config is not main's config, so this is an estimate; on the two rows with the same config it is 1.3 and 1.6 us). The fp32 reduction costs 1.5 to 2.2 us: 0.2 to 0.7 us for the partial stores and 1.4 to 1.8 us for learning that every split has stored and reading the partials back. Those are two memory round trips after the K loop, and the atomics have none: main's kernel ends when it has issued them. On a 6 to 9 us kernel the 0.4 to 1.1 us of difference is 5% to 14%. On these rows the screen found no split, tile or wave class with 1 to 8 splits that is faster: they are small in M x N and long in K, so they need many workgroups along K, and with fewer splits the K loop loses more than the reduction gains. In the screen's own timing (one sample per config) the best 1-split, 2-split and 4-split configs of 1664x64x7168 are 36%, 16% and 4% slower than its best 8-split config. Ways to treat them:
Checks on MI355X
AI assistance (Claude Code) was used for the screen, the measurements and the commits. |
|
Decision on the rows that stay slower than main: I'm accepting them. After the retune, 257 of the 1733 affected rows are more than 2% slower than main, 102 more than 5%, 14 more than 10% and none more than 15%, with a median extra cost of 0.4 us per call. Against that, the kernel is 5.0% to 5.7% faster than main in geomean, returns the same bits on every call, and is as accurate as hipBLASLt. Switching those rows back to the atomic reduction would make 236 of them non-repeatable again, which is what this PR is here to remove. Still open as follow-up tuning, not for this PR: the screen covered 3.0 M of the 34.1 M (row, config) pairs, with nothing above 8 splits and 96 rows that got no pass. Taking this out of draft so the GPU CI runs. |
…artials Resolve the two tuned BF16 GEMM tables per shape key. Rows both sides agree on and rows only this branch changed keep this branch's row; rows only main changed keep main's row unless their kernel uses the FlyDSL gfx950 split-K or slice-K reduction this branch replaces. Those rows, and every key both sides changed, were timed on the merged tree (cold and warm HIP-graph replay plus the tuner's profiler timing, two passes, candidates alternated) among this branch's, main's and the merge-base config, and the fastest one that is exact on integer inputs and bitwise repeatable is kept, with us/tflops/bw/err_ratio rewritten from that measurement. - llama405B: 54 same, 5 branch-only, 71 main-only kept as is; 9 main-only split-K/slice-K rows and 17 keys changed by both re-timed (11 take this branch's config, 15 main's). - minimax_m3_eagle: 260 same, 49 branch-only, 9 main-only kept as is; the 9 new main split-K rows re-timed: 7 keep main's config, and 480/496x9216x6144 move to torch, which is about 30% faster than the ks3 config under the fp32 reduction. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
Conflicts: - gemm_a16w16_gfx950.py vs ROCm#8929: keep this branch's 4-argument write_cshuffle_vec_to_global (main's out_buf/is_split_k only serve the atomic split-K store this branch removes) and use main's int64 C offset at all three C stores, including store_c_vec of the slice-K combine and split-K reducers, which main does not have. - test_flydsl_hgemm.py: add 31777x67712x512 ft k_waves=2, a C past 2^31 elements through store_c_vec. It fails with an illegal memory access when store_c_vec uses an int32 offset. - kimik3 table vs ROCm#8915: 11 of the 12 _bnt rows take main's row; the 8 without split-K/slice-K as is, 1x6016, 8x6016 and 32x6016 after re-timing under the fp32 reduction. 32x6288x7168 keeps this branch's ks4 row (tuner time tied, faster with warm weights). Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
|
@eppaneamd the cached per-stream workspace is in now (982be6a). it uses power-of-two size buckets that are never freed, since a captured graph keeps the address. eager host overhead per split-K call went from about +7.2 us to about +1.7 us vs main. does that cover your concern? |
|
@aoli26 @coderfeli @xytpai main is merged in again, could you take a look when you have time? |
Conflict in gemm_a16w16_gfx950_utils.py vs ROCm#8460: main adds an s_nop 1 after the inline-asm global_store_dwordx4 in store_global_f32_vec and in SplitKProtocol.zero_c. This branch removes both (no zero-init of C, no atomic split-K store); its workspace and C stores go through BufferCopy128b and write_cshuffle_vec_to_global, which LLVM emits and pads itself. No inline-asm store is left in the A16W16 kernel, so the branch side is kept. gptoss_bf16_tuned_gemm.csv merges cleanly: the branch's gfx950 rows plus main's 14 gfx1250 rows from ROCm#8862, no duplicate keys. Co-authored-by: Claude <[email protected]> Signed-off-by: Andreas Karatzas <[email protected]>
split_k <= 16, the tile has at least 4096 elements and, fork_waves=1,split_k * tile >= 16384(not for half-tile-interleaved configs): each split promises to reduce one range of the tile, polls at most 64 times until every split has arrived, then adds every split's share of that range and writes it to C. A split whose polls run out stores its range and withdraws the promise with a CAS. The last split to arrive reduces every range that has no promise. No wait is unbounded.k_waves=1, through LDS fork_waves>1. With fragments and tiles of at least 1024 elements, it adds its own partial from registers (one copy of the sum per split index, picked by a scalar branch), and when the tiles cross M, partial stores and loads of 4-row groups past M point past the bounds-checked workspace, so nothing is written or read for them.group_m == 0, the grid is (n tiles, m tiles, splits): the same dispatch order as the linear tile id, without dividing it bynum_pid_n.get_split_k_buffers()loses itssplit_kargument, andop_tests/test_graph_alloc.pynow calls it asget_split_k_buffers(s, dev).split_kno longer has to divide K: each split takes wholeblock_ktiles and the last split takes the remainder. Configs that were valid before get the same partition. The gfx950 tuner triessplit_k1..16, 20, 24, 28, 32 andk_waves1, 2, 4, 8.fp32/f32, plusc(one-pass slice-K combine),s(shared reduction) andm(row-masked partials), so stale disk-cache binaries are not reused.split_kis a constexpr of the param, so the reduction is unrolled.graph_alloc.is_capturing()is added for this.minimax_m3_mxfp4128x12288x6144 uses the exact FlyDSL configt128x96x64x5 ks2 w4x1x1 stg3 bntfrom aca9344. 491a3ab had moved this row to hipBLASLt solution 17403. 1f8a4e5 removes that row again, because main removed all shipped hipBLASLt BF16 rows in [Config] [Bugfix] Remove all shipped hipBLASLt BF16 tuned rows #8490 ([Config] Check hipBLASLt solution indexes in tuned BF16 CSVs against the hipBLASLt they are used with #8406). This PR adds no hipBLASLt rows.aiter/aot/flydsl/gemm.pyis unchanged: main's replay-based AOT build ([FlyDSL] [JIT] Build the GEMM, conv, chunk_gdn_h and FP8 FMHA AOT caches by replaying the runtime #6956) launches each tuned row throughgemm_a16w16, so it builds the kernels with the workspace and the counter buffer without HGEMM-specific arguments.test_flydsl_hgemm.py: with integer inputs every fp32 partial is exact, so split-K and slice-K outputs must equal the exact product rounded once, and repeated runs must be bitwise identical. Adds one uneven split (4x1536x7168 ks5) and more split-K and slice-K cases.The gfx950 FlyDSL HGEMM rounded every split-K partial to bf16 and added it to C with packed bf16 atomics. It also summed slice-K wave partials through an LDS tile typed as the bf16 output. So each output went through several bf16 roundings instead of one rounding of the fp32 sum, and split-K results with 3 or more splits changed from run to run with the atomic order. This is #5976. The tuner accepts these kernels because it checks at 5e-2. We hit it in vLLM with bf16 linears and
VLLM_ROCM_USE_AITER=1: on the Kimi-K3 decode rows below, 37-50% of outputs are wrong (hipBLASLt: under 0.1%).An exact reduction has to store fp32 partials and read them back, which the bf16 atomics skipped. Sharing that reduction across the splits where they are all resident, doing the slice-K combine in one pass and loading the kernel arguments in one round trip bring the 1733 affected rows to 5.0% (cold) / 5.7% (warm) below main in geomean. 257 of them stay more than 2% slower than main (none above 15%); see Performance.
Outputs vs the correctly rounded fp64 product. Gaussian inputs, 20 runs, dispatched through
aiter.tuned_gemmwith each version's own tables:The remaining >1 ulp outputs are near-zero sums, where fp32 accumulation error is bigger than a bf16 ulp; hipBLASLt shows the same. Before this change, 656 of the 663 distinct gfx950 tuned FlyDSL split-K/slice-K configs gave inexact integer products and 424 were not reproducible. After it, all 663 and all 645 configs in the new tables are exact and reproducible. In a scan of every M from 1 to 128 over the 137 tuned (N, K) groups, every FlyDSL dispatch is exact.
What the old kernel loses
At the kernel level, compared with the exact fp64 product rounded once to bf16 (134M outputs, Gaussian inputs plus real activations and weights from Qwen3-8B and Llama-3.2-1B layers):
split_kandk_waves(roughly sqrt(ks/2)) and is flat in K from 1024 to 32768.buffer_atomic_pk_add_bf16on MI350X matched round-to-nearest-even on all 2,097,152 adds, including every tie. The pooled bias toward zero is about 1% of the RMS error; truncating atomics would make it 100-1000x larger. A bit-level emulator of the old rounding sequence reproduces 99.86% of 4.15M sampled outputs bit for bit.In vLLM with
VLLM_ROCM_USE_AITER=1, the affected kernels are hit in Qwen3-8B o_proj at M 6-128 and qkv at M 33-112, Llama-3.2-1B o_proj at M 6-8 and gate_up at M 33-128, and MiniMax-M3 qkv at TP4/TP8 for most M from 6-9 to 128. In gsm8k serving of Qwen3-8B at concurrency 32, 76% of forward steps had 17-32 tokens, where the old o_proj runs ks4.Model level, with ORIGINAL (old tree and tables), FIXED (this PR) and a reference arm with AITER linears off (
VLLM_ROCM_USE_AITER_LINEAR=0, hipBLASLt):max_num_batched_tokens=48so that every step is decode-sized, Qwen3-8B over 108k teacher-forced positions moves slightly further from an fp32 run of the same model. KL to fp32 rises 12.6% (+6.3e-5, 95% CI [+4.8e-5, +8.0e-5]) and mean |delta target logprob| rises 5.5% (+1.41e-3, CI [+1.18e-3, +1.65e-3]). Llama-1B: +11% KL, +3.0% logprob. FIXED and the reference are indistinguishable. Top-1 agreement and NLL do not move (CIs include 0). With default batching prefill never reaches these kernels and ORIGINAL equals FIXED bitwise.So the loss is real and easy to measure at the GEMM output, small but measurable in the logits under decode-sized batches, and below what gsm8k, arc, hellaswag and wikitext can resolve on these models. The clear model-level effect is that identical requests stop diverging.
Is it a speed/accuracy trade-off? Nothing in the old kernel selects it: there is no flag, it is not documented, and the error is set only by how many bf16 roundings a config does, so it changes with
split_k,k_waves, run order and batch size. The same tiles reduced in fp32 are as accurate as hipBLASLt. The tuner only kept these configs because it checks at 5e-2. On speed, the retuned exact kernels are 5.0% / 5.7% faster in geomean over the 1733 affected rows (table below), but not on every row: where storing and re-reading fp32 partials costs more than bf16 atomics, as at 64x2304x6144, the exact version is slower.Performance
Time through
aiter.tuned_gemm, main (dd6beb9; its gfx950 bf16 rows and gfx950 A16W16 kernel files are the same at 5bb98ce) against this PR, each with its own tables. MI355X, HIP-graph replay, weights rotated past 400 MB, one worker process per build on the same GPU plus a second main worker as a control, 9 interleaved rounds. "Cold" also rotates the activations, "warm" reuses one activation buffer. A row's ratio is the median of the per-round ratios; two passes with fresh processes are combined by their geometric mean. A row counts as slower only when it is slower than both main workers.Rows: every 256-CU gfx950 bf16 row that uses split-K or slice-K on either side, or whose pick this PR changes: 1733 rows. Cells with three numbers are cold / warm / either mode.
838 rows are more than 2% faster than main in both modes, and the summed cold time of the 1733 rows is 5.9% below main. The two main workers differ by 0.27% at the median, 1.1% at the 90th percentile and 3.2% at the 99th, so single rows near the 2% line do not carry signal; the single passes give 250 and 255 rows above 2%. Of 90 control rows this PR does not touch, two are above 2% (worst +4.5%).
257 rows are more than 2% slower than main (190 above 3%, 102 above 5%, 14 above 10%, none above 15%). 236 of them use 3 or more splits on main, and main's kernel takes under 12 us on 193 of them. They cost 0.40 us per call more than main at the median (0.84 us at the 90th percentile). The tables come from a staged screen of the tuner catalog: every tile, split and wave class with 1 to 8 splits, 3.0 M of the catalog's 34.1 M (row, config) pairs timed. The screen is not exhaustive (more than 8 splits and 96 rows were not screened), and it found no faster repeatable config for these rows. Their K loop is as fast as main's or faster; the reduction is not. Kernel time (cold, us) with parts of the reduction switched off:
On 11 such rows the K loop alone is 0.9 to 1.6 us faster than main's whole kernel, which puts main's atomics at about that cost, and the fp32 reduction costs 1.5 to 2.2 us: after its stores, a split has to learn that every other split has stored and then read the partials back, two memory round trips that the atomics do not have. Where fewer splits are enough the cost goes away: 288x2272x7168 with 3 splits and two k-waves (instead of 7 splits) runs at -0.8% / +1.6% against main.
Some rows are bimodal on this machine with both kernels (see the 99th percentile of the control above); the two passes and the per-round ratios absorb most of it.
End to end in vLLM, Llama-3.1-70B on one MI355X,
VLLM_ROCM_USE_AITER=1, prefix caching off, 32 prompts x 128 tokens, median of 7 runs: 1190, 1187 and 1167 tok/s on main (three processes), 1185, 1187, 1182 and 1186 tok/s with this PR (four processes). With 8 prompts at temperature 0, main returns 6 different outputs in 6 identical calls and this PR 1. MiniMax-M3-MXFP4, TP4, input 512, output 128 (vllm bench latency, earlier revision of this PR): batch 16 is 0.3% slower and batch 32 0.2% faster, both within the run-to-run spread.Merge with main and retune of M > 128 rows (42c04b5)
origin/main(581579a). Conflicts: the kernel keeps the fp32 workspace and the one-counterget_split_k_buffers(stream, device), and takes main'scapture_scoped_cache, kernarg preload,k_staggerandb_non_temporal.aot/flydsl/gemm.pytakes main's replay-based AOT build ([FlyDSL] [JIT] Build the GEMM, conv, chunk_gdn_h and FP8 FMHA AOT caches by replaying the runtime #6956), which launches through the runtime and needs no HGEMM arguments.test_graph_alloc.pycallsget_split_k_buffers(s, dev).gemm_a16w16_tune.py, flydsl/torch/triton) ran on them with a narrowed FlyDSL catalog, in two passes. Pass 1 used the row's tile and the tiles the tables use for the same N,K, with split_k up to the current one (about 60 candidates). Pass 2 used 300 seeded random catalog configs with split_k <= 16, plus the current tile. glm5 2624x6144 M=192/256 used 1200 random catalog configs. A new row is kept only if it is faster than the merged row by more than 1% in interleaved runs. 119 rows in 14 tables change (107 to other FlyDSL configs, 12 to torch). glm5 2624x6144 gets a new M=192 row (t128x128x64x3 ks6) and M=256 moves to t128x128x64x3 ks6 kw2. No row with M <= 128 changes.Timing as in the Performance section (
aiter.tuned_gemm, HIP-graph replay, weights rotated past the LLC, each version in its own process, interleaved rounds), on MI350X with FlyDSL 0.4.2. All 672 gfx950 rows with M > 128 that use split-K or slice-K in the tables this PR touches, 3 rounds:The rows that stay slower are mostly small-N split-K rows of 8-12 us (N = 64-768, K = 5120-7168, ks 5-8), where storing and reading back fp32 partials costs more than the bf16 atomics. hipBLASLt is not faster on them either: of the 88 retuned rows that stayed above +2%, it beat the FlyDSL pick on 1.
GLM-5.2 fused_qkv_a (2624x6144), 9 rounds. Before the retune, M=192 and M=256 were 6.3% and 5.8% slower than main:
M=24-84 stay 2-8% slower. A tuner rerun on M=24-84 (800 candidates each) reported no config faster than the times in the table, so these rows are unchanged. At 2624x6144, every M from 1 to 256 through
aiter.tuned_gemmis exact on integer inputs, and 20 runs on Gaussian inputs give bitwise identical outputs (0/19 differ from the first). Outputs that are not the correctly rounded fp64 product: 129 of 671744 at M=256 (hipBLASLt: 161), 118 of 503808 at M=192 (hipBLASLt: 118).One note on the tuner catalog: configs where (block_m / m_waves) x (block_n / n_waves) x split_k is large compile very slowly. One tuner shard finished no candidate for 50 minutes while it compiled t32x256x64x2 ks28 w1x4x1, and t64x128x64x4 ks14 w1x1x1 was among the compiles that did not finish in 10 minutes. The retune above capped split_k at 16 for this reason. The stock catalog still includes these configs.
Retune of M <= 128 rows that stayed slower than main (aca9344)
After the merge, 89 gfx950 rows with M <= 128 were still more than 2% slower than main. This commit searches them again with a wider candidate set. It changes only tables.
k_staggerandb_non_temporalvariants of the 40 best configs for each M (1,200 configs).split_kwithin 3 of it, plus 600 random configs from the catalog for each row (122,261 configs). Then thek_staggerandb_non_temporalvariants of the 15 best configs for each row (4,600 configs).split_k20 to 32 and (block_m / m_waves) x (block_n / n_waves) x split_k of 28,672 or more. They are not used.aiter.tuned_gemm(main, the previous head 42c04b5, and this commit, each in its own process). A row changes only if the new config is exact on integer inputs, gives bitwise identical outputs in 20 runs, and is more than 1% faster than the previous row in both timing modes below.58 rows in 12 tables change, all to other FlyDSL configs (
dsv4,glm5,glm53_flash,gptoss,kimi,kimik3,minimax_m3_eagle,minimax_m3_mxfp4,mistral_large4,qwen32B,qwen38_flash_next,qwen3_5_397b). 6 of them (M = 1 and 2) use the skinny kernel, 5 of them instead of split-K. In this commit, no row moves to hipBLASLt, torch or Triton. 491a3ab moved 128x12288x6144 to hipBLASLt, and 1f8a4e5 removes that row again (see below).The
uscolumn of the 58 changed rows is the median kernel time from the interleaved kernel-only rounds of the selection (HIP-graph replay, weights rotated past the LLC). It is not the tuner's time, so it does not compare directly with theusof rows that the tuner wrote. On 25 of the 58 rows the newusis larger than the oldus, but the new config is faster in the interleaved runs below.Timing as in the Performance section (MI350X, HIP-graph replay, weights rotated past the LLC, each version in its own process, interleaved rounds). The harness of the Performance section calls
torch.cuda.empty_cache()between rows, so weights and workspace get new addresses for each row. This moves both kernels by up to 0.7 us on some rows. So the 89 rows were timed in both modes, 7 rounds on each of two GPUs for each mode (GPUs 2 and 4 with empty_cache, GPUs 3 and 5 without). The ratios below are the median of the 14 per-round ratios for each row:On the 58 changed rows, this commit is 6.6% faster than 42c04b5 in geomean with empty_cache and 7.2% faster without it. Over the four GPUs, each changed row is 0.9% to 19.4% faster than 42c04b5 (median of 28 per-round ratios for each row). In a single 7-round run on one GPU, a changed row can show up to 4% slower. The 15-round rechecks were on 64x2560x2560 and 2x4480x7168, in both modes on four other GPUs: 64x2560x2560 was 4.4% to 5.6% faster than 42c04b5, and 2x4480x7168 was 1.4% to 4.9% faster. The largest changes are 8x4x10240 (-19.4%), 48x768x7168 (-17.7%), 1x2560x6144 (-14.3%), 112x768x7168 (-13.4%) and 1x2304x6144 (-13.1%). The M = 1 rows use the skinny kernel.
Over all 914 gfx950 rows with M <= 128 that use split-K or slice-K or changed in this PR (3 rounds, empty_cache, one GPU), the geomean vs main is 0.926 for 42c04b5 and 0.929 for this commit. This run used the first version of this commit with 60 changed rows. On the 854 rows that did not change, the two versions run the same kernel and differ by 0.6% in geomean. That is the noise of this run, and it is larger than the effect of the changed rows on the geomean of 914.
GLM-5.2 fused_qkv_a (2624x6144), 9 rounds, empty_cache, measured on one GPU:
Only M=24 changes. It is 3.4% faster than 42c04b5 in this run and 2.9% to 3.4% faster in the four-GPU runs above (both modes). M=32, 48 and 84 had configs that were 2-4% faster in the screen and in the interleaved rounds of the kernels alone, but through
aiter.tuned_gemmin separate processes the gain was 1% or less in at least one mode, so those rows did not change.GLM-5 2624x6144 at M=32 to 64 is still 5-8% slower than main. The cause is the exact fp32 reduction: each split stores its fp32 partial and the reduction reads it back, and the bf16 atomics of main did not. The full-catalog search found no config that is more than 1% faster than the current rows. Main's own configs with the exact reduction are 1-2% slower than the current rows (kernels only, M=60: +1.2%, M=64: +1.8%). hipBLASLt is slower on all six rows: its best solution takes 12.6-15.9 us against 10.0-13.4 us for FlyDSL.
On 6 of the other rows, the best hipBLASLt solution was faster than the previous row in the screen. Through
aiter.tuned_gemmit is faster than the new FlyDSL row by more than 1% on one of them: 128x12288x6144 with solution 17403. 491a3ab used it, and 1f8a4e5 removes it again (see below). torch (default hipBLASLt heuristic) was 8-33% slower than the new FlyDSL rows on the six rows where hipBLASLt looked close.Correctness through
aiter.tuned_gemmwith the final tables: all 58 changed rows and the 2 rows put back are exact on integer inputs, and 0/19 runs on Gaussian inputs differ from the first. For GLM-5 2624x6144, every M from 1 to 256 is exact on integer inputs and 0/19 runs differ from the first.op_tests/tuning_tests/test_config_shape_collision.py: 32 passed.minimax_m3_mxfp4 128x12288x6144: hipBLASLt row removed (491a3ab, 1f8a4e5)
491a3ab moved this row to hipBLASLt solution 17403. Through
aiter.tuned_gemmit was 5-12% faster than the FlyDSL row on MI350X with hipBLASLt 1.4.1. A hipBLASLt solution index belongs to one hipBLASLt build, and with another build it can be invalid or point to another kernel. Main removed all shipped hipBLASLt BF16 rows for this reason in #8490 (wrong output after a hipBLASLt upgrade, #8406). So 1f8a4e5 puts back the exact FlyDSL row of aca9344:t128x96x64x5 ks2 w4x1x1 stg3 bnt, 41.81 us. Main still has its own row for this shape from #6235 (t128x96x64x4 ks2 w2x2x1, 43.58 us, err_ratio 0.0057). That row was tuned for the bf16 atomics, and aca9344 replaced it with a faster exact config, so the merge does not take it. After 1f8a4e5,git diff origin/main -- aiter/configshas no hipBLASLt row.Merge with main after #7624 (e438aae)
Merged
origin/main(ef0a5a2). #7624 retuned the gfx950 router GEMM row 128x384x5120 indsv41_bf16_tuned_gemm.csvtot32x32x128x4 ks5 w2x2x1. This PR also changed that row (t32x32x64x8 ks5 w2x2x1). No other row conflicts. Main's tile is split-K, so it was timed with the fp32 reduction of this PR against the row of this PR. Main's tile is faster, so the merge keeps main's row. The row is now the same as on main.Timing through
aiter.tuned_gemm(MI350X, HIP-graph replay, interleaved, 15 rounds on each of two GPUs, median us):Correctness of the merged row through
aiter.tuned_gemm: exact on integer inputs (0/49152 differ), 0/19 Gaussian runs differ from the first. Main gives 25848/49152 inexact and 19/19 runs differ.test_config_shape_collision.py,test_csv_validation.pyandtest_a16w16_tuned_config_lookup.py: 61 passed.op_tests/test_flydsl_hgemm.py: passed.Merge with main (48106c6, 2f25095)
origin/main(13a7499). The kernel keeps this PR's whole-tile split partition and validator, and takes main's bpreshuffle shape check. The kimik3, qwen38_flash_next and qwen3_5_397b tables are merged row by row. For the five gfx950 kimik3 896x3584 rows (M 8-64) that both sides changed, the merge keeps this PR's exact rows.origin/main(c86d490). The kernel takes main's AOT-cache launch ([FlyDSL] [CI] [AOT_TO_C] Fix/flydsl aot key guards hgemm #8565, [FlyDSL] Launch the planner, GDN, conv3d, FP8 attention and MegaMoE launchers through the AOT cache #8600):bind_aot, and_run_compiledwith the param items and the device as the specialization key. It keeps this PR's fp32 workspace argument. The param items includesplit_k_residentandm_tail, so the AOT key covers the reduction that the host picks for each launch.make_gemm_a16w16_param_and_validatefor every gfx950 FlyDSL row in all tables: 2891 valid, 0 invalid (main: 2945 valid, 0 invalid). 10 of 10 runs:python op_tests/test_gemm_a16w16.pyandpython op_tests/test_flydsl_hgemm.pyexit 0,pytest tests/test_flydsl_aot_launch.py tests/test_flydsl_aot_cache.pygives 32 passed and 3 skipped, andpytest op_tests/test_graph_alloc.py op_tests/test_flydsl_hgemm.py op_tests/tuning_tests/{test_a16w16_tuned_config_lookup,test_asm_splitk_guard,test_config_shape_collision,test_csv_validation}.pygives the same 17 failures as main (script-styletest_flydsl_hgemm.pyfunctions that pytest calls without arguments) plus the setup error oftest_hgemm_partial_sumsfor the same reason.Merge with main and hipBLASLt row removal (cdcb1aa, 1f8a4e5)
origin/main(dd6beb9). No conflicts. None of the 7 new main commits changes a gfx950 bf16 tuned table.minimax_m3_mxfp4128x12288x6144 with the FlyDSL row of aca9344 (see above).make_gemm_a16w16_param_and_validate(arch gfx950, 256 CUs) for every gfx950 FlyDSL row in all bf16 tables: 2913 valid, 0 invalid, plus 38 skinny rows (main: 2966 valid, 0 invalid).pytest op_tests/tuning_tests/{test_config_shape_collision,test_csv_validation,test_a16w16_tuned_config_lookup}.py: 68 passed, 8 failed. The same 8 subtests oftest_gfx1250_legacy_wrapper_routingfail on main on this host. black 26.10.1 and ruff 0.16.0: clean.Merge with main after #8929 and #8915 (d6e4fd4)
Merged
origin/main(2f019ba). Two files conflicted.gemm_a16w16_gfx950.pyvs [FlyDSL] [Bugfix] Fix gfx950 FlyDSL HGEMM output offset overflow #8929: [FlyDSL] [Bugfix] Fix gfx950 FlyDSL HGEMM output offset overflow #8929 makes the C offset int64, because a contiguous C can have more than 2^31 elements. The merge keeps this PR's 4-argumentwrite_cshuffle_vec_to_global(out, offset, vec, is_fp32). Main'sout_bufandis_split_karguments are not new in [FlyDSL] [Bugfix] Fix gfx950 FlyDSL HGEMM output offset overflow #8929. They exist only for the bf16/fp32 atomic split-K store that this PR removes, so the merge does not bring them back. The int64 offsetfx.Int64(global_row) * n + global_colgoes to all three C stores of this PR: the full-tile store, the half-tile-interleaved store, andstore_c_vec, which the one-pass slice-K combine and the split-K reducers use.store_c_vecis not in main, so a plain merge leaves it on int32. With an int32 offset there, a slice-K launch with a C of more than 2^31 elements stops with an illegal memory access.test_flydsl_hgemm.pyadds one case next to [FlyDSL] [Bugfix] Fix gfx950 FlyDSL HGEMM output offset overflow #8929's: 31777x67712x512, ft, k_waves=2. It goes throughstore_c_vec.test_hgemm_partial_sumsalso runs it and checks every element of C, so it covers the rows past element 2^31. It fails with an illegal memory access whenstore_c_vecuses an int32 offset, and passes with the merge.split_k2, 4 and 8 are rejected.kimik3_bf16_tuned_gemm.csvvs [Config] [Perf] Use non-temporal B loads in twelve Kimi-K3 decode BF16 GEMM rows on gfx950 #8915: [Config] [Perf] Use non-temporal B loads in twelve Kimi-K3 decode BF16 GEMM rows on gfx950 #8915 moves 12 rows (6016x7168 and 6288x7168, M = 1, 2, 4, 8, 16, 32) to the_bntnames. The rule of the earlier merges applies. 8 keys changed only on main and have no split-K and no slice-K, so they take main's row. 4 keys were timed on the merged tree (MI350X, FlyDSL 0.5.3, two sessions of 2 and 5 interleaved passes) among the merge-base, branch and main configs: 1x6016 and 8x6016 (both sides changed; main's is slice-K), 32x6016 (main only, ks4) and 32x6288 (both sides changed, split-K). Every candidate is exact on integer inputs and gives the same bits in 20 calls. 8x6016 and 32x6016 take main's row (2% to 4% faster, tuner method, in both sessions). For 1x6016 and 32x6288 the tuner time is a tie in the 5-pass session (within 0.2%). The 2-pass session puts them 1% to 2% apart, in opposite directions, and the cold-graph order changes between sessions. Warm-graph time decides: 1x6016 takes main's row (13.9 us vs 15.1 us), 32x6288 keeps this PR's ks4 row (17.1 us vs 18.6 us). So 11 rows take main's row as it is, and 1 keeps this PR's row. Theus,tflopsandbwcolumns are copied from the row that is kept, not measured again.minimax_m3_mxfp4and 5 (128 CUs) inqwen38_flash_next. They merge without conflict and now run with the fp32 reduction. All 14 are exact on integer inputs and repeatable in 20 calls. With the tuner method, 13 are faster than torch and one (1024x1024x4096 with bias) is a tie (21.8 us vs 21.6 us). The merge keeps main's rows. The 128-CU rows were timed on a 256-CU MI350X, so their times do not show 128-CU performance.Merge with main after #8460 and #8862 (ec803d3)
Merged
origin/main(f90c562). One file conflicted, and main's CK pin moves to 39483cc9.gemm_a16w16_gfx950_utils.pyvs [FlyDSL] [CI] [Build] Pin FlyDSL to v0.5.5 #8460: [FlyDSL] [CI] [Build] Pin FlyDSL to v0.5.5 #8460 pins FlyDSL 0.5.5 and addss_nop 1after the inline-asmglobal_store_dwordx4instore_global_f32_vecandSplitKProtocol.zero_c. The hazard recognizer cannot see into inline asm, and gfx950 needs two wait states before a VALU overwrites the data VGPRs of a wide store. This PR removes both functions (no zero-init of C, no atomic split-K store), so the merge keeps this PR's file. The fp32 workspace stores (BufferCopy128b, sc1) and the C stores are emitted by LLVM, which handles the hazard itself. The only inline asm left in the kernel is the empty kernarg-preload asm. In the final ISA of four split-K kernels (fp32 output, half-tile interleaved, bias, k_waves=2 shared reduction), theASMSTART/ASMENDpair is empty and every wide store is compiler-emitted.gptoss_bf16_tuned_gemm.csvvs [OPUS][Config] gfx1250 96cu bf16 GEMM: GPT-OSS TP2 LM head, M 33..256 #8862: merges cleanly. It keeps this PR's gfx950 rows and adds main's 14 gfx1250 rows, with no duplicate keys.bnt), called throughtuned_gemm.flydsl_gemm. Every row is exact on integer inputs, and 0 of 19 eager calls and 0 of 20 graph replays differ from the first output. Graph-replay time per call is within the round-to-round spread on the shared GPU, or slightly faster on 0.5.5. 5-round medians: 56x896x7168 fp32 out 7.03 vs 7.07 us, 32x64x7168 ks14 3.62 vs 3.73 us, 64x16384x26624 ks4 183.5 vs 182.7 us.PR Self-Review
Reviewed revision
ec803d3d1e0f076cefb5255226eff9250942057eBehavior and intent
The gfx950 FlyDSL A16W16 GEMM rounded every split-K partial to bf16 and added it to C with packed bf16 atomics, and summed slice-K wave partials through a bf16 LDS tile. Outputs went through several bf16 roundings instead of one (37-68% not correctly rounded, 1.45-3.2x hipBLASLt's error), and with 3 or more splits they changed from run to run with the atomic order (#5976). This PR keeps every partial in fp32 and adds them once in split order, so outputs are as accurate as hipBLASLt and bitwise repeatable. The reduction is picked per launch on the host (shared across splits when the grid is resident, otherwise by the last split to arrive). The fp32 workspace is cached per stream, so eager calls do not allocate it each time. The affected rows are retuned for the exact reduction, and 39 asm split-K rows that were not repeatable move to repeatable configs. Over the 1733 affected rows this is 5.0% (cold) / 5.7% (warm) faster than main in geomean; 257 rows stay more than 2% slower (median +0.4 us per call, none above 15%), and I accept that cost for repeatability. Rows outside gfx950 bf16 are untouched.
Validation and unverified scope
On this head (ec803d3), MI350X (gfx950), FlyDSL 0.5.5:
python op_tests/test_flydsl_hgemm.py: exit 0 in 10 of 10 runs, 31 exact-and-deterministic cases each.pytest op_tests/test_graph_alloc.py: 7 passed, 1 skipped.pytest op_tests/tuning_tests/{test_csv_validation,test_config_shape_collision,test_a16w16_tuned_config_lookup,test_asm_splitk_guard}.py: 94 passed, 5244 subtests passed.On d6e4fd4, MI350X (gfx950), FlyDSL 0.5.3:
python op_tests/test_flydsl_hgemm.py: exit 0 in 10 of 10 runs, 31 exact-and-deterministic cases (the new 31777x67712x512 slice-K case included).python op_tests/test_gemm_a16w16.py: exit 0.pytest op_tests/test_graph_alloc.py: 7 passed, 1 skipped.pytest op_tests/tuning_tests/{test_csv_validation,test_config_shape_collision,test_a16w16_tuned_config_lookup}.py: 91 passed.On fb04752 (tables of 98615f7 + fb04752, kernel of 982be6a), MI355X (gfx950):
python op_tests/test_flydsl_hgemm.py: exit 0, 30 exact-and-deterministic cases.python op_tests/test_gemm_a16w16.pyandpython op_tests/test_gemm_a16w16.py -t normal out compile -d bf16: exit 0.python op_tests/test_gemm_codegen.py: 74 passed.pytest op_tests/test_graph_alloc.py: 7 passed, 1 skipped. The new workspace test fails without 982be6a, and fails when the cache is made to serve a capturing stream or to share one buffer between streams.pytest op_tests/tuning_tests/{test_a16w16_tuned_config_lookup,test_csv_validation,test_config_shape_collision,test_asm_splitk_guard}.py: 71 passed, 8 failed. The 8 aretest_gfx1250_legacy_wrapper_routingsubtests that also fail at 1f8a4e5 and pass after a local merge with main (9da5928).aiter.tuned_gemm(two other GEMM processes on the same GPU; 32 outputs per case from eager, synced, interleaved and graph-replayed calls): all 2819 FlyDSL rows plus 312 changed rows at two more M (3337 cases) and all 1038 torch, Triton and skinny-default rows: 0 differ. In 8 identical calls, 0 of the 1733 affected rows differ (main: 1215).aiter.tuned_gemm, HIP-graph replay, weights rotated past 400 MB, 9 interleaved rounds against main and a second main worker, cold and warm activations, two full passes (see Performance).Earlier revisions (MI350X, FlyDSL 0.4.1 / 0.4.2), kept for the kernel history:
python op_tests/test_flydsl_hgemm.py: 10/10 runs.python op_tests/test_gemm_a16w16.py -t normal out compile -d bf16on 6 split-K shapes and the defaults: 10/10.Unverified:
llama405B_bf16_tuned_gemm.csv: 26 rows were re-timed under this PR's kernel (9 main-only split-K rows and 17 rows changed on both sides); 11 keep this PR's config and 15 take main's.minimax_m3_eagle_bf16_tuned_gemm.csv: main's 9 new split-K rows were re-timed; 7 keep main's config, and 480x9216x6144 and 496x9216x6144 move to torch (about 28% faster than main's ks3 config under the fp32 reduction). All 35 re-timed rows give the same bits in 5 calls, with rel. L2 0.00165 to 0.00168 vs fp32 torch. The GPU was shared during this timing. After the merge:tests/test_moe_dispatch_snapshot.py3 passed (it failed on fb04752 because [MoE] Refresh the legacy dispatch golden for #7611's intermediate_pad #8790 was missing);test_csv_validation.py,test_config_shape_collision.pyandtest_a16w16_tuned_config_lookup.py91 passed;test_graph_alloc.py7 passed, 1 skipped;python op_tests/test_flydsl_hgemm.pyexit 0.test_gemm_a16w16.pyprintscheckAllclose ... failed!for the two asm variants at 64x256x5120, as it did at b155ae8 and does on d6e4fd4; not checked on main.test_gemm_a16w16.pyand the full-table sweeps were not rerun.PR-specific question
The changed rows are gfx950 bf16 rows in 22
aiter/configs/model_configs/*_bf16_tuned_gemm.csvtables: DeepSeek-V3/V4/V4.1, Gemma-4-26B-A4B, GLM-5, GLM-5.3-Flash, gpt-oss, inkling, Kimi, Kimi-K2, Kimi-K3, Llama 70B/405B, MiniMax-M3 and its EAGLE draft, Mistral Large 4, Qwen3-VL (q3vl), Qwen 32B, Qwen3.8-Flash-Next, Qwen3.5-397B, Qwen3.8-27B and Qwen3.8-2.4T-A95B. Against main (dd6beb9, the last main merge), 1181 of the 4192 gfx950 rows in these tables change their pick (libtype, solidx, splitK or kernelName): 1068 FlyDSL to FlyDSL, 61 FlyDSL to torch, 10 FlyDSL to Triton, 1 FlyDSL to skinny, 2 Triton to FlyDSL, and 39 asm to FlyDSL (37), torch (1) or Triton (1). 4 rows are added and none is removed. No row uses hipBLASLt. Every other row, and every non-gfx950 row, is byte-identical to main, so other shapes keep their selection. Largest per-table changes: DeepSeek-V4 237 rows, Kimi-K3 207, GLM-5 92, Qwen3.8-Flash-Next 87, MiniMax-M3 84. A pick changes only if the new config is exact on integer inputs, bitwise repeatable, and faster in the interleaved harness.aiter/tuned_gemm.pyis unchanged.gemm_a16w16_policy.pyonly widens the tuner's candidate catalog (split_k 1..16, 20-32, k_waves 1/2/4/8, fp32 LDS sizing).graph_alloc.pyaddsis_capturing()for the workspace cache. Neither changes how tuned rows are looked up.Changed op tests
op_tests/test_flydsl_hgemm.py: addstest_hgemm_partial_sums. Small-integer inputs keep every fp32 partial exact in any order, so split-K and slice-K outputs must equal the exact product rounded once, bit for bit, and repeated Gaussian runs must be bitwise identical. The existing tests compare against torch with a tolerance (5e-2 scale), which is why the bf16-partial kernels passed; nothing else in op_tests checks exactness or run-to-run determinism of these kernels. The cases cover k_waves 2/4/8, split_k up to 32, an uneven split, bias, fp32 output and half-tile-interleaved configs. It also adds 31777x67712x512 with k_waves=2, next to the two int64-offset cases of #8929. That C has more than 2^31 elements and goes through the slice-K store, which is not in main. It fails with an illegal memory access if that store uses an int32 offset.op_tests/test_graph_alloc.py:test_every_cached_scratch_comes_from_the_private_poolcallsget_split_k_buffers(s, dev)(new signature) and adds the cached fp32 workspace as a site, so the workspace must also come from the private pool.test_gfx950_split_k_workspace_is_cached_per_stream_and_size(gfx950 only). It checks that one buffer serves each stream and size bucket, that two streams never share a buffer, and that a capture on a stream without a buffer caches nothing. It fills the workspace with NaN before each call and requires the exact product on integer inputs, eager and under graph replay, so stale partials can never reach C. No other test covers this cache; it fails without 982be6a.AI assistance (Claude Code) was used to draft this change. Every line was reviewed by the submitter.