From 636e28dd7f5529d2fc7417c673965ed22cd7284f Mon Sep 17 00:00:00 2001 From: rafasmour <54501936+rafasmour@users.noreply.github.com> Date: Fri, 4 Dec 2026 11:29:11 +0000 Subject: [PATCH] fattn-mma: use the spill-free streaming-Q D256 config up to ncols2 8 on RDNA3 flash_attn_ext_f16<256,256,8,8> (D256, GQA8, full 64-column tile) spilled with the default RDNA config: 256 VGPR, 932 B scratch (1344 B for the sparse variant). Widening the existing streaming-Q config condition from ncols2 2..4 to 2..8 gives 206 VGPR and no scratch. Prototype measurement (variant A): D256 GQA8 kernel 11437 -> 8559 us, pp512@d32768 +10.2% on Qwen3.6 (same shape as Qwen4 full attention: 16 Q / 2 KV heads). Assisted-by: Claude Sonnet 5.5 --- ggml/src/ggml-cuda/fattn-mma-f16.cuh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml-cuda/fattn-mma-f16.cuh b/ggml/src/ggml-cuda/fattn-mma-f16.cuh index 7aaf89da0c52..e9dd9fd3e93d 100644 --- a/ggml/src/ggml-cuda/fattn-mma-f16.cuh +++ b/ggml/src/ggml-cuda/fattn-mma-f16.cuh @@ -276,8 +276,10 @@ static constexpr __host__ __device__ fattn_mma_config ggml_cuda_fattn_mma_get_co // RDNA3 WMMA operands are mirrored, so keeping Q in registers for head size 256 spills heavily. // Stream Q from shared memory and use a smaller KV batch to reduce register pressure. K and V are loaded in one // batch each: with several batches some compilers move the WMMAs of a batch past the loads of the next one and spill. - // Only for 2-4 Q heads per KV head: with 8 this config is not faster than the default one. - if (ncols2 >= 2 && ncols2 <= 4) { + // Also used for 8 Q heads per KV head (Qwen3.6/Qwen4 full attention, 16 Q / 2 KV heads): the default config spills there + // (flash_attn_ext_f16<256,256,*,8>: 256 VGPR + 1196 B scratch, 529 spilled VGPRs). With this config the spill is gone + // (207 VGPR, no scratch); measured on a D256 GQA8 kernel 11437 -> 8559 us, pp512@d32768 +10.2% on Qwen3.6. + if (ncols2 >= 2 && ncols2 <= 8) { GGML_CUDA_FATTN_MMA_CONFIG_CASE(256, 256, 64, 256, 2, 32, 128, 128, 64, 1, false); }