Skip to content

[Triton/Gluon] [JIT] Identify MI350P, and stop hardcoding the XCD count - #5182

Merged
zufayu merged 23 commits into
ROCm:mainfrom
RElbers:relbers/gfx950_mi350p_identity
Oct 27, 2026
Merged

zufayu merged 23 commits into
ROCm:mainfrom
RElbers:relbers/gfx950_mi350p_identity

Conversation

@RElbers

@RElbers RElbers commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

  1. get_device_name() misreports MI308 as MI300 on ROCm 7.1 and newer. _get_pci_chip_id hardcoded hipDeviceAttributePciChipId = 10019, but 7.1 inserted MaxAvailableVgprsPerThread ahead of it and renumbered everything after. The call still succeeds and still returns an integer, so the result is tested against MI308_CHIP_IDS and silently misses.

  2. MI350P was not identified at all. It is a half-size gfx950 (4 XCDs against 8 on MI350X/MI355X), and get_device_name() returned "MI350" for it.

  3. The XCD count was hardcoded to 8, with a comment saying it could not be queried. It can, from ROCm 7.0 on. On a 4-XCD part every remap_xcd consumer computes its L2 locality swizzle against the wrong die count.

Test Result

Three parts, all HIP 7.2. Top four rows are raw HIP and sysfs reads, bottom three are what aiter's shipped functions return:

MI300X (gfx942) MI350P (gfx950) MI355X (gfx950)
raw NumberOfXccs (10018) 8 4 8
raw PciChipId old (10019) 512 512 512
raw PciChipId new (10020) 0x74A1 0x75A8 0x75A3
sysfs device id 0x74A1 0x75A8 0x75A3
get_num_xcds() 8 4 8
_get_pci_chip_id() 0x74A1 0x75A8 0x75A3
get_device_name() MI300 MI350P MI350

10019 returns 512 on every part because it is MaxAvailableVgprsPerThread, not a chip id. 10020 matches sysfs everywhere. MI355X is the negative control for the new name: same architecture as MI350P, 8 dies rather than 4, so it stays MI350. Reproducible with a ctypes read of attributes 10018/10019/10020 cross-checked against /sys/bus/pci/devices/<bdf>/device.

Not measured on MI308. No MI308 was available, so bug 1 is derived rather than observed: on all three parts above 10019 returns 512, which is MaxAvailableVgprsPerThread, an architectural constant. MI308 is gfx942 like the MI300X measured, so it returns 512 too, and 512 is not in MI308_CHIP_IDS = {0x74A2, 0x74A8, 0x74B6, 0x74BC}, so main names it MI300. The fix (reading 10020) is likewise unverified on MI308.

On ROCm 7.0.2 (MI355X, 8 GPUs) the guard selects 10019: it returns 0x75A3 on every device, matching sysfs, while 10020 fails with hipErrorInvalidValue.

Notes

Why the die count and not the chip id. MI350P reports 0x75A8, which hipBLASLt's Tensile table lists as mi350-unknown1, alongside a sibling 0x75B8. So it's unclear those ids can be considered stable enough.

What the die count does not distinguish. Compute partitioning (SPX/DPX/TPX/CPX) means a partition sees a subset of the dies, so a DPX-partitioned MI350X would also report 4 XCCs and be named MI350P.

@github-actions

github-actions Bot commented Sep 1, 2026

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 5182 --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.

@RElbers
RElbers marked this pull request as ready for review September 1, 2026 13:14
@RElbers
RElbers requested a review from a team September 1, 2026 13:14
@github-actions github-actions Bot changed the title Identify MI350P, and stop hardcoding the XCD count [Triton/Gluon] [JIT] Identify MI350P, and stop hardcoding the XCD count Sep 1, 2026
- Adds get_num_xcds to chip_info, alongside the other device queries, since the
  die count is a fact about the hardware rather than about Triton.
- Reads hipDeviceAttributeNumberOfXccs through ctypes, gated on a HIP runtime of
  7.0 or newer, because the attribute does not exist before then.
- Adds _hip_version, which asks the loaded libamdhip64 rather than trusting the
  installed headers, so an ordinal is checked against the library that will
  interpret it.
- Warns and falls back to eight when the attribute is unavailable, keeping the
  return type a plain int so no caller has to handle None.
- Removes the hardcoded copy from triton.utils.device_info and re-exports the new
  one there, so existing Triton importers are unaffected.
- Reads hipDeviceAttributePciChipId at 10019 below ROCm 7.1 and 10020 from 7.1
  on, since 7.1 inserted MaxAvailableVgprsPerThread ahead of it and renumbered
  every attribute that follows.
- Defaults to the current ordinal when the runtime version cannot be read.

The hardcoded 10019 reads MaxAvailableVgprsPerThread on 7.1 and newer, which is
512 on gfx942. The call still succeeds and yields an integer, so get_device_name
tests 512 for membership in the MI308 chip ids and misses without any error.
MI300X is unaffected in practice since it reports MI300 either way, but an MI308
is reported as MI300.
@RElbers
RElbers force-pushed the relbers/gfx950_mi350p_identity branch from fcf5f2a to 1246ec6 Compare September 1, 2026 13:26
@samremes
samremes requested a balanced review from Copilot September 1, 2026 13:46

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.

Pull request overview

Adds runtime GPU topology detection to improve MI308/MI350P identification and XCD-aware Triton/Gluon dispatch.

Changes:

  • Selects the PCI chip-ID attribute by HIP version.
  • Identifies 4-XCD gfx950 devices as MI350P.
  • Queries visible XCDs through HIP with an 8-XCD fallback.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
aiter/jit/utils/chip_info.py Adds HIP version, chip-ID, and XCD detection.
aiter/ops/triton/utils/device_info.py Re-exports the centralized XCD helper.

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

Comment thread aiter/jit/utils/chip_info.py Resolved
Comment thread aiter/jit/utils/chip_info.py Resolved
Comment thread aiter/jit/utils/chip_info.py Resolved
- Adds hip_runtime, holding the libamdhip64 load and the runtime version
  query, with no torch and no aiter imports so both aiter.jit.utils and
  aiter.dist can import it.
- Replaces three parallel copies: the version probe in chip_info, the
  inline decode in rocm_version, and the loader in vmm_allocator, which
  keeps re-exporting the name for its existing importers.
- Gives the chip_info attribute queries the versioned soname fallback they
  lacked, so they no longer fail when only libamdhip64.so.N is on the
  runtime path.
- Reports every candidate soname's error on failure rather than the last,
  which discarded the informative one whenever a present but unloadable
  library was tried first.

The three probes gated different ABI decisions off the same library, so a
fix applied to one silently left the others behind.
- Resolves the calling thread's device through hipGetDevice and caches the
  XCD count per device ordinal, replacing a single process-wide result
  taken from device zero.
- Applies the same to the PCI chip id probe, which get_device_name pairs
  with the XCD count, so both halves describe one device.
- Adds get_current_hip_device to hip_runtime, uncached because
  torch.cuda.set_device moves it between calls.
- Names the device in the fallback warning, which now fires once per
  device instead of once per process.

A process that keeps several GPUs visible and switches between them, as the
multiprocess tuner does, launched kernels with another device's locality
swizzle. Identical devices hide this, so it surfaces only on heterogeneous
or differently partitioned hosts.
@zufayu
zufayu requested review from a team and vgokhale September 2, 2026 01:21
@samremes

samremes commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Review (SKU identity / non-comm enablement)

Fits SILOTIGER-971 / SILOTIGER-975: live NumberOfXccs is the right discriminator for the L2 swizzle (4 vs 8 dies). Hardcoded NUM_XCDS=8 inside kernels remains SILOTIGER-977 and is correctly out of this PR. CU-count tuning identity is #5340, not this change.

Successful path looks right: ROCm 7.1 PciChipId ordinal, per-device XCC cache (addresses the earlier device-0 Copilot note), shared hip_runtime loader, and existing get_num_xcds() consumers that already pass the live value.

Request changes on the failure / naming contract before merge:

  1. Silent fallback to 8 XCCs / device 0. get_current_hip_device and get_num_xcds turn query failures into values that are also valid topology. A 4-XCC gfx950 that fails NumberOfXccs keeps the old 8-XCD swizzle with only a warning. Prefer an explicit failure (or a fallback that cannot be confused with a real 8-XCC part).

  2. get_device_name() == "MI350P" from XCC count. HIP NumberOfXccs is the partition die count. DPX on an 8-XCC gfx950 is named MI350P. The PR body already flags this; either document that the name is a partition class, or name the physical SKU from PCI chip id and keep XCC count as separate topology.

  3. Mixed device sources. PCI/XCC now follow the current HIP device; get_gfx() is still a process-wide cached build/native arch. get_device_name can pair gfx942 architecture with another device's XCC/PCI facts.

  4. No focused tests. The old PCI bug returned a plausible integer and did not fail a GPU op test. Add a host-side synthetic HIP-library test for 7.0 vs 7.1 ordinals, attribute failure, set_device, and per-device cache isolation.

I did not run this on a 4-XCC part or MI308. Series comments on #5340 / #5341 / #5342 will follow.

- Resolves the arch in get_device_name from the live GPU rather than
  GPU_ARCHS, which paired one device's architecture with another device's
  PCI id and XCD count.
- Returns None from get_current_hip_device when hipGetDevice fails, since 0 is
  a real ordinal and a caller would read that device's topology as its own.
- Raises from get_num_xcds and _get_pci_chip_id when there is no current
  device, rather than falling back to device 0.
- Raises from the XCC query with the HIP status code, or with the value it
  returned when that is outside a usable range, instead of collapsing every
  failure into one missing answer.
- Moves the ROCm 7.0 gate ahead of that query, so a runtime that cannot be
  asked and a runtime that failed to answer stop being the same case.
- Keeps the eight XCD default only for a runtime older than ROCm 7.0, which has
  no such attribute, and for one whose version cannot be read.
- Drops the blanket except around the query, so a HIP loader failure reaches
  the caller naming every soname it tried.

Eight XCDs and device 0 are both real configurations, so a probe that resolved
to either was indistinguishable from one that succeeded.
@RElbers
RElbers force-pushed the relbers/gfx950_mi350p_identity branch from dac009e to 0347467 Compare September 9, 2026 14:49
RElbers and others added 2 commits September 14, 2026 12:10
- Warns and returns the default when the attribute query reports an error,
  which is what the two checks above it already do for a runtime that is
  unreadable or too old to know the attribute.
- Keeps raising when the count falls outside a plausible range, since that is
  an answer from a different attribute rather than a missing one.
- Passes the default in rather than repeating it, so all three fallbacks name
  the same value.

A launch path that cannot ask is in the same position as one whose runtime
predates the attribute, so the two now behave alike. Raising there made the die
count the only piece of device identity that could stop a launch outright.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 20:16
@RElbers

RElbers commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

@zufayu thanks for your comments. I've addressed your 4 points and added more tests. Let me know if there are still tests missing.

  1. Bind to torch's HIP runtime (11449093b): load_hip_runtime() now probes with RTLD_NOLOAD first, so it reuses the loaded copy instead of mapping a second one, and the VMM handle loads at first use. Similar to in [Bugfix] Bind load_hip_runtime to the HIP runtime already loaded #6398 (by @omirosh), but without the string parsing. Validated using their repro.py script on rocm/sgl-dev:v0.5.21-rocm10-mi35x-20261009, MI355X, 20 runs per case:

    Case libamdhip64 mapped Result
    SGLang only 1 20/20 pass
    aiter loader, image 2 20/20 fail (709, context is destroyed)
    aiter loader, this PR 1 20/20 pass
  2. Rebase, keep Linux and Windows loading (793b41d30, d1248af00): main's amdhip64*.dll search moved into the shared loader.

  3. One device for arch, PCI id and XCD count (249d22727): done.

  4. Old runtime vs failure (ea6d05c8a, 8b9879a18): failed lookups are retried, not cached. get_num_xcds() falls back to a caller default (8), default=None raises, and get_device_name() uses None.

Verified in hardware: MI350P reports 4 XCDs and MI350P; MI355X reports 8 and MI350 on ROCm 7.2.4 and ROCm 10.

Also fixed from Copilot (a85857dba): AITER_TRITON_ONLY=1 imports, and the PciChipId ordinal on an unknown HIP version. Let me know if you think I should address any of the other copilot comments.

This comment was marked as resolved.

@Boss2002n

Copy link
Copy Markdown
Contributor

please resolve merge conflicts :)

…0p_identity

# Conflicts:
#	aiter/dist/device_communicators/vmm_allocator.py
#	aiter/ops/triton/utils/device_info.py
- Adds torch's HIP major as a candidate soname, so a runtime with a soname
  newer than the fixed list still binds to torch's copy instead of loading a
  second one by name.
- Reads torch only from sys.modules, keeping the module free of a torch import.
- Covers a loaded runtime whose soname is outside the fixed list.

The soname major has followed the HIP major so far (HIP 7.15 on ROCm 10 still
ships libamdhip64.so.7); if that ever breaks, the loader falls back to the
previous name search.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:23

This comment was marked as resolved.

- Moves test_chip_info_xcds.py from op_tests to tests, where CI runs it through
  pytest instead of executing the file as a script.

Run as a script, the file has no entry point, so CI imported it, executed no
test and reported a pass. The suite is CPU-only and does not belong in the GPU
op_tests shards.
Copilot AI balanced review requested due to automatic review settings October 22, 2026 14:51

This comment was marked as resolved.

@RElbers

RElbers commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

@Boss2002n I merged with current main. The conflicts from #6398 and #6327 are resolved in favor of this PR's shared HIP loader and XCD query.

@zufayu
zufayu merged commit e902ad1 into ROCm:main Oct 27, 2026
75 checks passed
@RElbers
RElbers deleted the relbers/gfx950_mi350p_identity branch October 27, 2026 08:20
fsx950223 added a commit that referenced this pull request Oct 28, 2026
Resolve device_info.py conflict in favor of main: #5182 already replaced
the hardcoded XCD table with a HIP NumberOfXccs query in chip_info, which
covers gfx1250, so the branch's table entry is no longer needed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Nov 16, 2026
…pci_chip_id

main (#5182) fixed _get_pci_chip_id to pick the PciChipId attribute from the HIP
runtime version, which was the reason this PR read the PCI id from sysfs instead. That
left chip_info with two chip-id readers that failed differently (the sysfs one raised
OSError and the gate then guessed from the device name). The sysfs reader and the name
fallback are removed; the MI325X ids sit next to MI308_CHIP_IDS, and the a8w4 gate reads
the id through _get_pci_chip_id and fails closed if it cannot (review item 16).

On MI325X with ROCm 7.2 _get_pci_chip_id returns 0x74a5, as the sysfs read did. With the
reader stubbed, the gate is on for 0x74A5 / 0x74B9 and off for 0x74A1 and for a failed
read. The op test passes (24/24 fused_moe checks) and the AOT replay of the gfx942
kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
vedenev-amd added a commit that referenced this pull request Dec 2, 2026
* [FlyDSL] gfx942 a8w4 MoE stage1 fp8 kernel

* Raise on non-gfx942 instead of assert

* Add Triton MXFP8 quant for a8w4 (FNUZ-correct, a8w4 byte order)

* gfx942 a8w4: fused_moe wiring, tuned rows, op test

- moe_kernels: register the _g942 stage-1 names (flydsl_moe1_afp8_wfp4_bf16_*_g942*)
  and route fp8 x fp4 stage 1 on gfx942 to gemm1_a8w4_gfx942 (bf16 sorted
  intermediate, consumed by the unchanged a16w4 stage 2).
- fused_moe: no inter-stage requant for the _g942 stage 1 (a2/a2_scale = None).
- gemm1_a8w4_gfx942: x_layout="moe_sort" reads x / scales as produced by
  fused_dynamic_mxfp8_quant_moe_sort; exponent rule bitwise equal to it.
- kimik3_a8w4_tuned_fmoe.csv: 32 gfx942 (cu 304) rows, inter 384/512,
  M 1..32768 except M=3 (fused_moe pads 3 -> 4); input shapes in
  kimik3_a8w4_gfx942_untuned_fmoe.csv.
- op_tests/test_flydsl_moe_a8w4_gfx942.py: a16w4 vs a8w4 through fused_moe.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* op test a8w4 gfx942: scale atol with the MoE output

checkAllclose(rtol=atol=1e-2) reported err ~0.22 for both a16w4 and a8w4:
the MoE output is O(1e3) and the paths and the torch reference round the
bf16 intermediate differently (1-3 bf16 ulps, <= 1.2 % of max|ref| on all
8 shapes). atol = 2e-2 * max|ref| gives err 0 for both paths; cos checks
unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* gfx942 a8w4: quantise x inside stage 1 for M=1,2 (_qi kernels)

At M=1 the separate fused_dynamic_mxfp8_quant_moe_sort launch cost more
than the fp8 stage 1 saved, so a8w4 lost to a16w4 (0.96x). The new
x_layout="bf16" stage-1 variant reads bf16 x and quantises each K tile
to MXFP8 straight into LDS in A8W4_K8_ORDER, bitwise equal to the
separate quant:
- x of tile kt+1 is loaded before compute_tile(kt), quantised after it;
- block amax via maxnum + DPP quad swaps (no NaN-propagating max, no
  LDS swizzle with a full lgkmcnt wait);
- padding rows of the M tile are not quantised (their LDS is zeroed once).

Registry: every _g942 name gets a _qi variant (x_layout="bf16");
fused_moe skips the separate x quant for _qi rows and passes bf16 x.
CSV: gfx942 M=1,2 rows use the _qi stage 1; inter 384 M=1 uses the
a16w4 t16x256x128_atomic stage 2.

MI300X, whole MoE vs a16w4 at M=1: 1.05x (inter 512), 1.11-1.16x
(inter 384), was 0.96x / 1.00x. Non-_qi kernels compile to the same ISA
as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* gfx942 a8w4: MI325X only; LDS swizzle in _qi kernels; _qi rows for M<=8

- Enable the gfx942 a8w4 stage 1 on MI325X only (PCI device id 0x74A5, read
  from sysfs); elsewhere raise NotImplementedError. On MI300X a8w4 is slower
  than a16w4 at large M and the tuned CSV rows are shared by both cards.
  The op test skips on other gfx942 parts.
- XOR-swizzle the A tile in LDS (as gemm2) only in the _qi kernels, where the
  in-kernel quant hit LDS bank conflicts; other kernels unchanged.
- With that, _qi also wins at M=4, 8: switch those CSV rows to _qi.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: allow MI325X VF; fix gate comment and error text

- Add 0x74B9 (MI325X VF, SR-IOV guests) to the MI325X allow-list.
- The PciChipId comment: chip_info.py's hardcoded 10019 is wrong on ROCm
  7.2.4 / 7.13 / 7.14 (PciChipId is 10020), hence sysfs.
- Error text: MI300X numbers of this PR (0.81-0.89x at M>=1024).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* gfx942 a8w4: skip _g942 stage 1 in FlyDSL MoE AOT; skip its rows off MI325X in test_moe_2stage

- aot/flydsl/moe.py: the `_g942` stage-1 kernels are built by
  gemm1_a8w4_gfx942 (JIT on first use); the AOT stage-1 compile would build
  the gfx950 mixed-MoE kernel for them and fail (wheel build: 64 failed).
- test_moe_2stage.py: tuned-CSV rows are selected by cu_num only, so on MI300X
  (cu 304) the gfx942 a8w4 rows were picked up and the MI325X-only stage 1
  raises; skip them where a8w4_gfx942_supported() is False
  (test_flydsl_moe_a8w4_gfx942.py covers them on MI325X).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: drop unused x layouts, @flyc.jit runtime if, fix tests

- Remove x_layout="a8w4", x_scale="row" and the Triton MXFP8 quantiser from
  gemm1_a8w4_gfx942 (no production caller or test reached them). The gfx942 ISA
  is bitwise identical on 5 variants (moe_sort and _qi, k_wave 1/2/4).
- _if_then: a local @flyc.jit dispatch instead of a raw scf.IfOp.
- test_moe_2stage: always skip _g942 rows; the CSV sweep prepares neither the
  a8w4 relayout nor the separated gate/up layout they need, so they aborted
  the run on MI325X. test_flydsl_moe_a8w4_gfx942.py covers them.
- test_flydsl_moe_a8w4_gfx942: set AITER_SITUV2_A8W4 to 1 or 0 explicitly and
  restore the caller's value; add M = 1024 and 4096.

The merge with main (previous commit) resolves the fused_moe_2stages conflict with
#6165 and rejects prequantized_a1 together with the gfx942 a8w4 stage 1.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fixes for item1 and item 2

* item 3

* item 4

* [FlyDSL] a8w4 gfx942: prebuild the _g942 stage-1 kernels in the AOT replay

main's AOT now replays fused_moe for every tuned row, with caller inputs built per quant
family. For fp8 x fp4 it built the gfx950 gate/up-interleaved a16w4 weights, so all 360
replays of the gfx942 rows hit the W1-layout check and failed. A _g942 row now gets
separated gate/up W1 relaid and tagged by shuffle_{weight,scale}_a8w4_gfx942, and
a8w4_gfx942_supported() passes in an AOT replay, which has no device to check and
compiles for the arch GPU_ARCHS names. The replay of kimik3_a8w4_tuned_fmoe.csv for
gfx942 is now 360 ok / 0 failed, so these kernels are prebuilt instead of JIT-compiled
on first use (review item 7).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: name things in comments, not PR numbers

Review item 11: comments referred to "the a16w4 port", "the a8w4 port" and
"the #6144 table", which only make sense to someone who followed the
development history. They now name the function or constant they mean
(compile_gemm1_a16w4_port, compile_gemm1_a8w4_gfx942,
_FP4_E2M1_FP8_LUT_LO / _HI). Comments only, no code change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tune the _g942 stage-1 kernels with the MoE tuner

Review item 5: the tuner rejected per_1x32 on anything but gfx950, so the
shipped gfx942 a8w4 rows could not be regenerated with it. On gfx942 it now
tunes the _g942 stage-1 kernels together with the a16w4 stage 2. The _qi
kernels get the bf16 x and the others the output of the HIP MXFP8 quant; the
separate x-quant launch time is added to the moe_sort kernels and the _qi
rows are marked xbf16, as is already done for per_1x128. The gfx950
inter-stage fp8 cast is not added, because the a16w4 stage 2 reads the bf16
intermediate. Timing and selection are unchanged. On MI325X it picks a _qi
stage 1 at every M <= 8, for both inter dims.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: key the kernel cache on a source hash, not a hand-bumped rev

The hand-bumped `rev` tag in the kernel name did not invalidate anything in FlyDSL 0.3.4.1:
the kernel name is not part of FlyDSL's cache key, and the key follows the functions the
kernel body calls but not one reached two calls deep. With the decoder in _fp4x8_to_fp8x8
(called from _gemm1_body_a8w4) changed to give wrong numbers, the cached binary was still
served and the test passed; with an empty cache the same edit fails it (cos diff 0.024).

As pa_decode does in implementation_cache_tag, the factory now hashes the sources the
device code comes from once per process, and the kernel and launcher bodies read the hash,
which puts it into the key. The same helper edit now rebuilds the kernel and fails the test,
an unchanged file still hits the cache, and no tag has to be bumped by hand (review item 9).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: cache the stage-1 compile factory again

The source-hash change (63c794a) put _source_tag between the @functools.cache line and
compile_gemm1_a8w4_gfx942, so the hash function got the decorator twice and the factory none.
Every stage-1 call then built a new launcher, which FlyDSL loads from its disk cache and
unloads again when the launcher is dropped. On MI325X this made an eager fused_moe call on the
a8w4 path take 37.6 ms instead of 0.33 ms (M = 1, inter 512), and CUDA-graph capture of it
failed with hipErrorStreamCaptureUnsupported on hipModuleUnload, so the path could not run
under the graphs vLLM uses for decode. The a16w4 path was unaffected.

The factory is cached again (one compiled launcher per config) and _source_tag keeps a single
decorator. The stage-1 kernel test, which runs on every gfx942, now also captures the launch in
a CUDA graph and checks that the replay gives the same output: it fails on 63c794a for both
kernels and passes with this change. The full op test passes on MI325X (exit 0). This was not
pushed when found, so CI has not run it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] moe_2stage_a16wmix: share the stage-1 XCD tile map and grid size

The a16w4 stage 1 (gemm1.py) and the gfx942 a8w4 stage 1 each carried their own copy of the
bijective XCD round-robin + M-group swizzle and of the flattened grid size (review item 10).
Both now come from utils.py (xcd_tile_map, gemm1_grid, NUM_XCD); gemm1_a16w4_grid stays as the
public name the package exports. The divisions of the valid-tile bound still happen where the
caller builds the map, as they did inline, so the generated code is unchanged.

Checked by dumping the final ISA of every production config through the AOT replay of the
tuned CSVs that use these kernels (kimik2_i4, kimik3_a16w4, kimik3_a8w4, kimik3_i4,
minimax_m3_a16w4), before and after, with the source-hash suffix of the _g942 kernel names
stripped and nothing else ignored: identical for all 46 a16w4 and 17 _g942 stage-1 kernels on
gfx942 and all 82 a16w4 stage-1 kernels on gfx950 (21 and 31 of the a16w4 ones use the XCD
swizzle); the stage-2 and reduction kernels compiled alongside are identical too. No registered _g942
name uses the XCD swizzle, so that branch of the a8w4 kernel is covered only through the
shared helper. The a8w4 op test passes on MI325X and the AOT replay of
kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950 jobs without failures.

The k_wave reduction and the epilogue stay separate: gemm1.py keeps its accumulators in
memrefs (fx.memref_load_vec / acc.store) while the a8w4 kernel keeps them as SSA values, so
sharing them would mean rewriting one of the kernels rather than moving code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: use the stable FlyDSL APIs where the ISA stays the same

Review item 8 asked the gfx942 a8w4 stage 1 to move off FlyDSL calls outside the stable API.
Each swap was applied on its own and the final ISA of the 17 _g942 stage-1 kernels of
kimik3_a8w4_tuned_fmoe.csv's gfx942 rows (AOT replay, FLYDSL_DUMP_IR) compared with the
previous commit, source-hash suffix stripped and nothing else ignored:

- .shrui(n) -> >> n (both results are masked to bits the arithmetic shift leaves alone):
  17/17 identical.
- gpu.thread_id / gpu.block_id -> fx.thread_idx.x / fx.block_idx.x: 17/17 identical.
- _raw(x) -> x.ir_value() at all 25 sites (the buffer resource is already an ir.Value, so its
  wrapper is dropped; tensor_shim._to_raw is no longer imported): 17/17 identical.
- rocdl.mfma_f32_16x16x32_fp8_fp8 -> fx.make_mma_atom(fx.rocdl.MFMA(16, 16, 32,
  fx.Float8E4M3FNUZ)) + fx.gemm on register fragments: 17/17 identical.

Not taken: the output store through fx.rocdl.make_buffer_tensor + BufferCopy16b changes one
instruction in every kernel. BufferCopy takes a bf16 element index, so a masked row can no
longer get buffer_store's byte offset 0x7FFFFFFF (v_bfrev_b32 -2); it gets 0x7FFFFFFE
(v_mov_b32 with a literal). The store itself and its addressing are unchanged, but the ISA is
not identical, so buffer_ops.create_buffer_resource_from_addr / buffer_store stay.

perm_b32, cvt_pk_fp8_f32 and readfirstlane have no stable FlyDSL wrapper (they are not in
rocdl.__all__ in FlyDSL 0.3.4.1); a one-line comment at their uses says so. With all of this
the final ISA of the 17 kernels is identical to the previous commit's, the a8w4 op test passes
on MI325X, and the AOT replay of kimik3_a8w4_tuned_fmoe.csv builds 360 gfx942 and 732 gfx950
jobs without failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Read the gfx942 a8w4 PCI chip id from sysfs via a shared chip_info helper

The a8w4 gfx942 stage-1 dispatch is gated on the PCI device id so it only
enables on MI325X, and reading that id through hipDeviceGetAttribute(PciChipId)
is unreliable because the attribute ordinal is not stable across ROCm releases
(10019 before HIP 7.1, 10020 after, and 10019 returns a bogus 0x200 on ROCm
7.2.4 / 7.13 / 7.14). The sysfs `device` file holds the id directly, so move
that sysfs read into chip_info as a reusable get_pci_chip_id_sysfs() and have
a8w4_gfx942_supported() use it instead of its own inlined copy. The existing
hipDeviceGetAttribute path (_get_pci_chip_id, attribute 10019/10020) is left
untouched so the MI308 device-name gate keeps its current behaviour.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* gfx942 a8w4: adopt tuner-picked rows where the whole-MoE A/B wins

Update the tuned rows for the _g942 stage-1 / a16w4 stage-2 kernels to the
in-PR tuner's picks for the 12 shapes where a whole-MoE CUDA-graph A/B
confirms a speedup over the previously shipped rows: M=1,2,8 at inter 512
and 384, and inter-384 M=256,1024,2048,4096,8192,16384 (2.4-8.0% faster).
M=4 and inter-384 M=512 are kept on the existing graph-measured rows, where
the tuner regresses (M=512 +4.8%, M=4 +0.6-0.8%). inter-512 large-M, inter-384
M=16..128 and M=32768 were not re-tuned and keep their current rows. The
swapped rows are numerically equivalent to the ones they replace (cos ~1e-6,
no NaN); only the kernel/tile choice changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* [FlyDSL] a8w4 gfx942: decide the stage-1 arch at runtime with get_gfx_runtime

The gfx942 a8w4 decision was made in four places from two helpers: the stage-1 launcher
(twice) and the compile factory used FlyDSL's get_rocm_arch(), which follows
FLYDSL_GPU_ARCH / ARCH, and the tuner used get_gfx(), which follows GPU_ARCHS. The launcher
and the tuner now use chip_info.get_gfx_runtime(), which reads the live device and answers
the single GPU_ARCHS target in an AOT replay. The launcher's second "gfx942 only" check is
dropped; compile_gemm1_a8w4_gfx942 keeps the one hard check against its compile target
(review item 15).

The op test passes on MI325X (non-_g942 fp8 x fp4 name still refused, 24/24 fused_moe
checks) and the AOT replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: read the MI325X chip id through chip_info._get_pci_chip_id

main (#5182) fixed _get_pci_chip_id to pick the PciChipId attribute from the HIP
runtime version, which was the reason this PR read the PCI id from sysfs instead. That
left chip_info with two chip-id readers that failed differently (the sysfs one raised
OSError and the gate then guessed from the device name). The sysfs reader and the name
fallback are removed; the MI325X ids sit next to MI308_CHIP_IDS, and the a8w4 gate reads
the id through _get_pci_chip_id and fails closed if it cannot (review item 16).

On MI325X with ROCm 7.2 _get_pci_chip_id returns 0x74a5, as the sysfs read did. With the
reader stubbed, the gate is on for 0x74A5 / 0x74B9 and off for 0x74A1 and for a failed
read. The op test passes (24/24 fused_moe checks) and the AOT replay of the gfx942
kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: one predicate for the _g942 stage-1 kernels

Whether a stage-1 kernel is the gfx942 a8w4 one was written out in six places: the
stage-1 dispatch, fused_moe, the AOT replay and the tuner compared in_dtype with the
"a8w4_gfx942" string, the op test did too, and test_moe_2stage.py looked for "_g942" in
the name (review item 17). moe_kernels.py now exports is_a8w4_gfx942_kernel(name or
params) and A8W4_GFX942_IN_DTYPE, and all of them use it, so a rename or a second gfx942
a8w4 family changes one line. The tuner's _is_a8w4_g942 stays: it decides per shape,
from arch and dtypes, which candidate family to sweep, before any kernel name exists.

Checked: true for all 128 _g942 names (by name and by params), false for the other 5965
registered kernels and for None / {} / an unknown name; the op test passes and the AOT
replay of the gfx942 kimik3_a8w4 rows builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check the stage-1 inputs in one helper, not in fused_moe_2stages

The gfx942 a8w4 input checks (W1 / W1-scale layout tag in both directions, no
caller-prequantized A for a _g942 stage 1, bf16 / fp16 x only for the _qi kernels) were
spread over about 40 lines of fused_moe_2stages, next to the shared a16w4 logic (review
item 18). They are now check_a8w4_gfx942_inputs in moe_kernels.py, beside
is_a8w4_gfx942_kernel, called once before the stage-1 input is prepared. The checks and
their messages are unchanged.

Checked: each of the seven input combinations (good _qi and moe_sort inputs, untagged W1,
tagged W1 with an a16w4 stage 1, untagged a16w4, prequantized A, fp8 x on a _qi row)
passes or raises as before; the op test passes (24/24 fused_moe checks, including the
fp8-x and mixed-layout cases) and the AOT replay of the gfx942 kimik3_a8w4 rows builds
360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: bound the x-scale buffer descriptor

Every buffer descriptor in the gfx942 a8w4 stage 1 was bounded except the one for the
MXFP8 x scales, which set num_records to 0xFFFFFFFF, so hardware bounds checks never
applied to those reads (review item 20). The kernel reads scale rows below cumsum[0] only,
and fused_dynamic_mxfp8_quant_moe_sort allocates pad32(sorted rows) x _ms_npad bytes, so
the descriptor is now bounded at pad32(cumsum[0]) x _ms_npad, the same source the output
descriptor uses. An indexing slip would now read zeros instead of neighbouring memory.

Checked on MI325X: the bound never exceeds the quantiser's allocation (M 1 to 32768,
BM 16 / 32); the 12 CSV _g942 kernels give bitwise-identical output (36/36); the `_qi`
kernels compile to identical ISA (they do not read the scale buffer), the moe_sort ones
gain 12 to 15 scalar setup instructions with the same VGPR count; whole fused_moe a8w4
time is unchanged (new/old 0.999 to 1.001, 6 interleaved runs, M 16 / 128 / 1024 / 2048,
inter 384 / 512). The op test passes and the AOT replay builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: drop the source-hash cache tag, FlyDSL 0.5.0 tracks the helpers

The source-hash tag (_source_tag, read as `_ = _a8w4_src_tag` in the kernel and launcher
bodies and appended to the kernel name) worked around FlyDSL 0.3.4.1's cache key, which
did not follow a helper reached two calls deep. main now pins FlyDSL 0.5.0 (#7600), which
dropped the same pattern from pa_decode (review item 21).

Re-ran the repro at 0.5.0 without the tag: with _fp4x8_to_fp8x8 (called from
_gemm1_body_a8w4) broken, the same cache got a new entry and the kernel-only test failed
as it should (cos diff 0.024, as with an empty cache), and an unchanged file still hit the
cache. So the tag, its reads and its name suffix are removed. The factory keeps its
functools.cache. Final ISA of all 17 _g942 kernels is identical to the previous commit
apart from the name, outputs of the 12 CSV kernels are bitwise identical, the op test
(including its CUDA-graph replay check) passes, and the AOT replay builds 360/360 jobs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: keep the kernel module to the kernel, move the oracle and relayouts out

The torch MXFP8 oracle, the W1 relayouts and their layout tag are host-side tensor
helpers, so they now live next to the other shuffles in aiter/ops/shuffle.py and the
shared exponent rule in fp4_utils, where the tuner imports it as well. The op test
builds its own oracle from that rule, and the kernel entry point is exported from the
moe_2stage_a16wmix package like the a16w4 ones. Outputs of the 12 tuned kernels are
bitwise unchanged and AOT replay compiles all 360 rows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: make the stage-1 op test fail on one wrong block scale

A cos-diff bound of 1e-3 passed outputs with one zeroed column, so test_stage1_kernel
now requires every element within checkAllclose's default tolerances and proves it on
a W1 whose up scale is doubled for one 32-wide block of one column. W1 is scaled by
1/8, which keeps the FP4 codes and keeps every output below SiTUv2's saturation at
100, where about 1 % of the outputs sat before and hid such errors.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: say why the output descriptor and store stay on buffer_ops

The reasons were only in the PR thread, so the next FlyDSL pin bump would have to
rediscover why these two calls were not moved to make_buffer_tensor / BufferCopy16b.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* FlyDSL a8w4 gfx942: raise on GUGU input in shuffle_weight/scale_a8w4_gfx942

Both relayout functions require GGUU (separated gate/up) layout as input.
A GUGU-preshuffled (gate_up_interleave=True) W1 passes the relayout silently
and receives the a8w4_gfx942_layout tag, but half its bytes are misplaced
relative to the GGUU order the stage-1 kernel reads, giving wrong output
without an error. Add an explicit ValueError check on the gate_up_interleave
attribute so the mislayout is caught at relayout time.

* FlyDSL a8w4 gfx942: assert err == 0 in test_moe_a8w4_gfx942, add self-check

The checkAllclose result was recorded but never asserted, so a localized
output error (e.g. one wrong token) could pass silently. Add assert err == 0
after each checkAllclose call in the candidates loop.

Add a self-check that zeroes one output row and confirms the tolerance catches
it (err > 0), so the check cannot go silent if the tolerance is too loose.
Remove the weaker assert on a8w4 cos < 1e-3 (superseded by err == 0).

* FlyDSL a8w4 gfx942: extend test_stage1_kernel to cover all CSV tile families

The M=1 kernel name in main() was stale since 5d7e4e1: the CSV M=1 rows
now use t16x32x256_g942_kw2_qi, not t16x32x128_g942_kw4_qi. Fix it.

test_stage1_kernel hardcoded tile_m=16 and asserted it, so BM=32 kernels
(t32x*) could not be tested. Remove the tile_m==16 assertion; derive tile_m
from the kernel params instead.

Add five more calls in main() to cover each distinct tile family in
kimik3_a8w4_tuned_fmoe.csv that was not reached on MI300X CI runners:
TILE_K=256 (t16x128x256_g942), bnt0 (t16x128x128_g942_bnt0_kw2),
BM=32 (t32x128x128_g942), and BM=32+TILE_K=256 (t32x128x256_g942_bnt0).

* FlyDSL a8w4 gfx942: apply black formatting to test file

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py and gemm.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.
aiter/aot/flydsl/gemm.py has a shebang but was not executable (EXE001);
set the executable bit.

* FlyDSL a8w4 gfx942: fix pre-existing ruff errors in gemm1.py

gemm1.py imported gemm1_grid from .utils but never used it (F401); remove it.
gemm1.py called _udiv and _umod from .utils but did not import them (F821);
add them to the import list.

* FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)

The file has a #!/usr/bin/env python3 shebang but was not marked executable
(mode 100644). Set the executable bit (100755) to match. Pre-existing lint
error caught by ruff 0.16.0.

* Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)"

This reverts commit f9f5db0.

* Revert "Revert "FlyDSL a8w4 gfx942: mark aiter/aot/flydsl/gemm.py executable (ruff EXE001)""

This reverts commit 2b777e7.

* FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178

#8178 changed get_2stage_cfgs so that per-token FP8 + clamped SiLU on
gfx942 uses the FlyDSL full_impl path (stage1=None) instead of CK stage1.
The test asserted stage1.func is ck_moe_stage1 without guarding against
the None case, crashing on MI300X CI.

Accept both outcomes: if stage1 is None assert full_impl is set
(FlyDSL took over), otherwise keep the existing CK assertions.

* [FlyDSL] a8w4 gfx942: keep _qi stage 1 rows at M <= 8 so pre-quantised x is accepted above that

The inter-384 M = 256 row used a _qi stage 1, which quantises x itself and refuses MXFP8
x + a1_scale, so a caller passing pre-quantised x at 129-256 tokens got a ValueError
although the contract promises the passthrough from M = 16 on. The row goes back to the
moe_sort kernel it had before the tuner swap. The op test now checks that the CSV uses
_qi only up to M = 8, and accepts a refused pre-quantised x only there.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check every _qi stage 1 of the CSV on full M tiles

The only _qi case in CI was M = 1 with 8 experts, so each M tile held one real row,
where the A swizzle and the per-row x-scale slots are the identity; a mismatch between
the in-kernel quant's write and the read would have passed. test_stage1_kernel now
also runs all five _qi kernels of the CSV with 2 experts / top 2 and 16 tokens, so
every tile row is real. A read without the swizzle, or x-scales written to the
neighbouring row, fails these cases and still passes the M = 1 one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tag the a16w4 scale preshuffle with its gate/up order

shuffle_scale_a8w4_gfx942 refuses a gate/up-interleaved (GUGU) scale by its
gate_up_interleave tag, but only shuffle_weight set that tag, so a GGUU W1 paired with a
GUGU W1 scale passed both relayouts and gave wrong output without an error.
shuffle_scale now tags its interleave-branch output the way shuffle_weight does, and the
op test checks that both relayouts refuse a GUGU input.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: check all twelve CSV stage-1 kernels on every gfx942

Two kernels of the CSV, t16x128x128_g942_kw2 (inter-384 M = 256 and 512) and
t32x128x128_g942_bnt0 (eight large-M rows), were checked only through fused_moe on
MI325X, which CI does not have. test_stage1_kernel now runs them too, and main() asserts
that every stage-1 kernel in the CSV was run, so a row with a new kernel cannot slip
past the MI300X runners.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Revert "FlyDSL a8w4 gfx942: fix test_plain_fp8_swiglu_limit_dispatch for #8178"

This reverts commit 7cb2fdc. test_plain_fp8_swiglu_limit_dispatch is not
part of this PR; it fails on main since #8178 and #8350 fixes it there.
Keeping a partial fix here made the PR fail at a different assertion than
main, which hid that the failure is the same one.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45177648946.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Retrigger CI without the ci:mi300x label.

MI300X shard 5 fails on main since #8178 (fixed by #8350); this PR's gfx942
test passed on MI300X in run 45348931160, attempt 2.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: tune the _g942 stage 1 with TUNE_ONLY unset, and fail loudly when the selection leaves it out

With TUNE_ONLY unset the tuner asked the flydslv2 generator first; it has no arch check, so it returned tasks for a gfx942 a8w4 row, TUNE_ONLY became "flydslv2", and the a8w4 branch, which only queues the FlyDSL `_g942` stage 1, then queued nothing and reported no error. The default now skips flydslv2 for these rows, and a TUNE_ONLY or OPUS_ONLY that excludes flydsl raises instead of tuning nothing. A CPU test drives tune() with the generators mocked: 0 queued stage-1 tasks before, all `_g942` ones after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: offer the _qi stage 1 to the tuner only up to 8 tokens

A `_qi` stage 1 quantises x itself and refuses pre-quantised x, so the CSV keeps it to M <= 8, but the tuner offered all 52 `_qi` names at every M and a re-tune could again pick one for M = 256, breaking test_csv_qi_rows and the pre-quantised x path there. The limit now lives in moe_kernels.A8W4_GFX942_QI_MAX_TOKEN, used by the tuner and the op test. A CPU test checks that the tuner offers `_qi` at 8 tokens and none at 9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: refuse a stage-1 tile over the 64 KiB LDS at compile time and keep it out of the tuner

At K = 7168 a BM 32, TILE_K 256, k_wave 4 `_qi` tile needs 73728 B of LDS (double-buffered A plus its f32 scales). Nothing checked it: the compiler only printed "local memory (73728) exceeds limit (65536)", FlyDSL went on, and the launch failed with hipErrorIllegalState, which says nothing about LDS and can leave the GPU context unusable. a8w4_gfx942_stage1_lds_bytes now sizes the tile, compile_gemm1_a8w4_gfx942 raises a ValueError over the limit, and the tuner skips those tiles. K = 3584 (Kimi-K3) has no such tile.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: refuse a moe_sort stage 1 with TILE_K other than 128 or 256

load_x_scale_moe_sort builds one E8M0 base from y0 // 8 for the whole tile, which holds only while every block of the tile is in the same 8-block group, i.e. TILE_K 128 or 256. The check only asked for a multiple of 128, so a direct call with 384 or 512 built a kernel that read the wrong scale for half the blocks, up to a 256x error, without any message. The registered names use 128 and 256 only; compile now raises for the others, and a CPU test covers it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: stop a tuner run off MI325X with one up-front error

The tuner recognised a gfx942 a8w4 row by the arch alone, while the runtime path also requires a8w4_gfx942_supported(), so on an MI300X every `_g942` candidate raised NotImplementedError on its own and nothing said the shape is MI325X-only. The a8w4 branch now checks the gate once and raises with that message before queuing anything.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: apply swiglu_limit to the silu stage 1, as the a16w4 one does

With act="silu" the epilogue called gate_up_act with no SiTU parameters, so a finite swiglu_limit was ignored, while the a16w4 stage 1 clamps gate and up with clamp_gate_up before the unclamped SiLU and runtime_swiglu_limit documents that a positive SiLU limit is applied. The silu path now builds the parameters and clamps the same way (+inf without a limit). test_stage1_kernel takes act and limit and checks silu with limit 1.0 against torch: equal with the change, 84 % of the elements outside the tolerance without it. The shipped rows are SiTUv2 and unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: gate the op test on the running GPU, not on GPU_ARCHS

get_gfx() follows GPU_ARCHS and takes its last entry, so with GPU_ARCHS="gfx942;gfx950" the test decided it was on gfx950 and skipped everything on a real MI325X, still exiting 0. It now uses get_gfx_runtime(), as the dispatcher does, for the gate and for the gfx column: with that GPU_ARCHS on MI325X the old test ran 0 stage-1 checks, the new one all 14.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* [FlyDSL] a8w4 gfx942: make the stage-1 shape checks raise, so python -O keeps them

The eleven shape checks in compile_gemm1_a8w4_gfx942 were asserts, which python -O removes; with D_INTER not a multiple of TILE_N, for example, the kernel would then floor NUM_N_BLOCKS and leave the last columns of the intermediate unwritten, and the `_g942` branch returns before any upstream tile check. They now raise ValueError through one helper, with the same conditions, messages and order. A test compiles a bad shape in a python -O subprocess: it raises now and passed silently before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop the gfx942 a8w4 FlyDSL rows for M >= 1024 so main's asm 1-stage rows (#8211) serve those keys again.

The main merge kept both rows for the same 12 keys and the first one, ours, won, so test_moe_mxfp4fp8_gfx942_asm.py failed on MI300X. Measured on MI325X in one process, eager wall clock, A/B/B/A pairs, null control within 0.9%: asm is 20-33% faster on all 12 keys and won every pair. The FlyDSL rows for M = 1..512, where main has no gfx942 row, stay. The untuned CSV drops the same tokens so a re-tune reproduces the tuned CSV, and the op test runs fused_moe only at M served by FlyDSL rows (1..512); the stage-1 kernel checks are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Justify the MI325X-only a8w4 gate with the MI300X numbers at the M the rows still serve, now that #8211 serves M >= 1024.

The gate docstring, the NotImplementedError and the op test's skip message cited the 0.81-0.89x slowdown at M >= 1024, where the _g942 stage 1 no longer runs. On MI300X a8w4 is also slower than a16w4 at M = 128-512 (0.92-0.99x at inter 384), which is what the texts now give. The "MI325X only" substring the tests match is unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop test_a8w4_gfx942_tune_sources.py: no CI job runs it, and review suggested removing tests that only serve local validation.

It held the unit tests of the review-round-3 tuner fixes; they passed at bd616e3 and d9ab86b (10 tests), and the result is posted in the review thread. The op test test_flydsl_moe_a8w4_gfx942.py stays, as the only numeric check of the _g942 stage-1 kernels on the MI300X CI runners.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Co-authored-by: Vedenev <[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.

6 participants