Skip to content

perf: accelerate distance kernels with SIMD - #20

Merged
zhenghaoz merged 1 commit into
mainfrom
feat/simd-distance
Aug 12, 2026
Merged

perf: accelerate distance kernels with SIMD#20
zhenghaoz merged 1 commit into
mainfrom
feat/simd-distance

Conversation

@zhangzhenghao

Copy link
Copy Markdown
Collaborator

Summary

  • add an internal/floats package with pure-float32 scalar, AVX, AVX-512, and NEON kernels for squared L2, inner product, and one-pass dot/norm accumulation
  • generate architecture implementations with GoAT, dispatch by runtime CPU features, and retain a noasm scalar fallback
  • route checked and prevalidated dense metrics through the new kernels while preserving validation and zero-vector behavior
  • skip architecture-specific tests when the current CPU lacks the required instruction set

Performance

Measured on an Intel Core i7-4500U with AVX, comparing default dispatch against -tags=noasm:

Kernel (1536 dimensions) noasm AVX
L2 squared 1598 ns/op 210.6 ns/op
Inner product 1597 ns/op 208.1 ns/op
Dot + norms 1914 ns/op 242.0 ns/op

All benchmarks report 0 B/op and 0 allocs/op.

Verification

  • go test ./... -count=1
  • go test -tags=noasm ./... -count=1
  • go vet ./...
  • go test ./internal/floats ./internal/ailego -count=10
  • GoAT regeneration hash comparison
  • Linux ARM64, Darwin ARM64, Windows AMD64, and Windows ARM64 test-binary cross-compilation
  • host AVX-specific tests pass; AVX-512-specific test skips because the host CPU does not support AVX-512

Local golangci-lint was not used because the installed binary was built with Go 1.24 and refuses modules targeting Go 1.26; the repository CI uses its pinned Go 1.26-compatible lint action.

@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.14286% with 24 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.32%. Comparing base (579bc98) to head (f8a975d).

Files with missing lines Patch % Lines
internal/floats/floats_amd64.go 52.00% 24 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #20      +/-   ##
==========================================
- Coverage   61.33%   61.32%   -0.02%     
==========================================
  Files         145      147       +2     
  Lines       40173    40203      +30     
==========================================
+ Hits        24642    24654      +12     
- Misses      12318    12339      +21     
+ Partials     3213     3210       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zhenghaoz
zhenghaoz merged commit c8e0544 into main Aug 12, 2026
7 checks passed
@zhenghaoz
zhenghaoz deleted the feat/simd-distance branch August 12, 2026 00:08
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.

2 participants