mirror of
https://github.com/facebookresearch/faiss.git
synced 2025-06-03 16:44:17 +08:00
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
96 lines
2.7 KiB
CMake
96 lines
2.7 KiB
CMake
# 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.
|
|
|
|
# =============================================================================
|
|
# Copyright (c) 2023, NVIDIA CORPORATION.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
|
# in compliance with the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
|
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
|
# or implied. See the License for the specific language governing permissions and limitations under
|
|
# the License.
|
|
# =============================================================================
|
|
|
|
cmake_minimum_required(VERSION 3.23.1 FATAL_ERROR)
|
|
|
|
set(FAISS_LANGUAGES CXX)
|
|
|
|
if(FAISS_ENABLE_GPU)
|
|
list(APPEND FAISS_LANGUAGES CUDA)
|
|
endif()
|
|
|
|
if(FAISS_ENABLE_RAFT)
|
|
include(cmake/thirdparty/fetch_rapids.cmake)
|
|
include(rapids-cmake)
|
|
include(rapids-cpm)
|
|
include(rapids-cuda)
|
|
include(rapids-export)
|
|
include(rapids-find)
|
|
|
|
rapids_cuda_init_architectures(faiss)
|
|
rapids_cuda_init_architectures(pyfaiss)
|
|
rapids_cuda_init_architectures(faiss_c_library)
|
|
endif()
|
|
|
|
project(faiss
|
|
VERSION 1.7.4
|
|
DESCRIPTION "A library for efficient similarity search and clustering of dense vectors."
|
|
HOMEPAGE_URL "https://github.com/facebookresearch/faiss"
|
|
LANGUAGES ${FAISS_LANGUAGES})
|
|
include(GNUInstallDirs)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
|
|
|
# Valid values are "generic", "avx2", "avx512".
|
|
option(FAISS_OPT_LEVEL "" "generic")
|
|
option(FAISS_ENABLE_GPU "Enable support for GPU indexes." ON)
|
|
option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
|
|
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
|
|
option(FAISS_ENABLE_C_API "Build C API." OFF)
|
|
|
|
if(FAISS_ENABLE_GPU)
|
|
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
|
|
enable_language(CUDA)
|
|
endif()
|
|
|
|
if(FAISS_ENABLE_RAFT)
|
|
find_package(raft COMPONENTS compiled distributed)
|
|
endif()
|
|
|
|
add_subdirectory(faiss)
|
|
|
|
if(FAISS_ENABLE_GPU)
|
|
add_subdirectory(faiss/gpu)
|
|
endif()
|
|
|
|
if(FAISS_ENABLE_PYTHON)
|
|
add_subdirectory(faiss/python)
|
|
endif()
|
|
|
|
if(FAISS_ENABLE_C_API)
|
|
add_subdirectory(c_api)
|
|
endif()
|
|
|
|
add_subdirectory(demos)
|
|
add_subdirectory(benchs)
|
|
add_subdirectory(tutorial/cpp)
|
|
|
|
# CTest must be included in the top level to enable `make test` target.
|
|
include(CTest)
|
|
if(BUILD_TESTING)
|
|
add_subdirectory(tests)
|
|
|
|
if(FAISS_ENABLE_GPU)
|
|
add_subdirectory(faiss/gpu/test)
|
|
endif()
|
|
endif()
|