]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
vulkan: Add fusion support for RMS_NORM+MUL (#14366)
authorJeff Bolz <redacted>
Sun, 29 Jun 2025 07:43:36 +0000 (02:43 -0500)
committerGitHub <redacted>
Sun, 29 Jun 2025 07:43:36 +0000 (09:43 +0200)
commitbd9c981d7226107f18deb8344c3301450311bb8b
tree0106d36f737c7f048d33824b370ef8afd055a0bc
parent27208bf657cfe7262791df473927225e48efe482
vulkan: Add fusion support for RMS_NORM+MUL (#14366)

* vulkan: Add fusion support for RMS_NORM+MUL

- Add a use_count to ggml_tensor, so we can detect if an output is used more than once.
- Change the ggml-vulkan rms_norm shader to optionally multiply by another tensor.
- Add detection logic and basic fusion logic in ggml-vulkan.
- Add some testing support for fusion. Rather than computing one node at a time, allow
for computing the whole graph and just testing one node's results. Add rms_norm_mul tests
and enable a llama test.

* extract some common fusion logic

* fix -Winconsistent-missing-override

* move ggml_can_fuse to a common function

* build fix

* C and C++ versions of can_fuse

* move use count to the graph to avoid data races and double increments when used in multiple threads

* use hash table lookup to find node index

* change use_counts to be indexed by hash table slot

* minimize hash lookups

style fixes

* last node doesn't need single use.
fix type.
handle mul operands being swapped.

* remove redundant parameter

---------

Co-authored-by: slaren <redacted>
ggml/include/ggml-backend.h
ggml/src/ggml-backend.cpp
ggml/src/ggml-impl.h
ggml/src/ggml-vulkan/ggml-vulkan.cpp
ggml/src/ggml-vulkan/vulkan-shaders/rms_norm.comp
ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp
ggml/src/ggml.c
tests/test-backend-ops.cpp