Skip to content

[FlyDSL] [CI] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128) - #8554

Closed
ganyi1996ppo wants to merge 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-bf16-ring-gemm
Closed

ganyi1996ppo wants to merge 3 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-bf16-ring-gemm

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds a gfx950 small-M BF16 GEMM for a weight that is read once per call and is HBM-bound, the shape of a vocabulary-shard lm_head (out[M, N] = x[M, K] @ w[N, K]^T, 1 <= M <= 128; e.g. N=50016, K=6144 for a 200k vocab at TP4). Every model's lm_head at decode / draft / verify row counts can use it through the host op.

  • aiter/ops/flydsl/kernels/gemm_a16w16_ring_gfx950.py: one launch, 256 XCD-interleaved column tiles, a buffer-load-to-LDS DMA ring (3-4 K=64 stages), mfma_f32_16x16x32_bf16, fp32 accumulate. No split-K and no cross-tile reduction, so the result is deterministic and CUDA-graph safe. Generalized in N and K (N % 16 == 0, N / 16 >= 256, K % 64 == 0); one M half (4 waves) up to 64 rows, two M halves (8 waves) for 65-128 rows.
  • aiter/ops/flydsl/gemm_a16w16_ring.py: host op gemm_a16w16_ring(x, w, out=None, shuffled=True), ring_supported(m, n, k), shuffle_weight_ring / unshuffle_weight_ring (the [N/16, K/64, 16, 64] tile layout, a bit-exact permutation made once at load), warmup_ring (compile every row tier before graph capture). It reuses tensor_shim._run_compiled.
  • op_tests/flydsl_tests/test_flydsl_gemm_a16w16_ring.py: correctness vs a torch fp32 reference over 3 (N, K) shapes x 12 row counts, shuffled == row-major, row-tier invariance, CUDA-graph replay, and a ring-vs-tgemm perf table.

The kernel is adapted from the amd-kernels project's gemm/bf16_n50016_k6144 (revision fd233ef, Apache-2.0; attribution and license in the file header). It uses the legacy buffer_ops module and raw rocdl DMA / s_barrier, as the band-stream HGEMM next to it does, because the explicit per-wave vmcnt waits depend on the exact DMA issue order; the comments at the raw calls say so.

Verification (MI355X, node with FlyDSL 0.5.0, 1 GPU)

  • pytest op_tests/flydsl_tests/test_flydsl_gemm_a16w16_ring.py: 39 passed.
  • Against the source kernel (amd_kernels.gemm.bf16_n50016_k6144, same random inputs, N=50016, K=6144): torch.equal is True at M = 7, 8, 16, 17, 32, 48, 64, 65, 96, 97, 128 (eager, and CUDA-graph replay equals eager at every tested M, 1, 3, 6 and 7-128). The weight layout equals amd_kernels' shuffle_weight bit for bit.
  • Cold-weight (2.3 GiB rotation) CUDA-graph-replay median, us per call, N=50016, K=6144, vs the source kernel and vs aiter.tuned_gemm.tgemm.mm (the node's default tuned table):
M ring amd-kernels tgemm
7 94.8 94.6 100.1
8 94.7 94.8 100.4
16 94.7 94.9 111.2
32 96.4 96.6 120.1
64 99.8 99.7 179.2
65 98.1 104.3 170.3
96 100.3 127.1 180.6
128 105.9 186.2 195.1

Equal to the source kernel at 7-64 rows (same instruction stream), faster at 65-128, 94-96% of the HBM floor at 7-64 rows. The row-major (shuffled=False) path is correct and bit-identical to the shuffled one but ~30 us slower, so a caller keeps a one-time shuffled copy of the weight.

Notes

  • gfx950 with 256 CUs only (ring_supported says no otherwise); other shapes or archs keep their existing GEMM.
  • The paired ATOM change (ParallelLMHead keeps the shuffled copy and routes 1..128 rows here, behind ATOM_LM_HEAD_RING) is a separate PR on ROCm/ATOM.

🤖 Generated with Claude Code

ganyi1996ppo and others added 2 commits November 24, 2026 02:51
…M<=128)

out[M, N] = x[M, K] @ w[N, K]^T for 1 <= M <= 128 on a weight read once per
call (a vocabulary-shard lm_head: N=50016, K=6144 at TP4 of a 200k vocab).
One launch, 256 XCD-interleaved column tiles, buffer-load-to-LDS DMA ring,
mfma_f32_16x16x32_bf16, no split-K and no cross-tile reduction, so it is
deterministic and CUDA-graph safe.

- aiter/ops/flydsl/kernels/gemm_a16w16_ring_gfx950.py: the kernel, generalized
  in N and K (N % 16 == 0, N / 16 >= 256, K % 64 == 0) with the M-halves and
  ring-depth parameters free; one M half up to 64 rows, two halves for 65-128.
- aiter/ops/flydsl/gemm_a16w16_ring.py: host op (gemm_a16w16_ring,
  ring_supported, shuffle_weight_ring / unshuffle_weight_ring, warmup_ring).
  The weight is read in a [N/16, K/64, 16, 64] tile layout (a bit-exact
  permutation made once at load); the row-major weight also works but is
  ~30 us slower at N=50016, K=6144.
- op_tests/flydsl_tests/test_flydsl_gemm_a16w16_ring.py: correctness vs a torch
  fp32 reference over three (N, K) shapes x 12 row counts, layout / row-tier
  invariance, CUDA-graph replay, and a ring-vs-tgemm perf table.

Kernel adapted from the amd-kernels project's gemm/bf16_n50016_k6144 (MIT),
revision fd233ef; bit-identical to that kernel at every row count 7-128.

Co-Authored-By: Claude <[email protected]>
@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot November 24, 2026 08:54
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
ci:mi300x Run Aiter standard tests on MI300X in PRs; main branch always runs them
ci:gfx1250-ffm-triton Run the five-shard gfx1250 FFM Triton test suite
ci:triton-300x Run an additional Triton test job on MI300X in PRs (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
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: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
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 8554 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@aiter-bot

aiter-bot commented Nov 24, 2026 •

Copy link
Copy Markdown

DRAFT — evaluation paused

PR Self-Review

Revision bf83e6868bc6 · mode shadow

This pull request is a draft, so readiness evaluation is paused and no verdict applies. Evaluation resumes when it is marked ready for review and the required CI completes.

Copilot AI 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.

🟡 Changes recommended

Unresolved critical defects allow CPU or mismatched-device tensors into the raw-pointer launcher, reuse device-bound handles across GPUs, and overflow DMA offsets for large weights.

5 open issues
What changed in this PR

Adds a FlyDSL BF16 GEMM for small-row lm_head workloads on gfx950 GPUs with 256 compute units, exposed through a new host operation.

Changes:

  • Implements a single-launch DMA-ring kernel with FP32 accumulation for 1–128 rows.
  • Adds shape/device support checks, weight shuffling helpers, and compilation warmup.
  • Adds numerical, layout, row-tier, graph-replay tests and a comparison benchmark against tgemm.
File Description
op_tests/​flydsl_tests/​test_flydsl_gemm_a16w16_ring.py Adds correctness cases and a ring-versus-tgemm benchmark.
aiter/​ops/​flydsl/​kernels/​gemm_a16w16_ring_gfx950.py Implements the gfx950 BF16 DMA-ring GEMM kernel.
aiter/​ops/​flydsl/​gemm_a16w16_ring.py Provides the host operation, support checks, weight conversion, and warmup helpers.

Review effort: Balanced

Comment thread aiter/ops/flydsl/gemm_a16w16_ring.py Resolved
Comment thread aiter/ops/flydsl/gemm_a16w16_ring.py Resolved
Comment on lines +151 to +152
if __name__ == "__main__":
main()
…on, benchmark assert

- gemm_a16w16_ring requires CUDA x/w/out on one device, launches under that device and its stream, and
  keys the compiled handle per device.
- supported_shape rejects weights whose N*K*2 bytes reach the 0x70000000 DMA-offset sentinel
  (N=K=65536 passed fits() and wrapped the 32-bit offset).
- the standalone benchmark asserts the ring result matches the fp32 reference instead of only logging it.
- register test_flydsl_gemm_a16w16_ring.py in split_tests.sh and dispatch it through pytest in
  aiter_test.sh so CI runs the pytest cases.
- tests for the 32-bit bound and the CPU / foreign-device rejection.

Co-Authored-By: Claude <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:44
@github-actions github-actions Bot changed the title [FlyDSL] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128) [FlyDSL] [CI] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128) Nov 24, 2026
@github-actions github-actions Bot added the CI label Nov 24, 2026
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

ROCm/aiter PR #8554 — [FlyDSL] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128)

Adds a one-launch FlyDSL BF16 GEMM for 1<=M<=128 on gfx950 that streams the weight through an LDS ring with a fixed K order (deterministic, graph safe), ported from the amd-kernels lm_head kernel and generalized in N and K.

Review (advisory): ⚠️ NEEDS WORK -- not independently refuted
Validation (deterministic): NOT RUN -- the auto-run's evidence was rejected (jsonschema missing on the review host); by hand on gfx950 (035 GPU 0, head bf83e68): pytest op_tests/flydsl_tests/test_flydsl_gemm_a16w16_ring.py 41 passed, covering M in {1,7,8,16,17,32,48,64,65,96,97,128} at (N,K) = (50016,6144), (32000,4096), (24576,7168) against an independent fp32 torch matmul, graph replay, and layout invariance
Perf (advisory): NOT RUN -- the PR claims no number and the standalone benchmark's table was not captured on this run
Size: 566 lines / 3 files
Design (advisory): the decision to ship the ring GEMM as a standalone host op (gemm_a16w16_ring) that the consumer calls after ring_supported, with its own tile-shuffled weight layout, instead of a policy of the flydsl hgemm / tgemm dispatch
Human: recommend Bernard-Liu review whether a standalone op with a consumer-side ring_supported gate is acceptable for #8554 or the ring should become a policy of the flydsl hgemm / tuned_gemm dispatch

⚠️ [verified] The new op is not registered in tuned_gemm or the flydsl hgemm policy/name tables, and nothing in aiter calls it; only ATOM #3776 (ParallelLMHead) does, with its own gate and a second tile-shuffled copy of the weight shard per rank. Other aiter consumers of tgemm.mm do not benefit. Reviewer should ask whether a standalone op is the intended integration or the ring should become a dispatchable policy, since the integration route decides whether every ATOM model benefits.
⚠️ [verified] The description and benchmark give no latency or bandwidth number versus tgemm.mm; main() only prints a table. Author must attach the ring versus tgemm.mm microseconds at the production shape (N=50016, K=6144, M=8..128), baseline and GPU named.
📝 [verified] The attribution header names amd-kernels (fd233ef, Apache-2.0) and there is no amd_kernels import anywhere in the three files; Reviewer should ask nothing further unless the project wants the Apache-2.0 notice text carried alongside the MIT header.

Fixed on the branch in bf83e68 (the Copilot findings were real and reproduced by reading): the op now requires CUDA x, w and out on one device, launches under that device and its stream and keys the compiled handle per device; supported_shape rejects weights whose NK2 bytes reach the 0x70000000 DMA-offset sentinel (N=K=65536 passed fits() and wrapped the 32-bit offset); the standalone benchmark now asserts the ring result; the test file is registered in split_tests.sh and dispatched through pytest in aiter_test.sh so CI runs it; two tests cover the bound and the rejections.

🤖 Generated with Claude Code

Copilot AI 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.

🟡 Changes recommended

Missing input-rank validation allows empty non-matrix weights to reach the kernel and trigger out-of-bounds reads, while incomplete test gating causes failures on unsupported gfx950 configurations.

3 open issues
4 resolved since last review

Review effort: Balanced

Comment on lines +81 to +82
m, k = x.shape
n = w.shape[0]
Comment on lines +35 to +37
_SKIP = pytest.mark.skipif(
get_gfx_runtime() != "gfx950", reason="gfx950 and FlyDSL are required"
)
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

Closing: superseded. The small-M BF16 ring GEMM (policy rg) is being integrated into the FlyDSL hgemm catalog, the gemm tuner and the tgemm path (a combined PR with the DSpark FC ring follows), instead of a standalone op that ATOM calls directly. The fork branch stays.

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.

4 participants