-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Reinstate and test the native int7u bulk dot product #138317
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
Reinstate and test the native int7u bulk dot product #138317
Conversation
|
Pinging @elastic/es-search-relevance (Team:Search Relevance) |
|
I completely reverted the java portion of the PR. Sorry. We can add the java portion back, but just not use it until we figure out the segfault Thank you for the tests!!! |
Ah, got it. Thanks. I didn't realise that there was a problem with the original change that was reverted. I was noodling with an alternative implementation, which caused me to write the test. I think that we can squeeze a bit more perf out of this code, possibly another 15-20% on top of what you already got! |
|
Absolutely beautiful! I am not sure the cause of the segfault, but I suspect alignment issues by casting the int to a float. So maybe we need to adjust the function definition or we do the casting in such a way it doesn't suffer from alignment problems |
|
For my own future reference, a few command to help build and test locally. AArch64 x64 |
|
Posting some benchmarking numbers. Linux x64 - 11th Gen Intel(R) Core(TM) i5-11400 @ 2.60GHz Mac M2 |
| static void dotProduct7uBulk(MemorySegment a, MemorySegment b, int length, int count, MemorySegment result) { | ||
| Objects.checkFromIndexSize(0, length * count, (int) a.byteSize()); | ||
| Objects.checkFromIndexSize(0, length, (int) b.byteSize()); | ||
| Objects.checkFromIndexSize(0, count * Float.BYTES, (int) result.byteSize()); |
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 added these runtime checks here just before going native, similar to other functions, so that we have a handle on the values that we pass through. Passing invalid values could lead to crashes or worse, so we enforce these here.
ldematte
left a comment
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.
LGTM, and thanks for the additional tests!
I had a feeling the segfault was due to a wrong type size, but I was chasing the wrong guy :) Nice find!
| } | ||
| } | ||
|
|
||
| public void testInt7uBulk() { |
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.
This test reliably reproduces the previous segv issue.
This commit reinstates, fixes, and tests the native int7u bulk dot product #138239
The issue with the original change is that
size_tis 64 bit, while we pass a 32 bitintfrom java. This is also arguably an issue with the other native definitions, but doesn't cause an issue because of position in the declaration (last). We should fix these declarations, but as a separate PR.closes #138302