Repository navigation
[FlyDSL] [Perf] Select gfx1250 long-row top-k from one sampled-bound read - #7727
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: Reviews: |
…read On gfx1250, a long row of the one-block radix top-k first samples its keys, bounds the kth key's level-1 bucket from the sample, and compacts every key at or above the bound in one read of the row; the candidates then finish in LDS. A row whose candidates miss k or overflow the buffer falls back to the existing two-pass selection, so the sample decides only the speed. - Persistent blocks walk rows grid-strided, and the tensor data mover loads each block's next row, and its first sample keys, into an LDS row cache while the current row is selected. - Long rows with k <= 2048 run 512-thread blocks, two to a CU, when there are more rows than CUs, and 1024-thread blocks otherwise. - gfx1250 barriers fence LDS only, and its wave32 block scans use DPP. Every change to a path shared with other arches is gated by arch: the gfx950 kernels compile to the same ISA as before. Co-authored-by: Cursor <[email protected]>
- Build the row cache's TDM descriptor with tdm_ops_gfx1250.make_tensor_descriptor_2d, and the wave32 scans with dpp_utils.update_dpp_i32 and fx.coop.warp_broadcast. - Drop the bound's buffer hold (k = 2048 long rows go back to 1024-thread blocks), the single-wave kth search, the windowed level-1 choice, the sample keys gathered with the row cache, LDS-only barriers, the row-bounds asm, and the gfx1250 forms of paths shared with other arches. - One arch gate remains. gfx950 and the gfx1250 short-row kernels compile to main's ISA. Co-authored-by: Cursor <[email protected]>
fcd90da to
810ba0d
Compare
test_topk_per_row.py gains a flydsl-one-block-long-rows regression, run by CI's plain `python3 op_tests/test_topk_per_row.py`. It drives the one-block kernel at more rows than CUs, so blocks walk rows through the LDS row cache, on random rows, tied rows that overflow the sampled bound's candidate buffer and all-equal rows, and stable k = 4096 decode, which keeps 512-thread blocks without the cache. Stable rows are checked index for index against an exact reference, unstable rows by key multiset with each column once, and the written values against the logits at the returned indices. The half-block LDS budget comment now says it applies only without the row cache. Co-Authored-By: Claude Opus 5.5 <[email protected]>
WAITING ON AUTHORPR Self-ReviewRevision 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
Edit the Missing or invalid answers
Shadow mode reports what would block but keeps the status successful. Set |
Keep decode rows shorter than the sampled-bound threshold on a 512-thread unsampled build, avoiding the 1024-thread regression at 768x6144 k=2048. Move the one-row TDM stride fix, wave32/block scans, and the compiler dependency pin into shared helpers, and add the short long-row regression case. Co-authored-by: Cursor <[email protected]>
…ments Resolve the kernels_common.py conflict by keeping main's pin_i32 (#7727) and this branch's cross-lane reduction helpers. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
What this PR does
On gfx1250 (MI455X), the FlyDSL one-block radix top-k used to read each long row from HBM twice: once to build the level-1 histogram, and again to compact the kth key's bucket. This PR reduces that to one read, and overlaps loading the next row with selecting the current one.
Sampled bound. For rows of at least max(4k, 4097) keys, the kernel samples about one key per 64 to estimate a lower bound on the kth key. It then compacts every key at or above that bound into LDS in a single pass, and runs the histogram levels on the compacted keys.
Row cache with persistent blocks. Each block walks rows grid-strided. The tensor data mover loads the head of the next row into an LDS cache while the current row is selected.
Block size. This combines with [FlyDSL] [gfx1250] Radix top-k: 512-thread blocks for long decode rows, index-sort output for streaming rows #7662 (already on main):
Every combination fits in gfx1250's 320 KiB LDS per CU, with no scratch and no spills.
Only gfx1250 is affected. gfx950 and the gfx1250 short-row kernels compile to the same code as on
main.Benefit
Setup.
score_topk_quantized) callstop_k_per_row_prefill/top_k_per_row_decode. Rows are packed into the score workspace. Each query row is bounded by its causal position, at compression ratio r over a plane of 1M / r columns.aiter/ops/flydsl,aiter/ops/topk.py,aiter/utility/graph_alloc.pyandaiter/jit/utils/hip_runtime.pycopied in, under the pinned FlyDSL 0.5.0.aiter/ops/flydsl.Prefill. bs 1, 16384 tokens, k = 512, 16384 rows per call. Each cell is event time / kernel time per call.
Decode. bs 128, with each request's newest token plus 5 drafts, gives 768 rows per call. A step makes 3 r2 calls, 1 r1 call, 1 r1 block pick (k = 2048) and 4 r1 candidate calls. Each cell is the total kernel time of one step.
The same decode step at ctx 65536, broken down by call. Each cell is kernel time per call, randn / N(12.8, 3.3):
"Before" is main at 6916e20, which predates #7662. Measured against current
main(which has #7662's 512-thread decode blocks), the change still holds: synthetic full-width decode calls (768 rows, width 65536) are 1.2–2.8x faster at k = 512–2048, stable k = 4096 runs the same kernel as main and is unchanged, and prefill k = 512 stable is 2.0–2.8x faster.Testing
All on MI455X.
New CI regression
flydsl-one-block-long-rowsinop_tests/test_topk_per_row.py, 16 cases, all pass. It covers:Each case is checked against an exact reference.
Existing tests pass unchanged:
op_tests/test_topk_per_row.py,test_topk_per_row_stable.pyandtest_topk_row_prefill.py.