|
| 1 | +cmake_minimum_required(VERSION 3.12) |
| 2 | +cmake_policy(SET CMP0074 NEW) |
| 3 | +if(POLICY CMP0135) |
| 4 | + cmake_policy(SET CMP0135 NEW) |
| 5 | +endif() |
| 6 | + |
| 7 | +# Valgrind does not support AVX512 and Valgrind in running in Debug |
| 8 | +# so disable it if we are in Debug mode |
| 9 | +string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE) |
| 10 | +if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG") |
| 11 | + message(STATUS "SVS: Disabling AVX512 support in Debug mode due to Valgrind") |
| 12 | + set(SVS_NO_AVX512 ON) |
| 13 | +endif() |
| 14 | + |
| 15 | +if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86_64)|(AMD64|amd64)") |
| 16 | + set(SVS_SUPPORTED 1) |
| 17 | +else() |
| 18 | + set(SVS_SUPPORTED 0) |
| 19 | + message(STATUS "SVS is not supported on this architecture") |
| 20 | +endif() |
| 21 | + |
| 22 | +# GCC < v11 does not support C++20 features required for SVS |
| 23 | +# https://gcc.gnu.org/projects/cxx-status.html |
| 24 | +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 25 | + if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.0") |
| 26 | + set(SVS_SUPPORTED 0) |
| 27 | + message(STATUS "Skipping SVS: requires GCC >= 11.") |
| 28 | + endif() |
| 29 | +endif() |
| 30 | + |
| 31 | +include(CMakeDependentOption) |
| 32 | + |
| 33 | +# USE_SVS option forcibly OFF if CPU or compiler is not supported |
| 34 | +# elsewhere let user disable SVS |
| 35 | +cmake_dependent_option(USE_SVS "Build with SVS library support" ON "SVS_SUPPORTED" OFF) |
| 36 | + |
| 37 | +if(USE_SVS) |
| 38 | + message(STATUS "SVS support enabled") |
| 39 | + # Configure SVS build |
| 40 | + add_compile_definitions("HAVE_SVS=1") |
| 41 | + set(svs_factory_file "index_factories/svs_factory.cpp") |
| 42 | + |
| 43 | + # detect if build environment is using glibc |
| 44 | + include(CheckSymbolExists) |
| 45 | + unset(GLIBC_FOUND CACHE) |
| 46 | + check_symbol_exists(__GLIBC__ "features.h" GLIBC_FOUND) |
| 47 | + if(NOT GLIBC_FOUND) |
| 48 | + message(STATUS "GLIBC is not detected - SVS shared library is not supported") |
| 49 | + endif() |
| 50 | + |
| 51 | + cmake_dependent_option(SVS_SHARED_LIB "Use SVS pre-compiled shared library" ON "USE_SVS AND GLIBC_FOUND" OFF) |
| 52 | + set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.8-dev/svs-shared-library-0.0.8-NIGHTLY-20250423.tar.gz" CACHE STRING "SVS URL") |
| 53 | + |
| 54 | + if(SVS_SHARED_LIB) |
| 55 | + include(FetchContent) |
| 56 | + FetchContent_Declare( |
| 57 | + svs |
| 58 | + URL "${SVS_URL}" |
| 59 | + ) |
| 60 | + FetchContent_MakeAvailable(svs) |
| 61 | + list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}") |
| 62 | + find_package(svs REQUIRED) |
| 63 | + set(SVS_LVQ_HEADER "svs/extensions/vamana/lvq.h") |
| 64 | + else() |
| 65 | + # This file is included from both CMakeLists.txt and python_bindings/CMakeLists.txt |
| 66 | + # Set `root` relative to this file, regardless of where it is included from. |
| 67 | + get_filename_component(root ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE) |
| 68 | + add_subdirectory( |
| 69 | + ${root}/deps/ScalableVectorSearch |
| 70 | + deps/ScalableVectorSearch |
| 71 | + ) |
| 72 | + set(SVS_LVQ_HEADER "svs/quantization/lvq/impl/lvq_impl.h") |
| 73 | + endif() |
| 74 | + |
| 75 | + if(EXISTS "${svs_SOURCE_DIR}/include/${SVS_LVQ_HEADER}") |
| 76 | + message("SVS LVQ implementation found") |
| 77 | + add_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=1" PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\"") |
| 78 | + else() |
| 79 | + message("SVS LVQ implementation not found") |
| 80 | + add_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=0") |
| 81 | + endif() |
| 82 | +else() |
| 83 | + message(STATUS "SVS support disabled") |
| 84 | + add_compile_definitions("HAVE_SVS=0") |
| 85 | +endif() |
0 commit comments