3232#include < svs/core/data.h>
3333#include < svs/core/distance.h>
3434#include < svs/core/query_result.h>
35- #include < svs/cpuid.h>
3635#include < svs/extensions/vamana/scalar.h>
3736#include < svs/lib/exception.h>
3837#include < svs/lib/float16.h>
3938#include < svs/orchestrators/dynamic_vamana.h>
4039#include < svs/quantization/scalar/scalar.h>
4140
41+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
4242#ifndef SVS_LVQ_HEADER
4343#define SVS_LVQ_HEADER " svs/quantization/lvq/lvq.h"
4444#endif
4949
5050#include SVS_LVQ_HEADER
5151#include SVS_LEANVEC_HEADER
52+ #include < svs/cpuid.h>
53+ #endif
5254
5355namespace svs ::runtime {
5456
@@ -92,7 +94,9 @@ inline auto runtime_error_wrapper(Callable&& func) noexcept -> Status {
9294 }
9395}
9496
97+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
9598using LeanVecMatricesType = svs::leanvec::LeanVecMatrices<svs::Dynamic>;
99+ #endif
96100
97101namespace storage {
98102
@@ -105,6 +109,7 @@ inline constexpr bool is_simple_dataset<svs::data::SimpleData<Elem, Extent, Allo
105109template <typename T>
106110concept IsSimpleDataset = is_simple_dataset<T>;
107111
112+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
108113// Consolidated storage kind checks using constexpr functions
109114inline constexpr bool is_lvq_storage (StorageKind kind) {
110115 return kind == StorageKind::LVQ4x0 || kind == StorageKind::LVQ4x4 ||
@@ -115,6 +120,7 @@ inline constexpr bool is_leanvec_storage(StorageKind kind) {
115120 return kind == StorageKind::LeanVec4x4 || kind == StorageKind::LeanVec4x8 ||
116121 kind == StorageKind::LeanVec8x8;
117122}
123+ #endif
118124
119125// Storage kind processing
120126// Most kinds map to std::byte storage, but some have specific element types.
@@ -129,12 +135,14 @@ template <StorageKind K> struct StorageKindTag {
129135SVS_DEFINE_STORAGE_KIND_TAG (FP32);
130136SVS_DEFINE_STORAGE_KIND_TAG (FP16);
131137SVS_DEFINE_STORAGE_KIND_TAG (SQI8);
138+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
132139SVS_DEFINE_STORAGE_KIND_TAG (LVQ4x0);
133140SVS_DEFINE_STORAGE_KIND_TAG (LVQ4x4);
134141SVS_DEFINE_STORAGE_KIND_TAG (LVQ4x8);
135142SVS_DEFINE_STORAGE_KIND_TAG (LeanVec4x4);
136143SVS_DEFINE_STORAGE_KIND_TAG (LeanVec4x8);
137144SVS_DEFINE_STORAGE_KIND_TAG (LeanVec8x8);
145+ #endif
138146
139147#undef SVS_DEFINE_STORAGE_KIND_TAG
140148
@@ -153,6 +161,7 @@ template <typename T>
153161using SQDatasetType = svs::quantization::scalar::
154162 SQDataset<T, svs::Dynamic, svs::data::Blocked<svs::lib::Allocator<T>>>;
155163
164+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
156165template <size_t Primary, size_t Residual>
157166using LVQDatasetType = svs::quantization::lvq::LVQDataset<
158167 Primary,
@@ -168,6 +177,7 @@ using LeanDatasetType = svs::leanvec::LeanDataset<
168177 svs::Dynamic,
169178 svs::Dynamic,
170179 svs::data::Blocked<svs::lib::Allocator<std::byte>>>;
180+ #endif
171181
172182// Storage type mapping - use macro to reduce repetition
173183template <StorageTag Tag> struct StorageType ;
@@ -181,12 +191,14 @@ template <StorageTag Tag> using StorageType_t = typename StorageType<Tag>::type;
181191DEFINE_STORAGE_TYPE (FP32, SimpleDatasetType<float >);
182192DEFINE_STORAGE_TYPE (FP16, SimpleDatasetType<svs::Float16>);
183193DEFINE_STORAGE_TYPE (SQI8, SQDatasetType<std::int8_t >);
194+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
184195DEFINE_STORAGE_TYPE (LVQ4x0, LVQDatasetType<4 , 0 >);
185196DEFINE_STORAGE_TYPE (LVQ4x4, LVQDatasetType<4 , 4 >);
186197DEFINE_STORAGE_TYPE (LVQ4x8, LVQDatasetType<4 , 8 >);
187198DEFINE_STORAGE_TYPE (LeanVec4x4, LeanDatasetType<4 , 4 >);
188199DEFINE_STORAGE_TYPE (LeanVec4x8, LeanDatasetType<4 , 8 >);
189200DEFINE_STORAGE_TYPE (LeanVec8x8, LeanDatasetType<8 , 8 >);
201+ #endif
190202
191203#undef DEFINE_STORAGE_TYPE
192204
@@ -211,6 +223,7 @@ SQStorageType make_storage(const svs::data::ConstSimpleDataView<float>& data, Po
211223 return SQStorageType::compress (data, pool);
212224}
213225
226+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
214227template <
215228 svs::quantization::lvq::IsLVQDataset LVQStorageType,
216229 svs::threads::ThreadPool Pool>
@@ -232,16 +245,19 @@ LeanVecStorageType make_storage(
232245 data, std::move (matrices), pool, 0 , svs::lib::MaybeStatic{leanvec_d}
233246 );
234247}
248+ #endif
235249
236250template <StorageTag Tag, typename ... Args>
237251auto make_storage (Tag&& SVS_UNUSED(tag), Args&&... args) {
238252 return make_storage<StorageType_t<Tag>>(std::forward<Args>(args)...);
239253}
240254
241- inline bool is_supported_storage_kind (StorageKind kind) {
255+ inline bool is_supported_storage_kind (StorageKind SVS_UNUSED (kind)) {
256+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
242257 if (is_lvq_storage (kind) || is_leanvec_storage (kind)) {
243258 return svs::detail::lvq_leanvec_enabled ();
244259 }
260+ #endif
245261 return true ;
246262}
247263
@@ -259,6 +275,7 @@ auto dispatch_storage_kind(StorageKind kind, F&& f, Args&&... args) {
259275 return f (FP16Tag{}, std::forward<Args>(args)...);
260276 case StorageKind::SQI8:
261277 return f (SQI8Tag{}, std::forward<Args>(args)...);
278+ #if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
262279 case StorageKind::LVQ4x0:
263280 return f (LVQ4x0Tag{}, std::forward<Args>(args)...);
264281 case StorageKind::LVQ4x4:
@@ -271,6 +288,7 @@ auto dispatch_storage_kind(StorageKind kind, F&& f, Args&&... args) {
271288 return f (LeanVec4x8Tag{}, std::forward<Args>(args)...);
272289 case StorageKind::LeanVec8x8:
273290 return f (LeanVec8x8Tag{}, std::forward<Args>(args)...);
291+ #endif
274292 default :
275293 throw ANNEXCEPTION (" not supported SVS storage kind" );
276294 }
0 commit comments