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 optimized decoded square distance #89

Merged
merged 3 commits into from
Sep 20, 2023
Merged

Conversation

jkni
Copy link
Collaborator

@jkni jkni commented Sep 19, 2023

This also implements the necessary SimdOps backing methods, mirroring the dotProduct implementation.

As a side benefit, PQ encoding is about twice as fast.

@jkni jkni requested a review from jbellis September 19, 2023 22:59
@@ -128,8 +128,6 @@ static float dotProduct64(float[] v1, int v1offset, float[] v2, int v2offset, in
if (length == FloatVector.SPECIES_64.length())
return dot64(v1, v1offset, v2, v2offset);

assert length == 3; // or we should be calling dot 128
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note: this is removed because it's not quite right. You could be down this code path with a one-dimensional vector, which is valid everywhere else in the codebase

return diff.mul(diff).reduceLanes(VectorOperators.ADD);
}

static float squareDistance512(float[] v1, int offset1, float[] v2, int offset2) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This should be squareDistancePreferred, will fix

@jkni jkni linked an issue Sep 20, 2023 that may be closed by this pull request
Copy link
Owner

@jbellis jbellis left a comment

Choose a reason for hiding this comment

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

LGTM, but please update decodedSquareDistance to use vectorized sum like I updated decodedDP to do

@jkni jkni merged commit 439e0a5 into jbellis:main Sep 20, 2023
4 checks passed
@jkni
Copy link
Collaborator Author

jkni commented Sep 20, 2023

Pushed update to use VectorUtil.sum. Thank you for the review!

@jkni jkni deleted the jvector-85 branch November 10, 2023 22:38
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.

Add decodedSquareDistance fast-path to pq
2 participants