Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions aiter/ops/mha.py
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ def _flash_attn_forward(
swa = (window_size_left > 0) or (window_size_right > 0)

def is_fmha_v3_fp8():
ret = get_gfx() == "gfx942"
ret = get_gfx() in ("gfx942", "gfx950")
ret = ret and (hdim_q == 128)
ret = ret and (q.dtype == dtypes.fp8)
ret = ret and (
Expand All @@ -1319,6 +1319,11 @@ def can_impl_fmha_v3_fwd():
ret = ret and (not swa)
ret = ret and (q.dtype == dtypes.bf16 or is_fmha_v3_fp8())
ret = ret and (cu_seqlens_q is None and cu_seqlens_kv is None)
# FP8 ASM kernels assemble the GQA-shift from a fixed log2 table
# (1,2,4,8,16); arbitrary divisor ratios route to CK.
if is_fmha_v3_fp8():
gqa_ratio = nhead_q // nhead_k
ret = ret and ((gqa_ratio & (gqa_ratio - 1)) == 0)
return ret

q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
Expand Down Expand Up @@ -2074,7 +2079,7 @@ def _flash_attn_varlen_forward(
swa = (window_size_left > 0) or (window_size_right > 0)

def is_fmha_v3_fp8():
ret = get_gfx() == "gfx942"
ret = get_gfx() in ("gfx942", "gfx950")
ret = ret and (hdim_q == 128)
ret = ret and (q.dtype == dtypes.fp8)
ret = ret and (
Expand All @@ -2100,6 +2105,11 @@ def can_impl_fmha_v3_fwd():
ret = ret and (not swa)
ret = ret and (q.dtype == dtypes.bf16 or is_fmha_v3_fp8())
ret = ret and logits_soft_cap == 0.0
# FP8 ASM kernels assemble the GQA-shift from a fixed log2 table
# (1,2,4,8,16); arbitrary divisor ratios route to CK.
if is_fmha_v3_fp8():
gqa_ratio = nhead_q // nhead_k
ret = ret and ((gqa_ratio & (gqa_ratio - 1)) == 0)
return ret

q, k, v = [maybe_contiguous(x) for x in (q, k, v)]
Expand Down
4 changes: 4 additions & 0 deletions csrc/cpp_itfs/mha_fwd.cu
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ std::tuple<int, int, int> get_grid_dim(const mha_fwd_args& a, int ts_qo, const s
{
tg_div = 1; // do not merge the head and tail in seqlen_q direction
}
if(arch_id == "gfx950")
{
tg_div = 1; // v2 asm kernel processes one Q tile per workgroup
}
// batch
int gdx = ((a.seqlen_q + ts_qo - 1) / ts_qo + tg_div - 1) / tg_div;
int gdy = a.nhead_q;
Expand Down
6 changes: 5 additions & 1 deletion hsa/gfx950/fmha_v3_fwd/fmha_fwd.csv
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ bf16,128,128,2,1,0,256,64,_ZN5aiter32fmha_fwd_hd128_bf16_causal_groupE,fwd_hd128
bf16,192,128,0,0,0,128,128,_ZN5aiter25fmha_fwd_hd192_hd128_bf16E,fwd_hd192_hd128_bf16.co
bf16,192,128,2,0,0,128,128,_ZN5aiter32fmha_fwd_hd192_hd128_bf16_causalE,fwd_hd192_hd128_bf16_causal.co
bf16,192,128,0,1,0,128,128,_ZN5aiter31fmha_fwd_hd192_hd128_bf16_groupE,fwd_hd192_hd128_bf16_group.co
bf16,192,128,2,1,0,128,128,_ZN5aiter38fmha_fwd_hd192_hd128_bf16_causal_groupE,fwd_hd192_hd128_bf16_causal_group.co
bf16,192,128,2,1,0,128,128,_ZN5aiter38fmha_fwd_hd192_hd128_bf16_causal_groupE,fwd_hd192_hd128_bf16_causal_group.co
fp8bf16,128,128,0,0,0,256,128,_ZN5aiter24fmha_fwd_hd128_fp8_gfx950E,fwd_hd128_fp8.co
fp8bf16,128,128,2,0,0,256,128,_ZN5aiter31fmha_fwd_hd128_fp8_causal_gfx950E,fwd_hd128_fp8_causal.co
fp8bf16,128,128,0,1,0,256,128,_ZN5aiter30fmha_fwd_hd128_fp8_group_gfx950E,fwd_hd128_fp8_group.co
fp8bf16,128,128,2,1,0,256,128,_ZN5aiter37fmha_fwd_hd128_fp8_causal_group_gfx950E,fwd_hd128_fp8_causal_group.co
Binary file added hsa/gfx950/fmha_v3_fwd/fwd_hd128_fp8.co
Binary file not shown.
Binary file added hsa/gfx950/fmha_v3_fwd/fwd_hd128_fp8_causal.co
Binary file not shown.
Binary file not shown.
Binary file added hsa/gfx950/fmha_v3_fwd/fwd_hd128_fp8_group.co
Binary file not shown.
Loading