Commit 30b900181 for llama.cpp

commit 30b900181be8193ff2e5267a28e9259eba5d1b0c
Author: ErsongWang <158176536+ErsongWang@users.noreply.github.com>
Date:   Tue Dec 1 22:47:26 2026 +0800

    CUDA/HIP: Use the MMA FA kernel for maskless attention on RDNA (#32930)

    * CUDA/HIP: Use the MMA FA kernel for maskless attention on RDNA

    Vision encoders commonly use non-causal, maskless attention. On RDNA GPUs, the MMA kernel runs faster than the tile kernel for this workload. However, the current AMD MMA path is only selected for GQA-optimized attention.

    Enable the wide MMA kernel (`ncols1 = 64`, `ncols2 = 1`) for maskless attention when `n_queries >= 128` on all AMD GPUs that support WMMA.

    Assisted-by: GitHub Copilot

    * Remove extra tests

    Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

    * CUDA: fix ALiBi slope in RDNA3 mma FA kernel

    Assisted-by: GitHub Copilot

    ---------

    Co-authored-by: uvos <devnull@uvos.xyz>
    Co-authored-by: Johannes Gäßler <johannesg@5d6.de>

diff --git a/ggml/src/ggml-cuda/fattn-mma-f16.cuh b/ggml/src/ggml-cuda/fattn-mma-f16.cuh
index 8c0e9328c..2cc338195 100644
--- a/ggml/src/ggml-cuda/fattn-mma-f16.cuh
+++ b/ggml/src/ggml-cuda/fattn-mma-f16.cuh
@@ -754,7 +754,7 @@ static __device__ __forceinline__ void flash_attn_ext_f16_iter(
                     const int i = i0 + T_C_KQ::get_j(l);
                     const int j = ((threadIdx.y / np)*cols_per_warp + T_C_KQ::get_i(l)) / ncols2;

-                    KQ_C[i00/(np*T_C_KQ::J)].x[l] += __half2float(tile_mask[j*(nbatch_fa + 8) + i]);
+                    KQ_C[i00/(np*T_C_KQ::J)].x[l] += slope*__half2float(tile_mask[j*(nbatch_fa + 8) + i]);
                 }
 #else
 #pragma unroll
@@ -1913,7 +1913,7 @@ static __global__ void flash_attn_ext_f16(
 #endif // __CUDA_ARCH__ == GGML_CUDA_CC_TURING

 #if defined(AMD_WMMA_AVAILABLE)
-    if (ncols1*ncols2 < 16 || ncols2 == 1 || DKQ > 256) {
+    if (ncols1*ncols2 < 16 || DKQ > 256) {
         NO_DEVICE_CODE;
         return;
     }
diff --git a/ggml/src/ggml-cuda/fattn.cu b/ggml/src/ggml-cuda/fattn.cu
index 3f2fb0193..f19ed6203 100644
--- a/ggml/src/ggml-cuda/fattn.cu
+++ b/ggml/src/ggml-cuda/fattn.cu
@@ -860,6 +860,12 @@ static best_fattn_kernel ggml_cuda_get_best_fattn_kernel(const int device, const
         return BEST_FATTN_KERNEL_MMA_F16;
     }

+    // Mask-less attention with many queries (e.g. vision encoders) cannot use the GQA tiles above.
+    // The WMMA kernel is still much faster than the tile kernel for this case:
+    if (amd_wmma_available(cc) && !mask && Q->ne[0] <= 256 && Q->ne[1] >= 128) {
+        return BEST_FATTN_KERNEL_MMA_F16;
+    }
+
     // If there are no tensor cores available, use the generic tile kernel:
     if (can_use_vector_kernel) {
         if (!ggml_is_quantized(K->type) && !ggml_is_quantized(V->type)) {
diff --git a/tests/test-backend-ops.cpp b/tests/test-backend-ops.cpp
index 5136668ff..648cf98d4 100644
--- a/tests/test-backend-ops.cpp
+++ b/tests/test-backend-ops.cpp
@@ -16067,6 +16067,8 @@ static std::vector<std::unique_ptr<test_case>> make_test_cases_perf() {
     test_cases.emplace_back(new test_flash_attn_ext(72, 72, 16, {1, 1}, 5776, 5776, false, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
     // Same non-causal vision-encoder shape for the other head size padded in-kernel by the CUDA MMA kernels
     test_cases.emplace_back(new test_flash_attn_ext(40, 40, 16, {1, 1}, 5776, 5776, false, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));
+    // Same for the Qwen2.5-VL head size
+    test_cases.emplace_back(new test_flash_attn_ext(80, 80, 16, {1, 1}, 4096, 4096, false, false, 0, 0, GGML_PREC_F32, GGML_TYPE_F16, GGML_TYPE_F16));

     // GCN sparse attention break-even for multiple query tokens.
     for (int64_t kv : {16384, 32768, 65536}) {