Skip to content

Commit bdd68a6

Browse files
committed
Define SVS_RUNTIME_ENABLE_LVQ_LEANVEC
1 parent d68f548 commit bdd68a6

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

bindings/cpp/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ DOWNLOAD_EXTRACT_TIMESTAMP TRUE
129129
)
130130
endif()
131131
target_compile_definitions(${TARGET_NAME} PRIVATE
132+
SVS_RUNTIME_ENABLE_LVQ_LEANVEC
132133
PUBLIC "SVS_LVQ_HEADER=\"${SVS_LVQ_HEADER}\""
133134
PUBLIC "SVS_LEANVEC_HEADER=\"${SVS_LEANVEC_HEADER}\""
134135
)

bindings/cpp/src/dynamic_vamana_index.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ struct DynamicVamanaIndexManagerBase : public DynamicVamanaIndex {
115115
};
116116

117117
using DynamicVamanaIndexManager = DynamicVamanaIndexManagerBase<DynamicVamanaIndexImpl>;
118-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
118+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
119119
using DynamicVamanaIndexLeanVecImplManager =
120120
DynamicVamanaIndexManagerBase<DynamicVamanaIndexLeanVecImpl>;
121121
#endif
@@ -170,7 +170,7 @@ Status DynamicVamanaIndex::load(
170170
});
171171
}
172172

173-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
173+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
174174
// Specialization to build LeanVec-based Vamana index with specified leanvec dims
175175
Status DynamicVamanaIndexLeanVec::build(
176176
DynamicVamanaIndex** index,

bindings/cpp/src/dynamic_vamana_index_impl.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#pragma once
1818

1919
#include "svs_runtime_utils.h"
20+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
21+
#include "training_impl.h"
22+
#endif
2023

2124
#include <svs/runtime/dynamic_vamana_index.h>
2225

@@ -491,7 +494,7 @@ class DynamicVamanaIndexImpl {
491494
size_t ntotal_soft_deleted{0};
492495
};
493496

494-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
497+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
495498
struct DynamicVamanaIndexLeanVecImpl : public DynamicVamanaIndexImpl {
496499
DynamicVamanaIndexLeanVecImpl(
497500
std::unique_ptr<svs::DynamicVamana>&& impl,

bindings/cpp/src/svs_runtime_utils.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <svs/orchestrators/dynamic_vamana.h>
3939
#include <svs/quantization/scalar/scalar.h>
4040

41-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
41+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
4242
#ifndef SVS_LVQ_HEADER
4343
#define SVS_LVQ_HEADER "svs/quantization/lvq/lvq.h"
4444
#endif
@@ -94,7 +94,7 @@ inline auto runtime_error_wrapper(Callable&& func) noexcept -> Status {
9494
}
9595
}
9696

97-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
97+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
9898
using LeanVecMatricesType = svs::leanvec::LeanVecMatrices<svs::Dynamic>;
9999
#endif
100100

@@ -109,7 +109,7 @@ inline constexpr bool is_simple_dataset<svs::data::SimpleData<Elem, Extent, Allo
109109
template <typename T>
110110
concept IsSimpleDataset = is_simple_dataset<T>;
111111

112-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
112+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
113113
// Consolidated storage kind checks using constexpr functions
114114
inline constexpr bool is_lvq_storage(StorageKind kind) {
115115
return kind == StorageKind::LVQ4x0 || kind == StorageKind::LVQ4x4 ||
@@ -135,7 +135,7 @@ template <StorageKind K> struct StorageKindTag {
135135
SVS_DEFINE_STORAGE_KIND_TAG(FP32);
136136
SVS_DEFINE_STORAGE_KIND_TAG(FP16);
137137
SVS_DEFINE_STORAGE_KIND_TAG(SQI8);
138-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
138+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
139139
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x0);
140140
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x4);
141141
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x8);
@@ -161,7 +161,7 @@ template <typename T>
161161
using SQDatasetType = svs::quantization::scalar::
162162
SQDataset<T, svs::Dynamic, svs::data::Blocked<svs::lib::Allocator<T>>>;
163163

164-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
164+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
165165
template <size_t Primary, size_t Residual>
166166
using LVQDatasetType = svs::quantization::lvq::LVQDataset<
167167
Primary,
@@ -191,7 +191,7 @@ template <StorageTag Tag> using StorageType_t = typename StorageType<Tag>::type;
191191
DEFINE_STORAGE_TYPE(FP32, SimpleDatasetType<float>);
192192
DEFINE_STORAGE_TYPE(FP16, SimpleDatasetType<svs::Float16>);
193193
DEFINE_STORAGE_TYPE(SQI8, SQDatasetType<std::int8_t>);
194-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
194+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
195195
DEFINE_STORAGE_TYPE(LVQ4x0, LVQDatasetType<4, 0>);
196196
DEFINE_STORAGE_TYPE(LVQ4x4, LVQDatasetType<4, 4>);
197197
DEFINE_STORAGE_TYPE(LVQ4x8, LVQDatasetType<4, 8>);
@@ -223,7 +223,7 @@ SQStorageType make_storage(const svs::data::ConstSimpleDataView<float>& data, Po
223223
return SQStorageType::compress(data, pool);
224224
}
225225

226-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
226+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
227227
template <
228228
svs::quantization::lvq::IsLVQDataset LVQStorageType,
229229
svs::threads::ThreadPool Pool>
@@ -252,30 +252,30 @@ auto make_storage(Tag&& SVS_UNUSED(tag), Args&&... args) {
252252
return make_storage<StorageType_t<Tag>>(std::forward<Args>(args)...);
253253
}
254254

255-
inline bool is_supported_storage_kind(StorageKind SVS_UNUSED(kind)) {
256-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
255+
inline bool is_supported_storage_kind(StorageKind kind) {
257256
if (is_lvq_storage(kind) || is_leanvec_storage(kind)) {
258257
return svs::detail::lvq_leanvec_enabled();
259258
}
260-
#endif
261259
return true;
262260
}
263261

264262
template <typename F, typename... Args>
265263
auto dispatch_storage_kind(StorageKind kind, F&& f, Args&&... args) {
264+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
266265
if (!is_supported_storage_kind(kind)) {
267266
throw StatusException(
268267
ErrorCode::NOT_IMPLEMENTED, "Requested storage kind is not supported by CPU"
269268
);
270269
}
270+
#endif
271271
switch (kind) {
272272
case StorageKind::FP32:
273273
return f(FP32Tag{}, std::forward<Args>(args)...);
274274
case StorageKind::FP16:
275275
return f(FP16Tag{}, std::forward<Args>(args)...);
276276
case StorageKind::SQI8:
277277
return f(SQI8Tag{}, std::forward<Args>(args)...);
278-
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
278+
#ifdef SVS_RUNTIME_ENABLE_LVQ_LEANVEC
279279
case StorageKind::LVQ4x0:
280280
return f(LVQ4x0Tag{}, std::forward<Args>(args)...);
281281
case StorageKind::LVQ4x4:

0 commit comments

Comments
 (0)