Repository navigation
[FlyDSL] Flydsl tdm new interface - #6252
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
793290f to
f3af619
Compare
c4f3eeb to
967eae9
Compare
c6a49c3 to
3c52bee
Compare
Build the A and B atoms over the full tensor with make_tiled_tdm_atom and cut them with tdm_partition: the coordinate tensor's rest carries the K tiles that imm_offset used to advance, and the LDS view carries the pipe rest. Row slack in the LDS box replaces pad_interval/pad_amount, and the M bound now comes from the tensor extent instead of an explicit per-dim extent. The coordinate index is a tile number and must be i32, so the i64 byte offset the remaining old-interface copies still use is kept alongside it. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Prefer make_tiled_tdm_atom / tdm_partition for new kernels and note what differs: the coordinate index is an i32 tile number, not a byte offset, and padding is row slack in the LDS box. The older make_tdm_atom stays documented for the copies the tiled atom cannot express. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
tdm_ops.tensor_wait is a one-line forwarder to rocdl.s_wait_tensorcnt, and the tiled TDM atom's documented drain is the latter. Call it directly so every TDM site in the tree spells the wait the same way. 40 call sites across 15 files; each keeps whatever accessor the file already had (rocdl., fx.rocdl., or a direct name import), so no new import style is introduced. Where tensor_wait was the only tdm_ops symbol a file used, the import goes with it. tdm_ops_gfx1250.py keeps its `tensor_wait = _tdm_ops.tensor_wait` re-export: that is an __all__ entry rather than a call site, and callers outside this repository may depend on it. Also fixes an unrelated stale import this surfaced: gemm_a16w16_kernel_gfx1250 pulled check_smem_capacity from flydsl.utils.smem_allocator, which only names it in a docstring saying it lives elsewhere. It is in flydsl.runtime.device -- the same path aiter already uses for get_rocm_arch and FlyDSL's own kernels use for this symbol. The module could not be imported before this. No GPU validation: the device was busy with another user's job. Verified by syntax check, black, ruff, and importing all 15 modules (15/15, up from 14/15). Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Build the scale-A and scale-B atoms over the full (M/32, K) and (N/32, K) tensors and cut them with tdm_partition, so the sa_imm/sb_imm offset closures and the explicit sa_oob super-row bound both go away: K advances through the coordinate rest and the M bound comes from the tensor extent. mx128 keeps the older atom for now - its scale-A has m-major and batched variants that need their own treatment. The C store also stays: its LDS box is deliberately wider than the tile with the global inner extent clamped narrower, which the tiled atom cannot express. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
mla_pagesize64 (KV-nope load, output store), qk_norm_rope_quant (Q row load)
and mla_pagesize1 (output store). What each site stops spelling by hand:
* mla_pagesize64: pad_interval/pad_amount. The LDS row stride is already
Q_LDS_ROW_BYTES, so the padding is the box's row slack and does not need to
be restated as a separate pair of arguments.
* qk_norm_rope_quant: the per-copy imm_offset. The row the old atom reached
with row_of(tile_idx) * D * eb is now an i32 tile index into the coordinate
rest.
* mla_pagesize1: the explicit [valid_rows, None] extent, which becomes the
global view's own shape -- boundary_check clamps the single tile to it. This
also left `layout` and `lds_view` dead; both are gone.
A runtime extent is not a reason to stay on the old atom: it lives in the view's
shape instead of in a tensor_extents argument, and neither API lets a call
change it afterwards (tdmFieldIndex only resolves WorkgroupMask, EarlyTimeout
and AtomicBarrierAddr).
Each LDS tile gains a size-1 rest so mode-0 stays the nested box tdm_partition
cuts; selecting every rest mode in zipped_divide collapses it and the partition
is rejected.
Verified on gfx1250 against the same tree before the change:
mla --mode ps1 33 rows, err identical row by row (all 0); 751-754 us total
vs 752-754 on main
mla --mode ps64 3 rows, err 0; 2048 and 4096 within noise, 8192 ~2% slower
against a baseline that itself spread 25.6-27.9 and 31.2-41.3
qk_norm 234 rows, err identical row by row (max 9.24e-07);
11063/11089 us total vs 11052/11085 on main
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Replace make_tdm_atom + whole-tile fx.copy with make_tiled_tdm_atom, zipped_divide and tdm_partition. The warp coordinate comes from the hardware wave id, which is what the old atom's lowering used internally, rather than a freshly computed readfirstlane(tid // 32). Verified with op_tests/test_gemm_a8w8_mxfp8_bpreshuffle.py: 36 shapes, err 0. Only one tuned shape (512x7168x16384, sk2_cm4_cn2_fsk) actually emits this epilogue; three interleaved runs of old and new overlap. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
combine.py: both slot loads and the token store. The LDS boxes are packed, so the store is legal; each gains the size-1 rest tdm_partition cuts against, and the runtime row clamps move from tensor_extents into the global view's shape. No runtime entry exists on a single GPU, so this is verified by construction only: a driver builds the reduce over topk 4/8 x hidden 2048/7168 x quant 0/8/4 and preloads each, 12/12 compiling both before and after. fmha_b16_buffer_managers.py: the 3-D single-warp Q loader. 12 interleaved runs of op_tests/test_mha_flydsl.py -l bshd over 336 shapes, per-shape median: +0.66%, no shape past +5%, err columns no worse than the old path. Two sites in that file are left on the old interface deliberately. The O stores drain a padded LDS tile, which tdmStoreOpType refuses outright (TENSOR_STORE_FROM_LDS has no de-padding) -- the same rule that blocks gemm_a8w8's C store when C_PAD is set. The 2-D segmented loader was converted and measured at +2.09% median, so it was reverted: the tiled atom takes the row count from the view's shape, and making that a runtime value costs what the old tensor_extents field did not. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Only the STORE_PAD == 0 branch; the padded one stays on make_tdm_atom because tdmStoreOpType refuses a store whose LDS tile carries a pad. The make_tdm_store helper had no other caller and goes away with it. op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify --no-check-aot-cache --inter-dim 512: a8w4 and a4w4 both pass with the same logits_diff as before (3.72348e-06 / 3.69724e-06). --scenario kernel, 6 interleaved rounds: gemm1 52.33 -> 52.30us (-0.05%), gemm2 36.83 -> 36.77us (-0.14%), ranges fully overlapping. That entry needs --no-check-aot-cache; without it the harness forces FLYDSL_RUNTIME_RUN_ONLY=1 and fails in seconds on a missing AOT cache, which looks like the kernel having no test. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
tuned_op_bench.csv was written by a benchmark run and committed by mistake; it is not part of the migration. Also removes the trailing comment on WARP1 that the earlier comment sweep missed, since it only matched whole-line comments. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main now gives this epilogue a padded LDS row (c_lds_row = tile_n + 8), and tdmStoreOpType refuses a store whose geometry carries a padAmount: a TDM store cannot drain a padded LDS tile (pad interval 256, amount 8); TENSOR_STORE_FROM_LDS has no de-padding The migration of this site was measured as neutral when c_lds_row == tile_n, but that no longer holds, so it joins the other padded stores on make_tdm_atom. The s_wait_tensorcnt change stays. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The comment-removal commit's hunks for these lines were dropped when the file was taken whole during conflict resolution. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main added an a_scale_preshuffled=False variant whose A-scale tile is (tile_m, tile_k // 32). At tile_k = 256 that is 8 bytes on the inner axis, and deriveTdmAtom requires 16: physical TDM tile_dim0 must span at least 16 bytes, got 8 elements at 8 bits The preshuffled layout is (tile_m // 32, tile_k) and stays on the tiled atom; so does the B scale, whose inner axis is tile_k either way. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The stores were blocked only by their own LDS padding, which the TDM store engine cannot drain. Dropping that padding unblocks all of them: gemm_a8w8_gfx1250.py C_PAD 8 -> 0 gemm_a8w8_256x256_gfx1250.py C_LDS_ROW tile_n + 8 -> tile_n The second one also feeds emit_fused_splitk_epilogue's c_lds_row, so both split-k stores convert with it and that file is now free of the old interface. The ds_store side loses its bank-conflict padding; that is a deliberate trade, not an oversight. fmha_b16_buffer_managers.py converts whole. Its two O stores were never padded -- OManager16bV2 already keeps row_elems == v_hdim and says so -- and the 2-D segmented loader goes with them, so the file no longer uses make_tdm_atom. Verified per file with its own FLYDSL_RUNTIME_CACHE_DIR, since edits to a helper module do not invalidate the shared cache: test_gemm_a8w8 --no-legacy 24 passed~ / 24 warning!, mxfp8 36 shapes err 0, test_mha_flydsl.py -l bshd 336 shapes err 0. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
STORE_PAD was 16 columns to spread a b128's 16 rows off one bank. The TDM store cannot drain a padded LDS tile, so on the non-scatter path it goes to zero and the padded branch -- the file's last store-side make_tdm_atom -- goes with it. The EP-scatter path keeps c_lds_pad_elems; it uses the gather engine, not this store. Verified with test_flydsl_grouped_gemm.py --scenario verify --no-check-aot-cache --inter-dim 512 in its own cache dir: logits_diff 3.72348e-06, identical to every earlier run. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The previous two commits dropped C_PAD, C_LDS_ROW's +8 and STORE_PAD to get past "a TDM store cannot drain a padded LDS tile". That was the wrong fix: those pads exist to spread a b128's rows off one LDS bank, and the old interface never handed the pad to the descriptor either. What it did instead was declare the global view as wide as the LDS row and clamp the extra columns away with tensor_extents. The tiled atom spells the same thing: make tdm_tile the padded width, so smem_layout matches it and geometry.padAmount is zero, and give the global view the real width as its inner extent so boundary_check drops the pad columns. tdm_tile = (tile_m, C_LDS_ROW) # was (tile_m, tile_n) global view = (mn_oob, tile_n) # was the full padded row All three pads are restored. test_gemm_a8w8 --no-legacy 23 passed~ / 25 warning! (the suite's usual jitter, no failures), mxfp8 36 shapes err 0, grouped-gemm verify logits_diff 3.72348e-06 unchanged. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The authoring skill's only runnable TDM example was still the old form -- make_tdm_atom + copy_atom_call + tdm_ops.tensor_wait + advance_tdm_atom -- under a one-line "prefer make_tiled_tdm_atom". Anyone following it wrote a new kernel against the retiring interface, down to the wait spelling this branch replaced everywhere else. The example is now the tiled atom, and it names the three parameters that became tensor properties: extents and strides live in the view's layout, the K advance is the coordinate tensor's i32 tile index, and LDS padding is row slack in the box (with the store's padded-tile rule). The cleanup skill said only "prefer the newer one". It now says how to recognise a site to migrate and what each old argument maps to, plus the two cases that keep the old atom: the gather/scatter family, and a tile whose innermost dimension spans under 16 bytes per warp. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The K remainder no longer needs a per-iteration extent write: give the view the whole split_k_chunk extent and let zipped_divide plus boundary_check clamp the tail tile. That deletes k_rem/k_left, both *_extents lists, both *_pad_interval constants, both *_imm_bytes/_imm_rt expressions and the IMM and KDIM slots of the side tuples -- 46 insertions against 66 deletions. A first attempt hung the GPU. The cause was not the K tail (the config that hung has k_rem == 0) but the partition contract: the atom was built with num_warps=num_warps while tdm_partition got fx.make_layout(1, 1). Its size must match num_warps, or every wave computes the same wrong slice and the transfer never retires. Passing fx.rocdl.wave_id() with fx.make_layout(num_warps, 1) fixes it. op_tests/flydsl_tests/test_gemm_a16w16.py in its own cache dir: 220 rows, no compile errors, and the 34 configs shared with the pre-change baseline match on the err column row for row. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
add_tdm_loads built one atom per (tensor, wave group) and the Job tuple carried the global view for two issue sites to copy from with an imm_offset. The tuple now carries the partitioned coordinate tensor instead: the view spans every K tile rather than one, and the surviving rest mode is the K tile number, so imm_offset and k_adv's byte arithmetic drop out of both issue paths. Jobs seeded with k_adv == 0 cover the whole K range in one tile and index that rest with 0. num_warps is 1 here -- the wave split is done by hand in the view's base offset -- so tdm_partition takes a size-1 warp layout to match. op_tests/flydsl_tests/test_flydsl_grouped_gemm.py --scenario verify, both formats, in its own cache dir: a8w4 logits_diff 3.72348e-06, a4w4 3.69724e-06, identical to every earlier run. mxfp8's 36 shapes stay at err 0. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
All four operand loads and the C store convert. The loads share one _tiled1 helper: the view spans every K tile instead of one, so the coordinate rest carries the K tile number and the per-copy imm_offset goes away. num_warps stays 1 -- the wave split is done by hand in the view's base offset -- so tdm_partition takes a size-1 warp layout. A's LDS padding rides on A_LDS_ROW = A_ROW_B + LDS_PAD_A, which is exactly the row slack the box layout expresses. The _tdm helper loses its only caller with the C store and goes. This file has no op_test that reaches it on a single GPU: the suite builds its inputs with aiter.ops.triton.quant, which fails here with "gluon.language.amd has no attribute 'cdna5'". Verified instead by driving flydsl_batched_gemm_a8w4_v2 directly over both layouts and two shapes with a fixed seed, and diffing the outputs against the same driver run on the unconverted file: bit-identical, max abs difference 0.0 on all four. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This reverts commit e3d0ba7.
Reverted earlier over a measured regression; restored because interface uniformity takes priority. The cost, measured over four interleaved rounds in per-variant cache dirs (err 0 on both sides throughout): shape sweep, 30-40 us GEMMs +1.21% median config sweep, 4-5 us shapes +3.09% median, up to +17.71% fused activation (silu/gelu/relu) +15.15% median 27 of 52 configurations land past +5%. Part of it is understood: forcing the M/N extent static (a diagnostic that breaks the tail) takes the config sweep to -0.86%, so the runtime extent in the view's shape is what costs the short kernels. It does not explain the fused path, which gets *worse* at +18.74% with static extents. That cause is unidentified -- a register-pressure interaction with the fused epilogue is the obvious suspect but was not confirmed. An earlier report of the TT layout diverging to 114 and 2771 us did not reproduce: that shape runs at a steady 35.6 us, and the baseline showed matching outliers in the same window, so it was machine noise. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main rewrote both fmha files while this branch was out (attention sink, a parametrised tensor_wait, an O manager rework), so the replay took main's copies and the conversions are redone here on top of them: the 2-D segmented loader, the 3-D single-warp Q loader and both O stores. The O stores keep OManager16bV2's padded row -- tdm_tile is the padded width so padAmount stays zero, and the view's inner extent is v_hdim, which is the "pad rides as dropped columns" the old code spelled with tensor_extents. gemm_a8w8's non-preshuffled mx32 A-scale converts now that FlyDSL #1302 gates the tile_dim0 span check on padding. Its 8-byte inner span was the one thing blocking it. gather_kv_b_proj_gfx1250.py arrived from main using the old interface for its B load; converted. Its A side stays on the gather descriptor, which the tiled atom cannot express. Repo-wide: no tdm_ops.tensor_wait call sites left, and one make_tdm_atom -- gemm_a8w8's _tdm1, still serving the mx128 scales, which regressed on accuracy when converted earlier. test_gemm_a8w8 --no-legacy 22 passed~ / 26 warning! and no failures, mxfp8 36 shapes err 0, test_mla_flydsl 34 rows err 0, qk-norm 465 passed~, test_mha_flydsl -l bshd 256 rows err 0. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
519d9d3 to
b8b077c
Compare
An earlier attempt at these three regressed accuracy and was reverted. The cause was a partial fix, not the mapping: gemm_a8w8 computes K_TILES = i32_k // (tile_k * split_k) # one split's tiles kti = fx.Int32(kt) + kt_base_i32 # global, carries the split base and the fix that gave the mx32 preshuffled path the whole K extent left these three on K_TILES. With split_k > 1 the index ran past the view and boundary_check returned zeros, so the scales read as zero -- an accuracy loss rather than an error. The suite improved but did not recover, which read as a second unknown problem instead of the same one in three more places. All four sites now span (i32_k // tile_k) * K_WS. _tdm1, _wcopy, sa_imm, sb_imm, ktg and kt_base lose their last users and go with them. Also refreshes comments the migration outdated: fmha_b16_buffer_managers' transport note still described V2 as copy_atom_call on a make_tdm_atom view, and three files still said tensor_wait in prose. The remaining copy_atom_call sites are buffer, atomic and WMMA-fragment atoms, not TDM. test_gemm_a8w8 --no-legacy 23 passed~ / 25 warning! and no failures (three verdicts move against the previous run, two up and one down, all within the suite's warning/passed jitter); mxfp8 36 shapes err 0; test_mla_flydsl 34 rows err 0; qk-norm 465 passed~; test_mha_flydsl -l bshd 256 rows err 0. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
`sa_m_major` is false off the batched path, and SA_SHAPE transposes with it: (tile_m, K_WS) when A-scale is M-major, (K_WS, tile_m) when K is. SA_LDS_ROW only ever described the first of those, and the migration to make_tiled_tdm_atom handed it to both, so the K-major box claimed a row stride of K_WS while its rows hold tile_m elements. K_WS is tile_k / 128, far under tile_m, and the rows overlap: make_tiled_tdm_load_atom: LDS mode 0 has stride 4, smaller than the 64 elements inside it; the tile overlaps itself 82 of the mxfp8_128 bpreshuffle AOT configurations failed to compile on that, the reported stride matching tile_k / 128 and the element count matching tile_m in every one. Before the migration this site passed (tile_m, 1) explicitly; _scopy and load_sa still address the box by tile_m, so the atom's layout was the only piece that disagreed. SA_TDM_SHAPE[1] is the row of whichever box is in play -- preload_ks under preload, K_WS when M-major, tile_m when K-major -- so it keeps the two working cases byte-identical. SB needs nothing: SB_SHAPE[1] is already SB_LDS_ROW. The remaining failures in that build are not this: 58 are a FlyDSL filler-dim ordering bug at tile_k = 128 (ROCm/FlyDSL tdm-filler-contiguous-first), and 7 want the tile_dim0 span floor that FlyDSL d00dd711 removed after 0.4.0, which requirements.txt still pins. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
main's typed-API pass (eb56b2d) rewrote the MoE route/quant/scatter and mega_moe TDM prims off raw ir/arith onto fx, landing on the same import blocks the TDM migration touched. Keep main's fx imports and this branch's s_wait_tensorcnt; neither file still references ir, arith or vector. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
CI builds the wheel against the pinned flydsl==0.4.0, not a local checkout of upstream, and the mx128 tiled-atom conversion fails there two ways: the innermost descriptor dim must be contiguous in global memory (stride 1), got global mode 0 -- the LDS tile's majorness does not match the global tensor's is a real bug: the sa_m_major=False branch builds the global view as (KT_ALL, mn_oob) strided (stride_ask64, 1), making M contiguous, while the LDS box stayed K-major. bd8fbfd set that box's row stride but left its majorness alone, so it did not help. FlyDSL #1309 addresses this compiler-side. physical TDM tile_dim0 must span at least 16 bytes, got 4 elements at 8 bits is invisible locally: upstream dropped that floor, the 0.4.0 wheel still has it. Restore both only after the flydsl pin moves past #1302 and #1309, and fix the majorness mismatch first. The steps are in the tdm-tiled-atom-migration skill, section 13; the migration itself is 039e267 plus bd8fbfd. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Same cause as the mx128 revert: b8b077c converted this site on the strength of FlyDSL #1302 gating the tile_dim0 span check on padding, but CI builds the wheel against the pinned flydsl==0.4.0, which still has the unconditional 16-byte floor. Its tile is SA_SHAPE = (tile_m, tile_k // 32) over 8-bit e8m0, so the inner span is tile_k/32 bytes: 4 at tile_k=128, 8 at tile_k=256. Every AOT flydsl_mxfp8_32_bpreshuffle* kernel takes this branch (none carries _aspre), and the ones at tile_k 128 or 256 would fail the same way the mx128 ones did. Restore it together with the mx128 loads once the pin moves; the steps are in the tdm-tiled-atom-migration skill, section 13. The conversion is b8b077c's two hunks in this file. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…6252)" This reverts commit cfc37f9, which backed out #6252 after review found four defects in it. The three commits that follow fix or contain all four; see each for the evidence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…6252)" This reverts commit cfc37f9, which backed out #6252 after review found four defects in it. The three commits that follow fix or contain all four; see each for the evidence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…6252)" This reverts commit cfc37f9, which backed out #6252 after review found four defects in it. The three commits that follow fix or contain all four; see each for the evidence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…6252)" This reverts commit cfc37f9, which backed out #6252 after review found four defects in it. The three commits that follow fix or contain all four; see each for the evidence. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist