faiss/tests/CMakeLists.txt

78 lines
2.1 KiB
CMake
Raw Normal View History

# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
set(FAISS_TEST_SRC
test_binary_flat.cpp
test_dealloc_invlists.cpp
test_ivfpq_codec.cpp
test_ivfpq_indexing.cpp
test_lowlevel_ivf.cpp
test_ivf_index.cpp
test_merge.cpp
test_omp_threads.cpp
test_ondisk_ivf.cpp
test_pairs_decoding.cpp
test_params_override.cpp
test_pq_encoding.cpp
test_sliding_ivf.cpp
test_threaded_index.cpp
test_transfer_invlists.cpp
test_mem_leak.cpp
test_cppcontrib_sa_decode.cpp
test_cppcontrib_uintreader.cpp
test_simdlib.cpp
test_approx_topk.cpp
test_RCQ_cropping.cpp
test_distances_simd.cpp
test_heap.cpp
test_code_distance.cpp
test_hnsw.cpp
test_partitioning.cpp
test_fastscan_perf.cpp
)
add_executable(faiss_test ${FAISS_TEST_SRC})
Introduce avx512 optimization mode and FAISS_OPT_LEVEL env variable (#3150) Summary: 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. ``` Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3150 Reviewed By: algoriddle Differential Revision: D51701077 Pulled By: mdouze fbshipit-source-id: 4db05a287e763ff1ce1f676df7f7402532bf1e9e
2023-12-05 01:39:52 -08:00
if(NOT FAISS_OPT_LEVEL STREQUAL "avx2" AND NOT FAISS_OPT_LEVEL STREQUAL "avx512")
target_link_libraries(faiss_test PRIVATE faiss)
endif()
if(FAISS_OPT_LEVEL STREQUAL "avx2")
if(NOT WIN32)
target_compile_options(faiss_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma>)
else()
target_compile_options(faiss_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:AVX2>)
endif()
target_link_libraries(faiss_test PRIVATE faiss_avx2)
Introduce avx512 optimization mode and FAISS_OPT_LEVEL env variable (#3150) Summary: 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. ``` Pull Request resolved: https://github.com/facebookresearch/faiss/pull/3150 Reviewed By: algoriddle Differential Revision: D51701077 Pulled By: mdouze fbshipit-source-id: 4db05a287e763ff1ce1f676df7f7402532bf1e9e
2023-12-05 01:39:52 -08:00
endif()
if(FAISS_OPT_LEVEL STREQUAL "avx512")
if(NOT WIN32)
target_compile_options(faiss_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-mavx2 -mfma -mavx512f -mavx512f -mavx512cd -mavx512vl -mavx512dq -mavx512bw>)
else()
target_compile_options(faiss_test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/arch:AVX512>)
endif()
target_link_libraries(faiss_test PRIVATE faiss_avx512)
endif()
include(FetchContent)
FetchContent_Declare(googletest
URL "https://github.com/google/googletest/archive/release-1.12.1.tar.gz")
set(BUILD_GMOCK CACHE BOOL OFF)
set(INSTALL_GTEST CACHE BOOL OFF)
FetchContent_MakeAvailable(googletest)
find_package(OpenMP REQUIRED)
target_link_libraries(faiss_test PRIVATE
OpenMP::OpenMP_CXX
gtest_main
)
# Defines `gtest_discover_tests()`.
include(GoogleTest)
gtest_discover_tests(faiss_test)