ggml-cuda: use mma-f16 flash-attn for D=256 on RDNA3.5#40
Open
roberteg16 wants to merge 1 commit into
Open
Conversation
Route D=256 GQA attention to the mma-f16 kernel and allow its AMD_WMMA path up to DKQ=256. On RDNA the kernel still runs on WMMA instructions, and it packs ncols2 GQA heads into a full 16-wide tile that the wmma kernel leaves mostly empty. Assisted-by: Claude Opus 4 (1M context)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this changes
A prefill optimization for D=256 GQA attention on RDNA3.5 when built with rocWMMA FlashAttention (
-DGGML_HIP_ROCWMMA_FATTN=ON). On this pathggml_cuda_get_best_fattn_kernelwould pick the wmma-f16 kernel, which for GQA leaves its 16-wide tile mostly empty. The mma-f16 kernel also lowers to RDNA WMMA instructions here, but it packsncols2GQA query heads into a full 16-wide tile, so it uses the same hardware far more efficiently.Two changes: (1) in
fattn.cu, route D=256 toBEST_FATTN_KERNEL_MMA_F16when the GQA optimization applies and the tile is actually filled (gqa_opt_applies && Q->ne[1]*gqa_ratio_eff >= 16); (2) infattn-mma-f16.cuh, raise the AMD_WMMA path's head-dim guard fromDKQ > 128toDKQ > 256so the D=256 kernel is allowed to compile. Both are restricted to RDNA3.5 (GGML_CUDA_CC_IS_RDNA3_5on the host, theRDNA3_5macro for the device-side limit), the only architecture this was tuned and validated on; other AMD WMMA architectures keep the previousDKQ <= 128behavior.Benchmarks
Measured on gfx1151 (Radeon 8060S), Qwen3.6-35B-A3B Q4_K_M,
-ngl 999 -r 1, built with-DGGML_HIP_ROCWMMA_FATTN=ON. Baseline isgfx11at the same commit base, also built with rocWMMA on.Larger-batch prefill (pp1024) improves clearly; pp128 and decode are within run-to-run noise. This only affects the rocWMMA-on build - with rocWMMA off,
ggml_cuda_should_use_wmma_fattnreturns false and the routing change is never reached.