Repository navigation
[ASM] [HIP] [gfx1250] asm mha bf16 hd256: batch and varlen forward - #7559
Conversation
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
423d129 to
f4d67e2
Compare
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 |
There was a problem hiding this comment.
🟡 Changes recommended
Critical correctness tests do not enforce output or LSE agreement with the Torch reference, and the FlyDSL benchmark performs less work than the other candidates, making the comparison inconsistent.
3 open issues
What changed in this PR
Adds gfx1250 BF16 head-dimension-256 assembly forward attention through AITER’s existing batch and variable-length APIs, supporting causal and non-causal execution with optional LSE output.
Changes:
- Registers D256 kernels and adds stride validation, per-call launch options, and variable-length grid padding.
- Extends Python routing while preserving sink restrictions and gradient fallbacks; fixes batch window eligibility.
- Expands correctness, routing, stride, empty-input, and performance tests.
| File | Description |
|---|---|
op_tests/test_fmha_fwd_with_sink_varlen_asm.py |
Adds D256 variable-length, stride, gradient-routing, and benchmark cases. |
op_tests/test_fmha_fwd_with_sink_asm.py |
Adds D256 batch coverage, routing gates, empty-input tests, and benchmarks. |
hsa/gfx1250/fmha_fwd_bf16/fmha_fwd_bf16.csv |
Registers causal and non-causal D256 batch kernels. |
hsa/gfx1250/fmha_fwd_bf16_varlen/fmha_fwd_bf16_varlen.csv |
Registers causal and non-causal D256 variable-length kernels. |
csrc/py_itfs_cu/asm_fmha_fwd_with_sink.cu |
Adds D256 validation and launch selection, plus empty-query handling. |
csrc/py_itfs_cu/asm_fmha_fwd_with_sink_varlen.cu |
Adds D256 strided arguments, launch selection, and grid padding. |
aiter/ops/mha.py |
Integrates D256 dispatch, stride checks, window restrictions, and gradient-aware routing. |
Review effort: Balanced
Add the gfx1250 BF16 hd256 ASM forward kernels to fmha_fwd_with_sink_asm and fmha_fwd_with_sink_varlen_asm, with strided q/k/v/out, empty-KV support and per-shape launch options. Routing keeps the existing ASM priority. Op tests cover hd256. Co-Authored-By: Claude Opus 5.5 <[email protected]>
f4d67e2 to
7487db6
Compare
…7559) Add the gfx1250 BF16 hd256 ASM forward kernels to fmha_fwd_with_sink_asm and fmha_fwd_with_sink_varlen_asm, with strided q/k/v/out, empty-KV support and per-shape launch options. Routing keeps the existing ASM priority. Op tests cover hd256. Co-authored-by: Claude Opus 5.5 <[email protected]>



Summary
Adds gfx1250 (MI450) BF16 ASM forward kernels for head dim 256 (q/k/v head dim 256). There are batch (bshd) and packed varlen (THD) variants, each with a causal (bottom-right aligned) and a non-causal code object, and all of them can return the LSE. They are served through the existing entries
aiter.fmha_fwd_with_sink_asmandaiter.fmha_fwd_with_sink_varlen_asm, and through the existing gfx1250 ASM routing inflash_attn_varlen_func/flash_attn_func.Motivation
Compared with what aiter runs today for bf16 head-dim-256 attention on gfx1250 (the current aiter baseline), the new kernels are faster:
attn/uniform/B4L16000/h32d256: 1.27x non-causal and 1.26x causal.The kernels peak at about 2.6 PFLOPS, the same level as the existing hd128 ASM kernel measured the same way (hd128 2638 TF, hd256 2575 TF on a common 32-shape set).
Changes
hsa/gfx1250/fmha_fwd_bf16/,hsa/gfx1250/fmha_fwd_bf16_varlen/):fmha_bf16_pertokenBf16_hd256_128x128[_mask][_varlen].coand their csv rows.ENABLE_SINK=0).csrc/py_itfs_cu/asm_fmha_fwd_with_sink.cu):csrc/py_itfs_cu/asm_fmha_fwd_with_sink_varlen.cu):cu_seqlens:total_k / batch) ≤ 2^17 rows.run_perfteston 16–64 heads, MHA and MQA, 1K–32K tokens, equal and variable lengths. Against the best option per shape, it loses 0.55% on average on the 216-shape fitting set and 0.82% on a 22-shape validation set.run_perftest) does not move the best threshold.max_q_lenstays the real maximum.aiter/ops/mha.py):fmha_fwd_with_sink_varlen_asmtreats (256, 256) as strided, like (192, 128)._select_gfx1250_fmha_fwd_varlen_asmaccepts (256, 256). Like D192x128, it is offered to the ASM ahead of FlyDSL;_prefer_flydsl_over_gfx1250_bf16_varlen_asmis unchanged.can_impl_fmha_fwd_with_sink_asmaccepts head dim 256 when there is no sink and_can_impl_fmha_fwd_asm_d256_stridespasses. WithoutNone, that check covers the dense outputfmha_fwd_with_sink_asmallocates.flash_attn_funcstill offers the call to FlyDSL first, as for D64 / D128.can_impl_fmha_fwd_with_sink_asm, all head dims: windows follow the CK convention, as in the varlen gate. A left window ≥ 0, or a right window ≥ 0 without causal, is a mask the kernels cannot apply, so such calls no longer reach them.(-1, 0)without causal and causal(0, -1)used to be computed as no mask and as plain causal.flash_attn_varlen_func: a call that needs gradients goes to the ASM forward only for head dims the gfx1250 ASM backward has (_GFX1250_BWD_HDIMS, now shared with the two backward gates). D256 has none. Such a call goes on as before this PR: FlyDSL takes no call that needs gradients, so it runs on Triton withENABLE_CK=0, or throughFlashAttnVarlenFuncwith CK built._can_impl_fmha_varlen_asm_d192_strides:dense_last_dim_laterskips the last-dim check of q/k/v only.outis used as given, so it is always checked.Routing impact:
flash_attn_varlen_funcnow go to this kernel instead of FlyDSL.FlashAttnVarlenFunc, and its backward is CK's.flash_attn_funcgives the call to FlyDSL when FlyDSL accepts it. Otherwise, with CK enabled,_flash_attn_forwardsends it to this kernel. WithENABLE_CK=0the call goes to Triton, as it already does for D64 / D128.Performance (if applicable)
run_perftest, 2 warm-up runs and 101 profiled iterations. The reported time is the device time of all kernels in one call. Each candidate is measured for one round.flash_attn_varlen_func(varlen tables) andflash_attn_func(batch table) run for these calls without this PR.Varlen, equal lengths:
Batch (bshd shape; sbhd memory for batch = 1, bshd memory for batch > 1):
Varlen, variable lengths:
Testing
The kernels are gfx1250-only; all testing ran on MI450 (gfx1250).
Documentation
Dependencies
Breaking Changes
None.
PR Self-Review
Reviewed revision
Behavior and intent
out.Validation and unverified scope
On MI450 (gfx1250 B0), the op tests were run as below. The two environment variables route the torch reference's GEMMs to rocBLAS. Without them, a hipBLASLt fp32 batched GEMM picked for some reference shapes intermittently reads out of bounds and faults the GPU (the same issue as mi455x-opbench known issue 1); the attention kernels are not involved.
Results: every check passed, with O and LSE error 0; every comparison with the torch reference asserts (
assertAllclose). The runs need no kernel serialization.ENABLE_CK=0).AITER_ENABLE_EXPERIMENTAL=1: the varlen test passes too. There, the calls offered to FlyDSL first skip the bit-for-bit public candidate and are routed as expected.Not verified (the test container has
ENABLE_CK=0):flash_attn_funcwith CK enabled, where_flash_attn_forwardwould reach the ASM. The batch gate is tested directly instead.PR-specific question
Changed op tests
op_tests/test_fmha_fwd_with_sink_varlen_asm.py:maybe_contiguous, a q with a non-unit last-dim stride is accepted and anoutwith one is refused.flash_attn_varlen_funcwith and without gradients, D128 / D192x128 / D256. With gradients, the backward must run.assertAllclose).op_tests/test_fmha_fwd_with_sink_asm.py:assertAllclose). The public LSE is compared on rows that see a key only (mask=): behindflash_attn_functhe call may go to FlyDSL, Triton or CK, and Triton writes LSE = 0 on rows that see no key. The ASM candidate is checked on every row._flash_attn_forward, with every forward entry replaced by a stand-in that raises instead of launching; withENABLE_CK=0,flash_attn_funcnever reaches it. Covers head dims, sinks, windows of 0, a k token stride of 2^24 B, and the output the wrapper allocates (batch stride 2^30 B accepted, 2^31 B refused, on meta tensors).