faiss/tests/CMakeLists.txt

102 lines
2.9 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
test_disable_pq_sdc_tables.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 17: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 17: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
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG 58d77fa8070e8cec2dc1ed015d66b454c8d78850 # release-1.12.1
OVERRIDE_FIND_PACKAGE)
set(BUILD_GMOCK CACHE BOOL OFF)
set(INSTALL_GTEST CACHE BOOL OFF)
FetchContent_MakeAvailable(googletest)
if(NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake
AND NOT EXISTS ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/GTestConfig.cmake)
file(
WRITE ${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/gtest-config.cmake
[=[
include(CMakeFindDependencyMacro)
find_dependency(googletest)
if(NOT TARGET GTest::GTest)
add_library(GTest::GTest INTERFACE IMPORTED)
target_link_libraries(GTest::GTest INTERFACE GTest::gtest)
endif()
if(NOT TARGET GTest::Main)
add_library(GTest::Main INTERFACE IMPORTED)
target_link_libraries(GTest::Main INTERFACE GTest::gtest_main)
endif()
]=])
endif()
find_package(OpenMP REQUIRED)
find_package(GTest CONFIG REQUIRED)
target_link_libraries(faiss_test PRIVATE
OpenMP::OpenMP_CXX
GTest::gtest_main
$<$<BOOL:${FAISS_ENABLE_RAFT}>:raft::raft>
)
# Defines `gtest_discover_tests()`.
include(GoogleTest)
gtest_discover_tests(faiss_test)