Skip to content

Commit

Permalink
Add standalone Link-Time Optimization option to CMake (#2943)
Browse files Browse the repository at this point in the history
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: #2943

Reviewed By: mengdilin

Differential Revision: D61868553

Pulled By: junjieqi

fbshipit-source-id: f07ade6fdaaa337876f28b9d06bdc5629cc486b0
  • Loading branch information
alexanderguzhva authored and facebook-github-bot committed Aug 27, 2024
1 parent 37f6b76 commit 4283e5b
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -63,6 +63,7 @@ option(FAISS_ENABLE_RAFT "Enable RAFT for GPU indexes." OFF)
option(FAISS_ENABLE_ROCM "Enable ROCm for GPU indexes." OFF)
option(FAISS_ENABLE_PYTHON "Build Python extension." ON)
option(FAISS_ENABLE_C_API "Build C API." OFF)
option(FAISS_USE_LTO "Enable Link-Time optimization" OFF)

if(FAISS_ENABLE_GPU)
if(FAISS_ENABLE_ROCM)
7 changes: 3 additions & 4 deletions INSTALL.md
Original file line number Diff line number Diff line change
@@ -122,10 +122,9 @@ Several options can be passed to CMake, among which:
- `-DCMAKE_BUILD_TYPE=Release` in order to enable generic compiler
optimization options (enables `-O3` on gcc for instance),
- `-DFAISS_OPT_LEVEL=avx2` in order to enable the required compiler flags to
generate code using optimized SIMD/Vector instructions. possible values are
below:
- On x86\_64, `generic`, `avx2` and `avx512`, by increasing order of optimization,
- On aarch64, `generic` and `sve` , by increasing order of optimization,
generate code using optimized SIMD instructions (possible values are `generic`,
`avx2` and `avx512`, by increasing order of optimization),
- `-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`).
- BLAS-related options:
- `-DBLA_VENDOR=Intel10_64_dyn -DMKL_LIBRARIES=/path/to/mkl/libs` to use the
Intel MKL BLAS implementation, which is significantly faster than OpenBLAS
14 changes: 14 additions & 0 deletions faiss/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -334,6 +334,20 @@ target_compile_definitions(faiss_avx2 PRIVATE FINTEGER=int)
target_compile_definitions(faiss_avx512 PRIVATE FINTEGER=int)
target_compile_definitions(faiss_sve PRIVATE FINTEGER=int)

if(FAISS_USE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_error)

if (ipo_supported)
message(STATUS "LTO enabled")
set_property(TARGET faiss PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set_property(TARGET faiss_avx2 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
set_property(TARGET faiss_avx512 PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(STATUS "LTO not supported: <${ipo_error}>")
endif()
endif()

find_package(OpenMP REQUIRED)
target_link_libraries(faiss PRIVATE OpenMP::OpenMP_CXX)
target_link_libraries(faiss_avx2 PRIVATE OpenMP::OpenMP_CXX)

0 comments on commit 4283e5b

Please sign in to comment.