Skip to content

perf: float32 Sqrt kernels on six targets; float32 survey against NumPy - #61

Merged
tannevaled merged 1 commit into
mainfrom
float32-sqrt
Oct 25, 2026
Merged

tannevaled merged 1 commit into
mainfrom
float32-sqrt

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Against NumPy 2.5.3 on one POWER9 core, float32 Sqrt was 6.8–7.5× slower than NumPy. It called math.Sqrt through a function value for every element.

Change. kernels.Sqrt32 runs a vector kernel on every 64-bit target, 16 floats per iteration:

target instruction gate
amd64 SQRTPS baseline
arm64 NEON VFSQRT .S4 baseline
ppc64le xvsqrtsp (go-asmgen) baseline
s390x vfsqsb (go-asmgen) useVXE (z14+)
loong64 LSX vfsqrt.s useLASX
riscv64 RVV vfsqrt.v E32 useRVV

Each is the correctly rounded float32 square root, so the result is float32(math.Sqrt(float64(x))) bit for bit. float64 carries more than twice float32's precision, so the double rounding cannot change it.

Measured with fleettools' abbench on POWER9: base and head alternated, 8 rounds, pinned core, --max-busy 15.

float32 Sqrt before after NumPy
2¹⁴ 102.9 µs 23.4 µs (−77%) 14.7 µs
2²⁰ 6.21 ms 1.08 ms (−83%) 0.835 ms

The controls (float64 Sqrt, float32/64 Add and AddInto) are flat. The gap left to NumPy is the allocation, an open defect already recorded in docs/perf.md.

Tests on real hardware. The kernel tests cover special values, every length to 70, in place, and a short src. Together with the PROT_NONE fence, which now includes Sqrt32:

  • after the rebase: they pass on Zen 3, Apple M, POWER9 and SpacemiT X60.
  • before the rebase (2026-10-20): they passed on IBM Z and Loongson 3C5000L.
    • Same code: regenerating with go-asmgen v0.20.0 (from fix(deps): update dependencies #57) changes no byte.
    • Not re-run since: today linuxone refuses the key (access probably expired) and cfarm401 drops connections.

The local coverage gate (covblocks) reports 0 uncovered blocks.

Survey (docs/perf.md): new DTypeSqrt, DTypeMax and DTypeMatMul benchmarks.

  • float32 Max is 11.9–15× slower than NumPy: there is no kernel. On ppc64le float64 Max has no kernel either, being 4.4–5.4× slower.
  • float32 MatMul is 9× slower than our own float64 GEMM.

Those are the next two pieces of work.

🤖 Generated with Claude Code

Against NumPy 2.5.3 on one POWER9 core, float32 Sqrt was 6.8-7.5x
slower: it called math.Sqrt through a function value per element.
kernels.Sqrt32 runs SQRTPS (amd64), NEON .S4 (arm64), xvsqrtsp
(ppc64le), vfsqsb (s390x, z14+), LSX vfsqrt.s (loong64) and RVV E32
(riscv64), 16 floats per iteration. Each is the correctly rounded
float32 square root, so float32(math.Sqrt(float64(x))) bit for bit.

POWER9, abbench (alternated, 8 rounds, pinned core): float32 Sqrt -77%
(2^14) / -83% (2^20); float64 Sqrt, Add and AddInto flat.

benchmarks: DTypeSqrt, DTypeMax, DTypeMatMul. docs/perf.md records the
survey: float32 Max is 11.9-15x slower than NumPy (no kernel; on
ppc64le float64 Max has none either), and float32 MatMul is 9x slower
than our float64 GEMM.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 8388dc6 into main Oct 25, 2026
12 checks passed
@tannevaled
tannevaled deleted the float32-sqrt branch October 25, 2026 19: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