Skip to content

[FlyDSL] gfx950 ring GEMM for the DSv4.1 router (16384x384x5120 BF16) - #7931

Draft
fhuizing wants to merge 2 commits into
ROCm:mainfrom
fhuizing:folkert/flydsl-router-16384x384x5120
Draft

fhuizing wants to merge 2 commits into
ROCm:mainfrom
fhuizing:folkert/flydsl-router-16384x384x5120

Conversation

@fhuizing

Copy link
Copy Markdown

Summary

Adds a gfx950 FlyDSL BF16/FP16 GEMM (gemm_a16w16_ring) for the DeepSeek-V4.1 MoE router, torch.mm(x, W.t()) with x[16384, 5120] and W[384, 5120]. It is registered as tuned-name policy rg, and the router's gfx950 row in dsv41_bf16_tuned_gemm.csv now uses it: 53.4 µs against 69.2 µs for the current row (torch) and 57.4 µs for the best tuned hipBLASLt solution.

Motivation

The router row in dsv41_bf16_tuned_gemm.csv is torch (77.0 µs tuner time). No FlyDSL configuration in the generic gfx950 catalog fits this shape well: the best is 65.4 µs. The shape (N=384) gives exactly 256 tiles of 128x192 on a 256-CU MI355X, and the generic kernels' 8-wave schedules do not reach that tile's matrix-core rate at one wave per SIMD.

Changes

  • aiter/ops/flydsl/kernels/gemm_a16w16_ring_gfx950.py: the kernel. A 128x192x64 tile with 4 waves of 64x96, and a 4-stage direct-to-LDS ring with one barrier per K tile. The next K chunk's LDS reads and half of a later tile's DMA are interleaved with each chunk's MFMAs by a sched_group_barrier plan derived from the tile's instruction counts. N and K are compile-time; M is dynamic, and partial M/N tiles are supported. It has no split-K, bias or fp32 output.
  • aiter/ops/flydsl/gemm_a16w16_ring.py: the launch contract. It dispatches through tensor_shim._run_compiled, keyed by config and device, gates on get_gfx_runtime() == "gfx950", checks dtype, contiguity, device and 16-byte alignment, and requires each operand under 2 GiB (32-bit buffer offsets).
  • aiter/ops/flydsl/gemm_kernels.py: tuned-name policy rg (for example flydsl_hgemm_abf16_wbf16_bf16_t128x192x64x4_ks1_w2x2x1_bias0_ktail0_gm1_prg_gfx950). The name parser accepts only same-dtype output, split_k 1, k_waves 1, no bias, gfx950 and a valid tile; flydsl_hgemm(policy="rg") launches it.
  • aiter/tuned_gemm.py: flydsl_gemm treats rg like skinny: input-dtype output, with a bias added after the call rather than fused.
  • aiter/configs/model_configs/dsv41_bf16_tuned_gemm.csv: the gfx950 16384x384x5120 BF16 row changes from torch (77.02 µs) to the rg kernel (54.03 µs).
  • op_tests/test_gemm_a16w16.py: a ring test, on by default.

Performance (if applicable)

MI355X (gfx950, 256 CUs), FlyDSL 0.5.0, torch 2.10.0+rocm7.2.4. Random BF16, W[N,K] as in SGLang, one process. Hot is the median over reps of 20 queued calls / 20. Producer means a 1 GiB write, then A rewritten, then one call. Cold means a 1 GiB write, then one call.

Hardware Workload/configuration Before After Change
MI355X 16384x384x5120 BF16, hot, current row (torch) 69.16 µs 53.42 µs 1.29x
MI355X same, hot, vs tuned hipBLASLt solution 440130 57.37 µs 53.42 µs 1.074x
MI355X same, producer-flush, vs 440130 85.32 µs 86.64 µs tie (−1.5%)
MI355X same, cold, vs 440130 99.20 µs 98.52 µs tie
MI355X same, cold, vs torch 82.40 µs 98.52 µs 0.84x
  • Error: max abs error against the fp32 reference is 0.9994 for all three, which is bf16 output rounding.
  • Cold timing: torch's 128-deep-K kernel stays faster cold. The row replaces torch because the hot and producer timings, which are the router's case, favour the new kernel.
  • Power cap: with random data the board runs at its power cap, about 1.82 GHz. At that clock the kernel is at 65% of MFMA peak.

Testing

  • Unit tests added or updated
  • Performance benchmarks run
  • Tested on MI250X
  • Tested on MI300X

The kernel is gfx950 only; on other cards the test skips with a warning. Validated on MI355X, see below.

Documentation

  • Docstrings updated
  • User guide updated
  • Performance guide updated
  • No documentation change is needed, with the reason stated below

The kernel and launcher docstrings state the contract. No user-facing API changes: the kernel is reached through the existing tuned GEMM dispatch.

Dependencies

  • No new third-party dependencies added
  • New dependencies are listed and justified below

Breaking Changes

None.

PR Self-Review

Reviewed revision

6b73626

Behavior and intent

The only shape whose dispatch changes is gfx950 cu_num 256, M=16384, N=384, K=5120, BF16 in and out, no bias. Through aiter.tuned_gemm it now runs the FlyDSL ring kernel instead of torch.mm. Every other row and policy is unchanged. The new rg name is accepted only for configurations the kernel implements, so an rg row with split-K, bias, fp32 output, another arch or another block_k is rejected at lookup, as other unknown names are.

Validation and unverified scope

  • op test: python3 op_tests/test_gemm_a16w16.py -t ring (FLYDSL_RUNTIME_ENABLE_CACHE=0, MI355X) passes every case with err 0, plus the exact permutation check on every case.
    • The test runs the router shape, a partial M tile (300), partial M and N tiles (129x200x1024), the shortest K the ring accepts (320), and FP16.
    • It also checks parser refusals (ks2, bias1, block_k 128, fp32 out) and that the launcher refuses K=1000.
  • Default test run: python3 op_tests/test_gemm_a16w16.py (default -t normal ring) passes, and so does -t out, which includes a FlyDSL tuned row.
  • Dispatch: with AITER_LOG_TUNED_CONFIG=1, the router shape resolves to libtype flydsl with the row's kernel name, and the profiler shows hgemm_ring_bf16_t128x192x64x4_w2x2_gm1_n384_k5120_0.
  • AOT: python -m aiter.aot.flydsl.gemm --csv <the router row> (GPU_ARCHS=gfx950) replays 1/1 ok and writes gemm_a16w16_ring_gfx950 into the cache.
  • Config guard: python3 -m unittest op_tests.tuning_tests.test_config_shape_collision passes 33/33.
  • Lint: ruff 0.16.0 and black are clean.
  • Unverified:
    • Other XCD counts: the tile order assumes 8 XCDs, as the other a16w16 FlyDSL kernels do. Elsewhere it stays a bijection and only L2 locality changes.
    • MI300X/MI250X: not applicable, the kernel is gfx950 only.
    • SGLang still calls torch.mm for the router, so the row takes effect only on an aiter.tuned_gemm call path.

PR-specific question

To be answered when the automated PR Self-Review comment is posted.

Changed op tests

op_tests/test_gemm_a16w16.py, new ring test (on by default):

  • It is the only coverage of the new kernel and of the rg policy.
  • It enters through flydsl_gemm with an injected row, so it does not depend on the production CSV.
  • It runs into a NaN-filled out.
  • A random-input check against the fp32 reference is paired with an exact permutation input, which a misplaced row, column or K tile changes.
  • The parser and launcher refusals cover the new gates.
  • No pre-existing case is changed; the summary table prints only when another test produced rows.

A 4-wave, 128x192x64 BF16/FP16 GEMM with a 4-stage direct-to-LDS ring, one
barrier per K tile, and a count-derived sched_group_barrier plan. Each K
tile's DMA is split across two half-tiles and issued through the buffer's
scalar offset. Registered as tuned-name policy 'rg', and the router row in
dsv41_bf16_tuned_gemm.csv now uses it.

Hot: 54.0 us (1192 TFLOP/s) vs 58.0 us for hipBLASLt 440130 and 69.4 us for
torch.mm. Producer-flush: 85.1 vs 85.5 us. Cold: 95.4 vs 97.0 us.
…6w16

- Move the launch wrapper to aiter/ops/flydsl/gemm_a16w16_ring.py and
  dispatch through tensor_shim._run_compiled, keyed by config and device.
  The wrapper gates on get_gfx_runtime(), checks devices and alignment,
  and keeps every operand under 2 GiB (32-bit buffer byte offsets).
- Kernel: issue the LDS DMA through the stable fx.copy async atom instead
  of the raw intrinsic (no flydsl._mlir import, no measurable change),
  and name the kernel through flyc.kernel(name=, known_block_size=).
  Document the remaining unstable sched_barrier/s_barrier sites and the
  DMA lane map.
- Name parser: one shape-independent ring_tile_error check for 'rg'.
- tuned_gemm.flydsl_gemm: ring, like skinny, writes its input dtype and
  takes no fused bias.
- Tests: fold the ring cases into op_tests/test_gemm_a16w16.py (-t ring,
  on by default; CI runs this file). The new tests use the tuned dispatch
  with an injected row, a NaN-filled out, an exact permutation input, and
  parser and launcher refusals, and print their own summary table.
@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 7931 --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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant