Skip to content
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

Implement UINT8 vector type - [MOD-8230, MOD-8408] #584

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

GuyAv46
Copy link
Collaborator

@GuyAv46 GuyAv46 commented Dec 26, 2024

Implement support for new type UINT8

This PR follows the implementation of the INT8 type and implements all the functionality required for the UINT8 type.

Mark if applicable

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

@GuyAv46 GuyAv46 changed the title Implement UINT8 vector type - [MOD-8230] Implement UINT8 vector type - [MOD-8230, MOD-8408] Dec 30, 2024
@GuyAv46 GuyAv46 marked this pull request as ready for review December 30, 2024 14:48
@GuyAv46 GuyAv46 requested a review from meiravgri December 30, 2024 14:48
Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.19%. Comparing base (3291f63) to head (727b86c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #584      +/-   ##
==========================================
+ Coverage   97.09%   97.19%   +0.10%     
==========================================
  Files         104      106       +2     
  Lines        5503     5713     +210     
==========================================
+ Hits         5343     5553     +210     
  Misses        160      160              

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

@GuyAv46 GuyAv46 requested a review from alonre24 December 31, 2024 09:14
src/VecSim/spaces/normalize/normalize_naive.h Outdated Show resolved Hide resolved
tests/unit/unit_test_utils.cpp Show resolved Hide resolved
Comment on lines +301 to +305
// For uint8 vectors with cosine distance, the extra float for the norm shifts alignment to
// `(dim + sizeof(float)) % 32`.
// Vectors satisfying this have a residual, causing offset loads during calculation.
// To avoid complexity, we skip alignment here, assuming the performance impact is
// negligible.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I need to better understand the considerations here (I see it follows INT8 as well)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍🏼. I also thought about it and if we put the norm at the beginning of the vector we will be able to use alignment

Copy link
Collaborator

Choose a reason for hiding this comment

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

As discussed - let's open a (small) spike to try that

tests/flow/test_bruteforce.py Show resolved Hide resolved
tests/flow/test_bruteforce.py Show resolved Hide resolved
Copy link
Collaborator

@meiravgri meiravgri left a comment

Choose a reason for hiding this comment

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

cool

src/VecSim/spaces/IP/IP.cpp Outdated Show resolved Hide resolved
src/VecSim/spaces/IP/IP_AVX512F_BW_VL_VNNI_UINT8.h Outdated Show resolved Hide resolved
src/VecSim/spaces/IP/IP_AVX512F_BW_VL_VNNI_UINT8.h Outdated Show resolved Hide resolved
src/VecSim/spaces/L2/L2.cpp Outdated Show resolved Hide resolved
src/VecSim/spaces/L2/L2.cpp Outdated Show resolved Hide resolved
src/VecSim/spaces/normalize/normalize_naive.h Outdated Show resolved Hide resolved
tests/benchmark/benchmarks.sh Show resolved Hide resolved
tests/flow/test_bruteforce.py Show resolved Hide resolved
@GuyAv46 GuyAv46 requested review from meiravgri and alonre24 January 2, 2025 15:28
Comment on lines +71 to +81
// The type should be able to hold `dimension * MAX_VAL(int_elem_t) * MAX_VAL(int_elem_t)`.
// To support dimension up to 2^16, we need the difference between the type and int_elem_t to be at
// least 2 bytes. We assert that in the implementation.
template <typename int_elem_t>
using ret_t = std::conditional_t<sizeof(int_elem_t) == 1, int, long long>;

template <typename int_elem_t>
static inline ret_t<int_elem_t>
INTEGER_InnerProductImp(const int_elem_t *pVect1, const int_elem_t *pVect2, size_t dimension) {
static_assert(sizeof(ret_t<int_elem_t>) - sizeof(int_elem_t) * 2 >= sizeof(uint16_t));
ret_t<int_elem_t> res = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This generic introduced for possible future integer types larger than 1 byte?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants