diff --git a/CMakeLists.txt b/CMakeLists.txt index d1c141b750..4f1b30fa35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/INSTALL.md b/INSTALL.md index 158efde091..4476666fb6 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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 diff --git a/faiss/CMakeLists.txt b/faiss/CMakeLists.txt index 688aaec7af..2871d9747c 100644 --- a/faiss/CMakeLists.txt +++ b/faiss/CMakeLists.txt @@ -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)