forked from facebookresearch/faiss
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
176 lines (154 loc) · 5.59 KB
/
Copy pathCMakeLists.txt
File metadata and controls
176 lines (154 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# @lint-ignore-every LICENSELINT
# 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-2024, 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.24.0 FATAL_ERROR)
set(FAISS_LANGUAGES CXX)
if(FAISS_ENABLE_GPU)
if (FAISS_ENABLE_ROCM)
list(APPEND FAISS_LANGUAGES HIP)
list(PREPEND CMAKE_MODULE_PATH "/opt/rocm/lib/cmake")
list(PREPEND CMAKE_PREFIX_PATH "/opt/rocm")
else()
list(APPEND FAISS_LANGUAGES CUDA)
endif()
endif()
if(FAISS_ENABLE_METAL)
list(APPEND FAISS_LANGUAGES OBJCXX)
endif()
# FAISS_ENABLE_METAL may not yet be in the cache on the first cmake run
# (the option() call is after project()). If the user didn't pass
# -DFAISS_ENABLE_METAL=... on the command line we pre-seed the cache
# now so that OBJCXX is added to the project languages.
# Only default to ON on Apple Silicon (arm64); Intel Macs are not
# supported by the Metal backend.
# Prefer CMAKE_SYSTEM_* (target platform, set by toolchain files for
# cross-compiles) and fall back to CMAKE_HOST_* (build machine).
if(NOT DEFINED FAISS_ENABLE_METAL)
if(DEFINED CMAKE_SYSTEM_NAME)
set(_faiss_metal_sys "${CMAKE_SYSTEM_NAME}")
set(_faiss_metal_proc "${CMAKE_SYSTEM_PROCESSOR}")
else()
set(_faiss_metal_sys "${CMAKE_HOST_SYSTEM_NAME}")
set(_faiss_metal_proc "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif()
if(_faiss_metal_sys STREQUAL "Darwin" AND _faiss_metal_proc STREQUAL "arm64")
set(FAISS_ENABLE_METAL ON CACHE BOOL
"Enable Metal GPU backend for Apple Silicon.")
list(APPEND FAISS_LANGUAGES OBJCXX)
endif()
endif()
if(FAISS_ENABLE_CUVS)
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.15.0
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 20)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Valid values are "generic", "avx2", "avx512", "avx512_spr", "sve".
option(FAISS_OPT_LEVEL "" "generic")
option(FAISS_ENABLE_GPU "Enable support for GPU indexes." ON)
option(FAISS_GPU_STATIC "Link GPU libraries statically." OFF)
option(FAISS_ENABLE_CUVS "Enable cuVS for GPU indexes." OFF)
option(FAISS_ENABLE_ROCM "Enable ROCm for GPU indexes." OFF)
option(FAISS_ENABLE_MKL "Enable MKL." ON)
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
option(FAISS_ENABLE_C_API "Build C API." OFF)
option(FAISS_ENABLE_EXTRAS "Build extras like benchmarks and demos" ON)
option(FAISS_USE_LTO "Enable Link-Time optimization" OFF)
if(APPLE AND CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(_FAISS_METAL_DEFAULT ON)
else()
set(_FAISS_METAL_DEFAULT OFF)
endif()
option(FAISS_ENABLE_METAL "Enable Metal GPU backend for Apple Silicon."
${_FAISS_METAL_DEFAULT})
option(FAISS_ENABLE_SVS "Enable SVS (Intel(R) Scalable Vector Search) integration." OFF)
set(FAISS_SVS_RUNTIME_VERSION "v0" CACHE STRING "Version of the SVS runtime API to use")
set_property(CACHE FAISS_SVS_RUNTIME_VERSION PROPERTY STRINGS "v0")
if(FAISS_ENABLE_GPU)
if(FAISS_ENABLE_ROCM)
enable_language(HIP)
add_definitions(-DUSE_AMD_ROCM)
find_package(HIP REQUIRED)
find_package(hipBLAS REQUIRED)
set(GPU_EXT_PREFIX "hip")
execute_process(COMMAND ${PROJECT_SOURCE_DIR}/faiss/gpu/hipify.sh)
else ()
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
enable_language(CUDA)
set(GPU_EXT_PREFIX "cu")
endif()
endif()
if(FAISS_ENABLE_CUVS AND NOT TARGET cuvs::cuvs)
find_package(cuvs)
endif()
if(FAISS_ENABLE_CUVS AND NOT TARGET rmm::rmm)
find_package(rmm REQUIRED)
endif()
add_subdirectory(faiss)
if(FAISS_ENABLE_GPU)
add_subdirectory(faiss/gpu)
endif()
if(FAISS_ENABLE_METAL)
if(NOT APPLE)
message(FATAL_ERROR "FAISS_ENABLE_METAL requires Apple (macOS) platform.")
endif()
add_subdirectory(faiss/gpu_metal)
endif()
if(FAISS_ENABLE_PYTHON)
add_subdirectory(faiss/python)
endif()
if(FAISS_ENABLE_C_API)
add_subdirectory(c_api)
endif()
if(FAISS_ENABLE_EXTRAS)
add_subdirectory(demos)
add_subdirectory(benchs)
add_subdirectory(tutorial/cpp)
endif()
# CTest must be included in the top level to enable `make test` target.
include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
if(NOT WIN32 AND NOT CMAKE_CROSSCOMPILING)
add_subdirectory(perf_tests)
endif()
if(FAISS_ENABLE_GPU)
if(FAISS_ENABLE_ROCM)
add_subdirectory(faiss/gpu/test)
else()
add_subdirectory(faiss/gpu/test)
endif()
endif()
if(FAISS_ENABLE_METAL)
add_subdirectory(faiss/gpu_metal/test)
endif()
endif()