vulkan: int8 coopmat1 matmul implementation for AMD RDNA3 and RDNA4 - #27952
vulkan: int8 coopmat1 matmul implementation for AMD RDNA3 and RDNA4#279520cc4m wants to merge 50 commits into
Conversation
Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com>
Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com>
Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com>
Co-authored-by: Piotr Wilkin (ilintar) <piotr.wilkin@syndatis.com>
This reverts commit fbaefe0.
This reverts commit 7fabc25.
… set BK_STEP back to 4
| #define ACC_BIAS_F 12582912.0f | ||
| const bool USE_MAGIC_BIAS = WARP != 32; | ||
|
|
||
| // Accumulator row for element e: RDNA4 blocked, RDNA3/3.5 interleaved. |
There was a problem hiding this comment.
Are these layouts entirely based on the hardware definition, or do they depend partly on the compiler. For example, at some point I changed the NVIDIA compiler so the layout of a 16x16 matrix in four registers was permuted to 0,2,1,3 vs earlier compiler versions.
There was a problem hiding this comment.
I think it's a little bit of both. I have confirmed that Linux' RADV driver based this layout on what the hardware requires, so it should be fixed. I have also checked that at least RDNA3.5 uses the same layout on the Windows driver, and this branch does improve performance there too.
I think we can replace this with a generic solution once enough drivers support coopmat maintenance1.
| return; | ||
| } | ||
| #else | ||
| // L2-friendly workgroup scheduling |
There was a problem hiding this comment.
Would be interesting to separate out what perf gain is from this vs using int8. I've been tempted to do something like this for the other shaders, but with ubatch=512 still being the default it usually doesn't matter much (probably helps more for stable diffusion kind of workloads)
There was a problem hiding this comment.
Very small, hard to measure. Maybe 2% on RDNA3.5, but my Strix Halo laptop has a lot of thermal noise in benchmarks, so not sure. Might not be worth it. I didn't measure a difference on RDNA4.
|
Built b10760 + this pr. Using a RX7900XT (RDNA3) with RADV. Running usloth/Qwen3.8-27B-Q4_0.gguf before applying this PR I was seeing: after the same sort of prefill gets (+8% at start to +3% at end of prefill) There is too much variance in token gen to say anything. This has positive effects in a real use case. |
|
Apologies if this is not helpful / spam, but I have been running this on my 7900XTX for a few days and it has been a big improvement, so wanted to share a before / after llama bench run: master: this PR: |
Overview
Based on @pwilkin's ideas in #27493, I finally managed to get coopmat1 int8 to work with good performance on RDNA3 and 4. This new MMQ cm1 shader supports q4_0, q4_1, q5_0, q5_1, q8_0, q3_k, q4_k, q5_k, q6_k, mxfp4, nvfp4 and iq4_nl on RDNA3 and RDNA4. Strix Halo prompt processing performance is significantly improved, RDNA4 is more neutral, but MoE prompt processing is also up significantly. The shader is limited to those two architectures since it hardcodes their specific coopmat access patterns. More architectures can be added if needed.
q4_1, q5_1, q4_k, q5_k and nvfp4 on RDNA4 are disabled for MUL_MAT since they run slower than existing fp16 matmul. Additionally nvfp4 is also disabled for MUL_MAT_ID.
Benchmarks
AMD Radeon 8060S (Strix Halo, RDNA3.5)
MUL_MAT test-backend-ops perf geomean us (lower = better)
MUL_MAT_ID test-backend-ops perf geomean us (lower = better)
llama-bench pp512 t/s (higher = better)
AMD Radeon AI PRO R9700 (RDNA4)
MUL_MAT test-backend-ops perf geomean us (lower = better)
MUL_MAT_ID test-backend-ops perf geomean us (lower = better)
llama-bench pp512 t/s (higher = better)
Requirements