Skip to content

perf: axis reductions split columns across cores and use the SIMD kernels - #13

Merged
tannevaled merged 1 commit into
mainfrom
perf/axis-reductions
Oct 4, 2026
Merged

tannevaled merged 1 commit into
mainfrom
perf/axis-reductions

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

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.

🤖 Generated with Claude Code

…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
tannevaled force-pushed the perf/axis-reductions branch from 1f2ee57 to 2fed20e Compare October 4, 2026 13:19
@tannevaled
tannevaled merged commit 90d0a5c into main Oct 4, 2026
12 checks passed
@tannevaled
tannevaled deleted the perf/axis-reductions branch October 4, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant