Skip to content

[FlyDSL] [AOT] Scan gfx1250 GEMM rows at representative M, not every M - #7652

Merged
coderfeli merged 4 commits into
mainfrom
gfx1250/gemm-aot
Nov 10, 2026
Merged

coderfeli merged 4 commits into
mainfrom
gfx1250/gemm-aot

Conversation

@aoli26

@aoli26 aoli26 commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Summary

On gfx1250, the GEMM AOT replay used to identify every M in each tuned row's range. It now identifies only the M at which the runtime can choose a different kernel: for the default tables, 2,267,447 identifications become 15,024, and the compiled kernels are the same.

Motivation

gfx1250 picks kernels non-monotonically in M, so these rows are scanned rather than bisected. Most of those M only re-confirm a kernel set the scan has already found. Identifying just the M in the CSV, or bisecting, misses kernels in the middle of a range.

Changes

  • gemm.py: new scan_sizes(job, low). It cuts the range wherever the padded-M lookup changes, found by bisecting the runtime's own monotone get_padded_m (gl=0/1). Each job now carries its shape's tuned M with their kernels' (tile_m, cluster_m). On each piece, the scan takes the first lcm(1..cluster_m) M-tile counts and the last count, each at its ragged M, the other parity, and its full M; it does this for the row's own kernel and for the kernel of any row the lookup finds there. Where the lookup finds no row, or the table may skip a row it cannot launch (a4w4, all_rows), it adds every size class the untuned-shape heuristics tell apart: the smallest tile still in play is octave top / 32, clamped to 16..256, and there is no M cap. Every power of two is included too. The runtime still computes cluster_m and bounded_m itself; no selection logic is copied.
  • replay.py: _scan identifies the sizes from module.scan_sizes, or every size if the module has none. The sizes are computed lazily inside the dry run, because get_padded_m needs its fake device.
  • Only SCAN_ARCHS=("gfx1250",) is affected. Other archs still bisect, unchanged.
  • README [SCAN] paragraph and docstrings updated. Unit tests added for _scan, _lookup_pieces and _tile_sizes, plus a sparse-table regression test.

Performance (if applicable)

Hardware Workload/configuration Before After Change
CPU dry run (GPUs hidden), FlyDSL 0.4.2 gfx1250 GEMM AOT, default tables (2011 tuned rows) 2,267,447 M identified 15,024 M identified 151x fewer; same 856 scan replays and same 1704 cache files
CPU dry run (GPUs hidden), FlyDSL 0.4.2 gfx1250 GEMM AOT, sparse tables (min/median/max M per shape, 312 rows) 2,253,402 M identified 40,258 M identified 56x fewer; same 918 scan replays as the full scan

Testing

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

Documentation

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

Dependencies

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

Breaking Changes

None

PR Self-Review

Reviewed revision

dfea4cc

Behavior and intent

The gfx1250 GEMM AOT scan identifies about 15K representative M for the default tables instead of every M in each row's range. Kernel coverage is unchanged, and archs other than gfx1250 are untouched. The first draft of this plan used tile edges plus all 256-tile edges (18,976 M) and missed 8 of 837 kernels. Two kinds of M were missing: an even M with a ragged last tile for abpreshuffle, which refuses odd M; and the top gl0 block of rows such as [8193, 16384] with N > 4096, whose lower part uses row 8192's kernel through the gl1 lookup. A later version covered the untuned-shape heuristics only up to M=4096, at an empirical grain. Copilot flagged sparse custom CSVs, and a sparse-table full scan confirmed 5 missed kernels. Heuristic size classes are now enumerated in full wherever the lookup finds no row; on the default tables this also lowers the count from 16,954 to 15,024, because pieces that hit a row no longer get heuristic sizes.

Validation and unverified scope

  • Ground truth: every M of all 2011 gfx1250 rows was identified (2,269,458 identifications in a CPU dry run). For each row, the kernels reached from scan_sizes were compared with the kernels reached from every M: 0/837 missing, and all 3 refusal reasons are reproduced. The same comparison on sparse tables (min/median/max M per shape, 312 rows, 2,253,714 identifications) found 0/425 missing; the previous rule missed 5 there.
  • End to end: GPU_ARCHS=gfx1250 FLYDSL_RUNTIME_CACHE_DIR=<A> python3 -m aiter.aot.flydsl.gemm gave 2011 ok, [SCAN] 856 with 0 failed, and 1704 cache files, identical to the earlier revision's cache. The pre-change full scan (scan_sizes removed) was then run with --check against cache A and passed, also replaying 856 scan sizes. The same build plus full-scan --check passes on the sparse tables (--csv), with 312 ok and 918 scan replays.
  • pytest tests/test_flydsl_aot_replay.py tests/test_aot_drivers.py: 17 passed. black and ruff (0.16.0) are clean on the changed files.
  • Not verified: identification cost under FlyDSL 0.5.0 (the reductions are identification counts, not measured times); gfx1250-strict, which still bisects as before; and other archs, where the code path is unchanged but the AOT was not run. Coverage assumes that the runtime still looks rows up via get_padded_m, and that the heuristics keep tiles of 16..256, with a tile below 256 rejected past 32 M tiles.

PR-specific question

Failure mode: a kernel that the runtime requests only at an M which scan_sizes does not name is silently left out of the AOT cache. The build still reports success, and the kernel is compiled at first use instead of shipped (or fails where JIT is disabled). The rule rests on three assumptions: (1) the lookup keys get_padded_m(gl=0/1) are monotone in M and gl=0 never pads below M, so lookup pieces are exact; (2) a found row's M-dependent parameters (fitted cluster_m, bounded_m, fused split-K) follow T mod lcm(1..cluster_m) of its kernel's tile_m; (3) where no row is found, the heuristics read M only through ceil(M / tile_m) of tiles 16..256, and this change enumerates those classes in full. The weakest boundary was assumption 3: a first version capped it at M=4096 with an empirical grain and missed 5 kernels on sparse tables, as Copilot flagged; with full enumeration none are missed. Evidence: every M of all 2011 gfx1250 rows was identified (2,269,458 identifications), and for each row the kernels from scan_sizes were compared with those from every M: 0/837 kernels missing, all 3 refusal reasons reproduced. On sparse tables the result is 0/425 missing. In addition, the pre-change full scan was run with --check against the cache built by this change and passed on both default and sparse tables, with the same scan replays (856 / 918) and the same 1704 default cache files. The check is sensitive: the earlier 256-tile-edge rule misses 8 kernels and the M=4096 cap misses 5. Coverage holds for the current runtime; a change to the gfx1250 GEMM heuristics or the padded-M lookup should be re-validated against a full scan.

Changed op tests

None

@aoli26
aoli26 requested review from a team and a balanced review from Copilot November 9, 2026 08:39
@github-actions

github-actions Bot commented Nov 9, 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 (added automatically when gfx942 configs change); main branch always runs both MI35X and MI300X
ci:triton-355 Run the full Triton test suite on MI35X, not only the tests the change affects
ci:windows Windows JIT op smoke test on the Radeon R9700 ROCm runner
ci:multi-gpu Aiter multi-GPU tests on the 8-GPU runner
ci:sglang SGLang integration tests: DeepSeek-R1-MXFP4 accuracy, Qwen 3.5 accuracy
ci:atom ATOM benchmark: DeepSeek-R1-0528, GPT-OSS-120B
ci:atom_full ATOM accuracy suite for PR and main models from ATOM models_accuracy.json
ci:vllm vLLM benchmark: DeepSeek-V4-Pro, MiniMax-M3-MXFP4
ci:all All standard extended tests (excludes ci:atom_full)

Only add ci:atom_full for FlyDSL or Triton upgrades.
Add labels via the sidebar or gh pr edit 7652 --add-label <label>

One backend per PR:
A PR changes one kernel backend: [Triton/Gluon] (Triton and Gluon count as one), [HIP], [ASM], [CK], [OPUS] or [FlyDSL]. If the title ends up with two backend tags, split the PR -- as stacked pull requests when one part cannot merge without the other.

PR title tags & labels:
Component tags ([Triton/Gluon], [HIP], [CK], [ASM], ...) are added to the PR title and as PR labels automatically from the changed files and re-synced on every push — change-type tags like [fix]/[Perf], op tags like [MLA], and human labels (ci:*) are left untouched. Add the no-auto-title label to stop the title rewrites; labels stay in sync either way.

Reviews:
A reviewer is usually assigned within one working day after the PR is ready for review (see Code Review Process). If nobody has responded for about a week, mention the area contact listed in CONTACTS.md. Want to help review? See REVIEWERS.md.

@github-actions github-actions Bot added the FlyDSL label Nov 9, 2026
@aiter-bot

aiter-bot commented Nov 9, 2026 •

Copy link
Copy Markdown

WAITING ON AUTHOR

PR Self-Review

Revision f622c0ab504d · 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. What is the most important boundary or failure mode introduced by this change, and what evidence covers 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 — Reviewed revision must contain at least the first 7 characters of the current head SHA

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 4096 scan cutoff can leave required fallback specializations unbuilt for supported sparse custom CSVs, so coverage must include higher fallback transitions and a sparse-CSV regression test.

1 open issue
What changed in this PR

This PR reduces gfx1250 GEMM ahead-of-time compilation discovery work by sampling representative M sizes instead of scanning every M in each tuned row’s range.

Changes:

  • Adds representative-size selection using padded-M lookup boundaries, tile counts, and heuristic size classes.
  • Makes replay consume optional, lazily generated scan sizes while preserving exhaustive scanning for modules without the hook.
  • Updates documentation and adds focused tests for scan selection and range partitioning.
File Description
tests/​test_flydsl_aot_replay.py Tests custom scan sizes, lookup boundaries, and tile representatives.
aiter/​aot/​flydsl/​replay.py Adds lazy support for a module-provided scan-size hook.
aiter/​aot/​flydsl/​README.md Documents representative scanning for gfx1250 GEMM.
aiter/​aot/​flydsl/​gemm.py Implements representative M selection for tuned-row ranges.

Review effort: Balanced

Comment thread aiter/aot/flydsl/gemm.py Resolved
Copilot AI balanced review requested due to automatic review settings November 9, 2026 09:44

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

Gaps in cross-table, mixed-backend, and clipped-tile sampling can omit required GEMM specializations from the AOT cache.

1 open issue
2 previously missed issues

In code that hasn't changed since last review

Medium severity Include borrowed table tilings when sampling lookup gaps

aiter/​aot/​flydsl/​gemm.py:489

On an abpreshuffle lookup miss, _abpreshuffle_config_from_bpreshuffle can borrow a kernel whose tiling is absent from this job's table. With N=7168/K=1024, local t256/cm2 rows at M=4096/16384 and a borrowed compute t128/cm4/cn4 row at M=8192, scanning from 4097 misses the (cluster_m=4, bounded_m=True) specialization reached at even M=4482, leaving it out of the AOT cache. Include the borrowed table's lookup boundaries and tilings, or scan these gaps exhaustively, and add a cross-table regression case.

Medium severity Sample heuristics when a hit has no parsed tiling

aiter/​aot/​flydsl/​gemm.py:495

A non-FlyDSL padded row is recorded as (0, 0), making hits truthy and suppressing heuristic sampling even though _get_mxfp8_bpreshuffle_config falls back to FlyDSL heuristics. For a custom MXFP8 table with M=1/8192/32768, N=7168/K=1024, a non-FlyDSL row at 8192 and a t256/cm1 row at 32768, this skips heuristic classes such as the one beginning at M=8449 and can leave the AOT cache incomplete. Include heuristic samples when a hit has no parsed tiling, and add a mixed-backend regression test.

1 resolved since last review

Review effort: Balanced

Comment thread aiter/aot/flydsl/gemm.py Resolved
…er a clipped first tile'

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 9, 2026 10:05

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 AOT sampler can omit required kernel specializations because it uses overly coarse sampling, suppresses heuristics for non-FlyDSL rows, and misses borrowed-table lookup boundaries and tilings.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

Medium severity AB-preshuffle sampling omits borrowed-table specialization

aiter/​aot/​flydsl/​gemm.py:488

AB-preshuffle can borrow a kernel from the separate mxscale bpreshuffle table via _abpreshuffle_config_from_bpreshuffle, but these lookup pieces and tilings describe only the AB table. With AB rows at M=1/32768 and a borrowed compute row at M=12288 (N=7168, K=1024, tile_m=256, nb2, cm1/cn4), the scan visits only M=12288 in its gl0 interval [12161,12288], omitting the bounded_m=True specialization requested at M=12162. Include the borrowed table's lookup boundaries and tilings, or retain exhaustive scanning for these fallback pieces, and add a cross-table regression.

Medium severity Non-FlyDSL hits suppress required heuristic sampling

aiter/​aot/​flydsl/​gemm.py:495

Non-FlyDSL rows contribute (0, 0) to hits, suppressing heuristic sampling even though _get_mxfp8_bpreshuffle_config ignores those rows and uses the heuristic. With a non-FlyDSL row at M=8192 and a generic FlyDSL tile_m=256/cluster_m=1 row at M=32768 (N=7168, K=1024), the samples miss the heuristic's cluster_m=2 specialization at M=8449, leaving it out of the AOT cache. Keep heuristic sampling enabled for unparsed hits and add a mixed-backend regression.

Medium severity Sampling misses bounded compute-kernel specialization at large M

aiter/​aot/​flydsl/​gemm.py:511

The 32-tile cutoff in kernel_fits_shape applies only to generic kernels; 128-row compute kernels remain eligible at large M, but this sampler uses 256-row classes. With an mxscale CSV containing a non-FlyDSL row at M=8448 and a generic FlyDSL tile_m=256/cluster_m=1 row at M=32768 (N=768, K=1024), it misses the t128x128x128/cm4_cn2 bounded_m=True specialization selected at M=8577, leaving it out of the AOT cache. Conservatively cap the sampling grain at 128 to include compute-kernel classes, and add this sparse-table regression.

1 resolved since last review

Review effort: Balanced

zhiding512
zhiding512 previously approved these changes Nov 9, 2026
Copilot AI balanced review requested due to automatic review settings November 10, 2026 01:39

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

AOT sampling can omit required kernel variants because its 256-row stride skips eligible compute specializations and its per-CSV bounds do not reflect merged runtime lookup tables.

2 open issues

Review effort: Balanced

Comment thread aiter/aot/flydsl/gemm.py Resolved
Comment thread aiter/aot/flydsl/gemm.py Resolved
@coderfeli
coderfeli merged commit 5373140 into main Nov 10, 2026
@coderfeli
coderfeli deleted the gfx1250/gemm-aot branch November 10, 2026 09:13
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.

5 participants