2020-08-15 06:01:43 +08:00
|
|
|
# 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.
|
|
|
|
|
2023-05-04 04:13:45 +08:00
|
|
|
# =============================================================================
|
|
|
|
# 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.
|
|
|
|
# =============================================================================
|
|
|
|
|
2024-04-17 18:43:57 +08:00
|
|
|
cmake_minimum_required(VERSION 3.24.0 FATAL_ERROR)
|
2020-08-15 06:01:43 +08:00
|
|
|
|
2023-05-04 04:13:45 +08:00
|
|
|
set(FAISS_LANGUAGES CXX)
|
|
|
|
|
|
|
|
if(FAISS_ENABLE_GPU)
|
2024-08-02 05:47:56 +08:00
|
|
|
if (FAISS_ENABLE_ROCM)
|
2024-08-01 06:00:10 +08:00
|
|
|
list(APPEND FAISS_LANGUAGES HIP)
|
2024-08-02 05:47:56 +08:00
|
|
|
list(PREPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake")
|
|
|
|
list(PREPEND CMAKE_PREFIX_PATH "/opt/rocm")
|
2024-08-01 06:00:10 +08:00
|
|
|
else()
|
|
|
|
list(APPEND FAISS_LANGUAGES CUDA)
|
|
|
|
endif()
|
2023-05-04 04:13:45 +08:00
|
|
|
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)
|
2023-06-13 23:43:18 +08:00
|
|
|
rapids_cuda_init_architectures(pyfaiss)
|
|
|
|
rapids_cuda_init_architectures(faiss_c_library)
|
2023-05-04 04:13:45 +08:00
|
|
|
endif()
|
|
|
|
|
2020-08-15 06:01:43 +08:00
|
|
|
project(faiss
|
2024-03-01 05:24:50 +08:00
|
|
|
VERSION 1.8.0
|
2020-08-15 06:01:43 +08:00
|
|
|
DESCRIPTION "A library for efficient similarity search and clustering of dense vectors."
|
|
|
|
HOMEPAGE_URL "https://github.com/facebookresearch/faiss"
|
2023-05-04 04:13:45 +08:00
|
|
|
LANGUAGES ${FAISS_LANGUAGES})
|
2020-11-25 15:09:01 +08:00
|
|
|
include(GNUInstallDirs)
|
2020-08-15 06:01:43 +08:00
|
|
|
|
2023-05-04 04:13:45 +08:00
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
2020-08-15 06:01:43 +08:00
|
|
|
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
|
|
|
|
Add sve targets (#2886)
Summary:
related: https://github.com/facebookresearch/faiss/issues/2884
This PR contains below changes:
- Add new optlevel `sve`
- ARM SVE is _extension_ of ARMv8, so it should be treated similar to AVX2 IMO
- Add targets for ARM SVE, `faiss_sve` and `swigfaiss_sve`
- These targets will be built when you give `-DFAISS_OPT_LEVEL=sve` at build time
- Design decision: Don't fix SVE register length.
- The python package of faiss is "fat binary" (for example, the package for avx2 contains `_swigfaiss_avx2.so` and `_swigfaiss.so`)
- SVE is scalable instruction set (= doesn't fix vector length), but actually we can specify the vector length at compile time.
- [with `-msve-vector-length=` option](https://developer.arm.com/documentation/101726/4-0/Coding-for-Scalable-Vector-Extension--SVE-/SVE-Vector-Length-Specific--VLS--programming)
- When this option is specified, the binary can't work correctly on the CPU which has other vector length rather than specified at compile time
- When we use fixed vector length, SVE-supported faiss python package will contain 7 shared libraries like `_swigfaiss.so` , `_swigfaiss_sve.so` , `_swigfaiss_sve128.so` , `_swigfaiss_sve256.so` , `_swigfaiss_sve512.so` , `_swigfaiss_sve1024.so` , and `_swigfaiss_sve2048.so` . The package size will be exploded.
- For these reason, I don't specify the vector length at compile time and `faiss_sve` detects the vector length at run time.
- Add a mechanism of detecting ARM SVE on runtime environment and importing `swigfaiss_sve` dynamically
- Currently it only supports Linux, but there is no SVE environment with non-Linux OS now, as far as I know
NOTE: I plan to make one more PR about add some SVE implementation after this PR merged. This PR only contains adding sve target.
Pull Request resolved: https://github.com/facebookresearch/faiss/pull/2886
Reviewed By: ramilbakhshyiev
Differential Revision: D60386983
Pulled By: mengdilin
fbshipit-source-id: 7e66162ee53ce88fbfb6636e7bf705b44e6c3282
2024-07-30 06:05:17 +08:00
|
|
|
# Valid values are "generic", "avx2", "avx512", "sve".
|
2020-08-15 06:01:43 +08:00
|
|
|
option(FAISS_OPT_LEVEL "" "generic")
|
|
|
|
option(FAISS_ENABLE_GPU "Enable support for GPU indexes." ON)
|
2023-05-04 04:13:45 +08:00
|
|
|
option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
|
2024-08-02 05:47:56 +08:00
|
|
|
option(FAISS_ENABLE_ROCM "Enable ROCm for GPU indexes." OFF)
|
2020-08-15 06:01:43 +08:00
|
|
|
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
|
2021-02-16 04:40:02 +08:00
|
|
|
option(FAISS_ENABLE_C_API "Build C API." OFF)
|
2024-08-28 04:36:53 +08:00
|
|
|
option(FAISS_USE_LTO "Enable Link-Time optimization" OFF)
|
2020-08-15 06:01:43 +08:00
|
|
|
|
|
|
|
if(FAISS_ENABLE_GPU)
|
2024-08-03 06:07:01 +08:00
|
|
|
if(FAISS_ENABLE_ROCM)
|
2024-08-01 06:00:10 +08:00
|
|
|
enable_language(HIP)
|
2024-08-03 06:07:01 +08:00
|
|
|
add_definitions(-DUSE_AMD_ROCM)
|
2024-08-01 06:00:10 +08:00
|
|
|
find_package(HIP REQUIRED)
|
|
|
|
find_package(hipBLAS REQUIRED)
|
|
|
|
set(GPU_EXT_PREFIX "hip")
|
|
|
|
else ()
|
|
|
|
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
|
|
|
|
enable_language(CUDA)
|
|
|
|
set(GPU_EXT_PREFIX "cu")
|
|
|
|
endif()
|
2020-08-15 06:01:43 +08:00
|
|
|
endif()
|
|
|
|
|
2024-02-21 22:41:08 +08:00
|
|
|
if(FAISS_ENABLE_RAFT AND NOT TARGET raft::raft)
|
2024-08-02 05:47:56 +08:00
|
|
|
find_package(raft COMPONENTS compiled distributed)
|
|
|
|
endif()
|
|
|
|
|
2020-08-15 06:01:43 +08:00
|
|
|
add_subdirectory(faiss)
|
|
|
|
|
|
|
|
if(FAISS_ENABLE_GPU)
|
2024-08-03 06:07:01 +08:00
|
|
|
if(FAISS_ENABLE_ROCM)
|
2024-08-01 06:00:10 +08:00
|
|
|
add_subdirectory(faiss/gpu-rocm)
|
|
|
|
else()
|
|
|
|
add_subdirectory(faiss/gpu)
|
|
|
|
endif()
|
2020-08-15 06:01:43 +08:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(FAISS_ENABLE_PYTHON)
|
|
|
|
add_subdirectory(faiss/python)
|
|
|
|
endif()
|
|
|
|
|
2021-02-16 04:40:02 +08:00
|
|
|
if(FAISS_ENABLE_C_API)
|
|
|
|
add_subdirectory(c_api)
|
|
|
|
endif()
|
|
|
|
|
2020-08-15 06:01:43 +08:00
|
|
|
add_subdirectory(demos)
|
2022-09-30 21:40:03 +08:00
|
|
|
add_subdirectory(benchs)
|
2020-08-15 06:01:43 +08:00
|
|
|
add_subdirectory(tutorial/cpp)
|
|
|
|
|
2020-10-13 01:38:08 +08:00
|
|
|
# CTest must be included in the top level to enable `make test` target.
|
|
|
|
include(CTest)
|
2020-08-15 06:01:43 +08:00
|
|
|
if(BUILD_TESTING)
|
|
|
|
add_subdirectory(tests)
|
|
|
|
|
|
|
|
if(FAISS_ENABLE_GPU)
|
2024-08-03 06:07:01 +08:00
|
|
|
if(FAISS_ENABLE_ROCM)
|
2024-08-01 06:00:10 +08:00
|
|
|
add_subdirectory(faiss/gpu-rocm/test)
|
|
|
|
else()
|
|
|
|
add_subdirectory(faiss/gpu/test)
|
|
|
|
endif()
|
2020-08-15 06:01:43 +08:00
|
|
|
endif()
|
|
|
|
endif()
|