Skip to content

[FlyDSL] Add gfx950 split-K concat-then-GEMM ring (five taps, M<=128) for the DSpark draft fc - #8573

Closed
ganyi1996ppo wants to merge 4 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-bf16-cat-x-ring
Closed

ganyi1996ppo wants to merge 4 commits into
ROCm:mainfrom
ganyi1996ppo:ganyi/flydsl-bf16-cat-x-ring

Conversation

@ganyi1996ppo

@ganyi1996ppo ganyi1996ppo commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

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]^T for five equal-width bf16 activation taps and 1 <= M <= 128 on gfx950, without materializing the concat (the DSpark draft fc: 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 split ks ways (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_kernel with 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.
  • Cold-weight (2 GiB rotation) CUDA-graph-replay median, us per call, ks=10, same lease, vs amd-kernels bf16_concat_linear and vs torch.cat + tgemm:
M this amd-kernels cat+tgemm
8 17.8 22.7 27.6
16 18.2 23.4
32 19.1 24.6 31.5
64 21.8 27.5
128 33.3 33.2 48.2

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+tgemm column is tgemm.mm on 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 in cat_x_ring_supported. The same device/offset points apply to #8554's gemm_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

  • Five taps with one common row stride; other shapes keep the existing path. gfx950 with 256 CUs.
  • No ATOM wiring in this PR: the draft fc call site is not in public ATOM main.

🤖 Generated with Claude Code

ganyi1996ppo and others added 3 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]>
… 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]>
@ganyi1996ppo
ganyi1996ppo requested review from a team and a balanced review from Copilot November 24, 2026 13:29
@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 8573 --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 b720826d6eb5 · 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.

… 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]>

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 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
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):
Comment on lines +120 to +122
ret[f"{name} err"] = checkAllclose(
ref.float(), out.float(), atol=0.05, rtol=1e-2, msg=name
)
Comment on lines +143 to +144
if __name__ == "__main__":
main()
Copilot AI balanced review requested due to automatic review settings November 24, 2026 13:38

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

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

Comment on lines +86 to +87
or x.stride(0) != stride
or (stride * 2) % 16
@ganyi1996ppo

Copy link
Copy Markdown
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants