]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commit
vulkan: Optimize mul_mat_vec p021 and nc shaders (llama/12505)
authorJeff Bolz <redacted>
Sat, 22 Mar 2025 08:40:11 +0000 (03:40 -0500)
committerGeorgi Gerganov <redacted>
Thu, 27 Mar 2025 09:06:03 +0000 (11:06 +0200)
commitcbb88c4050f5cdf2f02be2ba404a528552a83e39
treef4fe53e0ddb69f0d2bb8849e05defb324b83525b
parent13455c0b5f479c0dc7ecb7ba61a3085a1563ff77
vulkan: Optimize mul_mat_vec p021 and nc shaders (llama/12505)

* tests: add mul_mat perf/functional tests for p021/nc vulkan shaders

* vulkan: Optimize mul_mat_vec p021 and nc shaders.

These shaders are used in attention calculations, and when the KV cache grows
large they start to dominate the run time. For the nc shader (which is called
with large 'k' dimension), use unrolling and vector loads. For the p021 shader
(which is called with large 'm' and small 'k' dimensions), take advantage of
grouped query attention to reuse loads from the A matrix for the whole group,
and reduce the number of workgroups (too much overhead from tiny dispatches).

Using subgroupAdd in the p021 shader also helps, use that conditionally.
ggml/src/ggml-vulkan/ggml-vulkan.cpp
ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp
ggml/src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp
ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp