forked from NVIDIA/cuvs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathann_ivf_flat.cuh
More file actions
675 lines (590 loc) · 33 KB
/
Copy pathann_ivf_flat.cuh
File metadata and controls
675 lines (590 loc) · 33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "../test_utils.cuh"
#include "ann_utils.cuh"
#include "naive_knn.cuh"
#include <cuvs/core/bitset.hpp>
#include <cuvs/neighbors/brute_force.hpp>
#include <cuvs/neighbors/ivf_flat.hpp>
#include <raft/linalg/normalize.cuh>
#include <raft/stats/mean.cuh>
#include <thrust/reduce.h>
#include <thrust/sequence.h>
#include <raft/core/resource/cuda_stream_pool.hpp>
#include <raft/linalg/add.cuh>
#include <raft/matrix/gather.cuh>
#include <raft/util/fast_int_div.cuh>
#include <rmm/cuda_stream_pool.hpp>
namespace cuvs::neighbors::ivf_flat {
struct test_ivf_sample_filter {
static constexpr unsigned offset = 300;
};
template <typename IdxT>
struct AnnIvfFlatInputs {
IdxT num_queries;
IdxT num_db_vecs;
IdxT dim;
IdxT k;
IdxT nprobe;
IdxT nlist;
cuvs::distance::DistanceType metric;
bool adaptive_centers;
bool host_dataset = false;
// The kernel_copy_overlapping option is only applicable when host dataset is enabled.
bool kernel_copy_overlapping = false;
};
template <typename IdxT>
::std::ostream& operator<<(::std::ostream& os, const AnnIvfFlatInputs<IdxT>& p)
{
os << "{ " << p.num_queries << ", " << p.num_db_vecs << ", " << p.dim << ", " << p.k << ", "
<< p.nprobe << ", " << p.nlist << ", " << static_cast<int>(p.metric) << ", "
<< p.adaptive_centers << "," << p.host_dataset << "," << p.kernel_copy_overlapping << '}'
<< std::endl;
return os;
}
template <typename T, typename DataT, typename IdxT>
class AnnIVFFlatTest : public ::testing::TestWithParam<AnnIvfFlatInputs<IdxT>> {
public:
AnnIVFFlatTest()
: stream_(raft::resource::get_cuda_stream(handle_)),
ps(::testing::TestWithParam<AnnIvfFlatInputs<IdxT>>::GetParam()),
database(0, stream_),
search_queries(0, stream_)
{
}
void testIVFFlat()
{
size_t queries_size = ps.num_queries * ps.k;
std::vector<IdxT> indices_ivfflat(queries_size);
std::vector<IdxT> indices_naive(queries_size);
std::vector<T> distances_ivfflat(queries_size);
std::vector<T> distances_naive(queries_size);
if (ps.kernel_copy_overlapping) {
size_t n_streams = 1;
raft::resource::set_cuda_stream_pool(handle_,
std::make_shared<rmm::cuda_stream_pool>(n_streams));
}
{
rmm::device_uvector<T> distances_naive_dev(queries_size, stream_);
rmm::device_uvector<IdxT> indices_naive_dev(queries_size, stream_);
cuvs::neighbors::naive_knn<T, DataT, IdxT>(handle_,
distances_naive_dev.data(),
indices_naive_dev.data(),
search_queries.data(),
database.data(),
ps.num_queries,
ps.num_db_vecs,
ps.dim,
ps.k,
ps.metric);
raft::update_host(distances_naive.data(), distances_naive_dev.data(), queries_size, stream_);
raft::update_host(indices_naive.data(), indices_naive_dev.data(), queries_size, stream_);
raft::resource::sync_stream(handle_);
}
{
// unless something is really wrong with clustering, this could serve as a lower bound on
// recall
double min_recall = static_cast<double>(ps.nprobe) / static_cast<double>(ps.nlist);
rmm::device_uvector<T> distances_ivfflat_dev(queries_size, stream_);
rmm::device_uvector<IdxT> indices_ivfflat_dev(queries_size, stream_);
{
cuvs::neighbors::ivf_flat::index_params index_params;
cuvs::neighbors::ivf_flat::search_params search_params;
index_params.n_lists = ps.nlist;
index_params.metric = ps.metric;
index_params.adaptive_centers = ps.adaptive_centers;
search_params.n_probes = ps.nprobe;
index_params.add_data_on_build = false;
index_params.kmeans_trainset_fraction = 0.5;
index_params.metric_arg = 0;
cuvs::neighbors::ivf_flat::index<DataT, IdxT> idx(handle_, index_params, ps.dim);
cuvs::neighbors::ivf_flat::index<DataT, IdxT> index_2(handle_, index_params, ps.dim);
if (!ps.host_dataset) {
auto database_view = raft::make_device_matrix_view<const DataT, IdxT>(
(const DataT*)database.data(), ps.num_db_vecs, ps.dim);
idx = cuvs::neighbors::ivf_flat::build(handle_, index_params, database_view);
rmm::device_uvector<IdxT> vector_indices(ps.num_db_vecs, stream_);
thrust::sequence(raft::resource::get_thrust_policy(handle_),
thrust::device_pointer_cast(vector_indices.data()),
thrust::device_pointer_cast(vector_indices.data() + ps.num_db_vecs));
raft::resource::sync_stream(handle_);
IdxT half_of_data = ps.num_db_vecs / 2;
auto half_of_data_view = raft::make_device_matrix_view<const DataT, IdxT>(
(const DataT*)database.data(), half_of_data, ps.dim);
const std::optional<raft::device_vector_view<const IdxT, IdxT>> no_opt = std::nullopt;
index_2 = cuvs::neighbors::ivf_flat::extend(handle_, half_of_data_view, no_opt, idx);
auto new_half_of_data_view = raft::make_device_matrix_view<const DataT, IdxT>(
database.data() + half_of_data * ps.dim, IdxT(ps.num_db_vecs) - half_of_data, ps.dim);
auto new_half_of_data_indices_view = raft::make_device_vector_view<const IdxT, IdxT>(
vector_indices.data() + half_of_data, IdxT(ps.num_db_vecs) - half_of_data);
cuvs::neighbors::ivf_flat::extend(
handle_,
new_half_of_data_view,
std::make_optional<raft::device_vector_view<const IdxT, IdxT>>(
new_half_of_data_indices_view),
&index_2);
} else {
auto host_database = raft::make_host_matrix<DataT, IdxT>(ps.num_db_vecs, ps.dim);
raft::copy(
host_database.data_handle(), database.data(), ps.num_db_vecs * ps.dim, stream_);
idx =
ivf_flat::build(handle_, index_params, raft::make_const_mdspan(host_database.view()));
auto vector_indices = raft::make_host_vector<IdxT>(handle_, ps.num_db_vecs);
std::iota(vector_indices.data_handle(), vector_indices.data_handle() + ps.num_db_vecs, 0);
IdxT half_of_data = ps.num_db_vecs / 2;
auto half_of_data_view = raft::make_host_matrix_view<const DataT, IdxT>(
(const DataT*)host_database.data_handle(), half_of_data, ps.dim);
const std::optional<raft::host_vector_view<const IdxT, IdxT>> no_opt = std::nullopt;
index_2 = ivf_flat::extend(handle_, half_of_data_view, no_opt, idx);
auto new_half_of_data_view = raft::make_host_matrix_view<const DataT, IdxT>(
host_database.data_handle() + half_of_data * ps.dim,
IdxT(ps.num_db_vecs) - half_of_data,
ps.dim);
auto new_half_of_data_indices_view = raft::make_host_vector_view<const IdxT, IdxT>(
vector_indices.data_handle() + half_of_data, IdxT(ps.num_db_vecs) - half_of_data);
ivf_flat::extend(handle_,
new_half_of_data_view,
std::make_optional<raft::host_vector_view<const IdxT, IdxT>>(
new_half_of_data_indices_view),
&index_2);
}
auto search_queries_view = raft::make_device_matrix_view<const DataT, IdxT>(
search_queries.data(), ps.num_queries, ps.dim);
auto indices_out_view = raft::make_device_matrix_view<IdxT, IdxT>(
indices_ivfflat_dev.data(), ps.num_queries, ps.k);
auto dists_out_view = raft::make_device_matrix_view<T, IdxT>(
distances_ivfflat_dev.data(), ps.num_queries, ps.k);
tmp_index_file index_file;
cuvs::neighbors::ivf_flat::serialize(handle_, index_file.filename, index_2);
cuvs::neighbors::ivf_flat::index<DataT, IdxT> index_loaded(handle_);
cuvs::neighbors::ivf_flat::deserialize(handle_, index_file.filename, &index_loaded);
ASSERT_EQ(index_2.size(), index_loaded.size());
cuvs::neighbors::ivf_flat::search(handle_,
search_params,
index_loaded,
search_queries_view,
indices_out_view,
dists_out_view);
raft::update_host(
distances_ivfflat.data(), distances_ivfflat_dev.data(), queries_size, stream_);
raft::update_host(
indices_ivfflat.data(), indices_ivfflat_dev.data(), queries_size, stream_);
raft::resource::sync_stream(handle_);
// Test the centroid invariants
if (index_2.adaptive_centers()) {
// The centers must be up-to-date with the corresponding data
std::vector<uint32_t> list_sizes(index_2.n_lists());
std::vector<IdxT*> list_indices(index_2.n_lists());
rmm::device_uvector<float> centroid(ps.dim, stream_);
raft::copy(
list_sizes.data(), index_2.list_sizes().data_handle(), index_2.n_lists(), stream_);
raft::copy(
list_indices.data(), index_2.inds_ptrs().data_handle(), index_2.n_lists(), stream_);
raft::resource::sync_stream(handle_);
for (uint32_t l = 0; l < index_2.n_lists(); l++) {
if (list_sizes[l] == 0) continue;
rmm::device_uvector<float> cluster_data(list_sizes[l] * ps.dim, stream_);
cuvs::spatial::knn::detail::utils::copy_selected<float>((IdxT)list_sizes[l],
(IdxT)ps.dim,
database.data(),
list_indices[l],
(IdxT)ps.dim,
cluster_data.data(),
(IdxT)ps.dim,
stream_);
raft::stats::mean<float, uint32_t>(
centroid.data(), cluster_data.data(), ps.dim, list_sizes[l], false, true, stream_);
ASSERT_TRUE(cuvs::devArrMatch(index_2.centers().data_handle() + ps.dim * l,
centroid.data(),
ps.dim,
cuvs::CompareApprox<float>(0.001),
stream_));
}
} else {
// The centers must be immutable
ASSERT_TRUE(cuvs::devArrMatch(index_2.centers().data_handle(),
idx.centers().data_handle(),
index_2.centers().size(),
cuvs::Compare<float>(),
stream_));
}
}
ASSERT_TRUE(eval_neighbours(indices_naive,
indices_ivfflat,
distances_naive,
distances_ivfflat,
ps.num_queries,
ps.k,
0.001,
min_recall));
}
}
void testPacker()
{
ivf_flat::index_params index_params;
ivf_flat::search_params search_params;
index_params.n_lists = ps.nlist;
index_params.metric = ps.metric;
index_params.adaptive_centers = false;
search_params.n_probes = ps.nprobe;
index_params.add_data_on_build = false;
index_params.kmeans_trainset_fraction = 1.0;
index_params.metric_arg = 0;
auto database_view = raft::make_device_matrix_view<const DataT, IdxT>(
(const DataT*)database.data(), ps.num_db_vecs, ps.dim);
auto idx = ivf_flat::build(handle_, index_params, database_view);
const std::optional<raft::device_vector_view<const IdxT, IdxT>> no_opt = std::nullopt;
index<DataT, IdxT> extend_index = ivf_flat::extend(handle_, database_view, no_opt, idx);
auto list_sizes = raft::make_host_vector<uint32_t>(idx.n_lists());
raft::update_host(list_sizes.data_handle(),
extend_index.list_sizes().data_handle(),
extend_index.n_lists(),
stream_);
raft::resource::sync_stream(handle_);
auto& lists = idx.lists();
// conservative memory allocation for codepacking
auto list_device_spec = list_spec<uint32_t, DataT, IdxT>{idx.dim(), false};
for (uint32_t label = 0; label < idx.n_lists(); label++) {
uint32_t list_size = list_sizes.data_handle()[label];
ivf::resize_list(handle_, lists[label], list_device_spec, list_size, 0);
}
ivf_flat::helpers::recompute_internal_state(handle_, &idx);
using interleaved_group = raft::Pow2<kIndexGroupSize>;
for (uint32_t label = 0; label < idx.n_lists(); label++) {
uint32_t list_size = list_sizes.data_handle()[label];
if (list_size > 0) {
uint32_t padded_list_size = interleaved_group::roundUp(list_size);
uint32_t n_elems = padded_list_size * idx.dim();
auto list_data = lists[label]->data;
auto list_inds = extend_index.lists()[label]->indices;
// fetch the flat codes
auto flat_codes = raft::make_device_matrix<DataT, uint32_t>(handle_, list_size, idx.dim());
raft::matrix::gather(
handle_,
raft::make_device_matrix_view<const DataT, uint32_t>(
(const DataT*)database.data(), static_cast<uint32_t>(ps.num_db_vecs), idx.dim()),
raft::make_device_vector_view<const IdxT, uint32_t>((const IdxT*)list_inds.data_handle(),
list_size),
flat_codes.view());
helpers::codepacker::pack(
handle_, make_const_mdspan(flat_codes.view()), idx.veclen(), 0, list_data.view());
{
auto mask = raft::make_device_vector<bool>(handle_, n_elems);
raft::linalg::map_offset(
handle_,
mask.view(),
[dim = idx.dim(),
list_size,
padded_list_size,
chunk_size = raft::util::FastIntDiv(idx.veclen())] __device__(auto i) {
uint32_t max_group_offset = interleaved_group::roundDown(list_size);
if (i < max_group_offset * dim) { return true; }
uint32_t surplus = (i - max_group_offset * dim);
uint32_t ingroup_id = interleaved_group::mod(surplus / chunk_size);
return ingroup_id < (list_size - max_group_offset);
});
// ensure that the correct number of indices are masked out
ASSERT_TRUE(thrust::reduce(raft::resource::get_thrust_policy(handle_),
mask.data_handle(),
mask.data_handle() + n_elems,
0) == list_size * ps.dim);
auto packed_list_data = raft::make_device_vector<DataT, uint32_t>(handle_, n_elems);
raft::linalg::map_offset(handle_,
packed_list_data.view(),
[mask = mask.data_handle(),
list_data = list_data.data_handle()] __device__(uint32_t i) {
if (mask[i]) return list_data[i];
return DataT{0};
});
auto extend_data = extend_index.lists()[label]->data;
auto extend_data_filtered = raft::make_device_vector<DataT, uint32_t>(handle_, n_elems);
raft::linalg::map_offset(
handle_,
extend_data_filtered.view(),
[mask = mask.data_handle(),
extend_data = extend_data.data_handle()] __device__(uint32_t i) {
if (mask[i]) return extend_data[i];
return DataT{0};
});
ASSERT_TRUE(cuvs::devArrMatch(packed_list_data.data_handle(),
extend_data_filtered.data_handle(),
n_elems,
cuvs::Compare<DataT>(),
stream_));
}
auto unpacked_flat_codes =
raft::make_device_matrix<DataT, uint32_t>(handle_, list_size, idx.dim());
helpers::codepacker::unpack(
handle_, list_data.view(), idx.veclen(), 0, unpacked_flat_codes.view());
ASSERT_TRUE(cuvs::devArrMatch(flat_codes.data_handle(),
unpacked_flat_codes.data_handle(),
list_size * ps.dim,
cuvs::Compare<DataT>(),
stream_));
}
}
}
void testFilter()
{
size_t queries_size = ps.num_queries * ps.k;
std::vector<IdxT> indices_ivfflat(queries_size);
std::vector<IdxT> indices_naive(queries_size);
std::vector<T> distances_ivfflat(queries_size);
std::vector<T> distances_naive(queries_size);
{
rmm::device_uvector<T> distances_naive_dev(queries_size, stream_);
rmm::device_uvector<IdxT> indices_naive_dev(queries_size, stream_);
auto* database_filtered_ptr = database.data() + test_ivf_sample_filter::offset * ps.dim;
cuvs::neighbors::naive_knn<T, DataT, IdxT>(handle_,
distances_naive_dev.data(),
indices_naive_dev.data(),
search_queries.data(),
database_filtered_ptr,
ps.num_queries,
ps.num_db_vecs - test_ivf_sample_filter::offset,
ps.dim,
ps.k,
ps.metric);
raft::linalg::addScalar(indices_naive_dev.data(),
indices_naive_dev.data(),
IdxT(test_ivf_sample_filter::offset),
queries_size,
stream_);
raft::update_host(distances_naive.data(), distances_naive_dev.data(), queries_size, stream_);
raft::update_host(indices_naive.data(), indices_naive_dev.data(), queries_size, stream_);
raft::resource::sync_stream(handle_);
}
{
// unless something is really wrong with clustering, this could serve as a lower bound on
// recall
double min_recall = static_cast<double>(ps.nprobe) / static_cast<double>(ps.nlist);
auto distances_ivfflat_dev = raft::make_device_matrix<T, IdxT>(handle_, ps.num_queries, ps.k);
auto indices_ivfflat_dev =
raft::make_device_matrix<IdxT, IdxT>(handle_, ps.num_queries, ps.k);
{
ivf_flat::index_params index_params;
ivf_flat::search_params search_params;
index_params.n_lists = ps.nlist;
index_params.metric = ps.metric;
index_params.adaptive_centers = ps.adaptive_centers;
search_params.n_probes = ps.nprobe;
index_params.add_data_on_build = true;
index_params.kmeans_trainset_fraction = 0.5;
index_params.metric_arg = 0;
// Create IVF Flat index
auto database_view = raft::make_device_matrix_view<const DataT, IdxT>(
(const DataT*)database.data(), ps.num_db_vecs, ps.dim);
auto index = ivf_flat::build(handle_, index_params, database_view);
// Create Bitset filter
auto removed_indices =
raft::make_device_vector<IdxT, int64_t>(handle_, test_ivf_sample_filter::offset);
thrust::sequence(raft::resource::get_thrust_policy(handle_),
thrust::device_pointer_cast(removed_indices.data_handle()),
thrust::device_pointer_cast(removed_indices.data_handle() +
test_ivf_sample_filter::offset));
raft::resource::sync_stream(handle_);
cuvs::core::bitset<std::uint32_t, IdxT> removed_indices_bitset(
handle_, removed_indices.view(), ps.num_db_vecs);
auto bitset_filter_obj =
cuvs::neighbors::filtering::bitset_filter(removed_indices_bitset.view());
// Search with the filter
auto search_queries_view = raft::make_device_matrix_view<const DataT, IdxT>(
search_queries.data(), ps.num_queries, ps.dim);
ivf_flat::search(handle_,
search_params,
index,
search_queries_view,
indices_ivfflat_dev.view(),
distances_ivfflat_dev.view(),
bitset_filter_obj);
raft::update_host(
distances_ivfflat.data(), distances_ivfflat_dev.data_handle(), queries_size, stream_);
raft::update_host(
indices_ivfflat.data(), indices_ivfflat_dev.data_handle(), queries_size, stream_);
raft::resource::sync_stream(handle_);
}
ASSERT_TRUE(eval_neighbours(indices_naive,
indices_ivfflat,
distances_naive,
distances_ivfflat,
ps.num_queries,
ps.k,
0.001,
min_recall));
}
}
void SetUp() override
{
database.resize(ps.num_db_vecs * ps.dim, stream_);
search_queries.resize(ps.num_queries * ps.dim, stream_);
raft::random::RngState r(1234ULL);
if constexpr (std::is_same<DataT, float>{}) {
raft::random::uniform(
handle_, r, database.data(), ps.num_db_vecs * ps.dim, DataT(0.1), DataT(2.0));
raft::random::uniform(
handle_, r, search_queries.data(), ps.num_queries * ps.dim, DataT(0.1), DataT(2.0));
} else {
raft::random::uniformInt(
handle_, r, database.data(), ps.num_db_vecs * ps.dim, DataT(1), DataT(20));
raft::random::uniformInt(
handle_, r, search_queries.data(), ps.num_queries * ps.dim, DataT(1), DataT(20));
}
raft::resource::sync_stream(handle_);
}
void TearDown() override
{
raft::resource::sync_stream(handle_);
database.resize(0, stream_);
search_queries.resize(0, stream_);
}
private:
raft::resources handle_;
rmm::cuda_stream_view stream_;
AnnIvfFlatInputs<IdxT> ps;
rmm::device_uvector<DataT> database;
rmm::device_uvector<DataT> search_queries;
};
const std::vector<AnnIvfFlatInputs<int64_t>> inputs = {
// test various dims (aligned and not aligned to vector sizes)
{1000, 10000, 1, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{1000, 10000, 2, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 2, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 3, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{1000, 10000, 3, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 4, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 4, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 5, 16, 40, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 10000, 5, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 8, 16, 40, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{1000, 10000, 8, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 5, 16, 40, 1024, cuvs::distance::DistanceType::L2SqrtExpanded, false},
{1000, 10000, 5, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 8, 16, 40, 1024, cuvs::distance::DistanceType::L2SqrtExpanded, true},
{1000, 10000, 8, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
// test dims that do not fit into kernel shared memory limits
{1000, 10000, 2048, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 2048, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 2049, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 2049, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 2050, 16, 40, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 10000, 2050, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 2051, 16, 40, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{1000, 10000, 2051, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 2052, 16, 40, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 10000, 2052, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 2053, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{1000, 10000, 2053, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 2056, 16, 40, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{1000, 10000, 2056, 16, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
// various random combinations
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::L2Expanded, false},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::CosineExpanded, false},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
// host input data
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::L2Expanded, false, true},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::CosineExpanded, false, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true},
// // host input data with prefetching for kernel copy overlapping
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::L2Expanded, false, true, true},
{10000, 131072, 8, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false, true, true},
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{1000, 10000, 16, 10, 40, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{1000, 10000, 16, 10, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 10000, 16, 10, 70, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::InnerProduct, true},
{100, 10000, 16, 10, 20, 512, cuvs::distance::DistanceType::CosineExpanded, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{20, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 100000, 16, 10, 20, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
{10000, 131072, 8, 10, 50, 1024, cuvs::distance::DistanceType::InnerProduct, true},
{10000, 131072, 8, 10, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, true},
{1000, 10000, 4096, 20, 50, 1024, cuvs::distance::DistanceType::InnerProduct, false},
{1000, 10000, 4096, 20, 50, 1024, cuvs::distance::DistanceType::CosineExpanded, false},
// test splitting the big query batches (> max gridDim.y) into smaller batches
{100000, 1024, 32, 10, 64, 64, cuvs::distance::DistanceType::InnerProduct, false},
{100000, 1024, 32, 10, 64, 64, cuvs::distance::DistanceType::CosineExpanded, false},
{1000000, 1024, 32, 10, 256, 256, cuvs::distance::DistanceType::InnerProduct, false},
{1000000, 1024, 32, 10, 256, 256, cuvs::distance::DistanceType::CosineExpanded, false},
{98306, 1024, 32, 10, 64, 64, cuvs::distance::DistanceType::InnerProduct, true},
{98306, 1024, 32, 10, 64, 64, cuvs::distance::DistanceType::CosineExpanded, true},
// test radix_sort for getting the cluster selection
{1000,
10000,
16,
10,
raft::matrix::detail::select::warpsort::kMaxCapacity * 2,
raft::matrix::detail::select::warpsort::kMaxCapacity * 4,
cuvs::distance::DistanceType::L2Expanded,
false},
{1000,
10000,
16,
10,
raft::matrix::detail::select::warpsort::kMaxCapacity * 4,
raft::matrix::detail::select::warpsort::kMaxCapacity * 4,
cuvs::distance::DistanceType::InnerProduct,
false},
{1000,
10000,
16,
10,
raft::matrix::detail::select::warpsort::kMaxCapacity * 4,
raft::matrix::detail::select::warpsort::kMaxCapacity * 4,
cuvs::distance::DistanceType::CosineExpanded,
false},
// The following two test cases should show very similar recall.
// num_queries, num_db_vecs, dim, k, nprobe, nlist, metric, adaptive_centers
{20000, 8712, 3, 10, 51, 66, cuvs::distance::DistanceType::L2Expanded, false},
{100000, 8712, 3, 10, 51, 66, cuvs::distance::DistanceType::L2Expanded, false}};
} // namespace cuvs::neighbors::ivf_flat