Skip to content

Commit 12a3edc

Browse files
committed
Return NULL Index if SVS LVQ is requested but not supported.
1 parent 2138ca5 commit 12a3edc

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/VecSim/algorithms/svs/svs_utils.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
#include "svs/lib/float16.h"
77
#include "svs/index/vamana/dynamic_index.h"
88

9+
#include <cpuid.h>
10+
#include <cstdint>
11+
#include <cstdlib>
12+
#include <string>
13+
914
namespace svs_details {
1015
// VecSim->SVS data type conversion
1116
template <typename T>
@@ -133,6 +138,23 @@ inline svs::lib::PowerOfTwo SVSBlockSize(size_t bs, size_t elem_size) {
133138
return svs_bs;
134139
}
135140

141+
bool check_cpuid() {
142+
uint32_t eax, ebx, ecx, edx;
143+
__cpuid(0, eax, ebx, ecx, edx);
144+
std::string vendor_id = std::string((const char*)&ebx, 4) +
145+
std::string((const char*)&edx, 4) +
146+
std::string((const char*)&ecx, 4);
147+
return (vendor_id == "GenuineIntel");
148+
}
149+
150+
bool isSVSLVQModeSupported(VecSimSvsQuantBits quant_bits) {
151+
#if HAVE_SVS_LVQ
152+
// Check if the CPU supports SVS LVQ
153+
return check_cpuid();
154+
#endif
155+
return quant_bits == VecSimSvsQuant_NONE;
156+
}
157+
136158
} // namespace svs_details
137159

138160
template <typename DataType, size_t QuantBits, size_t ResidualBits, class Enable = void>

src/VecSim/index_factories/svs_factory.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ VecSimIndex *NewIndexImpl(const VecSimParams *params, bool is_normalized) {
3535

3636
template <typename MetricType, typename DataType>
3737
VecSimIndex *NewIndexImpl(const VecSimParams *params, bool is_normalized) {
38+
if (!svs_details::isSVSLVQModeSupported(params->algoParams.svsParams.quantBits)) {
39+
return NULL;
40+
}
41+
3842
switch (params->algoParams.svsParams.quantBits) {
3943
case VecSimSvsQuant_NONE:
4044
return NewIndexImpl<MetricType, DataType, 0>(params, is_normalized);

0 commit comments

Comments
 (0)