Skip to content

Commit 8e31fa8

Browse files
committed
Impl for two-level tree
1 parent 3ad36b9 commit 8e31fa8

5 files changed

Lines changed: 834 additions & 64 deletions

File tree

‎cpp/include/cuvs/neighbors/scann.hpp‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ struct index_params : cuvs::neighbors::index_params {
5050
/** the value of lambda for SOAR spilling **/
5151
float soar_lambda = 1;
5252

53+
/** the number of intermediate nodes in a two-level tree.
54+
* When == 0, only a single level tree with root + leaves if built.
55+
**/
56+
uint32_t n_coarse_clusters = 0;
57+
5358
// Residual quanitzation params
5459
/** the dimension of pq subspaces (must divide dataset dimension)**/
5560
uint32_t pq_dim = 8;
@@ -131,6 +136,7 @@ struct index : cuvs::neighbors::index {
131136
index(raft::resources const& res,
132137
cuvs::distance::DistanceType metric,
133138
uint32_t n_leaves,
139+
uint32_t n_coarse_clusters,
134140
uint32_t pq_bits,
135141
uint32_t pq_dim,
136142
IdxT n_rows,
@@ -146,6 +152,11 @@ struct index : cuvs::neighbors::index {
146152
centers_(raft::make_device_matrix<float, IdxT>(res, n_leaves, dim)),
147153
labels_(raft::make_device_vector<uint32_t, IdxT>(res, n_rows)),
148154
soar_labels_(raft::make_device_vector<uint32_t, IdxT>(res, n_rows)),
155+
coarse_centers_(raft::make_device_matrix<float, IdxT>(res, n_coarse_clusters, dim)),
156+
coarse_labels_(
157+
raft::make_device_vector<uint32_t, IdxT>(res, n_coarse_clusters > 0 ? n_leaves : 0)),
158+
coarse_soar_labels_(
159+
raft::make_device_vector<uint32_t, IdxT>(res, n_coarse_clusters > 0 ? n_leaves : 0)),
149160
pq_codebook_(
150161
raft::make_device_matrix<float, uint32_t, raft::row_major>(res, pq_clusters, dim)),
151162
quantized_residuals_(
@@ -164,6 +175,7 @@ struct index : cuvs::neighbors::index {
164175
: index(res,
165176
params.metric,
166177
params.n_leaves,
178+
params.n_coarse_clusters,
167179
params.pq_bits,
168180
params.pq_dim,
169181
n_rows,
@@ -200,6 +212,33 @@ struct index : cuvs::neighbors::index {
200212
return raft::make_const_mdspan(soar_labels_.view());
201213
}
202214

215+
raft::device_matrix_view<float, IdxT> coarse_centers() noexcept { return coarse_centers_.view(); }
216+
217+
raft::device_matrix_view<const float, IdxT> coarse_centers() const noexcept
218+
{
219+
return raft::make_const_mdspan(coarse_centers_.view());
220+
}
221+
222+
raft::device_vector_view<uint32_t, IdxT> coarse_labels() noexcept
223+
{
224+
return coarse_labels_.view();
225+
}
226+
227+
raft::device_vector_view<const uint32_t, IdxT> coarse_labels() const noexcept
228+
{
229+
return raft::make_const_mdspan(coarse_labels_.view());
230+
}
231+
232+
raft::device_vector_view<uint32_t, IdxT> coarse_soar_labels() noexcept
233+
{
234+
return coarse_soar_labels_.view();
235+
}
236+
237+
raft::device_vector_view<const uint32_t, IdxT> coarse_soar_labels() const noexcept
238+
{
239+
return raft::make_const_mdspan(coarse_soar_labels_.view());
240+
}
241+
203242
uint32_t n_rows() const noexcept { return n_rows_; }
204243

205244
uint32_t n_leaves() const noexcept { return n_leaves_; }
@@ -258,6 +297,9 @@ struct index : cuvs::neighbors::index {
258297
raft::device_matrix<float, IdxT, raft::row_major> centers_;
259298
raft::device_vector<uint32_t, IdxT> labels_;
260299
raft::device_vector<uint32_t, IdxT> soar_labels_;
300+
raft::device_matrix<float, IdxT, raft::row_major> coarse_centers_;
301+
raft::device_vector<uint32_t, IdxT, raft::row_major> coarse_labels_;
302+
raft::device_vector<uint32_t, IdxT, raft::row_major> coarse_soar_labels_;
261303
raft::device_matrix<float, uint32_t, raft::row_major> pq_codebook_;
262304
raft::host_matrix<uint8_t, IdxT, raft::row_major> quantized_residuals_;
263305
raft::host_matrix<uint8_t, IdxT, raft::row_major> quantized_soar_residuals_;

‎cpp/src/neighbors/scann/detail/scann_avq.cuh‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,6 @@ void apply_avq(raft::resources const& res,
633633
rescale_denom.view(),
634634
cluster_offsets.view(),
635635
dataset.extent(0));
636-
637636
raft::resource::sync_stream(res);
638637
}
639638
} // namespace cuvs::neighbors::experimental::scann::detail

0 commit comments

Comments
 (0)