-
Notifications
You must be signed in to change notification settings - Fork 22
Sq8 dist functions L2 [MOD-13169] #877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
81 commits
Select commit
Hold shift + click to select a range
746bf31
Add SQ8-to-SQ8 distance functions and optimizations
dor-forer 8697a3e
Add SQ8-to-SQ8 benchmark tests and update related scripts
dor-forer e0ce268
Format
dor-forer ab6b077
Orgnizing
dor-forer 931e339
Add full sq8 bencharks
dor-forer a56474d
Optimize the sq8 sq8
dor-forer a25f45c
Optimize SQ8 distance functions for NEON by reducing operations and i…
dor-forer 0ad941e
format
dor-forer 68cd068
Add NEON DOTPROD-optimized distance functions for SQ8-to-SQ8 calculat…
dor-forer 0b4b568
PR
dor-forer d0fd2e4
Remove NEON DOTPROD-optimized distance functions for INT8, UINT8, and…
dor-forer 9de6163
Fix vector layout documentation by removing inv_norm from comments in…
dor-forer 63a46a1
Remove 'constexpr' from ones vector declaration in NEON inner product…
dor-forer 101aa69
Add SQ8-to-SQ8 L2 squared distance functions with SIMD optimizations
dor-forer 5bef023
Change the name
dor-forer 72053af
Add full range tests for SQ8 distance functions with SIMD optimizations
dor-forer 525f8da
Refactor distance functions to remove inv_norm parameter and update d…
dor-forer 13a477b
Update SQ8 Cosine test to normalize both input vectors and adjust dis…
dor-forer c18000e
Rename 'compressed' to 'quantized' in SQ8 functions for clarity and c…
dor-forer b58f8ef
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 286990a
Rename 'compressed' to 'quantized' in SQ8 distance tests for clarity
dor-forer 8cdc3fc
Refactor quantization function to remove unused normalization calcula…
dor-forer 189290e
Add TODO to store vector's norm and sum in L2 squared distance calcul…
dor-forer bbf810e
Implement SQ8-to-SQ8 distance functions with precomputed sum and norm…
dor-forer dbbb7d9
Add edge case tests for SQ8-to-SQ8 precomputed cosine distance functions
dor-forer 36ab068
Refactor SQ8 test cases to use CreateSQ8QuantizedVector for vector po…
dor-forer 00617d7
Implement SQ8-to-SQ8 precomputed distance functions using ARM NEON, S…
dor-forer 4331d91
Implement SQ8-to-SQ8 precomputed inner product and cosine functions; …
dor-forer 2e7b30d
Refactor SQ8 distance functions and remove precomputed variants
dor-forer a111e36
Refactor SQ8 distance functions and tests for improved clarity and co…
dor-forer d510b8a
Refactor SQ8 benchmarks by removing precomputed variants and updating…
dor-forer ee26740
foramt
dor-forer afe1a4f
Remove serialization benchmark script for HNSW disk serialization
dor-forer a31f95c
Refactor SQ8 distance functions and tests to remove precomputed norm …
dor-forer f12ecf4
format
dor-forer 0e36030
Merge branch 'main' of https://github.com/RedisAI/VectorSimilarity in…
dor-forer fdc16c6
Refactor SQ8 distance tests to use compressed vectors and improve nor…
dor-forer e5f519c
Update vector layout documentation to reflect removal of sum of squar…
dor-forer 53f8e0e
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer b12c796
Refactor L2 SQ8 distance computation to remove unused accumulators an…
dor-forer db1e671
Refactor SQ8 distance functions to remove norm computation
dor-forer d5b8587
Update SQ8-to-SQ8 distance function comment to remove norm reference
dor-forer 91f48df
Refactor cosine similarity functions to remove unnecessary subtractio…
dor-forer 0050bb9
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer a75ddd6
Refactor L2 SQ8 distance functions to eliminate unused accumulators a…
dor-forer a37918b
Refactor SQ8 L2 and IP implementations to use common inner product fu…
dor-forer b660111
Refactor cosine similarity functions to use specific SIMD implementat…
dor-forer 40ef6a3
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 5a544db
Refactor L2 distance functions for SQ8 vectors to utilize common inne…
dor-forer 9166cac
Refactor benchmark setup to allocate additional space for sum and sum…
dor-forer f28f4e7
Add CPU feature checks to disable optimizations for AArch64 in SQ8 di…
dor-forer e50dc45
Add CPU feature checks to disable optimizations for AArch64 in SQ8 di…
dor-forer d24ea8e
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 6bbbc38
Fix formatting issues in SQ8 inner product function and clean up cond…
dor-forer 7983b70
Refactor SQ8 distance functions and tests for improved readability an…
dor-forer 7f4af80
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer c6353cb
Refactor SQ8 L2Sqr tests to use quantized vectors and improve alignme…
dor-forer 66a5f88
Enhance SQ8 Inner Product Implementations with Optimized Dot Product …
dor-forer d7972e9
Fix header guard duplication and update test assertion for floating-p…
dor-forer a8075bf
Add missing pragma once directive in NEON header files
dor-forer cddc497
Refactor SQ8 distance functions for improved performance and clarity
dor-forer 4f0fec7
Update SQ8 vector population functions to include metadata and adjust…
dor-forer 8ab4192
Refactor SQ8 inner product functions for improved clarity and perform…
dor-forer 63f4e87
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 5a52b79
Refactor L2 distance functions to utilize common inner product implem…
dor-forer 8c59cb2
Rename inner product implementation functions for AVX2 and AVX512 for…
dor-forer a0796db
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer a4ff5d0
Refactor SQ8 cosine function to utilize inner product function for im…
dor-forer c22158f
Remove redundant inner product edge case tests for SQ8 distance funct…
dor-forer 4c19d9e
Add SVE2 support to SQ8-to-SQ8 Inner Product distance function
dor-forer e2ad287
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 668315b
Fix SQ8_Cosine to call the correct inner product function for improve…
dor-forer 5c22af8
Remove SVE2 and other optimizations from SQ8 cosine function test for…
dor-forer ad515ba
Merge branch 'dorer-sq8-dist-functions-ip-cosine' of https://github.c…
dor-forer 695bbc0
Merge branch 'main' of https://github.com/RedisAI/VectorSimilarity in…
dor-forer cae2dd6
Add L2 distance function without optimizations for testing purposes
dor-forer b2506b9
Refactor L2 distance function and update test assertions for precision
dor-forer 59784db
Update L2 squared distance functions to support 64 residuals in NEON …
dor-forer 8d24786
Refactor L2 distance function conditions for NEON optimizations
dor-forer 0dde4d5
Adjust NEON_DOTPROD benchmark initialization to use a dimension of 16
dor-forer 3b38d8e
Update NEON benchmarks to support 64 dimensions for L2 and Cosine met…
dor-forer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright (c) 2006-Present, Redis Ltd. | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under your choice of the Redis Source Available License 2.0 | ||
| * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the | ||
| * GNU Affero General Public License v3 (AGPLv3). | ||
| */ | ||
| #pragma once | ||
| #include "VecSim/spaces/space_includes.h" | ||
| #include "VecSim/spaces/IP/IP_AVX512F_BW_VL_VNNI_SQ8_SQ8.h" | ||
|
|
||
| /** | ||
| * SQ8-to-SQ8 L2 squared distance using AVX512 VNNI. | ||
| * Computes L2 squared distance between two SQ8 (scalar quantized 8-bit) vectors, | ||
| * where BOTH vectors are uint8 quantized. | ||
| * | ||
| * Uses the identity: ||x - y||² = ||x||² + ||y||² - 2*IP(x, y) | ||
| * where ||x||² and ||y||² are precomputed sum of squares stored in the vector data. | ||
| * | ||
| * Vector layout: [uint8_t values (dim)] [min_val (float)] [delta (float)] [sum (float)] | ||
| * [sum_of_squares (float)] | ||
| */ | ||
|
|
||
| // L2 squared distance using the common inner product implementation | ||
| template <unsigned char residual> // 0..63 | ||
| float SQ8_SQ8_L2SqrSIMD64_AVX512F_BW_VL_VNNI(const void *pVec1v, const void *pVec2v, | ||
| size_t dimension) { | ||
|
|
||
| // Use the common inner product implementation (returns raw IP, not distance) | ||
| const float ip = SQ8_SQ8_InnerProductImp<residual>(pVec1v, pVec2v, dimension); | ||
|
|
||
| const uint8_t *pVec1 = static_cast<const uint8_t *>(pVec1v); | ||
| const uint8_t *pVec2 = static_cast<const uint8_t *>(pVec2v); | ||
| // Get precomputed sum of squares from both vectors | ||
| // Layout: [uint8_t values (dim)] [min_val] [delta] [sum] [sum_of_squares] | ||
| const float sum_sq_1 = *reinterpret_cast<const float *>(pVec1 + dimension + 3 * sizeof(float)); | ||
| const float sum_sq_2 = *reinterpret_cast<const float *>(pVec2 + dimension + 3 * sizeof(float)); | ||
|
|
||
| // L2² = ||x||² + ||y||² - 2*IP(x, y) | ||
| return sum_sq_1 + sum_sq_2 - 2.0f * ip; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright (c) 2006-Present, Redis Ltd. | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under your choice of the Redis Source Available License 2.0 | ||
| * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the | ||
| * GNU Affero General Public License v3 (AGPLv3). | ||
| */ | ||
| #pragma once | ||
| #include "VecSim/spaces/space_includes.h" | ||
| #include "VecSim/spaces/IP/IP_NEON_DOTPROD_SQ8_SQ8.h" | ||
|
|
||
| /** | ||
| * SQ8-to-SQ8 L2 squared distance functions for NEON with DOTPROD extension. | ||
| * Computes L2 squared distance between two SQ8 (scalar quantized 8-bit) vectors, | ||
| * where BOTH vectors are uint8 quantized. | ||
| * | ||
| * Uses the identity: ||x - y||² = ||x||² + ||y||² - 2*IP(x, y) | ||
| * where ||x||² and ||y||² are precomputed sum of squares stored in the vector data. | ||
| * | ||
| * Vector layout: [uint8_t values (dim)] [min_val (float)] [delta (float)] [sum (float)] | ||
| * [sum_of_squares (float)] | ||
| */ | ||
|
|
||
| // L2 squared distance using the common inner product implementation | ||
| template <unsigned char residual> // 0..63 | ||
| float SQ8_SQ8_L2SqrSIMD64_NEON_DOTPROD(const void *pVec1v, const void *pVec2v, size_t dimension) { | ||
| // Use the common inner product implementation (returns raw IP, not distance) | ||
| const float ip = | ||
| SQ8_SQ8_InnerProductSIMD64_NEON_DOTPROD_IMP<residual>(pVec1v, pVec2v, dimension); | ||
|
|
||
| const uint8_t *pVec1 = static_cast<const uint8_t *>(pVec1v); | ||
| const uint8_t *pVec2 = static_cast<const uint8_t *>(pVec2v); | ||
|
|
||
| // Get precomputed sum of squares from both vectors | ||
| // Layout: [uint8_t values (dim)] [min_val] [delta] [sum] [sum_of_squares] | ||
| const float sum_sq_1 = *reinterpret_cast<const float *>(pVec1 + dimension + 3 * sizeof(float)); | ||
| const float sum_sq_2 = *reinterpret_cast<const float *>(pVec2 + dimension + 3 * sizeof(float)); | ||
|
|
||
| // L2² = ||x||² + ||y||² - 2*IP(x, y) | ||
| return sum_sq_1 + sum_sq_2 - 2.0f * ip; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /* | ||
| * Copyright (c) 2006-Present, Redis Ltd. | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under your choice of the Redis Source Available License 2.0 | ||
| * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the | ||
| * GNU Affero General Public License v3 (AGPLv3). | ||
| */ | ||
| #pragma once | ||
| #include "VecSim/spaces/space_includes.h" | ||
| #include "VecSim/spaces/IP/IP_NEON_SQ8_SQ8.h" | ||
|
|
||
| /** | ||
| * SQ8-to-SQ8 L2 squared distance functions for NEON. | ||
| * Computes L2 squared distance between two SQ8 (scalar quantized 8-bit) vectors, | ||
| * where BOTH vectors are uint8 quantized. | ||
| * | ||
| * Uses the identity: ||x - y||² = ||x||² + ||y||² - 2*IP(x, y) | ||
| * where ||x||² and ||y||² are precomputed sum of squares stored in the vector data. | ||
| * | ||
| * Vector layout: [uint8_t values (dim)] [min_val (float)] [delta (float)] [sum (float)] | ||
| * [sum_of_squares (float)] | ||
| */ | ||
|
|
||
| // L2 squared distance using the common inner product implementation | ||
| template <unsigned char residual> // 0..63 | ||
| float SQ8_SQ8_L2SqrSIMD64_NEON(const void *pVec1v, const void *pVec2v, size_t dimension) { | ||
| // Use the common inner product implementation (returns raw IP, not distance) | ||
| const float ip = SQ8_SQ8_InnerProductSIMD64_NEON_IMP<residual>(pVec1v, pVec2v, dimension); | ||
|
|
||
| const uint8_t *pVec1 = static_cast<const uint8_t *>(pVec1v); | ||
| const uint8_t *pVec2 = static_cast<const uint8_t *>(pVec2v); | ||
|
|
||
| // Get precomputed sum of squares from both vectors | ||
| // Layout: [uint8_t values (dim)] [min_val] [delta] [sum] [sum_of_squares] | ||
| const float sum_sq_1 = *reinterpret_cast<const float *>(pVec1 + dimension + 3 * sizeof(float)); | ||
| const float sum_sq_2 = *reinterpret_cast<const float *>(pVec2 + dimension + 3 * sizeof(float)); | ||
|
|
||
| // L2² = ||x||² + ||y||² - 2*IP(x, y) | ||
| return sum_sq_1 + sum_sq_2 - 2.0f * ip; | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright (c) 2006-Present, Redis Ltd. | ||
| * All rights reserved. | ||
| * | ||
| * Licensed under your choice of the Redis Source Available License 2.0 | ||
| * (RSALv2); or (b) the Server Side Public License v1 (SSPLv1); or (c) the | ||
| * GNU Affero General Public License v3 (AGPLv3). | ||
| */ | ||
| #pragma once | ||
| #include "VecSim/spaces/space_includes.h" | ||
| #include "VecSim/spaces/IP/IP_SVE_SQ8_SQ8.h" | ||
|
|
||
| /** | ||
| * SQ8-to-SQ8 L2 squared distance functions for SVE. | ||
| * Computes L2 squared distance between two SQ8 (scalar quantized 8-bit) vectors, | ||
| * where BOTH vectors are uint8 quantized. | ||
| * | ||
| * Uses the identity: ||x - y||² = ||x||² + ||y||² - 2*IP(x, y) | ||
| * where ||x||² and ||y||² are precomputed sum of squares stored in the vector data. | ||
| * | ||
| * Vector layout: [uint8_t values (dim)] [min_val (float)] [delta (float)] [sum (float)] | ||
| * [sum_of_squares (float)] | ||
| */ | ||
|
|
||
| // L2 squared distance using the common inner product implementation | ||
| template <bool partial_chunk, unsigned char additional_steps> | ||
| float SQ8_SQ8_L2SqrSIMD_SVE(const void *pVec1v, const void *pVec2v, size_t dimension) { | ||
| // Use the common inner product implementation (returns raw IP, not distance) | ||
| const float ip = SQ8_SQ8_InnerProductSIMD_SVE_IMP<partial_chunk, additional_steps>( | ||
| pVec1v, pVec2v, dimension); | ||
|
|
||
| const uint8_t *pVec1 = static_cast<const uint8_t *>(pVec1v); | ||
| const uint8_t *pVec2 = static_cast<const uint8_t *>(pVec2v); | ||
|
|
||
| // Get precomputed sum of squares from both vectors | ||
| // Layout: [uint8_t values (dim)] [min_val] [delta] [sum] [sum_of_squares] | ||
| const float sum_sq_1 = *reinterpret_cast<const float *>(pVec1 + dimension + 3 * sizeof(float)); | ||
| const float sum_sq_2 = *reinterpret_cast<const float *>(pVec2 + dimension + 3 * sizeof(float)); | ||
|
|
||
| // L2² = ||x||² + ||y||² - 2*IP(x, y) | ||
| return sum_sq_1 + sum_sq_2 - 2.0f * ip; | ||
| } |
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should have a macro/ enum of the metadata indexes instead of hardcoding them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking about it.
Maybe I will add it in the renaming pr