Skip to content

Commit 93e3290

Browse files
committed
Support runtime bindings build from public source only
1 parent 6d74a20 commit 93e3290

File tree

5 files changed

+28
-14
lines changed

5 files changed

+28
-14
lines changed

bindings/cpp/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ set(TARGET_NAME svs_runtime)
1919
set(SVS_RUNTIME_HEADERS
2020
include/svs/runtime/version.h
2121
include/svs/runtime/api_defs.h
22-
include/svs/runtime/training.h
2322
include/svs/runtime/vamana_index.h
2423
include/svs/runtime/dynamic_vamana_index.h
2524
include/svs/runtime/flat_index.h
@@ -30,7 +29,6 @@ set(SVS_RUNTIME_SOURCES
3029
src/dynamic_vamana_index_impl.h
3130
src/flat_index_impl.h
3231
src/api_defs.cpp
33-
src/training.cpp
3432
src/vamana_index.cpp
3533
src/dynamic_vamana_index.cpp
3634
src/flat_index.cpp
@@ -39,6 +37,8 @@ set(SVS_RUNTIME_SOURCES
3937
option(SVS_RUNTIME_ENABLE_LVQ_LEANVEC "Enable compilation of SVS runtime with LVQ and LeanVec support" ON)
4038
if (SVS_RUNTIME_ENABLE_LVQ_LEANVEC)
4139
message(STATUS "SVS runtime will be built with LVQ support")
40+
list(APPEND SVS_RUNTIME_HEADERS include/svs/runtime/training.h)
41+
list(APPEND SVS_RUNTIME_SOURCES src/training.cpp)
4242
else()
4343
message(STATUS "SVS runtime will be built without LVQ or LeanVec support")
4444
endif()

bindings/cpp/src/dynamic_vamana_index.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,11 @@
2727
#include <svs/core/data.h>
2828
#include <svs/core/distance.h>
2929
#include <svs/core/query_result.h>
30-
#include <svs/cpuid.h>
3130
#include <svs/extensions/vamana/scalar.h>
3231
#include <svs/lib/float16.h>
3332
#include <svs/orchestrators/dynamic_vamana.h>
3433
#include <svs/quantization/scalar/scalar.h>
3534

36-
#include SVS_LVQ_HEADER
37-
#include SVS_LEANVEC_HEADER
38-
3935
namespace svs {
4036
namespace runtime {
4137

@@ -119,8 +115,10 @@ struct DynamicVamanaIndexManagerBase : public DynamicVamanaIndex {
119115
};
120116

121117
using DynamicVamanaIndexManager = DynamicVamanaIndexManagerBase<DynamicVamanaIndexImpl>;
118+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
122119
using DynamicVamanaIndexLeanVecImplManager =
123120
DynamicVamanaIndexManagerBase<DynamicVamanaIndexLeanVecImpl>;
121+
#endif
124122

125123
} // namespace
126124

@@ -172,6 +170,7 @@ Status DynamicVamanaIndex::load(
172170
});
173171
}
174172

173+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
175174
// Specialization to build LeanVec-based Vamana index with specified leanvec dims
176175
Status DynamicVamanaIndexLeanVec::build(
177176
DynamicVamanaIndex** index,
@@ -211,6 +210,7 @@ Status DynamicVamanaIndexLeanVec::build(
211210
*index = new DynamicVamanaIndexLeanVecImplManager{std::move(impl)};
212211
});
213212
}
213+
#endif
214214

215215
} // namespace runtime
216216
} // namespace svs

bindings/cpp/src/dynamic_vamana_index_impl.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#pragma once
1818

1919
#include "svs_runtime_utils.h"
20-
#include "training_impl.h"
2120

2221
#include <svs/runtime/dynamic_vamana_index.h>
2322

@@ -29,15 +28,11 @@
2928
#include <svs/core/data.h>
3029
#include <svs/core/distance.h>
3130
#include <svs/core/query_result.h>
32-
#include <svs/cpuid.h>
3331
#include <svs/extensions/vamana/scalar.h>
3432
#include <svs/lib/float16.h>
3533
#include <svs/orchestrators/dynamic_vamana.h>
3634
#include <svs/quantization/scalar/scalar.h>
3735

38-
#include SVS_LVQ_HEADER
39-
#include SVS_LEANVEC_HEADER
40-
4136
namespace svs {
4237
namespace runtime {
4338

@@ -496,6 +491,7 @@ class DynamicVamanaIndexImpl {
496491
size_t ntotal_soft_deleted{0};
497492
};
498493

494+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
499495
struct DynamicVamanaIndexLeanVecImpl : public DynamicVamanaIndexImpl {
500496
DynamicVamanaIndexLeanVecImpl(
501497
std::unique_ptr<svs::DynamicVamana>&& impl,
@@ -596,6 +592,7 @@ struct DynamicVamanaIndexLeanVecImpl : public DynamicVamanaIndexImpl {
596592
return kind;
597593
}
598594
};
595+
#endif
599596

600597
} // namespace runtime
601598
} // namespace svs

bindings/cpp/src/flat_index.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <svs/core/data.h>
2828
#include <svs/core/distance.h>
2929
#include <svs/core/query_result.h>
30-
#include <svs/cpuid.h>
3130
#include <svs/extensions/vamana/scalar.h>
3231

3332
namespace svs {

bindings/cpp/src/svs_runtime_utils.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@
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
@@ -49,6 +49,8 @@
4949

5050
#include SVS_LVQ_HEADER
5151
#include SVS_LEANVEC_HEADER
52+
#include <svs/cpuid.h>
53+
#endif
5254

5355
namespace 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
9598
using LeanVecMatricesType = svs::leanvec::LeanVecMatrices<svs::Dynamic>;
99+
#endif
96100

97101
namespace storage {
98102

@@ -105,6 +109,7 @@ inline constexpr bool is_simple_dataset<svs::data::SimpleData<Elem, Extent, Allo
105109
template <typename T>
106110
concept IsSimpleDataset = is_simple_dataset<T>;
107111

112+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
108113
// Consolidated storage kind checks using constexpr functions
109114
inline 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 {
129135
SVS_DEFINE_STORAGE_KIND_TAG(FP32);
130136
SVS_DEFINE_STORAGE_KIND_TAG(FP16);
131137
SVS_DEFINE_STORAGE_KIND_TAG(SQI8);
138+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
132139
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x0);
133140
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x4);
134141
SVS_DEFINE_STORAGE_KIND_TAG(LVQ4x8);
135142
SVS_DEFINE_STORAGE_KIND_TAG(LeanVec4x4);
136143
SVS_DEFINE_STORAGE_KIND_TAG(LeanVec4x8);
137144
SVS_DEFINE_STORAGE_KIND_TAG(LeanVec8x8);
145+
#endif
138146

139147
#undef SVS_DEFINE_STORAGE_KIND_TAG
140148

@@ -153,6 +161,7 @@ template <typename T>
153161
using SQDatasetType = svs::quantization::scalar::
154162
SQDataset<T, svs::Dynamic, svs::data::Blocked<svs::lib::Allocator<T>>>;
155163

164+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
156165
template <size_t Primary, size_t Residual>
157166
using 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
173183
template <StorageTag Tag> struct StorageType;
@@ -181,12 +191,14 @@ template <StorageTag Tag> using StorageType_t = typename StorageType<Tag>::type;
181191
DEFINE_STORAGE_TYPE(FP32, SimpleDatasetType<float>);
182192
DEFINE_STORAGE_TYPE(FP16, SimpleDatasetType<svs::Float16>);
183193
DEFINE_STORAGE_TYPE(SQI8, SQDatasetType<std::int8_t>);
194+
#if SVS_RUNTIME_ENABLE_LVQ_LEANVEC
184195
DEFINE_STORAGE_TYPE(LVQ4x0, LVQDatasetType<4, 0>);
185196
DEFINE_STORAGE_TYPE(LVQ4x4, LVQDatasetType<4, 4>);
186197
DEFINE_STORAGE_TYPE(LVQ4x8, LVQDatasetType<4, 8>);
187198
DEFINE_STORAGE_TYPE(LeanVec4x4, LeanDatasetType<4, 4>);
188199
DEFINE_STORAGE_TYPE(LeanVec4x8, LeanDatasetType<4, 8>);
189200
DEFINE_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
214227
template <
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

236250
template <StorageTag Tag, typename... Args>
237251
auto 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

Comments
 (0)