Skip to content

vulkan: skip unneeded MoE work in mul_mm coopmat1 path - #25483

Merged
ggerganov merged 1 commit into
ggml-org:masterfrom
fish-jiang:intel/xe-moe-skip-only
Sep 17, 2026
Merged

ggerganov merged 1 commit into
ggml-org:masterfrom
fish-jiang:intel/xe-moe-skip-only

Conversation

@fish-jiang

@fish-jiang fish-jiang commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Overview

For MUL_MAT_ID on the coopmat1 path, each workgroup's real row count (_ne1 - ic*BN) is frequently less than the full BN/WN tile once expert routing is accounted for. This adds required_work_items/required_warp_c bounds computed right after the existing "workgroup has no work" early-return, and uses them to skip the B-matrix memory load and the coopmat compute loop for subgroups/warps beyond what's actually needed for that workgroup.

Scope note: this is split out of #24407

Performance (Panther Lake B390 + Windows OS)

BEFORE:
C:\Users\dungeon\Desktop\fish\llama.cpp\build\bin\Release>llama-bench.exe -p 8192 -n 0 -r 2 -fa 0,1 --delay 10 -ngl 99 -m C:\Users\dungeon\Desktop\models\Qwen3.5-35B-A3B-Q4_K_M\Qwen3.5-35B-A3B-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\gpt-oss-20b-Q4_K_M\gpt-oss-20b-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\gemma-4-26B-A4B-it-UD-Q4_K_M\gemma-4-26B-A4B-it-UD-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\Qwen3-Coder-30B-A3B-Instruct-Q4_K_M\Qwen3-Coder-30B-A3B-Instruct-Q4_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = Intel(R) Arc(TM) B390 GPU (Intel Corporation) | uma: 1 | fp16: 1 | bf16: 0 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat

model size params backend ngl fa test t/s
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 0 pp8192 576.32 ± 32.67
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 1 pp8192 464.50 ± 5.42
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp8192 465.52 ± 1.08
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp8192 597.56 ± 4.14
gemma4 26B.A4B Q4_K - Medium 15.70 GiB 25.23 B Vulkan 99 0 pp8192 627.01 ± 4.07
gemma4 26B.A4B Q4_K - Medium 15.70 GiB 25.23 B Vulkan 99 1 pp8192 413.44 ± 0.32
qwen3moe 30B.A3B Q4_K - Medium 17.28 GiB 30.53 B Vulkan 99 0 pp8192 391.50 ± 6.02
qwen3moe 30B.A3B Q4_K - Medium 17.28 GiB 30.53 B Vulkan 99 1 pp8192 237.50 ± 0.03

build: bec4772 (9913)

AFTER:
C:\Users\dungeon\Desktop\fish\llama.cpp\build_moe\bin\Release>llama-bench.exe -p 8192 -n 0 -r 2 -fa 0,1 --delay 10 -ngl 99 -m C:\Users\dungeon\Desktop\models\Qwen3.5-35B-A3B-Q4_K_M\Qwen3.5-35B-A3B-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\gpt-oss-20b-Q4_K_M\gpt-oss-20b-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\gemma-4-26B-A4B-it-UD-Q4_K_M\gemma-4-26B-A4B-it-UD-Q4_K_M.gguf,C:\Users\dungeon\Desktop\models\Qwen3-Coder-30B-A3B-Instruct-Q4_K_M\Qwen3-Coder-30B-A3B-Instruct-Q4_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = Intel(R) Arc(TM) B390 GPU (Intel Corporation) | uma: 1 | fp16: 1 | bf16: 0 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat

model size params backend ngl fa test t/s
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 0 pp8192 742.77 ± 53.14
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 1 pp8192 575.90 ± 0.43
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp8192 485.12 ± 2.03
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp8192 620.07 ± 5.52
gemma4 26B.A4B Q4_K - Medium 15.70 GiB 25.23 B Vulkan 99 0 pp8192 713.68 ± 0.20
gemma4 26B.A4B Q4_K - Medium 15.70 GiB 25.23 B Vulkan 99 1 pp8192 465.10 ± 9.28
qwen3moe 30B.A3B Q4_K - Medium 17.28 GiB 30.53 B Vulkan 99 0 pp8192 440.88 ± 1.83
qwen3moe 30B.A3B Q4_K - Medium 17.28 GiB 30.53 B Vulkan 99 1 pp8192 254.77 ± 0.53

build: f63220399 (9914)

Requirements

I have read and agree with the contributing guidelines
AI usage disclosure: YES, used claude code, then lots of manual review/tweaking.

@github-actions github-actions Bot added Vulkan Issues specific to the Vulkan backend ggml changes relating to the ggml tensor library for machine learning labels Jul 9, 2026
@jeffbolznv

Copy link
Copy Markdown
Contributor

I ran this locally on RTX 5090 and it's actually a bit slower in some models:

before

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0 -p 512 -r 10 --prio 1 -m c:\models\Qwen_Qwen3-30B-A3B-Q2_K.gguf -m c:\models\gpt-oss-20b-mxfp4.gguf -m c:\models\granite-3.0-3b-a800m-instruct-Q8_0.gguf -m c:\models\Moonlight-16B-A3B-Instruct-Q4_K_M.gguf -m c:\models\Nemotron-3-Nano-30B-A3B-Q4_K_M.gguf -m c:\models\Qwen3.6-35B-A3B-UD-Q3_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = NVIDIA GeForce RTX 5090 (NVIDIA) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat
| model                          |       size |     params | backend    | ngl |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |   1 |           pp512 |      7627.01 ± 73.94 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |   1 |           pp512 |     7094.69 ± 191.14 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |   1 |           pp512 |    20084.83 ± 692.41 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |   1 |           pp512 |    10922.15 ± 831.74 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |   1 |           pp512 |      6773.15 ± 43.97 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |   1 |           pp512 |      5804.03 ± 42.00 |

after

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0 -p 512 -r 10 --prio 1 -m c:\models\Qwen_Qwen3-30B-A3B-Q2_K.gguf -m c:\models\gpt-oss-20b-mxfp4.gguf -m c:\models\granite-3.0-3b-a800m-instruct-Q8_0.gguf -m c:\models\Moonlight-16B-A3B-Instruct-Q4_K_M.gguf -m c:\models\Nemotron-3-Nano-30B-A3B-Q4_K_M.gguf -m c:\models\Qwen3.6-35B-A3B-UD-Q3_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = NVIDIA GeForce RTX 5090 (NVIDIA) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat
| model                          |       size |     params | backend    | ngl |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |   1 |           pp512 |      7897.99 ± 73.54 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |   1 |           pp512 |      6354.79 ± 49.52 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |   1 |           pp512 |    20886.09 ± 162.52 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |   1 |           pp512 |    10712.83 ± 107.95 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |   1 |           pp512 |     5748.97 ± 506.00 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |   1 |           pp512 |      5494.21 ± 35.12 |

This is not necessarily a blocker since NVIDIA devices should be using the coopmat2 path. I didn't debug why it's slower, but my first guess is that the branch prevents the A and B loads from happening at the same time.

I got a lot of mileage out of this kind of optimization in the coopmat2 path, but there it also changed how the loads and calculations are spread across warps. It might be beneficial to do something like that here, too, but GLSL is not the ideal language for it since it doesn't support writing templated functions.

@fish-jiang

fish-jiang commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I ran this locally on RTX 5090 and it's actually a bit slower in some models:

before

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0 -p 512 -r 10 --prio 1 -m c:\models\Qwen_Qwen3-30B-A3B-Q2_K.gguf -m c:\models\gpt-oss-20b-mxfp4.gguf -m c:\models\granite-3.0-3b-a800m-instruct-Q8_0.gguf -m c:\models\Moonlight-16B-A3B-Instruct-Q4_K_M.gguf -m c:\models\Nemotron-3-Nano-30B-A3B-Q4_K_M.gguf -m c:\models\Qwen3.6-35B-A3B-UD-Q3_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = NVIDIA GeForce RTX 5090 (NVIDIA) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat
| model                          |       size |     params | backend    | ngl |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |   1 |           pp512 |      7627.01 ± 73.94 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |   1 |           pp512 |     7094.69 ± 191.14 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |   1 |           pp512 |    20084.83 ± 692.41 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |   1 |           pp512 |    10922.15 ± 831.74 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |   1 |           pp512 |      6773.15 ± 43.97 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |   1 |           pp512 |      5804.03 ± 42.00 |

after

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0 -p 512 -r 10 --prio 1 -m c:\models\Qwen_Qwen3-30B-A3B-Q2_K.gguf -m c:\models\gpt-oss-20b-mxfp4.gguf -m c:\models\granite-3.0-3b-a800m-instruct-Q8_0.gguf -m c:\models\Moonlight-16B-A3B-Instruct-Q4_K_M.gguf -m c:\models\Nemotron-3-Nano-30B-A3B-Q4_K_M.gguf -m c:\models\Qwen3.6-35B-A3B-UD-Q3_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = NVIDIA GeForce RTX 5090 (NVIDIA) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: KHR_coopmat
| model                          |       size |     params | backend    | ngl |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |   1 |           pp512 |      7897.99 ± 73.54 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |   1 |           pp512 |      6354.79 ± 49.52 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |   1 |           pp512 |    20886.09 ± 162.52 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |   1 |           pp512 |    10712.83 ± 107.95 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |   1 |           pp512 |     5748.97 ± 506.00 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |   1 |           pp512 |      5494.21 ± 35.12 |

This is not necessarily a blocker since NVIDIA devices should be using the coopmat2 path. I didn't debug why it's slower, but my first guess is that the branch prevents the A and B loads from happening at the same time.

I got a lot of mileage out of this kind of optimization in the coopmat2 path, but there it also changed how the loads and calculations are spread across warps. It might be beneficial to do something like that here, too, but GLSL is not the ideal language for it since it doesn't support writing templated functions.

Thanks. I ran this on an Intel discrete GPU (B70) and saw the perf gain as well. It seems that on Intel GPUs, the branching cost is lower than the benefit it provides.
Before:
C:\Users\fish\Desktop\test\base\Release>llama-bench.exe -p 512 -n 0 -r 10 -fa 0,1 --delay 10 -ngl 99 -m C:\kernel\model\Qwen3.5-35B-A3B-Q4_K_M.gguf,C:\kernel\model\gpt-oss-20b-Q4_K_M.gguf

model size params backend ngl fa test t/s
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 0 pp512 1916.04 ± 22.19
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 1 pp512 1878.14 ± 26.70
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 2860.00 ± 42.52
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 2825.42 ± 40.10

build: bec4772 (9913)

After:
C:\Users\fish\Desktop\test\moe\Release>llama-bench.exe -p 512 -n 0 -r 10 -fa 0,1 --delay 10 -ngl 99 -m C:\kernel\model\Qwen3.5-35B-A3B-Q4_K_M.gguf,C:\kernel\model\gpt-oss-20b-Q4_K_M.gguf

model size params backend ngl fa test t/s
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 0 pp512 2392.66 ± 24.13
qwen35moe 35B.A3B Q4_K - Medium 20.49 GiB 34.66 B Vulkan 99 1 pp512 2355.04 ± 26.41
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 3047.08 ± 36.56
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 3032.09 ± 28.48

build: f63220399 (9914)

@fish-jiang

Copy link
Copy Markdown
Contributor Author

I ran this locally on a Radeon RX 7900 XT and saw some gain, though not as much as on the Intel GPU.

Before:
C:\Users\dungeon\Desktop\test\llama.cpp\build\bin\Release>llama-bench.exe -p 1024,8192 -n 0 -r 3 -fa 0,1 --delay 10 --device Vulkan0 -m c:\Users\dungeon\Downloads\Qwen3.6-35B-A3B-UD-Q2_K_XL.gguf,c:\Users\dungeon\Downloads\Qwen3-30B-A3B-Q2_K.gguf,c:\Users\dungeon\Downloads\gemma-4-26B-A4B-it-UD-Q3_K_M.gguf,c:\Users\dungeon\Downloads\gpt-oss-20b-Q4_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = AMD Radeon RX 7900 XT (AMD proprietary driver) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 64 | shared memory: 32768 | int dot: 1 | matrix cores: KHR_coopmat

model size params backend ngl fa dev test t/s
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 0 Vulkan0 pp1024 2691.77 ± 17.32
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 0 Vulkan0 pp8192 2496.92 ± 15.19
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 1 Vulkan0 pp1024 2693.58 ± 10.68
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 1 Vulkan0 pp8192 2460.69 ± 4.70
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 0 Vulkan0 pp1024 2802.48 ± 14.36
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 0 Vulkan0 pp8192 1905.07 ± 3.88
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 1 Vulkan0 pp1024 2826.51 ± 14.96
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 1 Vulkan0 pp8192 2006.66 ± 3.33
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 0 Vulkan0 pp1024 2847.31 ± 15.41
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 0 Vulkan0 pp8192 2666.88 ± 14.12
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 1 Vulkan0 pp1024 2567.78 ± 10.59
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 1 Vulkan0 pp8192 1278.31 ± 1.91
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 0 Vulkan0 pp1024 3544.41 ± 23.36
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 0 Vulkan0 pp8192 2755.74 ± 4.23
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 1 Vulkan0 pp1024 3773.29 ± 24.99
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 1 Vulkan0 pp8192 3313.23 ± 3.88

After:
C:\Users\dungeon\Desktop\test\llama.cpp-intel-xe-moe-skip-only\build\bin\Release>llama-bench.exe -p 1024,8192 -n 0 -r 3 -fa 0,1 --delay 10 --device Vulkan0 -m c:\Users\dungeon\Downloads\Qwen3.6-35B-A3B-UD-Q2_K_XL.gguf,c:\Users\dungeon\Downloads\Qwen3-30B-A3B-Q2_K.gguf,c:\Users\dungeon\Downloads\gemma-4-26B-A4B-it-UD-Q3_K_M.gguf,c:\Users\dungeon\Downloads\gpt-oss-20b-Q4_K_M.gguf
ggml_vulkan: Found 1 Vulkan devices:
ggml_vulkan: 0 = AMD Radeon RX 7900 XT (AMD proprietary driver) | uma: 0 | fp16: 1 | bf16: 1 | warp size: 64 | shared memory: 32768 | int dot: 1 | matrix cores: KHR_coopmat

model size params backend ngl fa dev test t/s
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 0 Vulkan0 pp1024 2864.21 ± 13.29
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 0 Vulkan0 pp8192 2663.42 ± 10.82
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 1 Vulkan0 pp1024 2866.73 ± 6.52
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan -1 1 Vulkan0 pp8192 2611.59 ± 2.62
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 0 Vulkan0 pp1024 2970.06 ± 12.61
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 0 Vulkan0 pp8192 1974.60 ± 4.33
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 1 Vulkan0 pp1024 3000.31 ± 17.10
qwen3moe 30B.A3B Q2_K - Medium 10.48 GiB 30.53 B Vulkan -1 1 Vulkan0 pp8192 2079.44 ± 3.03
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 0 Vulkan0 pp1024 3006.65 ± 20.61
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 0 Vulkan0 pp8192 2812.02 ± 7.55
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 1 Vulkan0 pp1024 2712.58 ± 15.41
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan -1 1 Vulkan0 pp8192 1310.71 ± 2.81
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 0 Vulkan0 pp1024 3582.46 ± 18.70
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 0 Vulkan0 pp8192 2770.81 ± 3.91
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 1 Vulkan0 pp1024 3830.70 ± 26.70
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan -1 1 Vulkan0 pp8192 3339.19 ± 1.94

@fish-jiang

Copy link
Copy Markdown
Contributor Author

@0cc4m , Could you please help review this PR? It has a general win on Intel GPUs, and based on the perf data in #25356, it also seems to have a win on AMD.

@0cc4m 0cc4m left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can measure neutral performance on Nvidia, and performance improvements on AMD. Looks good, thank you!

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 4, 2026
@fish-jiang

Copy link
Copy Markdown
Contributor Author

It seems this needs another approval from a maintainer. @jeffbolznv, could you please check the PR again?

@jeffbolznv

Copy link
Copy Markdown
Contributor

Is this still needed after #26686? If you rebase it is there still any perf gain?

@fish-jiang
fish-jiang force-pushed the intel/xe-moe-skip-only branch from 4ca667f to 0d910cd Compare September 7, 2026 03:24
@jeffbolznv

Copy link
Copy Markdown
Contributor

Is this still needed after #26686? If you rebase it is there still any perf gain?

Nevermind, I thought part of this change was in the load_row_ids path. Reviewing now...

@0cc4m

0cc4m commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

It seems this needs another approval from a maintainer. @jeffbolznv, could you please check the PR again?

It does not, I marked it as merge ready, it's in the queue.

@jeffbolznv

Copy link
Copy Markdown
Contributor

I'm not completely happy with the state of this one, let me see if I can find a reasonable improvement to suggest.

@0cc4m 0cc4m removed the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 7, 2026
load_a_to_shmem(pos_a, loadr_a, loadc_a + l, ir * BM + loadc_a + l, block, end_k);
}
#ifdef MUL_MAT_ID
if (gl_LocalInvocationID.x < required_work_items) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird to have this outside the loop, and then if the loop does multiple iterations the iterations after the first are unnecessary. But putting it inside the loop would mean the compiler can't batch the loads, so that's not great either. Also, this prevents batching with the A loads (the issue I had previously mentioned). All together this makes me feel like this is not the right way to go about this change.

My best suggestion is still to do something similar to what the coopmat2 shader does - check if the number of rows is <= 1/2 or <= 1/4 of BN and have a specialized code path for each of those, where the B load is fully spread across all invocations, and the A load is in the same branch so it can be batched with the B loads.

@fish-jiang fish-jiang Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion, @jeffbolznv.
I rebased the code and used Claude to make code changes similar to what the coopmat2 shader does. The changes are available here: fish-jiang@8f7945f
Could you please help check any implementation issue?

Below are my performance test results on the Intel B70 and AMD Radeon RX 7900 XT:

  • Intel B70: Noticeable performance drop (~11% for Qwen3.6_35B_A3B) for some models compared to this PR.
  • AMD RX 7900 XT: Flat performance data.

Intel B70
base build: 7a46b4b72 (10831)
llama-bench.exe -p 512 -n 0 -r 5 -fa 0,1 --delay 10 -ngl 99 -m C:\kernel\model\gpt-oss-20b-Q4_K_M.gguf,C:\Users\gta\Downloads\model\gemma-4-26B-A4B-it-UD-Q4_K_M.gguf,C:\kernel\model\Qwen3.6-35B-A3B-UD-Q4_K_M.gguf

model size params backend ngl fa test t/s
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 3040.26 ± 50.97
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 3066.65 ± 30.87
gemma4 26B.A4B Q4_K - Medium 15.77 GiB 25.23 B Vulkan 99 0 pp512 2700.69 ± 40.67
gemma4 26B.A4B Q4_K - Medium 15.77 GiB 25.23 B Vulkan 99 1 pp512 2374.27 ± 25.83
qwen35moe 35B.A3B Q4_K - Medium 20.60 GiB 34.66 B Vulkan 99 0 pp512 2157.81 ± 20.31
qwen35moe 35B.A3B Q4_K - Medium 20.60 GiB 34.66 B Vulkan 99 1 pp512 2121.66 ± 43.77

This PR:

 model                                 size     params backend     ngl  fa            test                  t/s
gpt-oss 20B Q4_K - Medium        10.81 GiB    20.91 B Vulkan      99   0           pp512      3241.69 ± 72.20
gpt-oss 20B Q4_K - Medium        10.81 GiB    20.91 B Vulkan      99   1           pp512      3306.12 ± 19.81
gemma4 26B.A4B Q4_K - Medium    15.77 GiB    25.23 B Vulkan      99   0           pp512      3133.23 ± 84.52
gemma4 26B.A4B Q4_K - Medium    15.77 GiB    25.23 B Vulkan      99   1           pp512       2708.86 ± 9.08
qwen35moe 35B.A3B Q4_K - Medium  20.60 GiB    34.66 B Vulkan      99   0           pp512      2668.74 ± 30.60
qwen35moe 35B.A3B Q4_K - Medium  20.60 GiB    34.66 B Vulkan      99   1           pp512      2626.17 ± 21.98

commit: fish-jiang@8f7945f:

model                                 size     params backend     ngl  fa            test                  t/s
gpt-oss 20B Q4_K - Medium        10.81 GiB    20.91 B Vulkan      99   0           pp512      3314.72 ± 64.80
gpt-oss 20B Q4_K - Medium        10.81 GiB    20.91 B Vulkan      99   1           pp512      3363.04 ± 34.97
gemma4 26B.A4B Q4_K - Medium    15.77 GiB    25.23 B Vulkan      99   0           pp512      2960.98 ± 54.47
gemma4 26B.A4B Q4_K - Medium    15.77 GiB    25.23 B Vulkan      99   1           pp512      2565.53 ± 23.82
qwen35moe 35B.A3B Q4_K - Medium  20.60 GiB    34.66 B Vulkan      99   0           pp512      2357.85 ± 24.48
qwen35moe 35B.A3B Q4_K - Medium  20.60 GiB    34.66 B Vulkan      99   1           pp512      2325.59 ± 26.90

AMD RX 7900 XT
Base

model size params backend ngl fa test t/s
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 0 pp512 2999.94 ± 50.29
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 1 pp512 3020.03 ± 72.54
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 3653.29 ± 84.19
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 3755.54 ± 31.25
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 0 pp512 2798.03 ± 43.30
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 1 pp512 2817.48 ± 60.68

This PR:

model size params backend ngl fa test t/s
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 0 pp512 3162.40 ± 59.93
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 1 pp512 3184.39 ± 63.63
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 3714.91 ± 63.39
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 3814.46 ± 24.63
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 0 pp512 2961.78 ± 56.02
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 1 pp512 2986.64 ± 74.84

commit: fish-jiang@8f7945f:

model size params backend ngl fa test t/s
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 0 pp512 3167.27 ± 50.98
gemma4 26B.A4B Q3_K - Medium 11.84 GiB 25.23 B Vulkan 99 1 pp512 3202.26 ± 68.92
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 0 pp512 3705.70 ± 142.58
gpt-oss 20B Q4_K - Medium 10.81 GiB 20.91 B Vulkan 99 1 pp512 3800.70 ± 70.85
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 0 pp512 2941.44 ± 54.04
qwen35moe 35B.A3B Q2_K - Medium 11.70 GiB 35.51 B Vulkan 99 1 pp512 2919.02 ± 73.72

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the other comment, I didn't see much difference from this, so maybe the load batching is not a big deal, and you can stick with a simpler version. I think it would make sense for the if (gl_LocalInvocationID.x < required_work_items) { path to not do the loop if not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the other comment, I didn't see much difference from this, so maybe the load batching is not a big deal, and you can stick with a simpler version. I think it would make sense for the if (gl_LocalInvocationID.x < required_work_items) { path to not do the loop if not needed.

I tried moving the check inside the loop. Based on limited test data, the perf is roughly on par with the current state of this PR. And it would mean the compiler can't batch the loads — so maybe the current version is already a reasonable balance, and it keeps the code simple.

}
}
#ifdef MUL_MAT_ID
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
} else {
// zero sums on unused threads, to help register allocations
[[unroll]] for (uint i = 0; i < cms_per_row * cms_per_col; i++) {
sums[i] = coopmat<ACC_TYPE, gl_ScopeSubgroup, TM, TN, gl_MatrixUseAccumulator>(0.0f);
}
}

I spent some time looking at the different load_b changes, and they didn't make much of a difference on my system, and I eventually realized it's the if (warp_c < required_warp_c) { that's slowing things down. I didn't dig into the assembly, but I suspect what happens is the branch requires the compiler to keep the old sums alive across the branch and phi them together after, and it's better to just clear them to zero to indicate to the compiler that they aren't needed (might also be possible to set them to an uninitialized value, I didn't try it).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the code suggestion. I applied the change and got the perf data on Intel B70 and AMD RX 7900 XT. Looks like there is some slight perf regression.

Intel B70:

model fa before (This PR) t/s after (+ sums-zero suggestion) t/s delta
gpt-oss 20B Q4_K - Medium 0 3241.69 ± 72.20 3231.51 ± 54.04 -0.31%
gpt-oss 20B Q4_K - Medium 1 3306.12 ± 19.81 3278.87 ± 31.30 -0.82%
gemma4 26B.A4B Q4_K - Medium 0 3133.23 ± 84.52 3146.39 ± 36.20 +0.42%
gemma4 26B.A4B Q4_K - Medium 1 2708.86 ± 9.08 2718.60 ± 33.23 +0.36%
qwen35moe 35B.A3B Q4_K - Medium 0 2668.74 ± 30.60 2663.57 ± 12.53 -0.19%
qwen35moe 35B.A3B Q4_K - Medium 1 2626.17 ± 21.98 2575.35 ± 26.12 -1.94%

AMD RX 7900 XT:

model fa before (This PR) t/s after (+sums-zero suggestion) t/s delta
gemma4 26B.A4B Q3_K - Medium 0 3162.40 ± 59.93 3107.71 ± 61.89 -1.73%
gemma4 26B.A4B Q3_K - Medium 1 3184.39 ± 63.63 3105.13 ± 61.12 -2.49%
gpt-oss 20B Q4_K - Medium 0 3714.91 ± 63.39 3572.79 ± 66.95 -3.83%
gpt-oss 20B Q4_K - Medium 1 3814.46 ± 24.63 3667.72 ± 35.85 -3.85%
qwen35moe 35B.A3B Q2_K - Medium 0 2961.78 ± 56.02 2898.88 ± 56.39 -2.12%
qwen35moe 35B.A3B Q2_K - Medium 1 2986.64 ± 74.84 2914.54 ± 66.72 -2.41%

load_a_to_shmem(pos_a, loadr_a, loadc_a + l, ir * BM + loadc_a + l, block, end_k);
}
#ifdef MUL_MAT_ID
if (gl_LocalInvocationID.x < required_work_items) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I mentioned in the other comment, I didn't see much difference from this, so maybe the load batching is not a big deal, and you can stick with a simpler version. I think it would make sense for the if (gl_LocalInvocationID.x < required_work_items) { path to not do the loop if not needed.

@jeffbolznv

jeffbolznv commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

At this point, since the perf regression on NVIDIA is understood, I withdraw my objection. I have a slight preference for applying my suggestion of zeroing the accumulators, but I'll leave it to you and @0cc4m to decide what to do.

@fish-jiang

Copy link
Copy Markdown
Contributor Author

At this point, since the perf regression on NVIDIA is understood, I withdraw my objection. I have a slight preference for applying my suggestion of zeroing the accumulators, but I'll leave it to you and @0cc4m to decide what to do.

Thanks @jeffbolznv. Hi @0cc4m, what is your opinion?

@fish-jiang

Copy link
Copy Markdown
Contributor Author

Hi @0cc4m , could you please check if this is good to move forward, or let me know if there's anything else you'd like looked at first?

@0cc4m

0cc4m commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

I think we should just follow the AMD/Intel benchmark in this case, since those are the primary consumers of the shader. That would mean keeping it as is.

@fish-jiang

Copy link
Copy Markdown
Contributor Author

Thanks @0cc4m, then, is it ok to mark this PR as merge ready now? Or do I need to rebase it first?

@0cc4m 0cc4m added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants