Skip to content

Vulkan: add hoisting support for row IDs and expert count in shaders - #26686

Open
ravel7524 wants to merge 3 commits into
ggml-org:masterfrom
ravel7524:vulkan-mmid-rowids-hoist
Open

Vulkan: add hoisting support for row IDs and expert count in shaders#26686
ravel7524 wants to merge 3 commits into
ggml-org:masterfrom
ravel7524:vulkan-mmid-rowids-hoist

Conversation

@ravel7524

@ravel7524 ravel7524 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR optimizes Vulkan MUL_MAT_ID for routed Mixture-of-Experts (MoE) prompt processing.

Each expert’s assigned token-row IDs are collected once and reused by the related GPU workgroups. Previously, every workgroup independently searched the routing table for the same rows.

This removes redundant routing work around the GEMM. Dense-model paths and token-generation/decode paths are unchanged.

Additional information

Hardware/software:

  • AMD Radeon PRO W7800 (gfx1100 / RDNA3)
  • RADV / Mesa 26.0.3-1ubuntu1; Vulkan device API 1.4.335
  • Schedule: A-B-A-B-A-B, with -r 5 per phase
  • Baseline A: optimization disabled
  • Candidate B: GGML_VK_MUL_MAT_ID_HOIST_ROW_IDS=1
  • Common options: `-ctk f16 -ctv f16 -fa on

Qwen3.6 35B-A3B Q4_K_M:

B/UB PP128 PP1024 PP4096 PP16384 PP32768 TG128
512/512 1145.8 → 1158.7 (+1.12%) 2236.2 → 2346.5 (+4.93%) 2125.5 → 2224.5 (+4.66%) 1838.2 → 1914.2 (+4.13%) 1561.7 → 1618.5 (+3.64%) 119.76 → 119.68 (-0.07%)
1024/1024 1131.1 → 1144.5 (+1.19%) 2701.0 → 2923.9 (+8.25%) 2577.7 → 2789.4 (+8.21%) 2164.4 → 2323.6 (+7.36%) 1813.6 → 1919.9 (+5.86%) 119.64 → 119.78 (+0.12%)
2048/2048 1137.7 → 1152.5 (+1.30%) 2706.4 → 2927.6 (+8.17%) 2780.7 → 3134.5 (+12.72%) 2315.4 → 2552.4 (+10.24%) 1804.3 → 1949.0 (+8.02%) 119.81 → 119.76 (-0.04%)
4096/4096 1140.5 → 1153.4 (+1.13%) 2707.9 → 2931.9 (+8.27%) 2676.5 → 3189.2 (+19.16%) 2240.2 → 2584.2 (+15.35%) 1719.7 → 1915.7 (+11.40%) 120.05 → 119.97 (-0.07%)
8192/8192 1137.8 → 1152.4 (+1.28%) 2710.6 → 2940.3 (+8.48%) 2683.3 → 3190.9 (+18.92%) 2040.0 → 2526.2 (+23.83%)* 1606.8 → 1898.8 (+18.17%) 119.73 → 119.78 (+0.04%)

Gemma 4 26B A4B IT Q8_0

B/UB PP128 PP1024 PP4096 PP16384 PP32768 TG128
512/512 1285.16 → 1303.25 (+1.41%) 2293.81 → 2386.78 (+4.05%) 2183.12 → 2266.86 (+3.84%) 1899.78 → 1957.54 (+3.04%) 1631.29 → 1676.90 (+2.80%) 106.39 → 106.61 (+0.20%)
1024/1024 1285.13 → 1303.47 (+1.43%) 2723.37 → 2901.48 (+6.54%) 2575.54 → 2733.97 (+6.15%) 2186.20 → 2293.09 (+4.89%) 1817.43 → 1889.73 (+3.98%) 106.61 → 106.63 (+0.02%)
2048/2048 1285.05 → 1304.53 (+1.52%) 2726.59 → 2900.06 (+6.36%) 2758.38 → 3020.89 (+9.52%) 2277.61 → 2450.40 (+7.59%) 1843.31 → 1949.91 (+5.78%) 106.51 → 106.72 (+0.19%)
4096/4096 1289.13 → 1303.39 (+1.11%) 2726.09 → 2906.08 (+6.60%) 2655.81 → 3045.56 (+14.68%) 2216.87 → 2481.25 (+11.93%) 1825.99 → 2002.14 (+9.65%) 106.42 → 106.74 (+0.30%)
8192/8192 1283.39 → 1302.33 (+1.48%) 2724.34 → 2899.07 (+6.41%) 2649.51 → 3038.06 (+14.67%) 2058.61 → 2459.16 (+19.46%) 1748.43 → 2020.54 (+15.56%) 106.57 → 106.74 (+0.15%)

Qwen3.6 35B-A3B UD Q6_K

B/UB PP128 PP1024 PP4096 PP16384 PP32768 TG128
512/512 1008.79 → 1018.57 (+0.97%) 2018.67 → 2102.30 (+4.14%) 1924.78 → 2000.29 (+3.92%) 1705.47 → 1757.72 (+3.06%) 1476.88 → 1524.26 (+3.21%) 114.96 → 115.09 (+0.11%)
1024/1024 1011.52 → 1018.31 (+0.67%) 2504.86 → 2690.49 (+7.41%) 2397.22 → 2562.28 (+6.89%) 2063.25 → 2183.05 (+5.81%) 1741.46 → 1827.73 (+4.95%) 115.02 → 115.01 (−0.01%)
2048/2048 1011.49 → 1019.47 (+0.79%) 2507.35 → 2688.94 (+7.24%) 2632.11 → 2942.17 (+11.78%) 2225.26 → 2439.22 (+9.62%) 1771.53 → 1903.82 (+7.47%) 115.00 → 115.19 (+0.17%)
4096/4096 1012.26 → 1019.85 (+0.75%) 2512.17 → 2690.97 (+7.12%) 2571.48 → 3043.98 (+18.37%) 2169.65 → 2493.93 (+14.95%) 1692.01 → 1881.37 (+11.19%) 115.17 → 115.16 (−0.01%)
8192/8192 1014.46 → 1021.24 (+0.67%) 2511.71 → 2697.61 (+7.40%) 2572.88 → 3038.68 (+18.10%) 1989.24 → 2457.97 (+23.56%) 1590.26 → 1871.92 (+17.71%) 115.20 → 115.12 (−0.07%)

Requirements

  • Yes, I have read and agree with the contributing guidelines
  • AI usage disclosure: YES, AI was used to help review the change and summarize benchmark results. I reviewed the final diff and can explain all code changes.

@sswtodo

sswtodo commented Aug 21, 2026

Copy link
Copy Markdown

FreeBSD 16, Mesa 26.2.0, 7900 xtx (RDNA3 gfx1100)

llama-cli --version
No such file or directory
version: 0.1.2-dev (build 10561, commit bacc09a5a)
built with Clang 22.1.8 for FreeBSD amd64

Qwen3.6-35B-A3B (MoE)

model backend batch test t/s (master) t/s (patched) delta (%)
qwen35moe 35B.A3B Q4_K - Medium Vulkan 1024 pp512 2948.47 3041.80 +3.17
qwen35moe 35B.A3B Q4_K - Medium Vulkan 1024 tg128 165.72 166.44 +0.43

Qwen3.8-27B (dense)

model backend batch test t/s (master) t/s (patched) delta (%)
qwen35 27B Q4_K - Medium Vulkan 512 pp512 858.32 859.46 +0.13
qwen35 27B Q4_K - Medium Vulkan 512 tg128 40.86 40.88 +0.05

@ravel7524 your patch is working properly, it gives 100 tok/s for MoE... nice !

@jeffbolznv

Copy link
Copy Markdown
Contributor

Please apply it to the coopmat2 path as well. I expect the gains will be small due tot he larger tile size, but probably still worth a bit and good for consistency.

@ravel7524

ravel7524 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

@jeffbolznv Thanks I agree it belongs in the coopmat2 path too.

I have no hardware with coopmat2 support, so I can't validate that change or even smoke test it. Please feel free to build on this branch directly. I'd like to take this out of draft first and I'm waiting on my other open PRs to close before adding to the queue, so don't wait for me if you want to move sooner.

One more thing: unless I'm misreading, this is currently a small regression on coopmat2 rather than just a missed optimisation. hoist_row_ids is decided in ggml_vk_mul_mat_id_q_f16 without checking which pipeline family was selected, so on a coopmat2 device the flag is set and count_experts takes the hoisted branch, one workgroup instead of n_as, while mul_mm_cm2.comp ignores the push constant and does the full walk anyway. Strictly more work than master. Reasoned from source only, I can't measure it. I can gate the flag off for coopmat2 pipelines as a stopgap before this leaves draft, if that's useful.

@ravel7524
ravel7524 marked this pull request as ready for review August 21, 2026 20:14
@ravel7524
ravel7524 requested a review from a team as a code owner August 21, 2026 20:14
Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp Outdated
Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp
Comment thread ggml/src/ggml-vulkan/ggml-vulkan.cpp Outdated
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp Outdated
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp
Comment thread ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp
@jeffbolznv

Copy link
Copy Markdown
Contributor

I had codex port to coopmat2 and I tested it, please cherry-pick this commit: fa24cd3.

@ravel7524

Copy link
Copy Markdown
Contributor Author

Cherry-picked as fa24cd3, thanks for writing and testing it. Reviewed the diff, the packing matches the existing cm2 load_row_ids, and the push constants were already plumbed through, so nothing else needed changing. This closes the coopmat2 regression I flagged above. No blocking questions from me.

@jeffbolznv

Copy link
Copy Markdown
Contributor

My results are noisier than usual today, but the trend is "it's a few percent faster":

before

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0  -p 512,1024,2048,4096,8192 -ub 8192 -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 | fp4: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: NV_coopmat2v
| model                          |       size |     params | backend    | ngl | n_ubatch |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | -------: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |    11648.08 ± 294.44 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    14586.32 ± 114.72 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     15413.66 ± 75.62 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |     14922.00 ± 49.41 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |    8417.56 ± 5479.12 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |     10551.77 ± 70.79 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    14854.73 ± 117.75 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |    16253.94 ± 105.11 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |   16047.26 ± 2675.49 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |    17238.22 ± 240.69 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |   23839.78 ± 1171.40 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    32905.11 ± 393.27 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |    37689.83 ± 305.18 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |    38447.91 ± 144.99 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |   33753.04 ± 8127.90 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |   15202.18 ± 1044.37 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    19736.86 ± 164.69 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     21297.76 ± 90.89 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |    20885.44 ± 110.70 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |    18497.23 ± 242.93 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |      9208.90 ± 75.08 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    12439.58 ± 110.49 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     13867.86 ± 42.25 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |   13070.31 ± 2174.21 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |     14374.26 ± 17.43 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |      8670.68 ± 77.62 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |   10418.63 ± 1245.65 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     10242.34 ± 48.96 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |    10639.43 ± 365.05 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |   10474.09 ± 1032.23 |

after

Z:\github\jeffbolznv\llama.cpp\build\bin\RelWithDebInfo>llama-bench.exe -fa 1 -n 0  -p 512,1024,2048,4096,8192 -ub 8192 -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 | fp4: 1 | warp size: 32 | shared memory: 49152 | int dot: 1 | matrix cores: NV_coopmat2v
| model                          |       size |     params | backend    | ngl | n_ubatch |  fa |            test |                  t/s |
| ------------------------------ | ---------: | ---------: | ---------- | --: | -------: | --: | --------------: | -------------------: |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |    11891.92 ± 154.16 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    14834.27 ± 115.78 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     15994.16 ± 70.17 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |     15481.02 ± 48.13 |
| qwen3moe 30B.A3B Q2_K - Medium |  10.15 GiB |    30.53 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |    13716.80 ± 401.15 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |    11848.13 ± 114.36 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    16187.15 ± 116.82 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |    17087.27 ± 151.30 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |    17767.90 ± 319.75 |
| gpt-oss 20B MXFP4 MoE          |  11.27 GiB |    20.91 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |     17914.17 ± 33.73 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |   28034.27 ± 1472.36 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    37419.59 ± 467.70 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |    40759.24 ± 261.89 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |  35514.65 ± 10013.59 |
| granitemoe 3B Q8_0             |   3.34 GiB |     3.37 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |    39001.34 ± 114.43 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |   14278.55 ± 1740.14 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |    20243.20 ± 182.60 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |    22552.83 ± 132.19 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |     22074.05 ± 86.58 |
| deepseek2 16B Q4_K - Medium    |   9.81 GiB |    15.96 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |     20021.17 ± 47.09 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |      9602.77 ± 66.63 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |     13001.83 ± 99.55 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     14456.32 ± 47.44 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |   13612.65 ± 2449.87 |
| nemotron_h_moe 31B.A3.5B Q4_K - Medium |  22.88 GiB |    31.58 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |   14519.69 ± 1014.03 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |           pp512 |      8753.25 ± 93.21 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp1024 |     11219.00 ± 89.85 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp2048 |     11560.28 ± 45.42 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp4096 |     11671.76 ± 21.19 |
| qwen35moe 35B.A3B Q3_K - Medium |  15.45 GiB |    34.66 B | Vulkan     |  -1 |     8192 |   1 |          pp8192 |   11024.42 ± 1706.28 |

@ravel7524

Copy link
Copy Markdown
Contributor Author

The latest results look very promising. Is there anything else you need from me to help move this PR toward merge?

@jeffbolznv

Copy link
Copy Markdown
Contributor

Just address the review feedback, thanks.

- use vk_op_count_experts_push_constants instead of a raw uint vector
- apply the fastdiv trick to the ne00 div/mod in count_experts
- compute the per-expert offsets with subgroupExclusiveAdd when the
  device supports it, keeping the serial path as fallback
- document the data_d layout and the hoisted_row_id_words bound
- drop a leftover debug print in ggml_vk_matmul_id
@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 Aug 21, 2026
@ravel7524

Copy link
Copy Markdown
Contributor Author

Addressed all six. Two things worth flagging rather than leaving in the diff:

fastdiv is now a third local copy of the same helper; generic_unary_head.glsl and glu_head.glsl already carry it. Happy to hoist it into utils.glsl if you'd prefer that over another copy.
I applied fastdiv to the non-hoisted loop further down as well, since it has the same div/mod. Easy to revert if you'd rather keep the change scoped.

The subgroup path is a count_experts_subgroup variant gated on subgroup_arithmetic && subgroup_require_full_support, with the serial version kept as fallback. Trip count is padded to a multiple of gl_SubgroupSize so the subgroup ops stay in uniform control flow.

(uint32_t)n_as,
uint32_t(hoist_row_ids),
0, 0 };
init_fastdiv_values(pc.ne00, pc.ne00mp, pc.ne00L);

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'd like this to be in a init_pushconst_fastdiv template specialization, to be consistent with other push constants.

Comment thread ggml/src/ggml-vulkan/vulkan-shaders/count_experts.comp Outdated
@jeffbolznv

Copy link
Copy Markdown
Contributor

I just had one nitpick remaining. I think these optimizations helped perf another 1% or so, but my numbers got noisier so I don't want to post them.

@jeffbolznv

Copy link
Copy Markdown
Contributor

I wrote the fastdiv cleanup here: #27526. Whichever change goes second will need to adapt, should be trivial.

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 Vulkan Issues specific to the Vulkan backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants