Skip to content

hip : tune D256 MMA FlashAttention on RDNA3 - #31746

Draft
ravel7524 wants to merge 2 commits into
ggml-org:masterfrom
ravel7524:hip-fattn-mma-d256-rdna3
Draft

ravel7524 wants to merge 2 commits into
ggml-org:masterfrom
ravel7524:hip-fattn-mma-d256-rdna3

Conversation

@ravel7524

@ravel7524 ravel7524 commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This PR tunes D256 MMA FlashAttention on RDNA3 and RDNA3.5 for 64-column tiles with ncols2 of 2 or 4. It streams Q from shared memory, halves the KV block from 64 to 32, and adds WMMA scheduling barriers. The config lookup now takes ncols2 to distinguish tiles with the same total width.

This revision restores master's single-batch K and V loads. nbatch_K2 and nbatch_V2 are both 128 half2 elements, covering all 256 values. A ROCm 7.2.4 run suggested a slowdown with the previous revision's smaller K and V batches.

Additional Information

Benchmark Summary

Radeon PRO W7800 (gfx1100), HIP, F16 K/V, 2,240 query tokens. Operator time relative to master 44f91a02b on the same toolchain (lower is faster). Geomean across 4,096, 32,768, and 131,072 KV positions, with three runs per build.

Toolchain GQA 2 GQA 4 GQA 6
ROCm 7.2.4 0.755× 0.836× 0.783×
ROCm 10.1 0.699× 0.823× 0.695×

GQA 6 matches the attention shape of Qwen3.5/3.6/3.8 27B, and GQA 2 represents Gemma 3-class models. The GQA 8 tile (ncols2 = 8) uses master's configuration.

On ROCm 7.2.4, the <32,2> kernel went from 558 VGPR spills and 1,316 B of scratch per lane to zero for both. Some SGPR spills remain.

Perplexity

On ROCm 10.1, llama-perplexity was run on the wikitext-2 test set with F16 KV cache and -c 8192 -b 2240 -ub 2240 -fa on -ngl 999. The -ub 2240 setting makes every prompt batch use the changed kernel. KL divergence is measured against master at the same -ub 2240 settings; the master -ub 512 row shows the effect of changing ubatch size. Master compared with itself was bit-identical, and each result reproduced exactly in a second run.

Model Run PPL Mean KLD Median KLD 99th-percentile KLD Same top-p
Qwen3.8-27B Q8_0 (GQA 6; 6 × 8,192 tokens) Master, -ub 512 6.2910 ± 0.1061 0.005536 ± 0.001597 0.000197 0.006863 98.860 ± 0.068%
Qwen3.8-27B Q8_0 (GQA 6; 6 × 8,192 tokens) PR, -ub 2240 6.2799 ± 0.1057 0.007312 ± 0.001961 0.000199 0.007340 98.844 ± 0.068%
gemma-3-4b-it Q8_0 (GQA 2; 2 × 8,192 tokens) Master, -ub 512 10.6987 ± 0.4079 0.002438 ± 0.000210 0.000330 0.03626 98.523 ± 0.133%
gemma-3-4b-it Q8_0 (GQA 2; 2 × 8,192 tokens) PR, -ub 2240 10.7312 ± 0.4095 0.002290 ± 0.000197 0.000334 0.03264 98.523 ± 0.133%

Requirements

  • Yes, I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, AI wrote the Code, helped Benchmarking and Fixing, I understand every line and can explain all changes

@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Nov 5, 2026
@ravel7524

ravel7524 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Fixed the Merge conflict while preserving D40/D72 padding and the D256 tuning.

The Benchmarks are run on W7800, Qwen3.8-27B Q8_0, F16 KV, prefill at 32k depth, batch/ubatch 2240:

ROCm Master PR Throughput ratio
10.1 512.9 t/s 576.8 t/s 1.125x
7.2.4 516.8 t/s 557.2 t/s 1.079x

abeloin added a commit to abeloin/llama.cpp-mix that referenced this pull request Nov 24, 2026
…8 jetons, fusions delta-net / porte d'expert partagé, IQ2/IQ3, FA indépendante des rangées masquées (rafasmour/llama.cpp-RDNA3, master @ 91c1855, commits 95bcd0c..e3a7e9c)

Commits cherry-pickés (-x, auteur d'origine) sur import/rdna3-sel-r3 puis
merge --no-ff. cefeb9b (ggml-org#43) vide ici (changement déjà présent). Ports
de PR amont ouvertes : 0fffeee (ggml-org#61 ← ggml-org ggml-org#31746), 855e1bf (ggml-org#75
← ggml-org ggml-org#31761). 7a0f09e et e3a7e9c : tests/test-backend-ops.cpp
côté mix. ggml-org#108 écarté (dépend de ggml_cuda_mmvq_q8_1_args, plus loin dans
la pile).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QBjnvFeJ4P7Jp71oC6pzWf

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant