]> git.djapps.eu Git - pkg/ggml/sources/ggml/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 07:35:24 +0000 (09:35 +0200)
commit382326dabf96a30481d3291f323b53c5bc47d0a4
tree12dc8264eee816e281fdf9a5929082707f70c130
parentdb0f4eee0322fd5abcd0dadf09ad191b6d7c30b0
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.
src/ggml-vulkan/ggml-vulkan.cpp
src/ggml-vulkan/vulkan-shaders/mul_mat_vec_nc.comp
src/ggml-vulkan/vulkan-shaders/mul_mat_vec_p021.comp
src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp
tests/test-backend-ops.cpp