Skip to content

Commit ed35da4

Browse files
rfsalievmeiravgri
andauthored
[MOD-9384] [SVS] Fix CI builds (#658)
* [SVS] Fix CI builds * Add CPU detection for SVS * Add MKL installation for SVS shared library * Extend MKL package lookup in CMAKE * Change MKL version to 2024.1 * Add --ignore-errors to MKL installer * Add GCC version check for SVS * Fix Alpine3 compilation error * Enable SVS_SHARED_LIB ON * Install MKL on Ubuntu/Debian via APT * Reduce MKL size in Ubuntu by using 'core' package. * durtyfix svs binary package issue * Disable SVS share lib if MKL not found * Revert "durtyfix svs binary package issue" This reverts commit 1a10a0a. * fixup! Disable SVS share lib if MKL not found * fixup! Refactor Info Report - [MOD-9321] (#650) * Revert SVS disabling changes made in f670214 * Move SVS cmake checks and definitions to a separate file. * Disable SVS AVX512 for Valgrind Debug build * Fix Valgrind tests * Disable SVS shared library for Valgrind tests * Update svs_allocator.patch * Disable SVS shared library by default * Add 'patch' tool installation required for SVS to rocky9 * Revert "Disable SVS shared library by default" This reverts commit 7b9c5ad. * Update SVS submodule and remove allocator patch * enable mac tests disable skipping * Revert "enable mac tests" This reverts commit 79c5682. * Address code review comments * Address code review comments s1e2 * Move all SVS configuration under one if * Remove MKL dependency * Add glibc detection for SVS shared library * Code review changes s1e1 --------- Co-authored-by: meiravgri <[email protected]>
1 parent 09e7b1c commit ed35da4

File tree

10 files changed

+108
-66
lines changed

10 files changed

+108
-66
lines changed

.install/alpine_linux_3.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ set -e
44

55
$MODE apk update
66

7-
$MODE apk add --no-cache build-base gcc g++ make wget git valgrind
7+
$MODE apk add --no-cache build-base gcc g++ make wget git valgrind linux-headers
88

99
$MODE apk add --no-cache cmake

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ IF(USE_PROFILE)
3333
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
3434
ENDIF()
3535

36+
include(cmake/svs.cmake)
37+
3638
include_directories(src)
3739

3840
if(VECSIM_BUILD_TESTS)

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ endif
197197

198198
flow_test:
199199
$(SHOW)poetry install $(POETRY_ARGS)
200-
$(SHOW)poetry run pytest tests/flow/$(TEST) --deselect=tests/flow/test_svs.py -v -s
200+
$(SHOW)poetry run pytest tests/flow/$(TEST) -v -s
201201

202202
.PHONY: flow_test
203203

cmake/svs.cmake

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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()

src/VecSim/CMakeLists.txt

+8-50
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,14 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g")
1717
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
1818
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
1919

20-
# option(SVS_EXPERIMENTAL_LEANVEC "Enable experimental LeanVec in SVS" YES)
21-
# if(SVS_EXPERIMENTAL_LEANVEC)
22-
# add_definitions(-DSVS_EXPERIMENTAL_LEANVEC)
23-
# endif()
24-
25-
# TODO: enable svs build again once MKL installation issue is resolved, and after we validate
26-
# that we only build for supported platforms (and fail gracefully for those that are not)
27-
option(SVS_SUPPORTED "Build with SVS library support" OFF)
20+
add_subdirectory(spaces)
2821

29-
# Configure SVS build
30-
set(SVS_SHARED_LIB ON CACHE BOOL "Use SVS pre-compiled shared library")
31-
set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.0.7/svs-shared-library-0.0.7-avx2.tar.gz" CACHE STRING "SVS URL")
22+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
3223

33-
if(SVS_SUPPORTED)
24+
if(USE_SVS)
3425
set(svs_factory_file "index_factories/svs_factory.cpp")
35-
if(SVS_SHARED_LIB)
36-
include(FetchContent)
37-
FetchContent_Declare(
38-
svs
39-
URL "${SVS_URL}"
40-
)
41-
FetchContent_MakeAvailable(svs)
42-
list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
43-
find_package(MKL REQUIRED)
44-
find_package(svs REQUIRED)
45-
set(SVS_LVQ_HEADER "svs/extensions/vamana/lvq.h")
46-
else()
47-
get_filename_component(root ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
48-
add_subdirectory(
49-
${root}/deps/ScalableVectorSearch
50-
deps/ScalableVectorSearch
51-
)
52-
set(SVS_LVQ_HEADER "svs/quantization/lvq/impl/lvq_impl.h")
53-
endif()
5426
endif()
5527

56-
add_subdirectory(spaces)
57-
58-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")
59-
6028
add_library(VectorSimilarity ${VECSIM_LIBTYPE}
6129
index_factories/brute_force_factory.cpp
6230
index_factories/hnsw_factory.cpp
@@ -78,23 +46,13 @@ add_library(VectorSimilarity ${VECSIM_LIBTYPE}
7846
${HEADER_LIST}
7947
)
8048

81-
if (SVS_SUPPORTED)
82-
target_link_libraries(VectorSimilarity VectorSimilaritySpaces svs::svs)
49+
target_link_libraries(VectorSimilarity VectorSimilaritySpaces)
50+
51+
if (TARGET svs::svs)
52+
target_link_libraries(VectorSimilarity svs::svs)
8353
if(TARGET svs::svs_shared_library)
84-
target_link_libraries(VectorSimilarity svs::svs_shared_library MKL::MKL)
54+
target_link_libraries(VectorSimilarity svs::svs_shared_library)
8555
endif()
86-
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS=1")
87-
else()
88-
target_link_libraries(VectorSimilarity VectorSimilaritySpaces)
89-
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS=0")
90-
endif()
91-
92-
if(EXISTS "${svs_SOURCE_DIR}/include/${SVS_LVQ_HEADER}")
93-
message("SVS LVQ implementation found")
94-
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=1" PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\"")
95-
else()
96-
message("SVS LVQ implementation not found")
97-
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=0")
9856
endif()
9957

10058
if(VECSIM_BUILD_TESTS)

src/VecSim/algorithms/svs/svs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
258258
return info;
259259
}
260260

261-
VecSimIndexDInfo debugInfo() const override {
261+
VecSimIndexDebugInfo debugInfo() const override {
262262
VecSimIndexDebugInfo info;
263263
info.commonInfo = this->getCommonInfo();
264264
info.commonInfo.basicInfo.algo = VecSimAlgo_SVS;

src/python_bindings/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ if(NOT pybind11_POPULATED)
2020
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
2121
endif()
2222

23+
include(${root}/cmake/svs.cmake)
2324
add_subdirectory(${root}/src/VecSim VectorSimilarity)
2425

2526
include_directories(${root}/src ${root}/tests/utils)

tests/unit/CMakeLists.txt

+7-4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ target_link_libraries(test_fp16 PUBLIC gtest_main VectorSimilarity)
6060
target_link_libraries(test_int8 PUBLIC gtest_main VectorSimilarity)
6161
target_link_libraries(test_uint8 PUBLIC gtest_main VectorSimilarity)
6262

63+
if(USE_SVS)
64+
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp unit_test_utils.cpp)
65+
target_link_libraries(test_svs PUBLIC gtest_main VectorSimilarity)
66+
endif()
67+
6368
include(GoogleTest)
6469

6570
gtest_discover_tests(test_hnsw)
@@ -75,8 +80,6 @@ gtest_discover_tests(test_fp16 TEST_PREFIX FP16UNIT_)
7580
gtest_discover_tests(test_int8 TEST_PREFIX INT8UNIT_)
7681
gtest_discover_tests(test_uint8 TEST_PREFIX UINT8UNIT_)
7782

78-
if(SVS_SUPPORTED)
79-
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp unit_test_utils.cpp)
80-
target_link_libraries(test_svs PUBLIC gtest_main VectorSimilarity)
83+
if(USE_SVS)
8184
gtest_discover_tests(test_svs)
82-
endif()
85+
endif()

tests/unit/test_svs.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ TYPED_TEST(SVSTest, svs_batch_iterator_non_unique_scores) {
484484
// as the number of results is 5, which is more than 0.1% of the index size. for index of size
485485
// 10000, we will run the heap-based search until we return 5000 results, and then switch to
486486
// select-based search.
487-
for (size_t n : {100, 10000}) {
487+
for (size_t n : {100, 1000}) {
488488
SVSParams params = {
489489
.dim = dim,
490490
.metric = VecSimMetric_L2,
@@ -1178,13 +1178,6 @@ TYPED_TEST(SVSTest, svs_test_inf_score) {
11781178
.dim = dim,
11791179
.metric = VecSimMetric_L2,
11801180
.blockSize = 1,
1181-
/* SVS-Vamana specifics */
1182-
.alpha = 1.2,
1183-
.graph_max_degree = 64,
1184-
.construction_window_size = 20,
1185-
.max_candidate_pool_size = 1024,
1186-
.prune_to = 60,
1187-
.use_search_history = VecSimOption_ENABLE,
11881181
};
11891182

11901183
VecSimIndex *index = this->CreateNewIndex(params);

0 commit comments

Comments
 (0)