@@ -23,9 +23,10 @@ class BM_VecSimCommon : public BM_VecSimIndex<index_type_t> {
23
23
BM_VecSimCommon () = default ;
24
24
~BM_VecSimCommon () = default ;
25
25
26
+ // index_offset: Offset added to base index types to access variants (0=original, 1=updated)
27
+
26
28
static void RunTopK_HNSW (benchmark::State &st, size_t ef, size_t iter, size_t k,
27
- std::atomic_int &correct, unsigned short index_offset = 0 ,
28
- bool is_tiered = false );
29
+ std::atomic_int &correct, unsigned short index_offset = 0 );
29
30
30
31
// Search for the K closest vectors to the query in the index. K is defined in the
31
32
// test registration (initialization file).
@@ -36,24 +37,22 @@ class BM_VecSimCommon : public BM_VecSimIndex<index_type_t> {
36
37
static void TopK_Tiered (benchmark::State &st, unsigned short index_offset = 0 );
37
38
38
39
// Does nothing but returning the index memory.
39
- static void Memory_FLAT (benchmark::State &st, unsigned short index_offset = 0 );
40
- static void Memory_HNSW (benchmark::State &st, unsigned short index_offset = 0 );
41
- static void Memory_Tiered (benchmark::State &st, unsigned short index_offset = 0 );
40
+ static void Memory (benchmark::State &st, IndexTypeIndex index_type);
42
41
};
43
42
44
43
template <typename index_type_t >
45
44
void BM_VecSimCommon<index_type_t >::RunTopK_HNSW(benchmark::State &st, size_t ef, size_t iter,
46
45
size_t k, std::atomic_int &correct,
47
- unsigned short index_offset, bool is_tiered ) {
46
+ unsigned short index_offset) {
48
47
HNSWRuntimeParams hnswRuntimeParams = {.efRuntime = ef};
49
48
auto query_params = BM_VecSimGeneral::CreateQueryParams (hnswRuntimeParams);
50
- auto hnsw_results = VecSimIndex_TopKQuery (
51
- INDICES[is_tiered ? VecSimAlgo_TIERED : VecSimAlgo_HNSWLIB + index_offset] ,
52
- QUERIES[iter % N_QUERIES].data (), k, &query_params, BY_SCORE);
49
+ auto hnsw_results =
50
+ VecSimIndex_TopKQuery ( GET_INDEX (INDEX_HNSW + index_offset) ,
51
+ QUERIES[iter % N_QUERIES].data (), k, &query_params, BY_SCORE);
53
52
st.PauseTiming ();
54
53
55
54
// Measure recall:
56
- auto bf_results = VecSimIndex_TopKQuery (INDICES[VecSimAlgo_BF + index_offset] ,
55
+ auto bf_results = VecSimIndex_TopKQuery (GET_INDEX (INDEX_BF + index_offset) ,
57
56
QUERIES[iter % N_QUERIES].data (), k, nullptr , BY_SCORE);
58
57
59
58
BM_VecSimGeneral::MeasureRecall (hnsw_results, bf_results, correct);
@@ -64,35 +63,15 @@ void BM_VecSimCommon<index_type_t>::RunTopK_HNSW(benchmark::State &st, size_t ef
64
63
}
65
64
66
65
template <typename index_type_t >
67
- void BM_VecSimCommon<index_type_t >::Memory_FLAT(benchmark::State &st, unsigned short index_offset) {
68
- auto index = INDICES[VecSimAlgo_BF + index_offset];
69
- index->fitMemory ();
70
-
71
- for (auto _ : st) {
72
- // Do nothing...
73
- }
74
- st.counters [" memory" ] = (double )VecSimIndex_StatsInfo (index).memory ;
75
- }
76
- template <typename index_type_t >
77
- void BM_VecSimCommon<index_type_t >::Memory_HNSW(benchmark::State &st, unsigned short index_offset) {
78
- auto index = INDICES[VecSimAlgo_HNSWLIB + index_offset];
66
+ void BM_VecSimCommon<index_type_t >::Memory(benchmark::State &st, IndexTypeIndex index_type) {
67
+ auto index = GET_INDEX (index_type);
79
68
index->fitMemory ();
80
69
81
70
for (auto _ : st) {
82
71
// Do nothing...
83
72
}
84
73
st.counters [" memory" ] = (double )VecSimIndex_StatsInfo (index).memory ;
85
74
}
86
- template <typename index_type_t >
87
- void BM_VecSimCommon<index_type_t >::Memory_Tiered(benchmark::State &st,
88
- unsigned short index_offset) {
89
- auto index = INDICES[VecSimAlgo_TIERED + index_offset];
90
- index->fitMemory ();
91
- for (auto _ : st) {
92
- // Do nothing...
93
- }
94
- st.counters [" memory" ] = (double )VecSimIndex_StatsInfo (index).memory ;
95
- }
96
75
97
76
// TopK search BM
98
77
@@ -101,8 +80,8 @@ void BM_VecSimCommon<index_type_t>::TopK_BF(benchmark::State &st, unsigned short
101
80
size_t k = st.range (0 );
102
81
size_t iter = 0 ;
103
82
for (auto _ : st) {
104
- VecSimIndex_TopKQuery (INDICES[VecSimAlgo_BF + index_offset] ,
105
- QUERIES[iter % N_QUERIES]. data (), k, nullptr , BY_SCORE);
83
+ VecSimIndex_TopKQuery (GET_INDEX (INDEX_BF + index_offset), QUERIES[iter % N_QUERIES]. data () ,
84
+ k, nullptr , BY_SCORE);
106
85
iter++;
107
86
}
108
87
}
@@ -126,8 +105,8 @@ void BM_VecSimCommon<index_type_t>::TopK_Tiered(benchmark::State &st, unsigned s
126
105
size_t k = st.range (1 );
127
106
std::atomic_int correct = 0 ;
128
107
std::atomic_int iter = 0 ;
129
- auto * tiered_index =
130
- dynamic_cast <TieredHNSWIndex<data_t , dist_t > *>(INDICES[VecSimAlgo_TIERED] );
108
+ auto tiered_index =
109
+ dynamic_cast <TieredHNSWIndex<data_t , dist_t > *>(GET_INDEX (INDEX_TIERED_HNSW) );
131
110
size_t total_iters = 50 ;
132
111
VecSimQueryReply *all_results[total_iters];
133
112
@@ -136,9 +115,9 @@ void BM_VecSimCommon<index_type_t>::TopK_Tiered(benchmark::State &st, unsigned s
136
115
HNSWRuntimeParams hnswRuntimeParams = {.efRuntime = search_job->ef };
137
116
auto query_params = BM_VecSimGeneral::CreateQueryParams (hnswRuntimeParams);
138
117
size_t cur_iter = search_job->iter ;
139
- auto hnsw_results =
140
- VecSimIndex_TopKQuery (INDICES[VecSimAlgo_TIERED], QUERIES[cur_iter % N_QUERIES].data (),
141
- search_job->k , &query_params, BY_SCORE);
118
+ auto hnsw_results = VecSimIndex_TopKQuery ( GET_INDEX (INDEX_TIERED_HNSW),
119
+ QUERIES[cur_iter % N_QUERIES].data (),
120
+ search_job->k , &query_params, BY_SCORE);
142
121
search_job->all_results [cur_iter] = hnsw_results;
143
122
delete job;
144
123
};
@@ -149,14 +128,14 @@ void BM_VecSimCommon<index_type_t>::TopK_Tiered(benchmark::State &st, unsigned s
149
128
tiered_index, k, ef, iter++, all_results);
150
129
tiered_index->submitSingleJob (search_job);
151
130
if (iter == total_iters) {
152
- BM_VecSimGeneral::mock_thread_pool. thread_pool_wait ();
131
+ BM_VecSimGeneral::mock_thread_pool-> thread_pool_wait ();
153
132
}
154
133
}
155
134
156
135
// Measure recall
157
136
for (iter = 0 ; iter < total_iters; iter++) {
158
137
auto bf_results =
159
- VecSimIndex_TopKQuery (INDICES[VecSimAlgo_BF + index_offset] ,
138
+ VecSimIndex_TopKQuery (GET_INDEX (INDEX_BF + index_offset) ,
160
139
QUERIES[iter % N_QUERIES].data (), k, nullptr , BY_SCORE);
161
140
BM_VecSimGeneral::MeasureRecall (all_results[iter], bf_results, correct);
162
141
@@ -165,7 +144,7 @@ void BM_VecSimCommon<index_type_t>::TopK_Tiered(benchmark::State &st, unsigned s
165
144
}
166
145
167
146
st.counters [" Recall" ] = (float )correct / (float )(k * iter);
168
- st.counters [" num_threads" ] = (double )BM_VecSimGeneral::mock_thread_pool. thread_pool_size ;
147
+ st.counters [" num_threads" ] = (double )BM_VecSimGeneral::mock_thread_pool-> thread_pool_size ;
169
148
}
170
149
171
150
#define REGISTER_TopK_BF (BM_CLASS, BM_FUNC ) \
0 commit comments