Skip to content

missing auto-vectorization for AVX512 #4511

@jinjunzh

Description

@jinjunzh

PR #4025 introduced a new architecture mode, avx512_spr, which enables the use of features available since Intel® Sapphire Rapids. During benchmarking OpenSearch on Sapphire Rapids server, it's observed that some key hot functions are not built as expected, such as faiss::fvec_inner_product and faiss::fvec_inner_product_batch_4.
Since this is definitely my FAISS library built with FAISS_OPT_LEVEL=avx512_spr, the two functions in the library should have been auto-vectorized using AVX-512 instructions, rather than AVX2.​

After conducting an in-depth analysis, I‘ve identified that the root cause is the absence of the compiler flag ​​-mprefer-vector-width=512​​ in the ​​CMakeLists.txt​​ file. A patch to fix this issue is provided below. Please help confirm whether this is indeed a bug.

diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt
index 8ee79bd9..46460501 100644
--- a/faiss/CMakeLists.txt
+++ b/faiss/CMakeLists.txt
@@ -291,7 +291,7 @@ endif()
if(NOT WIN32)
- target_compile_options(faiss_avx512_spr PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-march=sapphirerapids -mtune=sapphirerapids>)
+ target_compile_options(faiss_avx512_spr PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-march=sapphirerapids -mtune=sapphirerapids -mprefer-vector-width=512>)
else()
target_compile_options(faiss_avx512_spr PRIVATE $&lt;$&lt;COMPILE_LANGUAGE:CXX>:/arch:AVX512>)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions