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

Introduce avx512 optimization mode and FAISS_OPT_LEVEL env variable #3150

Closed

Conversation

alexanderguzhva
Copy link
Contributor

@alexanderguzhva alexanderguzhva commented Nov 28, 2023

Enables avx512 optimized code (AVX512 subsets F, CD, VL, DQ and BW, which are available for Intel Skylake+ and all AMD Zen4).
Also, introduces FAISS_OPT_LEVEL environment variable. Set it to AVX2, AVX512 or empty to pick the appropriate x86_64 instruction set.

Compiled via the following

cmake -B build -DCMAKE_BUILD_TYPE=Release -DFAISS_ENABLE_GPU=OFF -DFAISS_OPT_LEVEL=avx512 -DBUILD_TESTING=ON .
make -C build -j 8 faiss_test
make -C build -j 8 swigfaiss
make -C build -j 8 swigfaiss_avx2
make -C build -j 8 swigfaiss_avx512
cd build/faiss/python
python3 setup.py build
python3 setup.py install --force

Now, running the following script 1.py

import logging
logging.basicConfig(level=logging.DEBUG)

import faiss

produces the following:

root@6179abeef23c:~/faiss# LOGLEVEL=DEBUG FAISS_OPT_LEVEL= python3 1.py
DEBUG:faiss.loader:Using  as an instruction set.
INFO:faiss.loader:Loading faiss.
INFO:faiss.loader:Successfully loaded faiss.
root@6179abeef23c:~/faiss# LOGLEVEL=DEBUG FAISS_OPT_LEVEL=AVX2 python3 1.py
DEBUG:faiss.loader:Using AVX2 as an instruction set.
INFO:faiss.loader:Loading faiss with AVX2 support.
INFO:faiss.loader:Successfully loaded faiss with AVX2 support.
root@6179abeef23c:~/faiss# LOGLEVEL=DEBUG FAISS_OPT_LEVEL=AVX512 python3 1.py
DEBUG:faiss.loader:Using AVX512 as an instruction set.
INFO:faiss.loader:Loading faiss with AVX512 support.
INFO:faiss.loader:Successfully loaded faiss with AVX512 support.
root@6179abeef23c:~/faiss# LOGLEVEL=DEBUG python3 1.py
DEBUG:faiss.loader:Environment variable FAISS_OPT_LEVEL is not set, so let's pick the instruction set according to the current CPU
INFO:faiss.loader:Loading faiss with AVX512 support.
INFO:faiss.loader:Successfully loaded faiss with AVX512 support.

Copy link
Contributor

@mdouze mdouze left a comment

Choose a reason for hiding this comment

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

You probably added faiss/python/swigfaiss_avx512.swig by mistake

  • please add a flag to get_compile_options()

std::string get_compile_options() {

Maybe add an env variable FAISS_OPT_LEVEL that overrides the switching code between the capabilities, then we can run the test suite for the 3 opt levels (but that can be done in a subsequent diff).

@alexanderguzhva
Copy link
Contributor Author

@mdouze done, including FAISS_OPT_LEVEL. And you're correct, I've missed swigfaiss_avx512.swig

@alexanderguzhva
Copy link
Contributor Author

do not merge, 1 more change is needed

Signed-off-by: Alexandr Guzhva <alexanderguzhva@gmail.com>
@alexanderguzhva
Copy link
Contributor Author

good to go

@alexanderguzhva alexanderguzhva changed the title Introduce avx512 optimization mode. Introduce avx512 optimization mode and FAISS_OPT_LEVEL env variable Nov 29, 2023
@facebook-github-bot
Copy link
Contributor

@mdouze has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mdouze merged this pull request in eefa391.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants