Skip to content

[FlyDSL] Simplify kernel APIs and remove redundant wrappers - #6380

Merged
coderfeli merged 20 commits into
mainfrom
codex/flydsl-moe-gemm-api
Oct 21, 2026
Merged

coderfeli merged 20 commits into
mainfrom
codex/flydsl-moe-gemm-api

Conversation

@coderfeli

@coderfeli coderfeli commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Remove redundant scalar and vector reconstruction across FlyDSL attention, MoE, GEMM, routing, communication, and convolution kernels. Use typed arithmetic, pointers, atomics, layouts, and quantization helpers while preserving kernel schedules, memory ordering, and numerical behavior.

  • Remove same-type scalar casts, redundant wrappers around typed loads, duplicate element coercions, and singleton vectors used only for broadcasting. Use fx.full for vector fills. The repository-wide wrapper pass removes 719 scalar constructors, 60 vector constructors, and 30 from_elements calls, and shortens 145 fill calls.
  • Keep conversions required for signedness, width, fragment shape, and raw IR boundaries. Preserve the BF16 packing form that keeps gfx950 code generation unchanged, target-specific assembly, invariant LLVM loads, and required alignment/scope/order on atomics.
  • Merge main 5e3456494b877386d58c9ec6ca5e6a7fb37d40c7, including the updated persistent MLA and MegaMoE TP paths. Resolve the MLA conflict while retaining the new pipeline. The PR contains 115 source files and a net reduction of 612 lines. Validation scripts and generated artifacts are outside the diff.

Current merge validation

Against main 5e3456494b, using pinned FlyDSL 0.4.0:

  • 745/745 gfx1250 matrix cases have byte-identical emitted GPU code objects: 273 configured GEMM jobs, 356 configured grouped-MoE jobs with their auxiliary kernels, 20 batched-GEMM CSV rows through the runtime wrapper, and 96 page-size-1 FP8 MLA variants. MLA covers supported head counts/query tile sizes, causal and context-parallel flags, and final-LSE modes.
  • 54 additional unchanged-main comparisons match, covering quantization, FMHA, compression, routing, TDM helpers, page-size-64 MLA, gather, and combine sync/reduce.
  • 24 batched A8W4 cluster cases match main with its missing multicast-mask helper supplied by the vendored helper. Twelve nonconfigured shapes fail on both sides: four negative tensor-wait counts at tile M=32/K=256, and eight LDS alignment errors at tile M=32 or 64/K=768. These are pre-existing failures and are not counted as successful comparisons.
  • Across the 823 passing pairs, all 2929 actual code objects per side are byte-identical. Two standalone diagnostic .s dumps differ; their actual code objects and disassembly match. Repeated builds of unchanged main reproduce the dump-only variation because FlyDSL recompiles a clone to produce that diagnostic.
  • Black passes for all 1,504 Python files. Ruff, Python syntax checks, and git diff --check pass for the 115 changed files. This gfx1250 validation is compile-only.

Compilation used main 1b1bc88f20; the only subsequent main change is a Gluon utility update. The FlyDSL runtime and AOT source trees are identical in 5e3456494b.

Earlier validation

Using the pinned FlyDSL 0.4.0, with final comparisons against main 9e2884545:

  • 51/51 paired compilation cases produce byte-identical final ISA (54 generated kernel artifacts). Coverage includes mixed MoE stage 1/2, split-K and persistent paths, MXFP4 epilogues, preshuffle/HGEMM, Mega-MoE, routing and FP4/FP8 scatter, all-reduce, FMHA, MLA/MQA, GDR, compression, layouts, quantization, and conv3d reuse/padding. gfx942 a16w4 and gfx1250 TDM/FMHA/compression/routing paths are included.
  • 175 repository pytest cases pass on gfx950: 111 PA decode, 21 FMHA, 14 Minimax index-score, 26 gather, and 3 shared-expert cases. These cover scale modes, paging and variable lengths, output layouts, graph replays, shared-weight K offsets, and clamped SiLU.
  • 21 additional GPU cases pass: 11 compressor cases (BF16/FP8/FP4, decode/MTP, K-split and HCA), 3 QK norm/rope/quant cases, 3 Mega-MHC output modes with graph replay, and 4 convolution reference checks covering 2D/3D LDS reuse and reflect/replicate padding.
  • All 65,536 BF16 bit patterns produce 851,968 integer quantization outputs identical to main, including special values. All 65,280 finite FP4 nibbles also match an independent nearest-even reference.
  • HGEMM output checks pass with dirty output buffers and changed inputs across repeated launches and graph replays. Both BMM scale-block variants pass the exact all-ones check.
  • A final repository scan found no further removable wrappers under the checked type/shape rules. Black, Ruff, Python compilation, and git diff --check pass for all 114 changed files.

Performance

On an otherwise idle gfx950 GPU, run main→PR and PR→main after warm-up. The table reports medians of repeated HIP-event measurements around graph replays, with compilation outside timing. The 19 cases range from −0.52% to +0.41%; no performance regression was observed.

The timing baseline is eb56b2d45, whose measured kernel sources are unchanged in main 9e2884545. Convolution is checked separately against the current main with identical ISA and GPU reference results.

Case Main (µs) PR (µs) Change
BF16 GEMM, split-K 8 5.021 5.019 -0.03%
BF16 GEMM, split-K 8 + bias 4.955 4.943 -0.26%
BF16 GEMM, split-K 8, FP32 output 5.097 5.104 +0.15%
FP16 GEMM, split-K 8 4.927 4.926 -0.02%
BF16 GEMM, split-K 1 16.655 16.656 +0.00%
Gather GEMM, 512 tokens, K/V 128/128 7.459 7.445 -0.19%
Gather GEMM, 2048 tokens, K/V 192/256 14.214 14.185 -0.20%
MXFP8 BMM, scale block 32 2.449 2.437 -0.52%
MXFP8 BMM, scale block 128 2.466 2.455 -0.46%
Mixed FP8 × FP4 MoE stage 1 4.990 5.000 +0.20%
Mixed FP8 × FP4 MoE stage 2 2.999 2.996 -0.08%
MXFP4 GEMM stage 2 2.428 2.428 +0.02%
FP8 FMHA, GQA, split-K 1 33.563 33.577 +0.04%
FP8 FMHA, GQA, split-K 4 30.630 30.677 +0.16%
BF16 PA decode, MTP4 9.915 9.887 -0.29%
FP8 PA decode, per-token scale 7.554 7.585 +0.41%
CSA compressor, BF16 3.749 3.744 -0.14%
CSA compressor, FP4 3.151 3.147 -0.11%
HCA compressor, BF16 110.468 110.517 +0.04%

HGEMM: M/N/K = 32/384/7168. BMM: batch/M/N/K = 4/64/256/512. Mixed MoE: 32 tokens, 2 experts, top-k 2, model/intermediate dimensions 256; MXFP4 stage 2 uses 16 tokens. FMHA: batch 1, sequence 2048, 8 query heads/2 KV heads, dimensions 128. PA decode: context lengths 257/513, 2 partitions, head dimension 128. Compressors: batch 8 with MTP3, D=512 for BF16 and D=128 for FP4.

Runtime measurements cover representative shapes on gfx950. gfx942 and gfx1250 validation is compile-only; no runtime performance claim is made for those targets.

@coderfeli
coderfeli requested a review from a team October 10, 2026 15:26
@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
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 6380 --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.

@coderfeli coderfeli changed the title [FlyDSL] Use merged APIs in MoE GEMM kernels [FlyDSL] Use merged APIs in MoE and GEMM kernels Oct 10, 2026
@zufayu
zufayu requested a review from yadaish October 12, 2026 01:25
…-api

# Conflicts:
#	aiter/ops/flydsl/kernels/gemm_a16w16_gfx950_utils.py
#	aiter/ops/flydsl/kernels/mixed_moe_gemm_2stage_common.py
yadaish
yadaish previously approved these changes Oct 20, 2026

@yadaish yadaish 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.

LGTM

@coderfeli coderfeli changed the title [FlyDSL] Use merged APIs in MoE and GEMM kernels [FlyDSL] Simplify MoE and GEMM kernels with typed APIs Oct 20, 2026
@coderfeli coderfeli changed the title [FlyDSL] Simplify MoE and GEMM kernels with typed APIs [FlyDSL] Simplify kernel APIs and remove redundant wrappers Oct 20, 2026
Use floor division for integer layout and K-wave coordinates after the typed API migration. True division on fx.Index emits an invalid index-to-float conversion.

Use Python isinstance for the Fly pointer type; PointerType.isinstance is unavailable in the pinned FlyDSL 0.4.0 wheel.
Keep the rocdl dialect import required by the new gfx942 BufferTensor helper while retaining the typed TargetAddressSpace API.
Preserve the updated persistent MLA pipeline and reapply the existing typed-fill and comparison simplifications at their new locations.
@coderfeli
coderfeli merged commit 523ff0d into main Oct 21, 2026
@coderfeli
coderfeli deleted the codex/flydsl-moe-gemm-api branch October 21, 2026 01:37
Qubitium added a commit to Qubitium/aiter that referenced this pull request Oct 26, 2026
Resolve the conflict in aiter/ops/flydsl/kernels/moe_reduce.py by taking the
PR's route-validity gate (skip_invalid_ids plus the clamped EP mask gather)
on top of main's post-ROCm#6380 FlyDSL API, i.e. fx.full instead of the removed
fx.Vector.filled helper.

Two test expectations no longer matched main's retuned CSVs:

* dsv3_fp4_tuned_fmoe.csv was retuned to an MXMOE stage-1 for the inter_dim
  = 256 decode row and the 256-tile stage-2 moved to the 128-tile/persist
  variant. Point the determinism test at the remaining flydsl_moe1_ row
  (token=32, inter_dim=512).
* op_tests/test_moe_glm5_fp4_ep_dispatch.py (added upstream after the PR
  base) asserts the tuned atomic stage2 names; dispatch now rewrites those
  rows to their reduce sibling, so assert the resolved reduce name and that
  the cached tuning row keeps the atomic epilogue.

Validated on a gfx950 VF: 78 passed for
test_mxfp4_stage2_epilogue_determinism.py, test_moe_glm5_fp4_ep_dispatch.py
and flydsl_tests/test_flydsl_moe.py; black, ruff and git diff --check clean.
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.

2 participants