-
Notifications
You must be signed in to change notification settings - Fork 85
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
Add Int8Vector SIMD APIs for avx512/avx2/sse/ref #1098
Merged
sre-ci-robot
merged 1 commit into
zilliztech:main
from
cydrain:caiyd_977_simd_support_int8_part1
Feb 28, 2025
Merged
Changes from all commits
Commits
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 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 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 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 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 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 |
---|---|---|
|
@@ -2113,6 +2113,85 @@ bf16_vec_L2sqr_batch_4_neon(const knowhere::bf16* x, const knowhere::bf16* y0, c | |
dis3 = vaddvq_f32(res.val[3]); | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// int8 | ||
|
||
float | ||
int8_vec_inner_product_neon(const int8_t* x, const int8_t* y, size_t d) { | ||
// TODO caiyd: use ref implementation temporarily | ||
int32_t res = 0; | ||
for (size_t i = 0; i < d; i++) { | ||
res += (int32_t)x[i] * (int32_t)y[i]; | ||
} | ||
return (float)res; | ||
} | ||
|
||
float | ||
int8_vec_L2sqr_neon(const int8_t* x, const int8_t* y, size_t d) { | ||
// TODO caiyd: use ref implementation temporarily | ||
int32_t res = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
for (size_t i = 0; i < d; i++) { | ||
const int32_t tmp = (int32_t)x[i] - (int32_t)y[i]; | ||
res += tmp * tmp; | ||
} | ||
return (float)res; | ||
} | ||
|
||
float | ||
int8_vec_norm_L2sqr_neon(const int8_t* x, size_t d) { | ||
// TODO caiyd: use ref implementation temporarily | ||
int32_t res = 0; | ||
for (size_t i = 0; i < d; i++) { | ||
res += (int32_t)x[i] * (int32_t)x[i]; | ||
} | ||
return (float)res; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. implement a neon version. |
||
} | ||
|
||
void | ||
int8_vec_inner_product_batch_4_neon(const int8_t* x, const int8_t* y0, const int8_t* y1, const int8_t* y2, | ||
const int8_t* y3, const size_t d, float& dis0, float& dis1, float& dis2, | ||
float& dis3) { | ||
// TODO caiyd: use ref implementation temporarily | ||
int32_t d0 = 0, d1 = 0, d2 = 0, d3 = 0; | ||
|
||
for (size_t i = 0; i < d; ++i) { | ||
auto x_i = (int32_t)x[i]; | ||
d0 += x_i * (int32_t)y0[i]; | ||
d1 += x_i * (int32_t)y1[i]; | ||
d2 += x_i * (int32_t)y2[i]; | ||
d3 += x_i * (int32_t)y3[i]; | ||
} | ||
|
||
dis0 = (float)d0; | ||
dis1 = (float)d1; | ||
dis2 = (float)d2; | ||
dis3 = (float)d3; | ||
} | ||
|
||
void | ||
int8_vec_L2sqr_batch_4_neon(const int8_t* x, const int8_t* y0, const int8_t* y1, const int8_t* y2, const int8_t* y3, | ||
const size_t d, float& dis0, float& dis1, float& dis2, float& dis3) { | ||
// TODO caiyd: use ref implementation temporarily | ||
int32_t d0 = 0, d1 = 0, d2 = 0, d3 = 0; | ||
|
||
for (size_t i = 0; i < d; ++i) { | ||
auto x_i = (int32_t)x[i]; | ||
const int32_t q0 = x_i - (int32_t)y0[i]; | ||
const int32_t q1 = x_i - (int32_t)y1[i]; | ||
const int32_t q2 = x_i - (int32_t)y2[i]; | ||
const int32_t q3 = x_i - (int32_t)y3[i]; | ||
d0 += q0 * q0; | ||
d1 += q1 * q1; | ||
d2 += q2 * q2; | ||
d3 += q3 * q3; | ||
} | ||
|
||
dis0 = (float)d0; | ||
dis1 = (float)d1; | ||
dis2 = (float)d2; | ||
dis3 = (float)d3; | ||
} | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
// for cardinal | ||
|
||
|
This file contains 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.
Duplicated code here
{
return int8_vec_inner_product_ref(x, y, d);
}
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.
no, the duplicated code is correct, bcz it will be compiled with different compiler options