You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[FlyDSL] [AOT] Scan gfx1250 GEMM rows at representative M, not every M - #7652
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: newscan_sizes(job, low). It cuts the range wherever the padded-M lookup changes, found by bisecting the runtime's own monotoneget_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 firstlcm(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:_scanidentifies the sizes frommodule.scan_sizes, or every size if the module has none. The sizes are computed lazily inside the dry run, becauseget_padded_mneeds its fake device.SCAN_ARCHS=("gfx1250",)is affected. Other archs still bisect, unchanged.[SCAN]paragraph and docstrings updated. Unit tests added for_scan,_lookup_piecesand_tile_sizes, plus a sparse-table regression test.Performance (if applicable)
Testing
Documentation
Dependencies
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
scan_sizeswere 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.GPU_ARCHS=gfx1250 FLYDSL_RUNTIME_CACHE_DIR=<A> python3 -m aiter.aot.flydsl.gemmgave 2011 ok,[SCAN]856 with 0 failed, and 1704 cache files, identical to the earlier revision's cache. The pre-change full scan (scan_sizesremoved) was then run with--checkagainst cache A and passed, also replaying 856 scan sizes. The same build plus full-scan--checkpasses 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.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_sizesdoes 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 keysget_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 fromscan_sizeswere 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--checkagainst 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