Skip to content

Commit 4283e5b

Browse files
Add standalone Link-Time Optimization option to CMake (facebookresearch#2943)
Summary: Adds `-DFAISS_USE_LTO=ON` option to CMake to enable LTO. LTO increases the linking time, but potentially provides a small boost to the whole library. Pull Request resolved: facebookresearch#2943 Reviewed By: mengdilin Differential Revision: D61868553 Pulled By: junjieqi fbshipit-source-id: f07ade6fdaaa337876f28b9d06bdc5629cc486b0
1 parent 37f6b76 commit 4283e5b

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
6363
option(FAISS_ENABLE_ROCM "Enable ROCm for GPU indexes." OFF)
6464
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
6565
option(FAISS_ENABLE_C_API "Build C API." OFF)
66+
option(FAISS_USE_LTO "Enable Link-Time optimization" OFF)
6667

6768
if(FAISS_ENABLE_GPU)
6869
if(FAISS_ENABLE_ROCM)

INSTALL.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,9 @@ Several options can be passed to CMake, among which:
122122
- `-DCMAKE_BUILD_TYPE=Release` in order to enable generic compiler
123123
optimization options (enables `-O3` on gcc for instance),
124124
- `-DFAISS_OPT_LEVEL=avx2` in order to enable the required compiler flags to
125-
generate code using optimized SIMD/Vector instructions. possible values are
126-
below:
127-
- On x86\_64, `generic`, `avx2` and `avx512`, by increasing order of optimization,
128-
- On aarch64, `generic` and `sve` , by increasing order of optimization,
125+
generate code using optimized SIMD instructions (possible values are `generic`,
126+
`avx2` and `avx512`, by increasing order of optimization),
127+
- `-DFAISS_USE_LTO=ON` in order to enable [Link-Time Optimization](https://en.wikipedia.org/wiki/Link-time_optimization) (default is `OFF`, possible values are `ON` and `OFF`).
129128
- BLAS-related options:
130129
- `-DBLA_VENDOR=Intel10_64_dyn -DMKL_LIBRARIES=/path/to/mkl/libs` to use the
131130
Intel MKL BLAS implementation, which is significantly faster than OpenBLAS

faiss/CMakeLists.txt

+14
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,20 @@ target_compile_definitions(faiss_avx2 PRIVATE FINTEGER=int)
334334
target_compile_definitions(faiss_avx512 PRIVATE FINTEGER=int)
335335
target_compile_definitions(faiss_sve PRIVATE FINTEGER=int)
336336

337+
if(FAISS_USE_LTO)
338+
include(CheckIPOSupported)
339+
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)
340+
341+
if (ipo_supported)
342+
message(STATUS "LTO enabled")
343+
set_property(TARGET faiss PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
344+
set_property(TARGET faiss_avx2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
345+
set_property(TARGET faiss_avx512 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
346+
else()
347+
message(STATUS "LTO not supported: <${ipo_error}>")
348+
endif()
349+
endif()
350+
337351
find_package(OpenMP REQUIRED)
338352
target_link_libraries(faiss PRIVATE OpenMP::OpenMP_CXX)
339353
target_link_libraries(faiss_avx2 PRIVATE OpenMP::OpenMP_CXX)

0 commit comments

Comments
 (0)