Repository navigation
perf: float32 Sqrt kernels on six targets; float32 survey against NumPy - #61
Merged
Merged
Conversation
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>
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.
Against NumPy 2.5.3 on one POWER9 core, float32
Sqrtwas 6.8–7.5× slower than NumPy. It calledmath.Sqrtthrough a function value for every element.Change.
kernels.Sqrt32runs a vector kernel on every 64-bit target, 16 floats per iteration:SQRTPSVFSQRT .S4xvsqrtsp(go-asmgen)vfsqsb(go-asmgen)useVXE(z14+)vfsqrt.suseLASXvfsqrt.vE32useRVVEach 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'
abbenchon POWER9: base and head alternated, 8 rounds, pinned core,--max-busy 15.SqrtThe controls (float64
Sqrt, float32/64AddandAddInto) are flat. The gap left to NumPy is the allocation, an open defect already recorded indocs/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 includesSqrt32:linuxonerefuses the key (access probably expired) and cfarm401 drops connections.The local coverage gate (
covblocks) reports 0 uncovered blocks.Survey (
docs/perf.md): newDTypeSqrt,DTypeMaxandDTypeMatMulbenchmarks.Maxis 11.9–15× slower than NumPy: there is no kernel. On ppc64le float64Maxhas no kernel either, being 4.4–5.4× slower.MatMulis 9× slower than our own float64 GEMM.Those are the next two pieces of work.
🤖 Generated with Claude Code