Skip to content

perf: float32 MatMul on the float64 GEMM - #65

Merged
tannevaled merged 1 commit into
mainfrom
float32-matmul
Oct 26, 2026
Merged

tannevaled merged 1 commit into
mainfrom
float32-matmul

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

float32 MatMul ran a generic triple loop, 9× slower than our own float64 GEMM on a POWER9.

Change. float32 now runs on the float64 GEMM:

  • Widening: the operands are widened to float64, which is exact and O(n²).
  • GEMM: the packed, cache-blocked SIMD float64 GEMM does the multiply.
  • Rounding: each element is rounded once to float32.

That is at least as accurate as a BLAS sgemm, which accumulates in float32, and every architecture gets its existing micro-kernel at once. The result keeps the float32 dtype.

Measured with abbench: alternated, 5 rounds, pinned core.

float32 MatMul 64² 256² float64 control
POWER9 −77.1% −87.5% ~
Zen 3 −77.4% −90.4% ~

float32 is now within the widening of float64. On the POWER9 that is 86.7 against 54.0 µs at 64², and 2.56 against 2.25 ms at 256². A native float32 GEMM, with twice the lanes per register and half the bytes, is the next step for products; it is recorded in docs/perf.md.

Tests. TestMatMulFloat32 (40×50×30, large enough for the blocked path):

  • the result is exact on integer-valued operands;
  • on random operands it agrees with the float32 triple loop to float32 precision;
  • the dtype stays float32.

The float32 case leaves the generated matmulStore, where it is now dead. The local coverage gate (covblocks) reports 0 uncovered blocks.

A minor release, v0.21.0.

🤖 Generated with Claude Code

float32 MatMul ran a generic triple loop, 9x slower than our float64
GEMM. It now widens the operands (exact, O(n^2)), runs the packed,
cache-blocked SIMD float64 GEMM, and rounds each element once to
float32: at least as accurate as a BLAS sgemm accumulating in float32,
on every architecture at once.

abbench, 5 rounds, pinned core, float32 MatMul 64^2 / 256^2:
POWER9 -77% / -87%, Zen 3 -77% / -90%; float64 flat.

TestMatMulFloat32: exact on integer-valued operands, float32 precision
against the triple loop on random ones, float32 dtype kept. The float32
case leaves the generated matmulStore (dead now).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 543d1d0 into main Oct 26, 2026
12 checks passed
@tannevaled
tannevaled deleted the float32-matmul branch October 26, 2026 10:47
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