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 functionality to test if the host CPU supports native SIMD instructions #107429
Conversation
// There must be at least this number of bytes/elements available when going native | ||
static final int DOT_STRIDE = 32; | ||
static final int SQR_STRIDE = 16; | ||
static final MethodHandle dot8stride$mh = downcallHandle("dot8s_stride", FunctionDescriptor.of(JAVA_INT)); |
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.
@ChrisHegarty GH made a bit of a mess with the diff, but essentially code from here to the end is the same, just indendeted (encapsulated in the private inner class)
Pinging @elastic/es-search (Team:Search) |
@elasticmachine update branch |
libs/native/src/main/java/org/elasticsearch/nativeaccess/VectorSimilarityFunctions.java
Show resolved
Hide resolved
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
@elasticmachine update branch |
@elasticmachine update branch |
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
@elasticmachine update branch |
This commit adds the ability to check if the host CPU supports the instruction set we use in our native vector code.
This is to avoid having the process terminated (badly) because we tried to execute a non-supported instruction; better know this early, and avoid to take the native code path entirely.
The
int vec_caps()
function, implemented in the native code (C) of the library, returns 0 if the processor does not support (i.e. cannot run) the instructions used to implement the other functions.On ARM, we use the NEON vector instruction set (#106133):
vec_caps()
is trivial and returns1
; for M-series CPUs, we can safely assume NEON is always present.getauxval
withAT_HWCAP
, and test for theHWCAP_NEON
bit (4096).I've tested
getauxval
on various ARM systems and emulators (including Graviton on AWS); the NEON instruction set seems to be widely available - I was not able to find a processor supportingarmv8
and not supporting NEON; nevertheless, I think that adding this functionality is good for 3 reasons:The last point: since
vec_caps()
returns an integer, we may want to return different values (e.g. 2) to indicate some "advanced support", and dynamically bind to a different flavor of the function (e.g.dot8s_2
) that is implemented with a more performant but less diffused instruction set (e.g. AVX512, armv9, etc.)