Repository navigation
perf: axis reductions split columns across cores and use the SIMD kernels - #13
Merged
Merged
Conversation
…nels On a Zen 3 (16 cores) the axis reductions of a 1024x1024 matrix lost to NumPy 0.23-0.43x, for two reasons: - An axis-0 reduction ran on one core: it has a single outer slab, and RunAxisP only split outer slabs, on the belief that a column split needs a strided gather. A band of columns is a contiguous run of every row, so the kernels now take a column band [lo, hi) and RunAxisP hands bands of at least 512 columns to the workers when there are fewer slabs than workers. Rows are combined with the elementwise SIMD add/mul from 16 columns on, element by element in axis order, so the result is unchanged. - A row reduction (inner == 1) was a sequential scalar loop, latency-bound. Each row now goes through the SIMD sum/max/min. Max and min are exact; the sum is regrouped lane-parallel, as NumPy's pairwise sum is. Zen 3, 16 cores pinned, min of three interleaved runs: SumAxis(0) 696 -> 186 us (0.97x NumPy 1 thread) SumAxis(1) 531 -> 92 us (2.4x NumPy) MaxAxis(1) 601 -> 93 us (2.0x NumPy) New test: every RunAxisP schedule (serial, slab split, column bands for one slab and for fewer slabs than workers, narrow fallback, row sums) for Sum/Prod/Max/Min against a naive in-order oracle, exact except the regrouped row sum (1e-12). Shifting the band offset makes it fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
force-pushed
the
perf/axis-reductions
branch
from
October 4, 2026 13:19
1f2ee57 to
2fed20e
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.
On a Zen 3 (16 cores) the axis reductions of a 1024x1024 matrix lost to
NumPy 0.23-0.43x, for two reasons:
RunAxisP only split outer slabs, on the belief that a column split needs
a strided gather. A band of columns is a contiguous run of every row, so
the kernels now take a column band [lo, hi) and RunAxisP hands bands of
at least 512 columns to the workers when there are fewer slabs than
workers. Rows are combined with the elementwise SIMD add/mul from 16
columns on, element by element in axis order, so the result is
unchanged.
Each row now goes through the SIMD sum/max/min. Max and min are exact;
the sum is regrouped lane-parallel, as NumPy's pairwise sum is.
Zen 3, 16 cores pinned, min of three interleaved runs:
SumAxis(0) 696 -> 186 us (0.97x NumPy 1 thread)
SumAxis(1) 531 -> 92 us (2.4x NumPy)
MaxAxis(1) 601 -> 93 us (2.0x NumPy)
New test: every RunAxisP schedule (serial, slab split, column bands for
one slab and for fewer slabs than workers, narrow fallback, row sums)
for Sum/Prod/Max/Min against a naive in-order oracle, exact except the
regrouped row sum (1e-12). Shifting the band offset makes it fail.
🤖 Generated with Claude Code