perf(cpu): eliminate hot path index math + add SIMD threshold (#81, #90) - #150
Merged
Merged
Conversation
…atch matmul (#81) Reduce: replace coordinate decomposition with innerOuter block iteration. Scatter-add: replace per-element make([]int) with pre-allocated buffer. BatchMatMul: precompute batch offsets table, O(1) lookup vs O(ndim)/element. ScatterAdd allocs: O(N) → O(1). All 337 cpu tests pass.
Add simdMinLen=32 guard to all SIMD dispatch points (47 sites across element-wise, activation, sign, and sum ops). Below 32 elements, scalar loop runs — avoids function-pointer call overhead exceeding SIMD savings. Threshold empirically determined: covers 2 full AVX-256 vectors (2x8) and 2 AVX-512 half-widths (2x16). Benchmark + unit test suite added.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This was referenced Aug 4, 2026
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.
Summary
Closes #81 (all 8/8 items now complete) and #90 (SIMD min slice threshold).
CPU hot paths (#81) — 3 remaining items fixed
innerOuterblock iteration (same pattern as Gather/Chunk fixes)make([]int, ndim)allocation with pre-allocated buffer — allocs O(N) → O(1)SIMD threshold (#90)
simdMinLen = 32guard to all 47 SIMD dispatch pointsTest plan
go build ./...go test -short ./internal/backend/cpu/...— 337 tests passgolangci-lint run— 0 issuesCloses #81
Closes #90