]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commit
metal: fuse snake activation (mul, sin, sqr, mul, add) (#25459)
authorPascal <redacted>
Wed, 15 Jul 2026 10:53:31 +0000 (12:53 +0200)
committerGitHub <redacted>
Wed, 15 Jul 2026 10:53:31 +0000 (13:53 +0300)
commitb3c9d1b846cc80a6360adb6aeaa4fcd8c4c8dcac
tree2e30aa9073e68da835dfeb60e820b2db62a6d63b
parentf955e394bf94e01e5e36186d13c985727e5ef5b5
metal: fuse snake activation (mul, sin, sqr, mul, add) (#25459)

* metal: fuse snake activation (mul, sin, sqr, mul, add)

Mirror the CUDA, Vulkan and CPU snake fusion: same matcher on the naive
5-op chain, same F32 contract on a and inv_b, same F32/F16/BF16 kernel
with F32 compute. Follows the Metal backend idioms: bf16 instantiation
gated behind GGML_METAL_HAS_BF16 and concurrency ranges checked on the
remaining chain nodes before encoding, as done by the bin fusion.

Covered by the existing backend-agnostic SNAKE_FUSE tests.

* metal: absorb snake fusion into ggml_metal_op_bin

Extract the matcher to ggml_metal_op_can_fuse_snake, mirroring the
Vulkan naming, and dispatch the fused path from ggml_metal_op_bin.
The encode loop switch is back to a single call per case.

Address review from ggerganov

* metal: fix indentation in ggml_metal_op_can_fuse_snake
ggml/src/ggml-metal/ggml-metal-device.cpp
ggml/src/ggml-metal/ggml-metal-device.h
ggml/src/ggml-metal/ggml-metal-impl.h
ggml/src/ggml-metal/ggml-metal-ops.cpp
ggml/src/ggml-metal/ggml-metal-ops.h
ggml/src/ggml-metal/ggml-metal.metal