Repository navigation
Split ARM64 prefetches at the cache line size - #9599
Merged
alexreinking merged 1 commit intoOct 26, 2026
Merged
alexreinking merged 1 commit into
alexreinking merged 1 commit into
Conversation
2 of 5 tasks
abadams
approved these changes
Oct 23, 2026
slomp
approved these changes
Oct 23, 2026
slomp
left a comment
Contributor
There was a problem hiding this comment.
LGTM, with an experiment you can try.
| (t.os == Target::MacOS || t.os == Target::IOS)) { | ||
| // Apple's 64-bit ARM cores have 128-byte cache lines. | ||
| max_dim = 1; | ||
| max_byte_size = 128; |
Contributor
There was a problem hiding this comment.
Out of curiosity, have you tried 256 instead of 128?
Context: not long ago I wrote a benchmark, and found out that even though the cache line size of Apple Silicon is 128 bytes long, for false-sharing scenarios, using 256 bytes gave better performance still.
Curious to see if it would have an effect here.
alexreinking
force-pushed
the
alexreinking/arm-prefetch-line-size
branch
from
October 24, 2026 15:43
60606d1 to
bc53255
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alexreinking/simplify-div-bounded-offset #9599 +/- ##
============================================================================
+ Coverage 73.02% 73.05% +0.03%
============================================================================
Files 263 263
Lines 82415 82422 +7
Branches 20156 20159 +3
============================================================================
+ Hits 60181 60213 +32
- Misses 15913 15919 +6
+ Partials 6321 6290 -31 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
2 of 5 tasks
reduce_prefetch_dimension split every ARM prefetch into 32-byte pieces, the smallest line size of 32-bit ARM cores. 64-bit ARM cores have lines of at least 64 bytes, and Apple's have 128-byte lines, so most of the emitted prfm instructions touched an already-requested line. Split at 64 bytes for 64-bit ARM and 128 bytes for 64-bit ARM on macOS/iOS; keep 32 bytes for 32-bit ARM. correctness_prefetch now also lowers its tests for x86-64, 32-bit ARM, 64-bit ARM Linux, macOS, and iOS targets, not only the host. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
alexreinking
force-pushed
the
alexreinking/arm-prefetch-line-size
branch
from
October 26, 2026 19:58
bc53255 to
ddbe3ea
Compare
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.
reduce_prefetch_dimensionsplits every ARM prefetch into 32-byte pieces, which is the smallest cache line size of 32-bit ARM cores. 64-bit ARM cores have lines of at least 64 bytes, and Apple's cores have 128-byte lines. On Apple silicon, 3 of every 4prfminstructions therefore request a line that was already requested.This PR splits prefetches at:
correctness_prefetchused to check only the host target. It now also lowers its tests forx86-64-linux,arm-32-linux,arm-64-linux,arm-64-macos, andarm-64-ios.Benchmarks
The benchmark is an int8 smmla gemm from the GGML app (#9511), with a
Func::prefetchof the weight stream added at offsets 2, 4, and 8 iterations of the K loop. Each region is 128 bytes per iteration. Times are on an M3 Max, relative to the same kernel without the prefetch (lower is better), min of 3 runs:With the old split, the extra prefetch instructions made the kernel 3–9% slower. With this PR they cost nothing measurable. (The hardware prefetchers already cover this kernel's weight stream, so prefetching doesn't make it faster either.)
Stacked on #9520.
Checklist
Validation:
correctness_prefetchandcorrectness_bad_prefetchpass; the fullctest -L correctnessrun at the top of the stack passed 703/704 (the only failure iscorrectness_cross_compilation, because the local LLVM has no Hexagon backend).