Skip to content

[MOD-9384] [SVS] Fix CI builds #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
20911b2
[SVS] Fix CI builds
rfsaliev Apr 7, 2025
dec1b21
Extend MKL package lookup in CMAKE
rfsaliev Apr 7, 2025
63502e9
Change MKL version to 2024.1
rfsaliev Apr 8, 2025
a31a1c8
Add --ignore-errors to MKL installer
rfsaliev Apr 8, 2025
49c129e
Add GCC version check for SVS
rfsaliev Apr 8, 2025
f31ae17
Fix Alpine3 compilation error
rfsaliev Apr 8, 2025
2e7a169
Enable SVS_SHARED_LIB ON
rfsaliev Apr 8, 2025
7cd754b
Install MKL on Ubuntu/Debian via APT
rfsaliev Apr 8, 2025
0d40e5f
Reduce MKL size in Ubuntu by using 'core' package.
rfsaliev Apr 9, 2025
1a10a0a
durtyfix svs binary package issue
rfsaliev Apr 9, 2025
e815ade
Disable SVS share lib if MKL not found
rfsaliev Apr 10, 2025
a037c92
Revert "durtyfix svs binary package issue"
rfsaliev Apr 10, 2025
c39daee
fixup! Disable SVS share lib if MKL not found
rfsaliev Apr 10, 2025
4a33ae8
fixup! Refactor Info Report - [MOD-9321] (#650)
rfsaliev Apr 10, 2025
92eae96
Revert SVS disabling changes made in f6702147
rfsaliev Apr 10, 2025
d1f3a72
Move SVS cmake checks and definitions to a separate file.
rfsaliev Apr 11, 2025
f56a729
Disable SVS AVX512 for Valgrind Debug build
rfsaliev Apr 11, 2025
d456094
Fix Valgrind tests
rfsaliev Apr 14, 2025
7a11209
Disable SVS shared library for Valgrind tests
rfsaliev Apr 14, 2025
8223385
Update svs_allocator.patch
rfsaliev Apr 14, 2025
7b9c5ad
Disable SVS shared library by default
rfsaliev Apr 15, 2025
6673c3b
Add 'patch' tool installation required for SVS to rocky9
rfsaliev Apr 15, 2025
b4cdc4b
Revert "Disable SVS shared library by default"
rfsaliev Apr 15, 2025
ee12dbe
Update SVS submodule and remove allocator patch
rfsaliev Apr 16, 2025
79c5682
enable mac tests
meiravgri Apr 16, 2025
d67977a
Revert "enable mac tests"
meiravgri Apr 16, 2025
2138ca5
Address code review comments
rfsaliev Apr 16, 2025
b71c5d7
Address code review comments s1e2
rfsaliev Apr 17, 2025
cbd5b5d
Move all SVS configuration under one if
rfsaliev Apr 17, 2025
461e315
Remove MKL dependency
rfsaliev Apr 24, 2025
7a43227
Add glibc detection for SVS shared library
rfsaliev Apr 25, 2025
35cd71c
Code review changes s1e1
rfsaliev Apr 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .install/alpine_linux_3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ set -e

$MODE apk update

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

$MODE apk add --no-cache cmake
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ IF(USE_PROFILE)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-omit-frame-pointer")
ENDIF()

include(cmake/svs.cmake)

include_directories(src)

if(VECSIM_BUILD_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ endif

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

.PHONY: flow_test

Expand Down
85 changes: 85 additions & 0 deletions cmake/svs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
cmake_minimum_required(VERSION 3.12)
cmake_policy(SET CMP0074 NEW)
if(POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()

# Valgrind does not support AVX512 and Valgrind in running in Debug
# so disable it if we are in Debug mode
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if(uppercase_CMAKE_BUILD_TYPE STREQUAL "DEBUG")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please prompt here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added status message.

message(STATUS "SVS: Disabling AVX512 support in Debug mode due to Valgrind")
set(SVS_NO_AVX512 ON)
endif()

if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "(x86_64)|(AMD64|amd64)")
set(SVS_SUPPORTED 1)
else()
set(SVS_SUPPORTED 0)
message(STATUS "SVS is not supported on this architecture")
endif()

# GCC < v11 does not support C++20 features required for SVS
# https://gcc.gnu.org/projects/cxx-status.html
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "11.0")
set(SVS_SUPPORTED 0)
message(STATUS "Skipping SVS: requires GCC >= 11.")
endif()
endif()

include(CMakeDependentOption)

# USE_SVS option forcibly OFF if CPU or compiler is not supported
# elsewhere let user disable SVS
cmake_dependent_option(USE_SVS "Build with SVS library support" ON "SVS_SUPPORTED" OFF)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to have both SVS_SUPPORTED and USE_SVS? what is the difference between these variables?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SVS_SUPPORTED - is the result of SVS compatibility check
USE_SVS - is the option can be changed in CMAKE_FLAGS


if(USE_SVS)
message(STATUS "SVS support enabled")
# Configure SVS build
add_compile_definitions("HAVE_SVS=1")
set(svs_factory_file "index_factories/svs_factory.cpp")

# detect if build environment is using glibc
include(CheckSymbolExists)
unset(GLIBC_FOUND CACHE)
check_symbol_exists(__GLIBC__ "features.h" GLIBC_FOUND)
if(NOT GLIBC_FOUND)
message(STATUS "GLIBC is not detected - SVS shared library is not supported")
endif()

cmake_dependent_option(SVS_SHARED_LIB "Use SVS pre-compiled shared library" ON "USE_SVS AND GLIBC_FOUND" OFF)
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")

if(SVS_SHARED_LIB)
include(FetchContent)
FetchContent_Declare(
svs
URL "${SVS_URL}"
)
FetchContent_MakeAvailable(svs)
list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
find_package(svs REQUIRED)
set(SVS_LVQ_HEADER "svs/extensions/vamana/lvq.h")
else()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which case we expect to enter the else?

Copy link
Collaborator Author

@rfsaliev rfsaliev Apr 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when SVS_SHARED_LIB=OFF
e.g. when user provided -DSVS_SHARED_LIB=OFF in CMAKE_FLAGS or MKL library is not installed on the system.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so why do we need to compile this in this case? what capabilities are added to the library ?
add_subdirectory(
${root}/deps/ScalableVectorSearch
deps/ScalableVectorSearch
)
set(SVS_LVQ_HEADER "svs/quantization/lvq/impl/lvq_impl.h")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This option allows to compile SVSIndex without shared library from public sources without LVQ.
But also allows to compile with LVQ using SVS private sources which contain lvq_impl.h.

# This file is included from both CMakeLists.txt and python_bindings/CMakeLists.txt
# Set `root` relative to this file, regardless of where it is included from.
get_filename_component(root ${CMAKE_CURRENT_LIST_DIR}/.. ABSOLUTE)
add_subdirectory(
${root}/deps/ScalableVectorSearch
deps/ScalableVectorSearch
)
set(SVS_LVQ_HEADER "svs/quantization/lvq/impl/lvq_impl.h")
endif()

if(EXISTS "${svs_SOURCE_DIR}/include/${SVS_LVQ_HEADER}")
message("SVS LVQ implementation found")
add_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=1" PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\"")
else()
message("SVS LVQ implementation not found")
add_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=0")
endif()
else()
message(STATUS "SVS support disabled")
add_compile_definitions("HAVE_SVS=0")
endif()
58 changes: 8 additions & 50 deletions src/VecSim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,14 @@ set(CMAKE_CXX_FLAGS_DEBUG "-g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")

# option(SVS_EXPERIMENTAL_LEANVEC "Enable experimental LeanVec in SVS" YES)
# if(SVS_EXPERIMENTAL_LEANVEC)
# add_definitions(-DSVS_EXPERIMENTAL_LEANVEC)
# endif()

# TODO: enable svs build again once MKL installation issue is resolved, and after we validate
# that we only build for supported platforms (and fail gracefully for those that are not)
option(SVS_SUPPORTED "Build with SVS library support" OFF)
add_subdirectory(spaces)

# Configure SVS build
set(SVS_SHARED_LIB ON CACHE BOOL "Use SVS pre-compiled shared library")
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")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")

if(SVS_SUPPORTED)
if(USE_SVS)
set(svs_factory_file "index_factories/svs_factory.cpp")
if(SVS_SHARED_LIB)
include(FetchContent)
FetchContent_Declare(
svs
URL "${SVS_URL}"
)
FetchContent_MakeAvailable(svs)
list(APPEND CMAKE_PREFIX_PATH "${svs_SOURCE_DIR}")
find_package(MKL REQUIRED)
find_package(svs REQUIRED)
set(SVS_LVQ_HEADER "svs/extensions/vamana/lvq.h")
else()
get_filename_component(root ${CMAKE_CURRENT_LIST_DIR}/../.. ABSOLUTE)
add_subdirectory(
${root}/deps/ScalableVectorSearch
deps/ScalableVectorSearch
)
set(SVS_LVQ_HEADER "svs/quantization/lvq/impl/lvq_impl.h")
endif()
endif()

add_subdirectory(spaces)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall")

add_library(VectorSimilarity ${VECSIM_LIBTYPE}
index_factories/brute_force_factory.cpp
index_factories/hnsw_factory.cpp
Expand All @@ -78,23 +46,13 @@ add_library(VectorSimilarity ${VECSIM_LIBTYPE}
${HEADER_LIST}
)

if (SVS_SUPPORTED)
target_link_libraries(VectorSimilarity VectorSimilaritySpaces svs::svs)
target_link_libraries(VectorSimilarity VectorSimilaritySpaces)

if (TARGET svs::svs)
target_link_libraries(VectorSimilarity svs::svs)
if(TARGET svs::svs_shared_library)
target_link_libraries(VectorSimilarity svs::svs_shared_library MKL::MKL)
target_link_libraries(VectorSimilarity svs::svs_shared_library)
endif()
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS=1")
else()
target_link_libraries(VectorSimilarity VectorSimilaritySpaces)
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS=0")
endif()

if(EXISTS "${svs_SOURCE_DIR}/include/${SVS_LVQ_HEADER}")
message("SVS LVQ implementation found")
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=1" PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\"")
else()
message("SVS LVQ implementation not found")
target_compile_definitions(VectorSimilarity PUBLIC "HAVE_SVS_LVQ=0")
endif()

if(VECSIM_BUILD_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion src/VecSim/algorithms/svs/svs.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class SVSIndex : public VecSimIndexAbstract<svs_details::vecsim_dt<DataType>, fl
return info;
}

VecSimIndexDInfo debugInfo() const override {
VecSimIndexDebugInfo debugInfo() const override {
VecSimIndexDebugInfo info;
info.commonInfo = this->getCommonInfo();
info.commonInfo.basicInfo.algo = VecSimAlgo_SVS;
Expand Down
1 change: 1 addition & 0 deletions src/python_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(NOT pybind11_POPULATED)
add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
endif()

include(${root}/cmake/svs.cmake)
add_subdirectory(${root}/src/VecSim VectorSimilarity)

include_directories(${root}/src ${root}/tests/utils)
Expand Down
11 changes: 7 additions & 4 deletions tests/unit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ target_link_libraries(test_fp16 PUBLIC gtest_main VectorSimilarity)
target_link_libraries(test_int8 PUBLIC gtest_main VectorSimilarity)
target_link_libraries(test_uint8 PUBLIC gtest_main VectorSimilarity)

if(USE_SVS)
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp unit_test_utils.cpp)
target_link_libraries(test_svs PUBLIC gtest_main VectorSimilarity)
endif()

include(GoogleTest)

gtest_discover_tests(test_hnsw)
Expand All @@ -75,8 +80,6 @@ gtest_discover_tests(test_fp16 TEST_PREFIX FP16UNIT_)
gtest_discover_tests(test_int8 TEST_PREFIX INT8UNIT_)
gtest_discover_tests(test_uint8 TEST_PREFIX UINT8UNIT_)

if(SVS_SUPPORTED)
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp unit_test_utils.cpp)
target_link_libraries(test_svs PUBLIC gtest_main VectorSimilarity)
if(USE_SVS)
gtest_discover_tests(test_svs)
endif()
endif()
9 changes: 1 addition & 8 deletions tests/unit/test_svs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ TYPED_TEST(SVSTest, svs_batch_iterator_non_unique_scores) {
// as the number of results is 5, which is more than 0.1% of the index size. for index of size
// 10000, we will run the heap-based search until we return 5000 results, and then switch to
// select-based search.
for (size_t n : {100, 10000}) {
for (size_t n : {100, 1000}) {
SVSParams params = {
.dim = dim,
.metric = VecSimMetric_L2,
Expand Down Expand Up @@ -1178,13 +1178,6 @@ TYPED_TEST(SVSTest, svs_test_inf_score) {
.dim = dim,
.metric = VecSimMetric_L2,
.blockSize = 1,
/* SVS-Vamana specifics */
.alpha = 1.2,
.graph_max_degree = 64,
.construction_window_size = 20,
.max_candidate_pool_size = 1024,
.prune_to = 60,
.use_search_history = VecSimOption_ENABLE,
};

VecSimIndex *index = this->CreateNewIndex(params);
Expand Down
Loading