Skip to content

Conversation

@dor-forer
Copy link
Collaborator

@dor-forer dor-forer commented Dec 28, 2025

Describe the changes in the pull request

Added support to SQ8 to SQ8 Ip and Cosine spaces.
Intel:
AVX512_F_BW_VL_VNNI - needs it to support uint8 and in8 operations.
ARM:
SVE
NEON

The cosine functions assume that the vectors are normlized therefore don't divide by the norm.
Which issues this PR fixes

  1. MOD-13170

Main objects this PR modified

  1. ...
  2. ...

Mark if applicable

  • This PR introduces API changes
  • This PR introduces serialization changes

- Implemented inner product and cosine distance functions for SQ8-to-SQ8 vectors in SVE, NEON, and AVX512 architectures.
- Added corresponding distance function selection logic in IP_space.cpp and function headers in IP_space.h.
- Created benchmarks for SQ8-to-SQ8 distance functions to evaluate performance across different architectures.
- Developed unit tests to validate the correctness of the new distance functions against expected results.
- Ensured compatibility with existing optimization features for various CPU architectures.
@dor-forer dor-forer requested a review from Copilot December 28, 2025 09:39
@dor-forer dor-forer changed the title Sq8 to Sq8 dist functions - ip and cosine Sq8 to Sq8 dist functions - ip and cosine [MOD-13170] Dec 28, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for SQ8-to-SQ8 distance functions for Inner Product and Cosine similarity metrics, where both vectors are scalar-quantized 8-bit representations. This extends the existing SQ8 functionality which only handled float-to-SQ8 comparisons.

Key changes:

  • Implemented optimized SIMD versions for Intel (AVX512) and ARM (SVE, SVE2, NEON) architectures
  • Added comprehensive test coverage for all optimization variants
  • Integrated new benchmark suite for performance testing
  • Refactored existing helper function names to avoid naming conflicts

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/unit/test_spaces.cpp Added unit tests for SQ8_SQ8 IP and Cosine functions across all architectures; improved test suite naming consistency
tests/benchmark/spaces_benchmarks/bm_spaces_sq8_sq8.cpp New benchmark file for SQ8_SQ8 distance functions
tests/benchmark/spaces_benchmarks/bm_spaces_sq8.cpp Removed empty comment lines (cleanup)
tests/benchmark/benchmarks.sh Added spaces_sq8_sq8 to benchmark configurations
tests/benchmark/CMakeLists.txt Added sq8_sq8 data type to build system
src/VecSim/spaces/functions/SVE2.h Added function declarations for SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/functions/SVE2.cpp Implemented SVE2 function choosers for SQ8_SQ8 distance functions
src/VecSim/spaces/functions/SVE.h Added function declarations for SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/functions/SVE.cpp Implemented SVE function choosers for SQ8_SQ8 distance functions
src/VecSim/spaces/functions/NEON.h Added function declarations for SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/functions/NEON.cpp Implemented NEON function choosers for SQ8_SQ8 distance functions
src/VecSim/spaces/functions/AVX512F_BW_VL_VNNI.h Added function declarations for SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/functions/AVX512F_BW_VL_VNNI.cpp Implemented AVX512 function choosers for SQ8_SQ8 distance functions
src/VecSim/spaces/IP_space.h Added public API declarations for SQ8_SQ8 distance functions
src/VecSim/spaces/IP_space.cpp Implemented dispatcher functions that select appropriate SIMD implementation
src/VecSim/spaces/IP/IP_SVE_SQ8_SQ8.h New file with SVE-optimized SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/IP/IP_NEON_SQ8_SQ8.h New file with NEON-optimized SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/IP/IP_AVX512F_SQ8_SQ8_BW_VL_VNNI.h New file with AVX512-optimized SQ8_SQ8 IP and Cosine implementations
src/VecSim/spaces/IP/IP_AVX512F_SQ8_BW_VL_VNNI.h Renamed helper function to avoid naming conflicts with new SQ8_SQ8 implementations
src/VecSim/spaces/IP/IP_AVX2_SQ8.h Renamed helper function to avoid naming conflicts and fixed cosine normalization
src/VecSim/spaces/IP/IP.h Added function declarations for SQ8_SQ8 base implementations
src/VecSim/spaces/IP/IP.cpp Implemented baseline SQ8_SQ8 InnerProduct and Cosine functions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Dec 28, 2025

Codecov Report

❌ Patch coverage is 98.86364% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.09%. Comparing base (e493894) to head (afe1a4f).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/VecSim/spaces/IP_space.cpp 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #873      +/-   ##
==========================================
+ Coverage   97.06%   97.09%   +0.02%     
==========================================
  Files         126      127       +1     
  Lines        7403     7574     +171     
==========================================
+ Hits         7186     7354     +168     
- Misses        217      220       +3     

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 27 changed files in this pull request and generated 12 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@dor-forer dor-forer requested a review from meiravgri December 28, 2025 14:28
- Updated distance function declarations in IP_space.h to clarify that SQ8-to-SQ8 functions use precomputed sum/norm.
- Removed precomputed distance function implementations for AVX512F, NEON, and SVE architectures from their respective source files.
- Adjusted benchmark tests to remove references to precomputed distance functions and ensure they utilize the updated quantization methods.
- Modified utility functions to support the creation of SQ8 quantized vectors with precomputed sum and norm.
- Updated unit tests to reflect changes in the quantization process and removed tests specifically for precomputed distance functions.
…nsistency

- Updated include paths in AVX512F_BW_VL_VNNI.cpp to reflect new naming conventions.
- Modified unit tests in test_spaces.cpp to streamline vector initialization and quantization processes.
- Replaced repetitive code with utility functions for populating and quantizing vectors.
- Enhanced assertions in tests to ensure optimized distance functions are correctly chosen and validated.
- Removed unnecessary parameters from utility functions to simplify their interfaces.
- Improved test coverage for edge cases, including zero and constant vectors, ensuring accuracy across various scenarios.
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