|
15 | 15 | #include "svs/lib/float16.h"
|
16 | 16 | #include "svs/index/vamana/dynamic_index.h"
|
17 | 17 |
|
| 18 | +#include <cpuid.h> |
| 19 | +#include <cstdint> |
| 20 | +#include <cstdlib> |
| 21 | +#include <string> |
| 22 | +#include <utility> |
| 23 | + |
18 | 24 | namespace svs_details {
|
19 | 25 | // VecSim->SVS data type conversion
|
20 | 26 | template <typename T>
|
@@ -142,6 +148,43 @@ inline svs::lib::PowerOfTwo SVSBlockSize(size_t bs, size_t elem_size) {
|
142 | 148 | return svs_bs;
|
143 | 149 | }
|
144 | 150 |
|
| 151 | +// clang-format off |
| 152 | +inline bool check_cpuid() { |
| 153 | + uint32_t eax, ebx, ecx, edx; |
| 154 | + __cpuid(0, eax, ebx, ecx, edx); |
| 155 | + std::string vendor_id = std::string((const char*)&ebx, 4) + |
| 156 | + std::string((const char*)&edx, 4) + |
| 157 | + std::string((const char*)&ecx, 4); |
| 158 | + return (vendor_id == "GenuineIntel"); |
| 159 | +} |
| 160 | +// clang-format on |
| 161 | + |
| 162 | +// Check if the SVS implementation supports Quantization mode |
| 163 | +// @param quant_bits requested SVS quantization mode |
| 164 | +// @return pair<fallbackMode, bool> |
| 165 | +// @note even if VecSimSvsQuantBits is a simple enum value, |
| 166 | +// in theory, it can be a complex type with a combination of modes: |
| 167 | +// - primary bits, secondary/residual bits, dimesionality reduction, etc. |
| 168 | +// which can be incompatible to each-other. |
| 169 | +inline std::pair<VecSimSvsQuantBits, bool> isSVSQuantBitsSupported(VecSimSvsQuantBits quant_bits) { |
| 170 | + // If HAVE_SVS_LVQ is not defined, we don't support any quantization mode |
| 171 | + // else we check if the CPU supports SVS LVQ |
| 172 | + bool supported = quant_bits == VecSimSvsQuant_NONE |
| 173 | +#if HAVE_SVS_LVQ |
| 174 | + || check_cpuid() // Check if the CPU supports SVS LVQ |
| 175 | +#endif |
| 176 | + ; |
| 177 | + |
| 178 | + // If the quantization mode is not supported, we fallback to non-quantized mode |
| 179 | + // - this is temporary solution until we have a basic quantization mode in SVS |
| 180 | + // TODO: use basic SVS quantization as a fallback for unsupported modes |
| 181 | + auto fallBack = supported ? quant_bits : VecSimSvsQuant_NONE; |
| 182 | + |
| 183 | + // And always return true, as far as fallback mode is always supported |
| 184 | + // Upon further decision changes, some cases should treated as not-supported |
| 185 | + // So we will need return false. |
| 186 | + return std::make_pair(fallBack, true); |
| 187 | +} |
145 | 188 | } // namespace svs_details
|
146 | 189 |
|
147 | 190 | template <typename DataType, size_t QuantBits, size_t ResidualBits, class Enable = void>
|
|
0 commit comments