Skip to content

[HIP] [FlyDSL] FlyDSL gemm_decode: small-M dense GEMM kernels (BF16) - #4114

Closed
vedenev-amd wants to merge 110 commits into
mainfrom
GEMM_small_M_SILOTIGER-669
Closed

vedenev-amd wants to merge 110 commits into
mainfrom
GEMM_small_M_SILOTIGER-669

Conversation

@vedenev-amd

@vedenev-amd vedenev-amd commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Claude generated (Claude Code). Description version 9, 2026-12-01.

Motivation

LLM autoregressive decode runs linear projections at M=1..5 tokens per step. A standard 16×16 MFMA tile wastes ≥75% of compute slots at these sizes. This PR adds a FlyDSL BF16 decode GEMM optimised for small M, plus the tuned config rows for the shapes where it wins.

Target hardware: gfx942 and gfx950. Measured on MI325X (gfx942, 304 CU) and MI355X (gfx950, 256 CU).
Target shapes: Kimi-K3 TP8 decode GEMMs, N=896…40960, K=128…8448. Generic — no model-specific names in kernel or dispatch code.

Technical Details

Two complementary FlyDSL policies, selected by a runtime tuner:

Wave (gemm_decode_wave.py) — warp-per-scalar output-centric GEMM. One wavefront owns one tile of (M×N) output scalars; K is split across 64 lanes and reduced either with DPP row shifts or with a ds_bpermute butterfly. v_dot2_f32_bf16 on gfx950, scalar/packed FP32 on gfx942.

BlockMFMA (gemm_decode_block_mfma.py) — MFMA block policy with LDS A-staging and software prefetch.

The tuner picks the policy per shape; neither wins by M alone (gfx950 rows split roughly evenly, gfx942 rows are mostly BlockMFMA).

Low-level code. The kernels use FlyDSL APIs throughout: no inline assembly. The one remaining direct instruction call is the 4x4x4 MFMA, which the FlyDSL MMA atom does not support yet. Outputs are bitwise identical to the pre-cleanup kernels on every gfx950 row.

Entry point (gemm_kernels.py): gemm_decode_bf16(A, B, C, config), dispatching to either policy via a tuned config from iter_gemm_decode_configs. The kernel exists only for M≤5; the dispatcher honours a decode row on exact M match only, never through M padding. The activation A may have a row stride larger than K (for example a column slice of a fused projection output); it is read in place, without a copy. Packed A keeps the same machine code as before.

Dispatch, tuner and AOT. Decode sits next to the existing FlyDSL hgemm path in each hook, with no new framework: tuned_gemm.py has a flydsl_decode_ branch (exact-M check, row check, launch), gemm_a16w16_policy.py has get_flydsl_a16w16_decode_configs next to the hgemm catalog, and the tuner calls both. The GEMM AOT build replays every tuned row through gemm_a16w16, so it reaches the decode branch with no decode-specific code; for decode rows with M > 1 it also replays a column-slice A, which selects a kernel of its own. All FlyDSL rows use libtype = flydsl; the kernel-name prefix tells hgemm and decode apart. aiter.tuned_gemm.is_flydsl_decode_config(row) lets callers such as vLLM ask whether a row selects a decode kernel without matching on labels. Preshuffled-weight shapes get no decode candidates, since the decode kernels read the plain weight. The tuner flag --candidate-policy bounded|deep sets how many decode configurations are timed (documented in csrc/gemm_a16w16/README.md).

Tuned configs — decode rows (libtype = flydsl, kernel name flydsl_decode_…) in kimik3_bf16_tuned_gemm.csv for gfx950 and gfx942, M=1..5, covering the Kimi-K3 TP8 decode shapes. Most land where the dispatcher previously fell through to torch. On gfx950 the rest replace an existing flydsl or triton row, and each of those only where graph replay showed decode beats the incumbent for that exact shape and M. On gfx942 nothing is replaced — see below.

Duplicate shapes across model configs. A few keys at (2112,7168) also existed in dsv3_ and kimik2_bf16_tuned_gemm.csv, and (3584,7168) arrived in main via #5702 while this PR was open. Since the runtime merges every *bf16_tuned_gemm* file into one keyspace, duplicates raise at merge time. All were resolved by the repository's own guard — test_config_shape_collision.py --fix, lowest-us wins — not by hand. That accounts for the deletions in the two other model files.

The displaced rows were measured directly against the decode rows that replaced
them — both kernels by name, one process, packed HIP graph, alternating pairs,
null control ≤ 0.13%:

M displaced from decode, µs displaced flydsl, µs gain pairs won
1 dsv3 6.265 8.177 +23.4% 8359 / 8360
2 dsv3 6.808 8.030 +15.2% 8349 / 8350
4 kimik2 6.644 8.326 +20.2% 8320 / 8320

Max relative error vs FP32 is also lower for decode (2.8–3.5e-03 vs
8.6–8.9e-03), so dsv3 and kimik2 gain accuracy on this shape as well as speed.

Fixes along the way. The tuner's candidate selection discarded valid decode configs before benchmarking them.

Layouts the decode kernels do not take. A decode row is chosen from shape and dtype alone. At call time decode_layout_supported checks the operands; an A with a non-unit column stride, column-major B, or a non-packed out goes to torch_gemm, as an untuned shape would, so adding a row never breaks a working tgemm.mm call. The output-overlap guard measures a strided A row by row.

Performance

Measured against the kernel the config named for the same shape before this PR — the existing row, or torch where none existed. Both kernels invoked by name, dispatcher out of the loop.

Packed HIP graph, wall clock over launches, four rotating weights, alternating A/B/B/A pairs scored per pair, incumbent timed against itself as a null control (2% threshold). Both sides checked against an FP32 reference before each timing.

gfx950 (MI355X, 256 CU), every row in this PR, 3 independent passes:

M cells better tied worse ours, µs previous, µs gain
1 20 19 1 0 306.0 404.6 +24.4%
2 17 17 0 0 299.3 379.8 +21.2%
3 18 18 0 0 307.7 406.5 +24.3%
4 14 14 0 0 276.9 340.2 +18.6%
5 13 13 0 0 270.4 329.5 +17.9%
all 82 81 1 0 1460.4 1860.6 +21.5%

Every row confirmed in every pass, zero regressions. The one tie is (7168,1536) at M=1, where the kernels sit 0.3% apart; it never lost a pass.

After this measurement, 4 gfx950 rows were removed (M=2 12448x7168 and 6288x7168, M=3 7168x3072, M=4 8448x7168). They beat aiter's previous kernel, but through vLLM they lose to wvSplitK, so vLLM keeps wvSplitK for them. Two more rows (M=1 7168x8448, M=3 6288x7168) were removed because the same shape lost on gfx942 and the untuned CSV has no arch column, so a re-tune would bring them back. That leaves 76. The table above still includes all six.

An earlier revision of this description quoted −9%…−25% against wvSplitK. Those were taken against a September-2025 build of that kernel and are withdrawn.

Downstream: the current rows measured through vLLM's rocm_unquantized_gemm_impl give +5.4% on M=1..4 against wvSplitK, with no shape slower — a kernel aiter cannot select, as it lives in vLLM's own extension. Wiring and caveats in vllm-project/vllm#55860.

gfx942 (MI325X, 304 CU), every row in this PR, 3 independent passes:

M cells better tied worse ours, µs previous, µs gain
1 20 20 0 0 398.2 527.1 +24.5%
2 19 19 0 0 402.8 521.2 +22.7%
3 17 17 0 0 412.6 516.9 +20.2%
4 18 18 0 0 412.7 507.2 +18.6%
5 11 11 0 0 378.5 428.7 +11.7%
all 85 85 0 0 2004.8 2501.1 +19.8%

Every row confirmed in every pass, zero regressions; no measurement discarded by the null control (255 of 255 kept). Here previous is always the heuristic fallback, which resolved to torch: at the branch point no bf16 config carried a gfx942 row with cu_num=304, so all 85 rows are additions and none replaces an existing row. The rows are keyed (gfx942, cu_num=304), which also covers MI300X.

Four gfx942 rows that lose to wvSplitK through vLLM (M=1 7168x8448, M=2 7168x4224 and 6288x7168, M=3 6288x7168) had already been removed before this measurement. After it, 3 more rows were removed on shapes whose gfx950 row lost (M=2 12448x7168, M=3 7168x3072, M=4 8448x7168), so that a re-tune reproduces the CSV. That leaves 82. The table above still includes those 3.

Shapes deliberately left without a row. 13 cells at M=3,4,5 where opus is faster — router at M=5 by 22%, (7168,8448) at M=5 by 9%, (3072,7168) at M=3 and M=4, and nine other long-K cells at M=3,4,5 by 0.5…6%. Plus 3 cells where the tuner and graph replay disagree reproducibly ((7168,8448) at M=4, attention O and (4608,1536) at M=5).

Full evidence — protocol, benches, raw records, and the measurement errors made and corrected along the way — is attached as pr4114_evidence.tar.gz.

Architecture support

  • gfx950: Wave uses v_dot2_f32_bf16; BlockMFMA uses MFMA with two-stage prefetch
  • gfx942: Wave uses scalar_f32 contraction; BlockMFMA uses single-stage prefetch; both paths correctness-tested

Test Plan

  • op_tests/test_flydsl_decode_gemm.py — a standard op_test, plain script, no pytest. python3 <file> runs the correctness checks first, then a perf sweep of tgemm.mm against F.linear under CUDA graphs:
    • five kernel cases: Wave no-bias, Wave with bias and odd N/K tails, BlockMFMA global, BlockMFMA full LDS with K padding, BlockMFMA persistent-N multi-turn;
    • strided activation: a column slice of a wider tensor and an M=1 column vector must give bitwise the same output as packed A, directly and through tgemm.mm;
    • every shipped decode row for the running card must be selected by the dispatcher, and one shape per M runs end to end through tgemm.mm. The dispatcher drops a row with a malformed kernelName silently, so without this a broken row would pass CI;
    • overlap guard: C on a strided A's second row is rejected, C in the gap between rows is accepted and correct;
    • other layouts: A with column stride 2 and column-major B through tgemm.mm, with and without out=, fall back and give the right result;
    • AOT run-only: one decode row is precompiled into a fresh cache, then packed and strided A run in a fresh FLYDSL_RUNTIME_RUN_ONLY=1 process.
    • decode tuner candidates parse back from their kernel names to the config they were named from;
      The file sits where the runner already scans.
  • python3 -m unittest op_tests.tuning_tests.test_csv_validation — new test_bf16_decode_m4_rows_keep_m3_covered: a cell whose M = 4 row is a decode row also has an M = 3 row, so padded M never sends M = 3 to the default (a short list of cells that had no M = 4 row before is exempt).
  • python3 -m unittest op_tests.tuning_tests.test_config_shape_collision — Ran 33 tests ... OK. The config keyspace stays collision-free across every model file; includes a positive control (a planted duplicate must be caught).
  • Row-level verification: every row confirmed over 3 independent passes, zero regressions (raw records in the attached archive).
  • Black 26.10.1 and Ruff 0.16.0 (the CI pins) clean on all changed files.
  • CI on MI355X (gfx950); gfx942 checked by hand on MI325X at 46c2d37 (see Validation).

Attachment

pr4114_evidence.tar.gz

Submission Checklist

PR Self-Review

Reviewed revision

46c2d37

Behavior and intent

Adds a FlyDSL BF16 decode GEMM for exact M = 1..5 (Wave policy on v_dot2/FP32, BlockMFMA policy on 4x4x4 MFMA) and Kimi-K3 tuned rows that select it through the existing libtype=flydsl dispatch. At these M a 16x16 MFMA tile is >=75% padding, and the existing HGEMM catalog loses to the decode kernel on the tuned shapes. Shapes without a decode row, and layouts the decode kernels do not take, keep the existing path.

Validation and unverified scope

  • gfx950 (MI355X), FlyDSL 0.5.3 (main's pin), head ddff924: python3 op_tests/test_flydsl_decode_gemm.py exit 0, every check passes; the dispatcher selects all 72 decode rows (then checked in test_flydsl_gemm_dispatch.py, since folded into the decode test); python3 -m unittest op_tests.tuning_tests.test_config_shape_collision 33 OK.
  • The two kernel cleanups from review (one BlockMFMA body, Wave prefetch depth 0 = 1): all 41 BlockMFMA and 31 Wave shipped rows give bit-identical outputs to the previous code (plain, bias, strided A), and timing is unchanged within noise.
  • gfx942 (MI325X, 304 CU), FlyDSL 0.5.3, head 46c2d37: python3 op_tests/test_flydsl_decode_gemm.py exit 0, all its checks run, none skipped; the dispatcher selects all 82 gfx942 decode rows, 72 decode candidates round-trip by name. test_csv_validation and test_config_shape_collision pass (54 tests); with the gfx950 M = 3 (6288, 7168) row removed, the new M = 3 check fails and names that cell. tests/test_moe_dispatch_snapshot.py: 3 passed at 2d038bb.
  • Unverified: gfx950 at 46c2d37 (last run by hand at ddff924; the MI35X CI shards run it at this head); gfx942 on MI300X CI (no ci:mi300x run at this head); end-to-end model accuracy (the Atom Test accuracy jobs fail on main too, missing jsonschema in the ATOM image).

PR-specific question

The decode path is taken only when a tuned row names a flydsl_decode_* kernel whose arch, M, N, K and bias match the call exactly (check_flydsl_decode_row), dtype is BF16 in and out, with no scaling and no preshuffled weights. At call time decode_layout_supported requires A with a unit column stride (any row stride >= K), packed B and out, contiguous bias; anything else goes to torch_gemm. validate_gemm_decode_tensors applies the same decode_layout_supported rule and rejects arch other than gfx942/gfx950, M outside 1..5, and C overlapping A (row by row), B or bias.

Changed op tests

  • op_tests/test_flydsl_decode_gemm.py: correctness of both policies against torch (bias, odd K tails, LDS padding, persistent N), every shipped decode row dispatched through tgemm.mm, strided A bit-equal to packed A, overlap guard, layout fallback, and AOT run-only coverage, and decode kernel names parse back to their configs. It is the only test that exercises the decode kernels directly.
  • op_tests/tuning_tests/test_csv_validation.py: adds test_bf16_decode_m4_rows_keep_m3_covered, the CSV check that every cell whose M = 4 row is a decode row also has an M = 3 row, so padded M never sends M = 3 to the default; it sits with the other tuned-CSV checks, reads only the CSVs and needs no GPU.

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

  • ✅ Pre-checks (submodule verification, code formatting)
  • ✅ Aiter op tests (gfx942 + gfx950)
  • ✅ Triton tests on MI35X (only when aiter/ops/triton/** or related paths are changed)

Extended tests (opt-in via labels):

Label Tests
ci:triton-300x Run an additional Triton test job on MI300X in PRs; main branch always runs both MI35X and MI300X
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 4114 --add-label <label>

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

ruff

⚠️ [ruff] <E702> reported by reviewdog 🐶
Multiple statements on one line (semicolon)

st.record(); gemm_decode_bf16(A_prod, B_prod, C2, 2, N_prod, K_prod, stream=fx.Stream(s)); en.record()


⚠️ [ruff] <E702> reported by reviewdog 🐶
Multiple statements on one line (semicolon)

st.record(); gemm_decode_bf16(A_prod, B_prod, C2, 2, N_prod, K_prod, stream=fx.Stream(s)); en.record()


⚠️ [ruff] <E701> reported by reviewdog 🐶
Multiple statements on one line (colon)

if t > 5: times_direct.append(t)


⚠️ [ruff] <E731> reported by reviewdog 🐶
Do not assign a lambda expression, use a def

bw = lambda t: (2*K_prod*2 + N_prod*K_prod*2)/(t*1e-6)/1e9

Comment thread aiter/ops/flydsl/kernels/gemm_decode.py Resolved
@zufayu
zufayu requested a review from amd-ruitang3 July 8, 2026 02:15
@vedenev-amd
vedenev-amd marked this pull request as draft July 10, 2026 09:10
@vedenev-amd
vedenev-amd marked this pull request as ready for review July 10, 2026 13:08
vedenev and others added 15 commits July 13, 2026 11:18
Add predicated K tails and partial-column handling, use RNE output conversion, and expose named compile-time defaults. Strengthen gfx950 tests with strict assertions, sentinels, boundary shapes, and conversion checks.

Co-authored-by: Cursor <[email protected]>
Benchmark the direct FlyDSL kernel against the fast and fallback wave split-K kernels and explicit hipBLASLt using shared inputs, strict correctness checks, warmed event timing, spread, throughput, and relative speedup.

Co-authored-by: Cursor <[email protected]>
Retire duplicate decode paths in favor of unified tuned kernels, while adding architecture-isolated AOT and production small-M tuning coverage.

Co-authored-by: Cursor <[email protected]>
Restrict small-M support and remove superseded identities while hardening AOT and optional-backend validation around the production paths.

Co-authored-by: Cursor <[email protected]>
Move decode dispatch into the shared GEMM API, complete BF16 tuner integration, and restore the architecture-specific small-M path while retaining focused GPU correctness coverage.

Co-authored-by: Cursor <[email protected]>
Use one tensor-derived configuration entry point and perform optional bias directly in Wave and BlockMFMA epilogues, keeping persistence parsing outside the public kernel API.

Co-authored-by: Cursor <[email protected]>
…decode

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	aiter/aot/flydsl/gemm.py
…o longer sends it to torch.

On main an M = 3 call there ran the M = 4 hgemm row through padded M. Decode rows are exact-M, so once the M = 4 row became a decode row M = 3 fell through to the default. The new row names the hgemm kernel main used (t16x32x128x6_ks1, 17.55 us at M = 4). A CSV check under tuning_tests keeps every decode M = 4 row paired with an M = 3 row, except the five cells that had no M = 4 row before the decode rows and so already took the default at M = 3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd and others added 5 commits November 26, 2026 16:38
…n A's device, so a call on a second GPU no longer brings the process down.

A handle is bound to the device it was loaded on, and the decode launchers cached one per kernel for every device, launching on the caller's current device. In one process that ran a decode row on cuda:0, the same row on cuda:1 died with a GPU coredump. With specialization_key=A.device and the launch under torch.cuda.device(A.device), as aiter/ops/flydsl/AGENTS.md asks, that call now raises hipErrorInvalidDevice like every other FlyDSL kernel tried (sorted_sum, causal_conv1d_update). Running it there needs FlyDSL to load the module per device: ROCm/FlyDSL#1536.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… of raising.

The decode launch fuses the bias and requires it to have A's dtype, but decode_layout_supported, the check tgemm.mm makes before taking a decode row, only looked at the bias layout. A decode row with bias=True would have turned a call the hgemm path accepts (it adds such a bias after the GEMM) into a ValueError. No shipped decode row has a bias, so nothing hit it yet. The fallback log now names the bias dtype too.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… does, not from GPU_ARCHS.

get_gfx() follows GPU_ARCHS, while tgemm.mm and the decode tuner candidates use get_gfx_runtime(). With GPU_ARCHS=gfx950 on an MI325X the test compared gfx950 names against the gfx942 kernels the tuner produced and failed in the name round trip; with get_gfx_runtime() it checks the rows the dispatcher actually serves, as test_flydsl_decode_gemm.py already does.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ring, so the message is built only when it is logged.

This matches _warn_decode_layout_fallback next to it and the review-pr logging rule.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… so the cache_modifier change belonged in another PR.

No call site under aiter/ops/flydsl sets cache_modifier on a GTensor, so the change was inert, but it altered shared code every FlyDSL kernel imports. The decode and dispatch op tests pass without it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@xytpai Thanks for the re-review. All six points are addressed at e6d7912, one commit each.

1. M = 3 at gfx950 (6288, 7168) (aiter/tuned_gemm.py:211)

Fixed in 338b013. The cell now has an M = 3 row with the hgemm kernel main used through padded M (flydsl_hgemm_abf16_wbf16_bf16_t16x32x128x6_ks1_w1x2x1_bias0_ktail0_gm0_pft_gfx950, 17.55 us at M = 4), and the dispatcher picks it for M = 3 again. I checked the lookup with gfx950 / 256 CU mocked; I have no gfx950 here to time it.

Following your correction, the check lives with the CSV validation, in op_tests/tuning_tests/test_flydsl_decode_padded_m.py. Every cell whose M = 4 row is a decode row must also have an M = 3 row. The five cells you listed (gfx950 (7168, 3072) and the four gfx942 cells) are an explicit exception, because they had no M = 4 row before and M = 3 already took the default there. Without the new row the test fails and names gfx950 (6288, 7168).

2. Device in the compiled-handle key (gemm_decode_wave.py:310)

Fixed in e49d0c0: both decode launchers pass specialization_key=A.device, and gemm_decode_bf16 launches under torch.cuda.device(A.device).

I tested it in one process on two MI325X, with the same decode row first on cuda:0 and then on cuda:1:

cuda:0 cuda:1 after cuda:0
before the change correct process dies, GPU coredump
with the change correct hipErrorInvalidDevice (exception, process survives)

So the key alone does not make the second GPU work. Two FlyDSL kernels from main fail the same way on cuda:1 after cuda:0 (sorted_sum, and causal_conv1d_update, which already launches under torch.cuda.device), and both work on cuda:1 in a fresh process. This looks like FlyDSL 0.5.3/0.5.4 keeping one loaded module per compiled kernel, so I filed a FlyDSL issue with a repro: ROCm/FlyDSL issue #1536. Until that is fixed, the change turns the crash into the same exception the other FlyDSL kernels give. With the device already in the key, the decode path should work on several GPUs once FlyDSL loads per device.

3. Bias dtype in decode_layout_supported (gemm_kernels.py:740)

Fixed in 4048e9f. decode_layout_supported now also requires the bias to have A's dtype, so tgemm.mm sends such a call to torch, which adds the bias after the GEMM, instead of raising in the launch. The fallback warning names the bias dtype. check_tuned_row_other_layouts asserts that a bf16 bias is accepted and an fp32 one is not; without the change that assert fails.

4. get_gfx() in the dispatch test (op_tests/test_flydsl_gemm_dispatch.py:32)

Fixed in 4ea0a00: the test takes ARCH from get_gfx_runtime(). On MI325X with GPU_ARCHS=gfx950 the old test failed in the name round trip (it expected gfx950 names, the tuner gave gfx942 ones); now it passes and checks the 82 rows the dispatcher serves.

5. f-string in the logging call (aiter/tuned_gemm.py:152)

Fixed in 891c50d: the warning passes name and reason as %s arguments, like _warn_decode_layout_fallback. A bogus decode row still logs the same message.

6. GTensor.load and cache_modifier

Dropped in e6d7912: tensor_shim.GTensor.load is back to main's buf_copy_atom(vec_size * (elem.width // 8), elem). The decode kernels do not use GTensor.

At e6d7912 on MI325X (gfx942): test_flydsl_decode_gemm.py 39/39 passed, test_flydsl_gemm_dispatch.py selects all 82 decode rows (worst rel err 3.2e-3), test_config_shape_collision and test_flydsl_decode_padded_m pass.

@vedenev-amd
vedenev-amd requested a review from xytpai November 26, 2026 17:16
…again; keep main's fused-quant and FlyDSL-only AOT variants alongside the decode strided_a variant.

The one conflict was in _variants of aiter/aot/flydsl/gemm.py, where main (#8702) added the batched GEMM fused-quant entry and the rule that non-FlyDSL rows have no variant, and this branch added the strided_a variant for decode rows with M > 1. Decode rows are FlyDSL rows, so both apply: the AOT replay of the Kimi-K3 bf16 CSV still lists all 154 decode rows, with a strided_a job for each M > 1 row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@xytpai xytpai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-checked at 8d365e9. I read the six fix commits and the merge of main.

Fixed

All six are in, and I have nothing further on the code.

  1. M = 3 at gfx950 (6288, 7168). The new row is main's M = 4 row for this cell with M set to 3. I ran test_flydsl_decode_padded_m.py against the CSVs at this head: it passes, and it names the cell when I drop the row. A separate count over the 33 bf16 tuned CSVs finds the same five exceptions and no others.
  2. Device in the handle key. Both decode launchers pass specialization_key=A.device, and gemm_decode_bf16 launches under A's device. I could not check the second-GPU behaviour you describe in ROCm/FlyDSL#1536.
  3. Bias dtype. A bias of another dtype now goes to torch.
  4. get_gfx_runtime() in the dispatch test.
  5. %s arguments in the warning.
  6. GTensor.load is back to main's line.

The merge is fine too. _variants keeps main's fused-quant and FlyDSL-only rules next to the strided_a variant, and the wheel build's GEMM replay reports 24976 ok and 0 failed.

One small thing

No workflow runs the new test_flydsl_decode_padded_m.py. .github/scripts/split_tests.sh and the level 0+1 command in tuning-tests.yaml both list the tuning_tests files by name, and neither has it. One line next to test_config_shape_collision.py would wire it in. It does not block.

CI on this head

Aiter Test Gate is red, for two reasons outside this PR:

  • Shards 0 and 7 ran no tests. Download Aiter wheel artifact timed out after 30 minutes, twice in each. They need a re-run.
  • Shard 2 fails tests/test_moe_dispatch_snapshot.py. It fails the same way on main in run 45859420103: #7611 added intermediate_pad to the legacy dispatch and left the golden snapshot as it was. A re-run will not clear it. It needs the fix on main.

The decode tests pass on MI35X at this head: test_flydsl_decode_gemm.py, test_flydsl_gemm_dispatch.py (all 72 decode rows selected) and test_config_shape_collision.py.

I will approve once the gate is green.

@xytpai xytpai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things changed on main since my last comment:

  • The snapshot fix is in (#8790), so the shard 2 failure should go once this branch has it.
  • This branch now conflicts with main.

A merge of main covers both and gives the gate a fresh run on all eight shards.

vedenev-amd and others added 3 commits November 30, 2026 11:46
…apshot fix (#8790) and clear the conflicts with main.

The three conflicts keep both sides: main's MiniMax exports, ring catalog and policy_runs_on next to the decode exports, candidates and launch helpers. Main's ring tuning (#8675) dropped the early return for preshuffled shapes, which had kept decode candidates out of them; the tuner now skips decode candidates when is_shuffle, since decode kernels read the plain weight and the runtime rejects a preshuffled decode row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…l 0+1 tuning tests, since both list tuning_tests files by name and the new CSV check would otherwise never run in CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…og is not flooded with one ResourceWarning per file.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot changed the title [HIP] [FlyDSL] FlyDSL gemm_decode: small-M dense GEMM kernels (BF16) [HIP] [FlyDSL] [CI] FlyDSL gemm_decode: small-M dense GEMM kernels (BF16) Nov 30, 2026
@github-actions github-actions Bot added the CI label Nov 30, 2026
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

@xytpai Thanks. Main is merged and the test is wired in, at 2d038bb.

Merge of main (45e51f7)

  • Three files conflicted: aiter/ops/flydsl/__init__.py, gemm_a16w16_policy.py and gemm_kernels.py. Each keeps both sides. In the six files the branch shares with main, the branch's diff against main is the same as before the merge, apart from the tuner change below.
  • [HIP] [FlyDSL] [CI] [Perf] gfx950 small-M BF16 ring GEMM policies (rg lm_head, rk DSpark FC) in the hgemm catalog, tuner and tgemm path #8675 removed the early return for preshuffled shapes in the FlyDSL tuner, so decode candidates would also be timed for is_shuffle shapes, on the plain weight. The runtime rejects a preshuffled decode row, so such a winner would push the call to the fallback. The tuner now builds decode candidates only when is_shuffle is false.
  • With main's pinned black 26.10.1 and ruff 0.16.0, the merge needed two style fixes (black on the tuner change, RUF022 on the merged __all__). Both are clean now.

The new test in CI (a59eed8, 2d038bb)

  • test_flydsl_decode_padded_m.py is now listed in .github/scripts/split_tests.sh and in the level 0+1 command in tuning-tests.yaml, next to test_config_shape_collision.py. A local run of split_tests.sh --shards 8 puts it in shard 4.
  • The test now closes each CSV, so it no longer logs one ResourceWarning per file.

Checks at the merged head, MI325X (gfx942), FlyDSL 0.5.3:

  • tests/test_moe_dispatch_snapshot.py: 3 passed.
  • python3 op_tests/test_flydsl_decode_gemm.py: exit 0.
  • python3 op_tests/test_flydsl_gemm_dispatch.py: exit 0; the dispatcher selects all 82 gfx942 decode rows, worst relative error 3.2e-3.
  • Level 0+1 tuning unittests, including test_config_shape_collision and test_flydsl_decode_padded_m: all pass except TestFlydslRingTunerCandidates.test_policies_filter_keeps_only_the_named_policies and test_shuffled_catalog_is_ring_only (ValueError: unsupported FlyDSL kernel configuration). Both fail the same way on clean main (a47576e) on this gfx942, and that workflow runs on MI350X.
  • Not run here: gfx950. The gate's MI35X shards will cover it.

@vedenev-amd
vedenev-amd requested a review from xytpai November 30, 2026 11:53
…eanly; keep main's MINIMAX_M3_MOE_PREFILL_SWIGLU_LIMIT export next to BlockMfmaDecodeConfig in the sorted __all__.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
xytpai
xytpai previously approved these changes Dec 1, 2026

@xytpai xytpai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM at 11c76ff. This replaces my change request: everything in it and in my later comments is addressed.

  • Merges of main. The first had three conflicts (__init__.py, gemm_a16w16_policy.py, gemm_kernels.py) and the second had one (__init__.py). Each keeps both sides. I redid both three-way merges for the files this PR shares with main; apart from those hunks and the tuner guard, your results match them.
  • Tuner guard. Skipping decode candidates when is_shuffle is right, now that #8675 lets preshuffled shapes into the FlyDSL sweep.
  • Guard test. test_flydsl_decode_padded_m.py is wired in and ran in standard shard 4.
  • CI. The four required checks are green, and all eight MI35X standard shards ran. test_flydsl_decode_gemm.py and test_flydsl_gemm_dispatch.py pass with all 72 decode rows selected. The wheel build's GEMM replay reports 25299 ok and 0 failed.

This rests on reading the code and on this CI run. I did not run anything on gfx950 myself.

… test instead of three and no CI list changes, as review asked.

test_flydsl_gemm_dispatch.py repeated the decode test's check that every decode row is dispatched; its decode name round trip now lives in test_flydsl_decode_gemm.py, and its pass over the hgemm rows, which no decode change needs, is dropped. The M = 3 coverage check for decode M = 4 rows moves from its own tuning_tests file into test_csv_validation.py, which already validates the tuned CSVs, so split_tests.sh and tuning-tests.yaml go back to main.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot changed the title [HIP] [FlyDSL] [CI] FlyDSL gemm_decode: small-M dense GEMM kernels (BF16) [HIP] [FlyDSL] FlyDSL gemm_decode: small-M dense GEMM kernels (BF16) Dec 1, 2026
@github-actions github-actions Bot removed the CI label Dec 1, 2026
@vedenev-amd

Copy link
Copy Markdown
Contributor Author

Closing in favour of #9075. As agreed with Yutao Xu and Felix Li, the decode kernels will be integrated as a policy of the existing FlyDSL hgemm dispatch and its tuning space, instead of a separate pipeline.

@vedenev-amd vedenev-amd closed this Dec 2, 2026
vedenev-amd added a commit that referenced this pull request Dec 2, 2026
…m, so they share the one FlyDSL dispatch path and tuning space instead of a separate decode pipeline, as the review of #4114 asked.

The hgemm kernel name keeps its fields and gains five optional ones that only these policies use: _eu (waves per EU), _rbp (ds_bpermute lane reduction), _ct (scalar or packed FP32 contraction), _lds (A staged in LDS) and _pn (persistent over N). A tuned small-M row applies only at its exact M. Outputs are bitwise equal to the #4114 kernels on all 72 gfx950 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants