Repository navigation
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem.
gemm_blocaddresses its operands asA + lda * (ii + i) + lagainst the class members.On aarch64, GCC 14.2 does not form pointer induction variables over
lfrom that: it re-derives allseven operand addresses every iteration — 8
add+ 6lslwrapped around 12fmlaand 7ldr q, a35-instruction loop where 21 do the same work. The identical source with the bases and strides as
locals compiles to those 21, with the same compiler and the same flags (checked by compiling the
extracted block with ggml's own
flags.makeline).Fix. Hoist the two base pointers and the strides into locals before the loop. No arithmetic change
whatsoever — bit-identical output, and it is an addressing rewrite, not a numerical one.
Evidence. With PR #1602 also applied: 22.0 → 25.1 GFLOP/s at the eleven shapes, 4 threads.
Why it is scoped to aarch64. x86-64 does not want it: there GCC already forms the induction
variables, and the extra live values only add pressure — 55.4 → 53.6 GFLOP/s and 12 more
%rspreads in the block. With the
#if defined(__aarch64__)in place, the x86 object code isregister-renaming-identical to the current one, which is a better check than re-timing it. clang on
aarch64 is neutral (24.0 vs 23.8), since it already did this.
This is in the context of a new ggml-based engine targeting edge devices called loom.cpp. The optimization was derived from multiple iterations with Claude Code trying to close the gap for the same model against onnxruntime.