Skip to content

Commit 55325e1

Browse files
author
mnorris11
committed
Add inline, remove unused exception variable name, safe float computation
1 parent 814f628 commit 55325e1

12 files changed

Lines changed: 51 additions & 31 deletions

File tree

bindings/cpp/include/svs/runtime/api_defs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
namespace svs {
3434
namespace runtime {
35-
namespace v0 {
35+
inline namespace v0 {
3636

3737
class OptionalBool {
3838
enum class Value : int8_t { Undef = -1, True = 1, False = 0 };

bindings/cpp/include/svs/runtime/dynamic_ivf_index.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace svs {
2626
namespace runtime {
27-
namespace v0 {
27+
inline namespace v0 {
2828

2929
/// @brief Abstract interface for dynamic IVF indices (supports add/delete).
3030
struct SVS_RUNTIME_API DynamicIVFIndex : public IVFIndex {
@@ -69,8 +69,8 @@ struct SVS_RUNTIME_API DynamicIVFIndex : public IVFIndex {
6969
/// @param x Pointer to vector data (row-major, n x dimensions).
7070
/// @param reuse_empty Whether to reuse empty slots from deleted vectors.
7171
/// @return Status indicating success or error.
72-
virtual Status
73-
add(size_t n, const size_t* labels, const float* x, bool reuse_empty = false
72+
virtual Status add(
73+
size_t n, const size_t* labels, const float* x, bool reuse_empty = false
7474
) noexcept = 0;
7575

7676
/// @brief Remove vectors from the index by ID.

bindings/cpp/include/svs/runtime/dynamic_vamana_index.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace svs {
2727
namespace runtime {
28-
namespace v0 {
28+
inline namespace v0 {
2929

3030
// Abstract interface for Dynamic Vamana-based indexes.
3131
struct SVS_RUNTIME_API DynamicVamanaIndex : public VamanaIndex {
@@ -39,8 +39,8 @@ struct SVS_RUNTIME_API DynamicVamanaIndex : public VamanaIndex {
3939
// Utility function to check storage kind support
4040
static Status check_storage_kind(StorageKind storage_kind) noexcept;
4141

42-
static Status check_params(const VamanaIndex::DynamicIndexParams& dynamic_index_params
43-
) noexcept;
42+
static Status
43+
check_params(const VamanaIndex::DynamicIndexParams& dynamic_index_params) noexcept;
4444

4545
// Static constructors and destructors
4646
// ABI backward compatibility

bindings/cpp/include/svs/runtime/flat_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace svs {
2525
namespace runtime {
26-
namespace v0 {
26+
inline namespace v0 {
2727

2828
// Abstract interface for Flat indices.
2929
struct SVS_RUNTIME_API FlatIndex {

bindings/cpp/include/svs/runtime/ivf_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
namespace svs {
2626
namespace runtime {
27-
namespace v0 {
27+
inline namespace v0 {
2828

2929
// Abstract interface for IVF (Inverted File) indices.
3030
struct SVS_RUNTIME_API IVFIndex {

bindings/cpp/include/svs/runtime/training.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace svs {
2525
namespace runtime {
26-
namespace v0 {
26+
inline namespace v0 {
2727

2828
struct SVS_RUNTIME_API LeanVecTrainingData {
2929
virtual ~LeanVecTrainingData();

bindings/cpp/include/svs/runtime/vamana_index.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace svs {
2525
namespace runtime {
26-
namespace v0 {
26+
inline namespace v0 {
2727

2828
namespace detail {
2929
struct VamanaBuildParameters {

bindings/cpp/include/svs/runtime/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ inline namespace v0 {
8989
///
9090
/// @brief Version information structure for runtime queries
9191
///
92-
namespace svs::runtime::v0 {
92+
namespace svs::runtime::inline v0 {
9393

9494
struct VersionInfo {
9595
static constexpr int major = SVS_RUNTIME_VERSION_MAJOR;
@@ -110,4 +110,4 @@ struct VersionInfo {
110110
}
111111
};
112112

113-
} // namespace svs::runtime::v0
113+
} // namespace svs::runtime::inline v0

include/svs/index/ivf/index.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ class IVFIndex {
151151
, inter_query_threadpool_{threads::as_threadpool(std::move(threadpool_proto))}
152152
, intra_query_thread_count_{intra_query_thread_count}
153153
, logger_{std::move(logger)} {
154+
// Clamp thread pool: more threads than centroids causes OOB in
155+
// compute_centroid_distances and wastes resources.
156+
if (inter_query_threadpool_.size() > centroids_.size()) {
157+
inter_query_threadpool_ =
158+
InterQueryThreadPool(threads::DefaultThreadPool(centroids_.size()));
159+
}
154160
validate_thread_configuration();
155161
initialize_thread_pools();
156162
initialize_search_buffers();
@@ -269,7 +275,8 @@ class IVFIndex {
269275
return scratchspace_type{
270276
create_centroid_buffer(sp.n_probes_),
271277
create_leaf_buffers(buffer_leaves_size),
272-
extensions::per_thread_batch_search_setup(cluster0_, distance_)};
278+
extensions::per_thread_batch_search_setup(cluster0_, distance_)
279+
};
273280
}
274281

275282
/// @brief Return scratch space resources for external threading with default parameters
@@ -540,7 +547,8 @@ class IVFIndex {
540547
mutable std::vector<size_t> id_in_cluster_{};
541548
// Thread-safe initialization flag for ID mapping (wrapped in unique_ptr for movability)
542549
mutable std::unique_ptr<std::once_flag> id_mapping_init_flag_{
543-
std::make_unique<std::once_flag>()};
550+
std::make_unique<std::once_flag>()
551+
};
544552

545553
///// Threading Infrastructure /////
546554
InterQueryThreadPool inter_query_threadpool_; // Handles parallelism across queries
@@ -567,9 +575,11 @@ class IVFIndex {
567575
void initialize_thread_pools() {
568576
// Create thread pools for intra-query (cluster-level) parallelism
569577
for (size_t i = 0; i < inter_query_threadpool_.size(); i++) {
570-
intra_query_threadpools_.push_back(threads::ThreadPoolHandle(
571-
threads::DefaultThreadPool(intra_query_thread_count_)
572-
));
578+
intra_query_threadpools_.push_back(
579+
threads::ThreadPoolHandle(
580+
threads::DefaultThreadPool(intra_query_thread_count_)
581+
)
582+
);
573583
}
574584
}
575585

@@ -627,11 +637,13 @@ class IVFIndex {
627637

628638
void validate_query_batch_size(size_t query_size) const {
629639
if (query_size > MAX_QUERY_BATCH_SIZE) {
630-
throw std::runtime_error(fmt::format(
631-
"Query batch size {} exceeds maximum allowed {}",
632-
query_size,
633-
MAX_QUERY_BATCH_SIZE
634-
));
640+
throw std::runtime_error(
641+
fmt::format(
642+
"Query batch size {} exceeds maximum allowed {}",
643+
query_size,
644+
MAX_QUERY_BATCH_SIZE
645+
)
646+
);
635647
}
636648
}
637649

@@ -645,9 +657,11 @@ class IVFIndex {
645657
std::vector<SortedBuffer<Idx, distance::compare_t<Dist>>> buffers;
646658
buffers.reserve(intra_query_thread_count_);
647659
for (size_t j = 0; j < intra_query_thread_count_; j++) {
648-
buffers.push_back(SortedBuffer<Idx, distance::compare_t<Dist>>(
649-
buffer_size, distance::comparator(distance_)
650-
));
660+
buffers.push_back(
661+
SortedBuffer<Idx, distance::compare_t<Dist>>(
662+
buffer_size, distance::comparator(distance_)
663+
)
664+
);
651665
}
652666
return buffers;
653667
}

include/svs/index/ivf/sorted_buffer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ template <typename Idx, typename Cmp = std::less<>> class SortedBuffer {
139139
/// @brief Return ``true`` if a neighbor with the given distance can be skipped.
140140
///
141141
bool can_skip(float distance) const {
142-
return compare_(back().distance(), distance) && full();
142+
return full() && compare_(back().distance(), distance);
143143
}
144144

145145
///

0 commit comments

Comments
 (0)