Repository navigation
[FlyDSL] Add gfx950 split-K concat-then-GEMM ring (five taps, M<=128) for the DSpark draft fc - #8573
ganyi1996ppo wants to merge 4 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]>
… for the DSpark draft fc out[M, N] = concat(x0..x4)[M, 5*seg_k] @ w[N, 5*seg_k]^T without materializing the concat. Built on the small-M ring GEMM (previous commit): K is split ks ways (default 10, two splits per tap) so each workgroup reads ONE tap, chosen once from five kernel-argument base pointers (no host-side pointer table, so the launch is CUDA-graph capturable). Each split stores an fp32 partial; aiter's Triton split-K reduce kernel sums the partials in ascending order with one bf16 rounding: deterministic, not bit-identical to a single-pass K order. Adapted in idea from the amd-kernels project's gemm/bf16_concat_linear_n1536_k30720 (Apache-2.0), reimplemented on the ring kernel. 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. |
… on it, bound i32 byte offsets review-pr D13/D14 on the raw-pointer launch: the taps, out and workspace must be on the weight's CUDA device, the launch runs under torch.cuda.device(), the compiled-handle cache is keyed on the device index, and cat_x_ring_supported refuses a weight or fp32 partial buffer of 2 GiB or more (i32 byte offsets). Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved activation-buffer sizing and device-handling defects can cause out-of-bounds DMA, launches with CPU addresses, and reuse of device-bound handles across GPUs.
6 open issues
Validate tensor devices and launch on the correct GPU · New Include the device in the launcher cache key · New Size activation descriptors for the occupied row span · New Warm the final row tier when m_max is unaligned · New Fail the standalone run when benchmark outputs mismatch · New Register the correctness suite in Aiter CI · New
What changed in this PR
Adds a gfx950 BF16 split-K GEMM for five activation taps and 1–128 rows, targeting the DSpark draft fc without materializing concatenated inputs. It builds on the ring GEMM from stacked PR #8554; no ATOM call-site integration is included.
Changes:
- Adds a five-tap split-K ring kernel with FP32 partials and deterministic reduction.
- Provides a host wrapper, support checks, optional buffers and warmup helper.
- Adds correctness, split-choice, graph-replay and benchmark cases.
| File | Description |
|---|---|
op_tests/flydsl_tests/test_flydsl_gemm_a16w16_ring.py |
Base ring correctness and benchmarks from #8554. |
op_tests/flydsl_tests/test_flydsl_gemm_a16w16_cat_x_ring.py |
Five-tap correctness, graph replay and benchmarks. |
aiter/ops/flydsl/kernels/gemm_a16w16_ring_gfx950.py |
Base ring kernel and shared helpers from #8554. |
aiter/ops/flydsl/kernels/gemm_a16w16_cat_x_ring_gfx950.py |
Split-K kernel reading activation taps directly. |
aiter/ops/flydsl/gemm_a16w16_ring.py |
Base wrapper, weight-layout helpers and device gate from #8554. |
aiter/ops/flydsl/gemm_a16w16_cat_x_ring.py |
Five-tap wrapper, reduction and warmup helper. |
Review effort: Balanced
| xa = (seg == 3).select(x3, xa) | ||
| xa = (seg == 4).select(x4, xa) | ||
| xr = buffer_ops.create_buffer_resource_from_addr( | ||
| xa, num_records_bytes=i32_m * i32_xs |
| torch.zeros(m_max, seg_k, dtype=torch.bfloat16, device=w.device) | ||
| for _ in range(NSEG) | ||
| ] | ||
| for m in range(16, m_max + 1, 16): |
| ret[f"{name} err"] = checkAllclose( | ||
| ref.float(), out.float(), atol=0.05, rtol=1e-2, msg=name | ||
| ) |
| if __name__ == "__main__": | ||
| main() |
There was a problem hiding this comment.
🟡 Changes recommended
Accepted zero-stride and large-stride tap layouts can produce zero-length activation descriptors, making activation DMA out of bounds and preventing the kernel from reading the intended inputs.
5 open issues
2 resolved since last review
Review effort: Balanced
| or x.stride(0) != stride | ||
| or (stride * 2) % 16 |
|
Closing: superseded. The split-K concat-then-GEMM ring (policy rk) is being integrated into the FlyDSL hgemm catalog, the gemm tuner and the tgemm path together with the lm_head ring (a combined PR follows). The fork branch stays. |


Stacked on #8554 (it uses that PR's ring kernel and
_device_ok); review only the top commit until #8554 merges.Summary
out[M, N] = concat(x0..x4, dim=-1)[M, 5*seg_k] @ w[N, 5*seg_k]^Tfor five equal-width bf16 activation taps and 1 <= M <= 128 on gfx950, without materializing the concat (the DSpark draftfc: five taps of 6144, N=1536, K=30720).kernels/gemm_a16w16_cat_x_ring_gfx950.py: the ring GEMM of [FlyDSL] [CI] Add gfx950 small-M BF16 ring GEMM for lm_head-shaped GEMMs (M<=128) #8554 with a split-K grid. K is splitksways (default 10 = two per tap) so a workgroup reads one tap, selected once from five kernel-argument pointers. There is no host-side pointer table, so the launch is CUDA-graph capturable (the earlier Triton port needed a host-to-device copy per call).gemm_a16w16_cat_x_ring.py:gemm_a16w16_cat_x_ring(xs, w_ring),cat_x_ring_supported,warmup_cat_x_ring. The fp32 partials are summed in ascending split order by aiter's_gemm_splitk_reduce_kernelwith one bf16 rounding: deterministic, within bf16 rounding of a single-pass K order, not bit-identical to it or to the amd-kernels kernel (different summation order).op_tests/flydsl_tests/test_flydsl_gemm_a16w16_cat_x_ring.py: 25 tests (10 row counts x contiguous / padded-stride taps vs a torch fp32 reference, determinism, split choices 5/10/20, CUDA-graph replay, rejection of unsupported shapes) plus a perf table.Idea credited to the amd-kernels
gemm/bf16_concat_linear_n1536_k30720(revision fd233ef, Apache-2.0); this is a reimplementation on the ring kernel, not a copy.Verification (MI355X, 1 GPU)
pytest: 25 passed. Max |error| vs a torch fp32 reference is 1.97-2.0 on outputs of magnitude ~100-500 (bf16 rounding), at every row count 8..128.bf16_concat_linearand vstorch.cat+tgemm:Faster than the amd-kernels kernel at 8-64 rows, equal at 128 rows. (The earlier Triton port was 1.1-1.7x slower.) The
cat+tgemmcolumn istgemm.mmon the node's default config, from the op_test's own timing loop (a different harness, so only indicative).Review
review-pr (advisory) run on this PR's top commit; 25 rules derived, no style/import/AOT/guard/test-placement findings. Real findings (D13/D14, raw-pointer launch), fixed in the follow-up commit: tensors on one CUDA device and the launch under
torch.cuda.device, compile cache keyed on the device index, i32 byte-offset bound incat_x_ring_supported. The same device/offset points apply to #8554'sgemm_a16w16_ring(its owner is informed). Numerics: within bf16 rounding of a torch fp32 reference, deterministic, not bit-identical to amd-kernels or to a single-pass K order; no draft-acceptance run (no ATOM wiring here).Notes
fccall site is not in public ATOM main.🤖 Generated with Claude Code