Skip to content

[CK] [FlyDSL] Clean up kernel IR and consolidate shared helpers - #5476

Merged
coderfeli merged 13 commits into
mainfrom
codex/flydsl-ir-cleanup
Sep 15, 2026
Merged

coderfeli merged 13 commits into
mainfrom
codex/flydsl-ir-cleanup

Conversation

@coderfeli

@coderfeli coderfeli commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Single-GPU FlyDSL kernels duplicated activation, pointer and reduction helpers and used low-level constructs where the pinned API provides an equivalent. This consolidates the shared code while preserving numerical behavior, memory addressing and scheduling. Corresponding cleanup is ported to ROCm/FlyDSL#1127.

  • Share activation components through act.py, with LOG2E defined once in kernels_common.py. Preserve distinct clamp behavior, constant rounding, reciprocal placement and multiplication order.
  • Reuse pointer/base extraction, bounded buffer views, GDR memory operations, compressor reductions and dtype lookup. Preserve byte-offset alignment, atomic flags, memory metadata and required raw SSA interfaces.
  • Apply the same cleanup to the updated MXFP4 GEMM1 code: remove duplicated buffer/scale helpers, forwarding functions and redundant casts; use typed bitcasts and fx.copy. Keep the new A4/A8 input, FP4/FP8 output, bias, activation, prefetch and wave configurations.
  • Keep GEMM1/GEMM2 native scale padding shared with the public MoE allocation path, and retain stage2's actual-input-row argument through runtime and AOT launchers. Simplify reduction conversions and remove unused private validation arguments from both runtime and tuner callers.
  • Apply the same consolidation to the gfx1250 TDM MXFP4 GEMM: one strict 0/1 environment selector instead of two identical ones, host and kernel ceiling divisions through kernels_common.ceildiv, and one tensor_view in place of the separate global/LDS view builders now that the global offset folds into the pointer. Drop the AS_ROW alias of AS_FULL_INNER, two dead locals and a commented-out intrinsic.
  • Fix MQA FN low-dword packing by zero-extension; remove unused wrappers and stale comments; update the cleanup skill. Keep concise cond.select(t, f) expressions. FlyDSL itself and its pinned 0.3.2 dependency are unchanged.

Note that the MQA item is the one deliberate behavior change in this PR. In the FN to FNUZ conversion path, a cleaned low dword whose high byte held a negative fp8 value was sign-extended into the high dword and corrupted the packed result. It is reachable only on gfx942 with e4m3fn inputs.

Validation

Rerun against main ffa945f93 with the branch fully merged, so git diff origin/main..HEAD is exactly this cleanup. Installed FlyDSL 0.3.2, local gfx950, runtime disk cache disabled for every compile gate, and an origin/main worktree as the A/B baseline. gfx1250 is covered by cross-arch compile plus ISA comparison, since no gfx1250 device is available here.

  • AOT compile gates, cold. moe 2556, gemm 3408, mxfp4_moe 486, grouped_moe 222, chunk_gdn_h 288, mega_moe 144. 7104 kernels, 0 failures.
  • MoE ISA equality, 89 sampled job families (98 modules), one dump directory per variant. 91 modules byte-identical in 21_final_isa.s. The 7 that differ are all a16w4 / a16wi4: identical memory-operation multiset, identical MFMA multiset, identical VGPR and SGPR counts, zero spills, instruction counts within 12. The largest delta is 13 fewer s_waitcnt on the branch.
  • gfx950 device A/B against the baseline worktree. test_flydsl_moe.py, test_flydsl_moe_a16wfp4.py and test_silu_and_mul_fq.py: 49 passed on each tree. Script-mode test_flydsl_compress_attn, test_flydsl_moe_aux, test_flydsl_qk_norm_rope_quant, test_flydsl_causal_conv1d_update and test_flydsl_gdr_mtp: identical checkAllclose verdict histograms, including the 6 pre-existing bit-exact csa_indexer cache-scale failures, which fail identically on main.
  • gfx1250 ISA equality, 5 gates, one dump directory per variant. 981 modules compared against the origin/main worktree, 971 byte-identical in 21_final_isa.s:
    • TDM MXFP4 GEMM, 22 cross-arch COMPILE_ONLY variants (gemm1 and gemm2, fp8 and fp4 activations, row-major and blocked A-scale, A-scale prologue, next-stage prefetch, cluster, tile and buffer-count sweeps): 19 of 19 linkable modules identical. The 2 EP-scatter variants cannot link on either tree because the mori device bitcode is built for gfx950; compared at 18_reconcile_unrealized_casts.mlir, identical operation multisets.
    • grouped_moe AOT, 120 gfx1250 jobs run serially (route/quant/scatter, preshuffle, prefix-sum/remap, gather-reduce): 814 of 814 identical.
    • gemm AOT, all 71 gfx1250 job families (ptpc, mxfp8_128, mxfp8_128 compute-bound, split-K reduce): 63 of 73 identical, 10 differ (below).
    • Compress-attn csa_main, csa_indexer, hca_main cross-compiled with GPU_ARCHS=gfx1250 FLYDSL_GPU_ARCH=gfx1250 COMPILE_ONLY=1: 19 of 19 identical, covering fused_compress_attn_gfx1250 and the HCA compress/norm-rope-scatter kernels.
    • FMHA m32x8, 55 configs (thd and bshd, qk_hdim 128/192/256, bf16 and fp16, causal, GQA 1 and 4, sliding window, return_lse, sink): 54 of 54 identical.
  • The 10 differing gfx1250 modules are all gemm_a8w8_mx128_compute_*, from the one-line Vec.from_elements([zero] * n) to Vec.filled(n, 0, fx.Int32) change in gemm_a8w8_256x256_gfx1250.py. Both build the same zero vector, and it is a placeholder overwritten in the wave == 0 branch; the splat form just materializes with fewer scalar moves. Memory-operation multiset, WMMA multiset, VGPR count and LDS size are identical with zero spills; SGPR drops by 5 to 9 and instruction count by 12 to 45, entirely s_mov_b32 / s_mov_b64. No occupancy change.
  • Style. Black and Ruff pass on all 54 changed Python files.

Not covered locally: op_tests/test_moe_2stage.py, whose FLYDSL_RUNTIME_RUN_ONLY=1 gate misses even with the AOT cache populated because the tuned-CSV configs it selects are not in the AOT job set; multi-GPU and EP execution; and execution on architectures other than gfx950, which rely on the compile and ISA checks above. Under pytest, op_tests/test_flydsl_*.py reports 43 collection failures, an identical set on main and on this branch, because those test_* functions are argparse entry points rather than pytest tests.

Earlier per-area coverage of the attention, convolution, GDR and HSTU cleanup, recorded against main fe4814c64, still stands and is not repeated here. Temporary probes, reports and performance artifacts are outside the PR.

@coderfeli
coderfeli requested a review from a team September 12, 2026 13:15
@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; main branch always runs both MI35X and MI300X
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 5476 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot changed the title Clean up FlyDSL single-GPU IR and share kernel helpers [FlyDSL] Clean up FlyDSL single-GPU IR and share kernel helpers Sep 12, 2026
@coderfeli coderfeli changed the title [FlyDSL] Clean up FlyDSL single-GPU IR and share kernel helpers [FlyDSL] Clean up kernel IR and consolidate shared helpers Sep 13, 2026
Restore conditional method calls and remove the select migration wrappers and branches. Keep LOG2E in kernel common and retain the independent cleanup skill changes.
Preserve the upstream MXFP4 GEMM1 variants and stage2 input-row ABI while reusing shared activation, buffer and scale helpers. Remove redundant bitcasts, copies and unused validation parameters, and keep the native scale allocation caller aligned with the common helper.
@github-actions github-actions Bot changed the title [FlyDSL] Clean up kernel IR and consolidate shared helpers [CK] [FlyDSL] Clean up kernel IR and consolidate shared helpers Sep 13, 2026
@github-actions github-actions Bot added the CK label Sep 13, 2026
@coderfeli coderfeli changed the title [CK] [FlyDSL] Clean up kernel IR and consolidate shared helpers [FlyDSL] Clean up kernel IR and consolidate shared helpers Sep 13, 2026
Fold the two identical 0/1 environment selectors into one helper, route the
host and kernel ceiling divisions through kernels_common.ceildiv, and merge
the global/LDS view builders into a single tensor_view now that the global
offset folds into the pointer. Drop the AS_ROW alias of AS_FULL_INNER, two
dead locals, and a commented-out intrinsic call.

Gate: gfx1250 COMPILE_ONLY ISA dump over 22 kernel variants -- 20/20
byte-identical 21_final_isa.s; the two EP-scatter variants cannot link
locally (mori device bitcode is built for gfx950) and were compared at
18_reconcile_unrealized_casts.mlir, identical op multisets.
@github-actions github-actions Bot changed the title [FlyDSL] Clean up kernel IR and consolidate shared helpers [CK] [FlyDSL] Clean up kernel IR and consolidate shared helpers Sep 13, 2026
@coderfeli coderfeli removed the CK label Sep 13, 2026
@github-actions github-actions Bot added the CK label Sep 13, 2026
@zufayu
zufayu requested a review from yadaish September 14, 2026 01:43
@coderfeli coderfeli added ci:infra ci:multi-gpu Trigger multi-GPU op tests on PR labels Sep 14, 2026
@coderfeli coderfeli closed this Sep 14, 2026
@coderfeli coderfeli removed ci:multi-gpu Trigger multi-GPU op tests on PR ci:infra CK labels Sep 14, 2026
@coderfeli coderfeli reopened this Sep 14, 2026
@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; main branch always runs both MI35X and MI300X
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 5476 --add-label <label>

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 opt this PR out.

@github-actions github-actions Bot added the CK label Sep 14, 2026
@coderfeli coderfeli removed the ci:all label Sep 14, 2026
@coderfeli
coderfeli merged commit 630d08d into main Sep 15, 2026
219 of 252 checks passed
@coderfeli
coderfeli deleted the codex/flydsl-ir-cleanup branch September 15, 2026 01:12
sammysun0711 pushed a commit to sammysun0711/aiter that referenced this pull request Sep 16, 2026
…#5476)

* refactor(flydsl): share single-GPU helpers and replace raw dialects

* docs(flydsl): remove stale migration comments

Gate: gfx1250 COMPILE_ONLY ISA dump over 22 kernel variants -- 20/20
byte-identical 21_final_isa.s; the two EP-scatter variants cannot link
locally (mori device bitcode is built for gfx950) and were compared at
18_reconcile_unrealized_casts.mlir, identical op multisets.

Signed-off-by: Xiake Sun <[email protected]>
lalala-sh added a commit that referenced this pull request Sep 17, 2026
main reverted #5274 in #5581, so its compact-scale and a_gather work is gone
and this branch no longer overlaps it. The only conflict left is the scale
staging in launch_gemm_a8w4_tdm: take main's ceildiv helpers from #5476 while
keeping row_major_ascale dropped, which is what this branch's compact path
replaces.

Also drops AS_ROW. It was defined as (K // 128) * wmma_m_rep * 16, which is
exactly the AS_FULL_INNER that already existed a few lines above, and the merge
had already moved its uses over to that name.
jin-amd added a commit to jin-amd/recipes that referenced this pull request Sep 30, 2026
The gfx942 _CAPIPtr crash in AITER's FlyDSL fp8_mqa_logits is fixed in
AITER 0.1.23 (ROCm/aiter#5476), which vLLM picked up in #58867. The
current vllm/vllm-openai-rocm:nightly (0.30.1rc1.dev396+gac68c3087)
ships it: on MI325X the kernel-level repro with float8_e4m3fn inputs
returns max_rel 9.5e-4, where nightly-29468dde8b (AITER 0.1.22.post1)
still raises the AttributeError.

Replace the AMD-section warning with the AITER 0.1.23 requirement and
how to check a cached image, and key the troubleshooting entry to the
image's AITER version. Drop the vLLM #56607 fallback, whose diff no
longer applies to current nightlies, and the VLLM_ROCM_USE_AITER
fallback, which is no longer needed.

The serve command and benchmark were not re-run on the new nightly; the
end-to-end validation is still the 2026-09-21 nightly with #56607
applied.

Signed-off-by: Jin Tao <[email protected]>
Co-authored-by: Cursor <[email protected]>
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.

1 participant