Repository navigation
[FlyDSL] [CI] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128) - #8554
ganyi1996ppo wants to merge 3 commits into
Conversation
…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]>
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: Reviews: |
DRAFT — evaluation pausedPR Self-ReviewRevision 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. |
There was a problem hiding this comment.
🟡 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
Validate CUDA input and matching weight/output devices before dispatch · New Bind compilation and stream selection to the input device · New Bound weight span to prevent 32-bit DMA offset overflow · New Fail standalone benchmarks when checkAllclose reports mismatches · New Register the correctness suite in default Aiter CI shards · New
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
| 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]>
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):
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; 🤖 Generated with Claude Code |
There was a problem hiding this comment.
🟡 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
| m, k = x.shape | ||
| n = w.shape[0] |
| _SKIP = pytest.mark.skipif( | ||
| get_gfx_runtime() != "gfx950", reason="gfx950 and FlyDSL are required" | ||
| ) |
|
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. |


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'slm_headat 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 opgemm_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 reusestensor_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-tgemmperf 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 legacybuffer_opsmodule and rawrocdlDMA /s_barrier, as the band-stream HGEMM next to it does, because the explicit per-wavevmcntwaits 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.amd_kernels.gemm.bf16_n50016_k6144, same random inputs, N=50016, K=6144):torch.equalis 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 equalsamd_kernels'shuffle_weightbit for bit.aiter.tuned_gemm.tgemm.mm(the node's default tuned table):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
ring_supportedsays no otherwise); other shapes or archs keep their existing GEMM.ParallelLMHeadkeeps the shuffled copy and routes 1..128 rows here, behindATOM_LM_HEAD_RING) is a separate PR on ROCm/ATOM.🤖 Generated with Claude Code