Skip to content

Commit b28888a

Browse files
committed
Add tests for non-supported SVS cases.
1 parent 12a3edc commit b28888a

File tree

7 files changed

+92
-43
lines changed

7 files changed

+92
-43
lines changed

cmake/svs.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ set(SVS_URL "https://github.com/intel/ScalableVectorSearch/releases/download/v0.
6161

6262
if(USE_SVS)
6363
add_compile_definitions("HAVE_SVS=1")
64-
set(svs_factory_file "index_factories/svs_factory.cpp")
6564
set(SVS_TARGET_NAME "svs::svs")
6665
if(SVS_SHARED_LIB)
6766
include(FetchContent)

src/VecSim/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ add_library(VectorSimilarity ${VECSIM_LIBTYPE}
2929
index_factories/brute_force_factory.cpp
3030
index_factories/hnsw_factory.cpp
3131
index_factories/tiered_factory.cpp
32-
${svs_factory_file}
32+
index_factories/svs_factory.cpp
3333
index_factories/index_factory.cpp
3434
index_factories/components/components_factory.cpp
3535
algorithms/hnsw/visited_nodes_handler.cpp

src/VecSim/algorithms/svs/svs_utils.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,18 @@ inline svs::lib::PowerOfTwo SVSBlockSize(size_t bs, size_t elem_size) {
138138
return svs_bs;
139139
}
140140

141-
bool check_cpuid() {
141+
// clang-format off
142+
inline bool check_cpuid() {
142143
uint32_t eax, ebx, ecx, edx;
143144
__cpuid(0, eax, ebx, ecx, edx);
144145
std::string vendor_id = std::string((const char*)&ebx, 4) +
145146
std::string((const char*)&edx, 4) +
146147
std::string((const char*)&ecx, 4);
147148
return (vendor_id == "GenuineIntel");
148149
}
150+
//clang-format on
149151

150-
bool isSVSLVQModeSupported(VecSimSvsQuantBits quant_bits) {
152+
inline bool isSVSLVQModeSupported(VecSimSvsQuantBits quant_bits) {
151153
#if HAVE_SVS_LVQ
152154
// Check if the CPU supports SVS LVQ
153155
return check_cpuid();

src/VecSim/index_factories/index_factory.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
#include "hnsw_factory.h"
1010
#include "brute_force_factory.h"
1111
#include "tiered_factory.h"
12-
#if HAVE_SVS
1312
#include "svs_factory.h"
14-
#endif
1513

1614
namespace VecSimFactory {
1715
VecSimIndex *NewIndex(const VecSimParams *params) {
@@ -33,9 +31,7 @@ VecSimIndex *NewIndex(const VecSimParams *params) {
3331
break;
3432
}
3533
case VecSimAlgo_SVS: {
36-
#if HAVE_SVS
3734
index = SVSFactory::NewIndex(params);
38-
#endif
3935
break;
4036
}
4137
}
@@ -54,9 +50,7 @@ size_t EstimateInitialSize(const VecSimParams *params) {
5450
case VecSimAlgo_TIERED:
5551
return TieredFactory::EstimateInitialSize(&params->algoParams.tieredParams);
5652
case VecSimAlgo_SVS:; // empty statement if svs not available
57-
#if HAVE_SVS
5853
return SVSFactory::EstimateInitialSize(&params->algoParams.svsParams);
59-
#endif
6054
}
6155
return -1;
6256
}
@@ -70,9 +64,7 @@ size_t EstimateElementSize(const VecSimParams *params) {
7064
case VecSimAlgo_TIERED:
7165
return TieredFactory::EstimateElementSize(&params->algoParams.tieredParams);
7266
case VecSimAlgo_SVS:; // empty statement if svs not available
73-
#if HAVE_SVS
7467
return SVSFactory::EstimateElementSize(&params->algoParams.svsParams);
75-
#endif
7668
}
7769
return -1;
7870
}

src/VecSim/index_factories/svs_factory.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#include "VecSim/index_factories/svs_factory.h"
2+
3+
#if HAVE_SVS
24
#include "VecSim/memory/vecsim_malloc.h"
35
#include "VecSim/vec_sim_index.h"
46
#include "VecSim/algorithms/svs/svs.h"
@@ -173,3 +175,11 @@ size_t EstimateInitialSize(const SVSParams *params, bool is_normalized) {
173175
}
174176

175177
} // namespace SVSFactory
178+
179+
#else // HAVE_SVS
180+
namespace SVSFactory {
181+
VecSimIndex *NewIndex(const VecSimParams *params, bool is_normalized) { return NULL; }
182+
size_t EstimateInitialSize(const SVSParams *params, bool is_normalized) { return -1; }
183+
size_t EstimateElementSize(const SVSParams *params) { return -1; }
184+
}; // namespace SVSFactory
185+
#endif // HAVE_SVS

tests/unit/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ add_executable(test_bf16 ../utils/mock_thread_pool.cpp test_bf16.cpp unit_test_u
4646
add_executable(test_fp16 ../utils/mock_thread_pool.cpp test_fp16.cpp unit_test_utils.cpp)
4747
add_executable(test_int8 ../utils/mock_thread_pool.cpp test_int8.cpp unit_test_utils.cpp)
4848
add_executable(test_uint8 ../utils/mock_thread_pool.cpp test_uint8.cpp unit_test_utils.cpp)
49+
add_executable(test_svs ../utils/mock_thread_pool.cpp test_svs.cpp unit_test_utils.cpp)
4950

5051
target_link_libraries(test_hnsw PUBLIC gtest_main VectorSimilarity)
5152
target_link_libraries(test_hnsw_parallel PUBLIC gtest_main VectorSimilarity)
@@ -59,11 +60,7 @@ target_link_libraries(test_bf16 PUBLIC gtest_main VectorSimilarity)
5960
target_link_libraries(test_fp16 PUBLIC gtest_main VectorSimilarity)
6061
target_link_libraries(test_int8 PUBLIC gtest_main VectorSimilarity)
6162
target_link_libraries(test_uint8 PUBLIC gtest_main VectorSimilarity)
62-
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()
63+
target_link_libraries(test_svs PUBLIC gtest_main VectorSimilarity)
6764

6865
include(GoogleTest)
6966

@@ -79,7 +76,4 @@ gtest_discover_tests(test_bf16 TEST_PREFIX BF16UNIT_)
7976
gtest_discover_tests(test_fp16 TEST_PREFIX FP16UNIT_)
8077
gtest_discover_tests(test_int8 TEST_PREFIX INT8UNIT_)
8178
gtest_discover_tests(test_uint8 TEST_PREFIX UINT8UNIT_)
82-
83-
if(USE_SVS)
84-
gtest_discover_tests(test_svs)
85-
endif()
79+
gtest_discover_tests(test_svs)

0 commit comments

Comments
 (0)