]> git.djapps.eu Git - pkg/ggml/sources/ggml/commit
ggml : avoid duplicating function calls using MIN/MAX macros (llama/5325)
authorDr. Tom Murphy VII Ph.D <redacted>
Mon, 5 Feb 2024 11:13:57 +0000 (06:13 -0500)
committerGeorgi Gerganov <redacted>
Sat, 10 Feb 2024 07:30:58 +0000 (09:30 +0200)
commit2f79513935a85b0678046c22705abd41cc294a13
treeee0a91b94c4dcdd34d6f1748b7adbd8b17cf7b95
parent844a39b978ee67630f3499ec2823b487f33e7b3e
ggml : avoid duplicating function calls using MIN/MAX macros (llama/5325)

* Avoid duplicating function calls when using MIN/MAX macros.

Since these copy "a" and "b" they ask the compiler to evaluate one of them twice. The compiler doesn't have a problem with removing the duplication in something like MAX(0, x + 2), but in some cases we're calling functions, and those calls just happen twice.
By explicitly evaluating at the expression we get smaller and faster code without duplicate calls. See ggml_rope_yarn_corr_dims in Compiler Explorer:

https://godbolt.org/z/Ee4KMrvKh

Code behaves exactly the same.

* Update ggml.c

---------

Co-authored-by: Georgi Gerganov <redacted>
src/ggml.c