Repository navigation
HIP: fattn-mma: use fp32 accumulation on MFMA devices - #28576
Merged
Merged
Conversation
Contributor
Author
|
|
Contributor
Author
|
theres some weirdness in the tg perf results in the table above, will recheck that. |
Contributor
Author
|
reran the benchmarks and updated post, looks good now |
JohannesGaessler
approved these changes
Sep 11, 2026
Contributor
There was a problem hiding this comment.
Performance
| GPU | Model | Microbatch size | Test | t/s b10837 | t/s ca29eaf | Speedup |
|---|---|---|---|---|---|---|
| MI100 | deepseek2 16B Q4_0 | 1 | pp1024@d32768 | 88.76 | 89.08 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 2 | pp1024@d32768 | 95.21 | 95.18 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 4 | pp1024@d32768 | 125.38 | 125.61 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 8 | pp1024@d32768 | 194.61 | 194.04 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 16 | pp1024@d32768 | 254.62 | 254.30 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 32 | pp1024@d32768 | 310.44 | 310.21 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 64 | pp1024@d32768 | 328.14 | 327.70 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 128 | pp1024@d32768 | 373.90 | 373.37 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 256 | pp1024@d32768 | 407.12 | 406.58 | 1.00 |
| MI100 | deepseek2 16B Q4_0 | 512 | pp1024@d32768 | 427.02 | 426.73 | 1.00 |
| MI100 | gemma 2B Q4_0 | 1 | pp1024@d32768 | 214.51 | 212.63 | 0.99 |
| MI100 | gemma 2B Q4_0 | 2 | pp1024@d32768 | 362.33 | 358.09 | 0.99 |
| MI100 | gemma 2B Q4_0 | 4 | pp1024@d32768 | 508.54 | 504.71 | 0.99 |
| MI100 | gemma 2B Q4_0 | 8 | pp1024@d32768 | 727.70 | 724.42 | 1.00 |
| MI100 | gemma 2B Q4_0 | 16 | pp1024@d32768 | 1327.08 | 1356.96 | 1.02 |
| MI100 | gemma 2B Q4_0 | 32 | pp1024@d32768 | 2271.79 | 2328.55 | 1.02 |
| MI100 | gemma 2B Q4_0 | 64 | pp1024@d32768 | 2943.51 | 3013.69 | 1.02 |
| MI100 | gemma 2B Q4_0 | 128 | pp1024@d32768 | 3479.70 | 3572.91 | 1.03 |
| MI100 | gemma 2B Q4_0 | 256 | pp1024@d32768 | 3973.97 | 4113.12 | 1.04 |
| MI100 | gemma 2B Q4_0 | 512 | pp1024@d32768 | 4148.78 | 4306.51 | 1.04 |
| MI100 | llama 1B Q4_0 | 1 | pp1024@d32768 | 298.30 | 299.73 | 1.00 |
| MI100 | llama 1B Q4_0 | 2 | pp1024@d32768 | 469.37 | 471.36 | 1.00 |
| MI100 | llama 1B Q4_0 | 4 | pp1024@d32768 | 871.91 | 875.21 | 1.00 |
| MI100 | llama 1B Q4_0 | 8 | pp1024@d32768 | 1207.45 | 1244.28 | 1.03 |
| MI100 | llama 1B Q4_0 | 16 | pp1024@d32768 | 1994.46 | 2192.03 | 1.10 |
| MI100 | llama 1B Q4_0 | 32 | pp1024@d32768 | 2990.03 | 3088.38 | 1.03 |
| MI100 | llama 1B Q4_0 | 64 | pp1024@d32768 | 3706.98 | 4129.49 | 1.11 |
| MI100 | llama 1B Q4_0 | 128 | pp1024@d32768 | 4444.14 | 4812.09 | 1.08 |
| MI100 | llama 1B Q4_0 | 256 | pp1024@d32768 | 4952.48 | 5392.54 | 1.09 |
| MI100 | llama 1B Q4_0 | 512 | pp1024@d32768 | 5133.79 | 5606.22 | 1.09 |
| MI100 | llama 8B Q4_0 | 1 | pp1024@d32768 | 84.11 | 84.70 | 1.01 |
| MI100 | llama 8B Q4_0 | 2 | pp1024@d32768 | 138.13 | 139.26 | 1.01 |
| MI100 | llama 8B Q4_0 | 4 | pp1024@d32768 | 201.31 | 201.70 | 1.00 |
| MI100 | llama 8B Q4_0 | 8 | pp1024@d32768 | 324.43 | 332.78 | 1.03 |
| MI100 | llama 8B Q4_0 | 16 | pp1024@d32768 | 547.89 | 589.34 | 1.08 |
| MI100 | llama 8B Q4_0 | 32 | pp1024@d32768 | 830.59 | 914.65 | 1.10 |
| MI100 | llama 8B Q4_0 | 64 | pp1024@d32768 | 958.53 | 1054.09 | 1.10 |
| MI100 | llama 8B Q4_0 | 128 | pp1024@d32768 | 1054.31 | 1164.57 | 1.10 |
| MI100 | llama 8B Q4_0 | 256 | pp1024@d32768 | 1096.26 | 1213.88 | 1.11 |
| MI100 | llama 8B Q4_0 | 512 | pp1024@d32768 | 1143.41 | 1267.47 | 1.11 |
Contributor
Author
|
@ggml-org/ggml-cuda could i have a second review? |
am17an
approved these changes
Sep 14, 2026
dzannotti
added a commit
to halo-box/llama.cpp
that referenced
this pull request
Sep 15, 2026
* upstream/master: (72 commits) HIP: Enable AllReduce for ROCm (ggml-org#27825) opencl: choose the MoE expert matmul by batch size for speculative decoding/MTP (ggml-org#27637) ci: build MUSA for only 1 arch (ggml-org#28944) docs: Rule of thumb for AI review time [no ci] (ggml-org#28945) rpc : hash-cache only weights (ggml-org#28789) cuda: support row-contiguous SUM_ROWS (ggml-org#26308) models : move build_arch_graph() after graph() template specialization (ggml-org#28934) vulkan: support sparse Flash Attention (ggml-org#28105) OpenVINO: optimize stateful decode and GPU MoE inference (ggml-org#28638) opencl: add generic ssm_scan (ggml-org#28881) ci: bump kleidiai runners from 22.04 to 24.04 (ggml-org#28885) metal : add FA kernels for HSK=96, HSV=64 (MiniCPM3) (ggml-org#28599) ci: Bump CUDA Windows x64 builds to 13.4.1 (ggml-org#28930) ci : fix android release (ggml-org#28936) cuda : enable i16 and i32 for DUP (ggml-org#28897) cmake : use PROJECT_SOURCE_DIR instead of CMAKE_SOURCE_DIR (ggml-org#28771) webui: stop re-probing disabled /tools endpoint on every message (ggml-org#28646) ci : reuse build tag name when used instead of safe one (ggml-org#28911) CI: hip-quality-check: ignore spill added in bfdc321 (ggml-org#28909) HIP: fattn-mma: use fp32 accumulation on MFMA devices (ggml-org#28576) ...
fencerJP
pushed a commit
to fencerJP/llama-apu
that referenced
this pull request
Sep 16, 2026
use fp32 accumulators in fattn-mma on CDNA
quimmedes
pushed a commit
to quimmedes/cafe-llama.cpp
that referenced
this pull request
Sep 16, 2026
use fp32 accumulators in fattn-mma on CDNA
1 task done
roverdrubber
added a commit
to roverdrubber/llama.cpp
that referenced
this pull request
Oct 15, 2026
…etune kernel selection Three numeric defects made long prompts return NaN logits on an RX 7900 XTX. The tile and vector kernels summed the V-weighted softmax numerator in F16, and that sum is unnormalized: over a long KV cache it saturates and then overflows. Both now accumulate in F32, including the shared buffer the vector kernel combines through. The MMA kernel had the same problem twice over: RDNA3 used an F16 accumulator for every head size except 80 and 112, and even the F32 path writes the unnormalized sum into F16 shared memory before dividing by the row sum. RDNA3 now uses the head-80 tile layout everywhere, and an F32 accumulator is divided by its row sum before that write, with the row sum folded back through the meta data. Upstream carries the second half of that defect too. Kernel selection on RDNA3 with a quantized KV cache at head size 256 was also wrong for the small batches speculative decoding verifies with. The vector kernel's cost grows with batch times GQA ratio while the tile kernel packs the GQA columns, so the vector kernel now only runs below a product of 6 (below a GQA ratio of 16 for a single token) and WMMA only takes over past 32 packed columns instead of 16. Measured with test-backend-ops perf over 85 shapes (GQA 1 to 16, batch 1 to 8, 16K to 131K cells, q8_0 and q4_0): 48.1 ms to 41.8 ms in total, no shape more than 1 percent worse than before, and within 0.5 percent of the best kernel per shape. A batch of two is 1.3 to 2.8 times faster; the 35B's verify batch is 10 percent faster at 65K and beyond. Also ports the upstream flash-attention work this sits on: the kernel refactor (ggml-org#28079, hand-merged to keep the TurboQuant KV types and their fallback), the head-256 and gfx1201 tuning (ggml-org#28102), and the MFMA F32 accumulator (ggml-org#28576). FLASH_ATTN_EXT passes on gfx1100 (3975/3975 at the tip of this series, with the regression cases the last commit adds), and the 35B answers a 112K-token prompt with finite logits. The 27B's deep-context prefill costs 7 to 14 percent more than the saturating F16 path it replaces. Assisted-by: Claude Opus 5
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.
Overview
MFMA dose not support fp16 accumulation, mma.h implements a post V_MFMA downcast path, wich is used for VKQ, but we can gain some performance and also some minor accuracy (still downconverted for smem later) by skipping that.
This increased VGPR pressure and i had to retune the 64,64,64 case, as it saw a big perf drop.
Its possible some of the others could also be retuned for better performance.
performance
gfx908 @ 190 W
Requirements