Skip to content

[CK] [FlyDSL] Introduce FP8 a8w8 gemm kernel with fp32 blockscale to uplift the MI355 blockwise gemm perf - #5969

Merged
valarLip merged 48 commits into
ROCm:mainfrom
LuweiZhou2025:luwei/a8w8_blockscale
Nov 2, 2026
Merged

valarLip merged 48 commits into
ROCm:mainfrom
LuweiZhou2025:luwei/a8w8_blockscale

Conversation

@LuweiZhou2025

@LuweiZhou2025 LuweiZhou2025 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

FP8 blockwise gemm with fp32 scale has low perf on MI355. The pain point is have to apply dequantization scale on the none-scale MXFP8 MFMA ISA on every K block accumulation . This PR introduce a new algorithm implementation on to solve this. Support both plain B layout and preshuffled B layout.

Technical Details

To squeeze hardware performance, design a new pipeline algo:
1, Based on 8 wave gemm pipeline, introduce a new pipelining algorithm to break the dequantization dependency on MFMA C. MFMA engine can run parallel with VALU, which make dequantization latency is hidden by MFMA.
2. Tensor A scales would be loaded into LDS and B scale directly to registers.
3. Tensor A scales use [BK, M] layout to access HBM with coalescing
4. This algorithm consume too much VGPRs. Split M further on the 8 wave algo to remove VGPRs spill.
5. Use padding not swizzling to avoid bank conflicts.
6. Precalculated vmem/lds offset to lower down VGPRs footprint and also achieve clean mainloop
7. Permute lane to store 4xDWORD per lane in epilog part.
8. Prevent v_pk_fma to ensure VAL is hidden by FMA ops.

tuned model config update

test covered 12,611 gfx950 shapes and switched 7,252 rows to FlyDSL kernel.

Across all 7,252 tested replacements, FlyDSL's calc_diff is no worse than that of the replaced kernel. The diffs are identical in 7,246 cases, and FlyDSL achieves a lower diff in the remaining 6 cases.

Config Replacements Identical Old kernel max diff (FP32 ref) FlyDSL max diff (FP32 ref) FlyDSL max diff (BF16 ref)
ds_v3 5379 5379 1.84e-06 1.84e-06 5.9e-09
dsv4 625 625 1.79e-06 1.79e-06 4.0e-09
qwen3_next_80b 516 516 1.53e-06 1.53e-06 2.8e-09
dsv4 bpreshuffle 285 279 6.22e-06 1.79e-06 6.2e-09
bpreshuffle dsv3 202 202 1.76e-06 1.76e-06 4.0e-09
bpreshuffle qwen3.5_397b 115 115 1.53e-06 1.53e-06 3.0e-09
9 other configs 130 130 ≤1.54e-06 ≤1.54e-06 ≤5.7e-09

No numerical-accuracy regressions were observed under the calc_diff metric in these tested replacements.
In 7,236 of the 7,252 replacements, both diff values are exactly equal.
In 10 more (old kernel cktile), they differ by at most 3.3e-14: 5 slightly higher, 5 slightly lower.
In the remaining 6 (old kernel asm), FlyDSL is clearly better.

Performance Test Result

HW platform : smci355-ccs-aus-m09-09, this platform TFLOPS has some perf gap with top performance 355. About 5% -10% gap with top perf MI355 machine.

Ideal shape perf lift up:

Choose some gemm perf friendly shape and compare performance with aiter optus, ck,cktile, asm backend. Some shapes can achieve 3000 TFlops.

M N K TP B layout Best non-FlyDSL backend Best non-FlyDSL time (µs) FlyDSL time (µs) FlyDSL uplift FlyDSL TFLOPS
4096 4096 16384 1 plain CKTile 338.3454 195.6127 +72.967% 2810.43
4096 4096 16384 1 preshuffle CK 325.4680 191.9248 +69.581% 2864.43
4096 4096 32768 1 plain CKTile 656.1298 372.3301 +76.223% 2953.06
4096 4096 32768 1 preshuffle CK 620.3579 367.9619 +68.593% 2988.11
4096 8192 16384 1 plain CKTile 511.0976 377.0924 +35.536% 2915.76
4096 8192 16384 1 preshuffle CKTile 498.5045 372.3231 +33.890% 2953.11
4096 8192 32768 1 plain CKTile 997.7722 727.9060 +37.074% 3021.03
4096 8192 32768 1 preshuffle CKTile 990.7566 729.7929 +35.759% 3013.22
8192 4096 16384 1 plain CKTile 513.7172 382.0318 +34.470% 2878.06
8192 4096 16384 1 preshuffle CKTile 500.1461 374.9775 +33.380% 2932.21
8192 4096 32768 1 plain CKTile 998.3685 746.9098 +33.667% 2944.16
8192 4096 32768 1 preshuffle CKTile 981.6414 736.8643 +33.219% 2984.30
8192 8192 16384 1 plain CKTile 999.7680 744.1012 +34.359% 2955.27
8192 8192 16384 1 preshuffle CKTile 984.1253 734.5313 +33.980% 2993.78
8192 8192 32768 1 plain CKTile 1995.1244 1493.1098 +33.622% 2945.56
8192 8192 32768 1 preshuffle CKTile 1966.4486 1469.9134 +33.780% 2992.04

QKV fused projection uplift on some models:

tokens in [4096, 8192, 12288, 16394, 32768], tensor parallel [1,2,4,8]. compare with current AITER best backend gemm implementation and get average uplift for each model:

Model / Benchmark Suite Plain B Uplift Preshuffled B Uplift FlyDSL Throughput (TFLOPS)
Qwen3.5-397B-A17B +14.58% +15.09% 1548.01–2644.83
Qwen3.8-2.4T-A95B-FP8 +25.99% +27.66% 1757.95–2913.84
MiMo-V2.5-Pro +34.96% +35.77% 2014.99–2788.18
DeepSeek-V4-Flash +18.89% +18.69% 1026.27–2462.18
Ideal Shapes +41.98% +40.51% 2750.06–3000.16

MiMo-V2.5-Pro tokens= 16384 as example:

M N K TP B layout Best non-FlyDSL backend Best non-FlyDSL µs FlyDSL µs FlyDSL uplift FlyDSL TFLOPS
16384 27136 6144 1 plain CKTile 2400.9001 2010.1626 +19.438% 2717.79
16384 27136 6144 1 preshuffle CKTile 2562.8033 1983.8925 +29.181% 2753.78
16384 13568 6144 2 plain CKTile 1321.9890 1038.8930 +27.250% 2629.34
16384 13568 6144 2 preshuffle CKTile 1364.2935 1018.8552 +33.905% 2681.05
16384 6784 6144 4 plain CK 874.6821 521.2191 +67.815% 2620.39
16384 6784 6144 4 preshuffle CK 777.2436 513.5622 +51.344% 2659.46
16384 3392 6144 8 plain CKTile 347.1500 286.6007 +21.127% 2382.76
16384 3392 6144 8 preshuffle CKTile 339.4886 282.9456 +19.984% 2413.54

File github issue about fx.copy():

ROCm/FlyDSL#1339

Submission Checklist

@LuweiZhou2025
LuweiZhou2025 requested review from a team and a balanced review from Copilot September 30, 2026 01:36
@github-actions

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every PR:

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

Extended tests (opt-in via labels):

Label Tests
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
multigpu 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: GPT-OSS-120B, DeepSeek-R1-0528, Kimi-K2.5
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 5969 --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.

@github-actions github-actions Bot changed the title Luwei/a8w8 blockscale [CK] [FlyDSL] Luwei/a8w8 blockscale Sep 30, 2026
@LuweiZhou2025 LuweiZhou2025 removed the CK label Sep 30, 2026
@github-actions github-actions Bot added the CK label Sep 30, 2026

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.

Copilot review overview

🟡 Changes recommended

The tuned CSV contains unresolved conflict markers, and raw MoE weights are repeatedly reshuffled in the hot path.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 1 Low severity

Open (3)
What changed in this PR

Adds a gfx950 FlyDSL FP8 blockscale GEMM backend with dispatch, tuning, scale-layout handling, tests, and model configurations.

Changes:

  • Implements plain and B-preshuffled FlyDSL kernels and runtime routing.
  • Integrates FlyDSL candidates into the blockscale tuner.
  • Adds correctness, compilation, dispatch, and performance coverage.
File Description
op_tests/​tuning_tests/​test_flydsl_blockscale.py Adds CPU routing and tuner tests.
op_tests/​test_gemm_a8w8_blockscale_flydsl.py Adds GPU correctness/performance coverage.
csrc/​ck_gemm_a8w8_blockscale/​README.md Documents the FlyDSL backend.
csrc/​ck_gemm_a8w8_blockscale/​gemm_a8w8_blockscale_tune.py Adds FlyDSL tuning candidates.
aiter/​ops/​quant.py Tags transposed scale layouts.
aiter/​ops/​gemm_op_a8w8.py Adds tuned FlyDSL dispatch.
aiter/​ops/​flydsl/​kernels/​gemm_a8w8_blockscale_8wave.py Implements the GPU kernel.
aiter/​ops/​flydsl/​gemm_tune/​flydsl_gemm_a8w8_blockscale_common.py Defines kernel metadata and shape gates.
aiter/​ops/​flydsl/​gemm_a8w8_blockscale.py Adds the runtime adapter.
aiter/​fused_moe.py Adds automatic weight preshuffling.
aiter/​configs/​model_configs/​qwen35_mimo_tp8_tuned_fmoe.csv Adds Qwen MoE tuning rows.
aiter/​configs/​a8w8_blockscale_tuned_gemm.csv Updates plain blockscale tuning data.
aiter/​configs/​a8w8_blockscale_bpreshuffle_tuned_gemm.csv Adds preshuffled tuning rows.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread aiter/fused_moe.py Resolved
Comment thread csrc/ck_gemm_a8w8_blockscale/README.md Resolved
Copilot AI balanced review requested due to automatic review settings September 30, 2026 02:15

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.

Copilot review overview

🟡 Changes recommended

The ScaleA bound and quantization marker issues cause deterministic test failures, with additional coverage gaps.

Review effort: Balanced
Findings: 2 High severity · 1 Medium severity · 1 Low severity

Open (4)
Resolved since last review (1)
Previously missed (2)

In code that hasn't changed since last review

Low severity Missing coverage for raw-weight conversion behavior

aiter/​fused_moe.py:1155

No test exercises this new raw-weight conversion path. Existing blockscale MoE tests preshuffle both weights before calling fused MoE, so they do not verify that two raw weights are converted exactly once, that already-marked weights are preserved, or that non-gfx950/non-separated routes remain unchanged.

Low severity Plain-layout path ignores guarded output buffer

op_tests/​test_gemm_a8w8_blockscale_flydsl.py:92

The plain-layout branch does not pass out to the public API, so result uses a separate allocation while the later guard checks inspect untouched guarded_out. Consequently the advertised over-store check covers only the preshuffled API and cannot detect plain-kernel M/N-tail writes past the result buffer.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 02:25

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.

Copilot review overview

🟡 Changes recommended

Scale bounds are incomplete, a new producer-contract test fails, and several documentation links are unresolved.

Review effort: Balanced
Findings: 3 High severity · 1 Low severity

Open (4)
Resolved since last review (1)

Copilot AI balanced review requested due to automatic review settings September 30, 2026 14:47

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.

Copilot review overview

🟡 Changes recommended

The scale producer does not set the marker required by the new adapter, causing a test failure and potentially incorrect scale layout handling.

Review effort: Balanced
Findings: 3 High severity · 2 Low severity

Open (5)

Comment thread csrc/ck_gemm_a8w8_blockscale/README.md Resolved
@zufayu
zufayu requested a review from yadaish October 1, 2026 00:35

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.

🔵 Needs a closer look

The asynchronous GPU pipeline warrants human review with hardware correctness and performance evidence that was not independently verified here.

3 open issues

Review effort: Balanced

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.

🔵 Needs a closer look

The low-level GPU pipeline and production dispatch changes require human review of MI355 correctness and performance validation.

3 open issues

Review effort: Balanced

@LuweiZhou2025

Copy link
Copy Markdown
Contributor Author

update the tuned csv?

@solinzby1 , updated all model config. 7,252/12611 rows are switched to FLYDSL kernel. Since too many entries are switched, Also add some accuracy check to ensure no regression. For other non-model config, I want to apply tune changes after this PR merged. How do you think

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

Eight GLM5.2 backend switches lack supporting performance evidence because their committed latencies exceed the replaced CK values.

4 open issues

Review effort: Balanced

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.

🔵 Needs a closer look

The asynchronous GPU pipeline and production dispatch changes warrant final human review of target-hardware correctness and performance evidence.

4 open issues

Review effort: Balanced

valarLip
valarLip previously approved these changes Oct 28, 2026

@valarLip valarLip left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

The DMA path uses offsets excluded from gfx950 bounds checks, allowing out-of-allocation reads and possible faults in a newly selected configuration.

6 open issues
1 resolved since last review

Review effort: Balanced

return False
if Out.dtype not in (torch.bfloat16, torch.float16):
return False
gfx = torch.cuda.get_device_properties(XQ.device).gcnArchName.split(":", 1)[0]
Comment on lines +850 to +853
packed_a = acc_a.to(fx.Float16).bitcast(fx.Int32)
packed_b = acc_b.to(fx.Float16).bitcast(fx.Int32)
d0_a, d1_a = packed_a[0].ir_value(), packed_a[1].ir_value()
d0_b, d1_b = packed_b[0].ir_value(), packed_b[1].ir_value()

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.

🔵 Needs a closer look

The local architecture probe bypasses the shared replay-aware runtime helper, and the new FP16 packing path lacks numerical coverage for both B layouts and mixed-dtype launcher-cache reuse.

5 open issues
1 resolved since last review

Review effort: Balanced

Co-authored-by: Li, Tingqian <[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.

🔵 Needs a closer look

The change bypasses shared AOT-aware architecture detection, lacks correctness coverage for the new FP16 path, and replaces CK selections with entries showing higher recorded latencies without paired validation.

5 open issues

Review effort: Balanced

@aiter-bot

aiter-bot commented Oct 29, 2026 •

Copy link
Copy Markdown

NOT READY FOR HUMAN REVIEW

PR Self-Review

Revision 800c56298e57 · mode shadow

Waiting for the PR author. The readiness report will appear after the self-review answers are complete for this revision.

Questions to answer in the PR description

  1. What behavior does this PR change, and why is the existing behavior insufficient?
  2. What did you validate, and what remains unverified? Include commands, hardware/configuration and results.
  3. Which architecture, dtype and shape boundaries select the changed kernel path, and what invariant prevents unsupported inputs from reaching it?
  4. For every changed op_tests/ file, what behavior does it cover and why is it not redundant? Write None if no op test changed.

Edit the PR Self-Review section in the PR description. Include the current revision SHA; this comment refreshes automatically.

Missing or invalid answers

  • FAIL — missing ### Reviewed revision in the PR description
  • FAIL — missing ### Behavior and intent in the PR description
  • FAIL — missing ### Validation and unverified scope in the PR description
  • FAIL — missing ### PR-specific question in the PR description
  • FAIL — missing ### Changed op tests in the PR description
  • FAIL — Reviewed revision must contain at least the first 7 characters of the current head SHA
  • FAIL — Behavior and intent has no substantive answer
  • FAIL — Validation and unverified scope has no substantive answer
  • FAIL — PR-specific question has no substantive answer
  • FAIL — changed op test not explained in Changed op tests: op_tests/test_gemm_a8w8_blockscale.py
  • FAIL — Changed op tests must explain why each changed op test is necessary and non-redundant

Shadow mode reports what would block but keeps the status successful. Set AITER_PR_SELF_REVIEW_MODE=enforce only after reviewing real false positives.

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

The correctness test can pass despite numerical mismatches, while the FP16 paths lack correctness coverage and the local architecture probe bypasses shared runtime detection.

6 open issues

Review effort: Balanced

Comment thread op_tests/test_gemm_a8w8_blockscale.py Resolved
@solinzby1

Copy link
Copy Markdown
Contributor

LGTM

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.

7 participants