-
Notifications
You must be signed in to change notification settings - Fork 174
/
registers.cuh
794 lines (721 loc) · 34.7 KB
/
registers.cuh
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
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
/*
* Copyright (c) 2021-2022, 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 "common.cuh"
#include "../../ball_cover_common.h"
#include "../block_select_faiss.cuh"
#include "../haversine_distance.cuh"
#include "../selection_faiss.cuh"
#include <cstdint>
#include <limits.h>
#include <raft/cuda_utils.cuh>
#include <faiss/gpu/utils/Limits.cuh>
#include <faiss/gpu/utils/Select.cuh>
#include <faiss/utils/Heap.h>
#include <thrust/fill.h>
namespace raft {
namespace spatial {
namespace knn {
namespace detail {
/**
* To find exact neighbors, we perform a post-processing stage
* that filters out those points which might have neighbors outside
* of their k closest landmarks. This is usually a very small portion
* of the total points.
* @tparam value_idx
* @tparam value_t
* @tparam value_int
* @tparam tpb
* @param X
* @param n_cols
* @param R_knn_inds
* @param R_knn_dists
* @param R_radius
* @param landmarks
* @param n_landmarks
* @param bitset_size
* @param k
* @param output
* @param weight
*/
template <typename value_idx,
typename value_t,
typename value_int = std::uint32_t,
int col_q = 2,
int tpb = 32,
typename distance_func>
__global__ void perform_post_filter_registers(const value_t* X,
value_int n_cols,
const value_idx* R_knn_inds,
const value_t* R_knn_dists,
const value_t* R_radius,
const value_t* landmarks,
int n_landmarks,
value_int bitset_size,
value_int k,
distance_func dfunc,
std::uint32_t* output,
float weight = 1.0)
{
// allocate array of size n_landmarks / 32 ints
extern __shared__ std::uint32_t shared_mem[];
// Start with all bits on
for (value_int i = threadIdx.x; i < bitset_size; i += tpb) {
shared_mem[i] = 0xffffffff;
}
__syncthreads();
// TODO: Would it be faster to use L1 for this?
value_t local_x_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_x_ptr[j] = X[n_cols * blockIdx.x + j];
}
value_t closest_R_dist = R_knn_dists[blockIdx.x * k + (k - 1)];
// zero out bits for closest k landmarks
for (value_int j = threadIdx.x; j < k; j += tpb) {
_zero_bit(shared_mem, (std::uint32_t)R_knn_inds[blockIdx.x * k + j]);
}
__syncthreads();
// Discard any landmarks where p(q, r) > p(q, r_q) + radius(r)
// That is, the distance between the current point and the current
// landmark is > the distance between the current point and
// its closest landmark + the radius of the current landmark.
for (value_int l = threadIdx.x; l < n_landmarks; l += tpb) {
// compute p(q, r)
value_t dist = dfunc(local_x_ptr, landmarks + (n_cols * l), n_cols);
if (dist > weight * (closest_R_dist + R_radius[l]) || dist > 3 * closest_R_dist) {
_zero_bit(shared_mem, l);
}
}
__syncthreads();
/**
* Output bitset
*/
for (value_int l = threadIdx.x; l < bitset_size; l += tpb) {
output[blockIdx.x * bitset_size + l] = shared_mem[l];
}
}
/**
* @tparam value_idx
* @tparam value_t
* @tparam value_int
* @tparam bitset_type
* @tparam warp_q number of registers to use per warp
* @tparam thread_q number of registers to use within each thread
* @tparam tpb number of threads per block
* @param X
* @param n_cols
* @param bitset
* @param bitset_size
* @param R_knn_dists
* @param R_indptr
* @param R_1nn_inds
* @param R_1nn_dists
* @param knn_inds
* @param knn_dists
* @param n_landmarks
* @param k
* @param dist_counter
*/
template <typename value_idx,
typename value_t,
typename value_int = std::uint32_t,
typename bitset_type = std::uint32_t,
typename dist_func,
int warp_q = 32,
int thread_q = 2,
int tpb = 128,
int col_q = 2>
__global__ void compute_final_dists_registers(const value_t* X_index,
const value_t* X,
const value_int n_cols,
bitset_type* bitset,
value_int bitset_size,
const value_t* R_closest_landmark_dists,
const value_idx* R_indptr,
const value_idx* R_1nn_inds,
const value_t* R_1nn_dists,
value_idx* knn_inds,
value_t* knn_dists,
value_int n_landmarks,
value_int k,
dist_func dfunc,
value_int* dist_counter)
{
static constexpr int kNumWarps = tpb / faiss::gpu::kWarpSize;
__shared__ value_t shared_memK[kNumWarps * warp_q];
__shared__ faiss::gpu::KeyValuePair<value_t, value_idx> shared_memV[kNumWarps * warp_q];
const value_t* x_ptr = X + (n_cols * blockIdx.x);
value_t local_x_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_x_ptr[j] = x_ptr[j];
}
faiss::gpu::KeyValueBlockSelect<value_t,
value_idx,
false,
faiss::gpu::Comparator<value_t>,
warp_q,
thread_q,
tpb>
heap(faiss::gpu::Limits<value_t>::getMax(),
faiss::gpu::Limits<value_t>::getMax(),
-1,
shared_memK,
shared_memV,
k);
const value_int n_k = faiss::gpu::utils::roundDown(k, faiss::gpu::kWarpSize);
value_int i = threadIdx.x;
for (; i < n_k; i += tpb) {
value_idx ind = knn_inds[blockIdx.x * k + i];
heap.add(knn_dists[blockIdx.x * k + i], R_closest_landmark_dists[ind], ind);
}
if (i < k) {
value_idx ind = knn_inds[blockIdx.x * k + i];
heap.addThreadQ(knn_dists[blockIdx.x * k + i], R_closest_landmark_dists[ind], ind);
}
heap.checkThreadQ();
for (value_int cur_R_ind = 0; cur_R_ind < n_landmarks; ++cur_R_ind) {
// if cur R overlaps cur point's closest R, it could be a
// candidate
if (_get_val(bitset + (blockIdx.x * bitset_size), cur_R_ind)) {
value_idx R_start_offset = R_indptr[cur_R_ind];
value_idx R_stop_offset = R_indptr[cur_R_ind + 1];
value_idx R_size = R_stop_offset - R_start_offset;
// Loop through R's neighborhood in parallel
// Round R_size to the nearest warp threads so they can
// all be computing in parallel.
const value_int limit = faiss::gpu::utils::roundDown(R_size, faiss::gpu::kWarpSize);
i = threadIdx.x;
for (; i < limit; i += tpb) {
value_idx cur_candidate_ind = R_1nn_inds[R_start_offset + i];
value_t cur_candidate_dist = R_1nn_dists[R_start_offset + i];
value_t z = heap.warpKTopRDist == 0.00 ? 0.0
: (abs(heap.warpKTop - heap.warpKTopRDist) *
abs(heap.warpKTopRDist - cur_candidate_dist) -
heap.warpKTop * cur_candidate_dist) /
heap.warpKTopRDist;
z = isnan(z) || isinf(z) ? 0.0 : z;
// If lower bound on distance could possibly be in
// the closest k neighbors, compute it and add to k-select
value_t dist = std::numeric_limits<value_t>::max();
if (z <= heap.warpKTop) {
const value_t* y_ptr = X_index + (n_cols * cur_candidate_ind);
value_t local_y_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_y_ptr[j] = y_ptr[j];
}
dist = dfunc(local_x_ptr, local_y_ptr, n_cols);
}
heap.add(dist, cur_candidate_dist, cur_candidate_ind);
}
// second round guarantees to be only a single warp.
if (i < R_size) {
value_idx cur_candidate_ind = R_1nn_inds[R_start_offset + i];
value_t cur_candidate_dist = R_1nn_dists[R_start_offset + i];
value_t z = heap.warpKTopRDist == 0.00 ? 0.0
: (abs(heap.warpKTop - heap.warpKTopRDist) *
abs(heap.warpKTopRDist - cur_candidate_dist) -
heap.warpKTop * cur_candidate_dist) /
heap.warpKTopRDist;
z = isnan(z) || isinf(z) ? 0.0 : z;
// If lower bound on distance could possibly be in
// the closest k neighbors, compute it and add to k-select
value_t dist = std::numeric_limits<value_t>::max();
if (z <= heap.warpKTop) {
const value_t* y_ptr = X_index + (n_cols * cur_candidate_ind);
value_t local_y_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_y_ptr[j] = y_ptr[j];
}
dist = dfunc(local_x_ptr, local_y_ptr, n_cols);
}
heap.addThreadQ(dist, cur_candidate_dist, cur_candidate_ind);
}
heap.checkThreadQ();
}
}
heap.reduce();
for (value_int i = threadIdx.x; i < k; i += tpb) {
knn_dists[blockIdx.x * k + i] = shared_memK[i];
knn_inds[blockIdx.x * k + i] = shared_memV[i].value;
}
}
/**
* Random ball cover kernel for n_dims == 2
* @tparam value_idx
* @tparam value_t
* @tparam warp_q
* @tparam thread_q
* @tparam tpb
* @tparam value_idx
* @tparam value_t
* @param R_knn_inds
* @param R_knn_dists
* @param m
* @param k
* @param R_indptr
* @param R_1nn_cols
* @param R_1nn_dists
*/
template <typename value_idx = std::int64_t,
typename value_t,
int warp_q = 32,
int thread_q = 2,
int tpb = 128,
int col_q = 2,
typename value_int = std::uint32_t,
typename distance_func>
__global__ void block_rbc_kernel_registers(const value_t* X_index,
const value_t* X,
value_int n_cols, // n_cols should be 2 or 3 dims
const value_idx* R_knn_inds,
const value_t* R_knn_dists,
value_int m,
value_int k,
const value_idx* R_indptr,
const value_idx* R_1nn_cols,
const value_t* R_1nn_dists,
value_idx* out_inds,
value_t* out_dists,
value_int* dist_counter,
value_t* R_radius,
distance_func dfunc,
float weight = 1.0)
{
static constexpr value_int kNumWarps = tpb / faiss::gpu::kWarpSize;
__shared__ value_t shared_memK[kNumWarps * warp_q];
__shared__ faiss::gpu::KeyValuePair<value_t, value_idx> shared_memV[kNumWarps * warp_q];
// TODO: Separate kernels for different widths:
// 1. Very small (between 3 and 32) just use registers for columns of "blockIdx.x"
// 2. Can fit comfortably in shared memory (32 to a few thousand?)
// 3. Load each time individually.
const value_t* x_ptr = X + (n_cols * blockIdx.x);
// Use registers only for 2d or 3d
value_t local_x_ptr[col_q];
for (value_int i = 0; i < n_cols; ++i) {
local_x_ptr[i] = x_ptr[i];
}
// Each warp works on 1 R
faiss::gpu::KeyValueBlockSelect<value_t,
value_idx,
false,
faiss::gpu::Comparator<value_t>,
warp_q,
thread_q,
tpb>
heap(faiss::gpu::Limits<value_t>::getMax(),
faiss::gpu::Limits<value_t>::getMax(),
-1,
shared_memK,
shared_memV,
k);
value_t min_R_dist = R_knn_dists[blockIdx.x * k + (k - 1)];
value_int n_dists_computed = 0;
/**
* First add distances for k closest neighbors of R
* to the heap
*/
// Start iterating through elements of each set from closest R elements,
// determining if the distance could even potentially be in the heap.
for (value_int cur_k = 0; cur_k < k; ++cur_k) {
// index and distance to current blockIdx.x's closest landmark
value_t cur_R_dist = R_knn_dists[blockIdx.x * k + cur_k];
value_idx cur_R_ind = R_knn_inds[blockIdx.x * k + cur_k];
// Equation (2) in Cayton's paper- prune out R's which are > 3 * p(q, r_q)
if (cur_R_dist > weight * (min_R_dist + R_radius[cur_R_ind])) continue;
if (cur_R_dist > 3 * min_R_dist) return;
// The whole warp should iterate through the elements in the current R
value_idx R_start_offset = R_indptr[cur_R_ind];
value_idx R_stop_offset = R_indptr[cur_R_ind + 1];
value_idx R_size = R_stop_offset - R_start_offset;
value_int limit = faiss::gpu::utils::roundDown(R_size, faiss::gpu::kWarpSize);
value_int i = threadIdx.x;
for (; i < limit; i += tpb) {
// Index and distance of current candidate's nearest landmark
value_idx cur_candidate_ind = R_1nn_cols[R_start_offset + i];
value_t cur_candidate_dist = R_1nn_dists[R_start_offset + i];
// Take 2 landmarks l_1 and l_2 where l_1 is the furthest point in the heap
// and l_2 is the current landmark R. s is the current data point and
// t is the new candidate data point. We know that:
// d(s, t) cannot possibly be any smaller than | d(s, l_1) - d(l_1, l_2) | * | d(l_1, l_2) -
// d(l_2, t) | - d(s, l_1) * d(l_2, t)
// Therefore, if d(s, t) >= d(s, l_1) from the computation above, we know that the distance to
// the candidate point cannot possibly be in the nearest neighbors. However, if d(s, t) < d(s,
// l_1) then we should compute the distance because it's possible it could be smaller.
//
value_t z = heap.warpKTopRDist == 0.00 ? 0.0
: (abs(heap.warpKTop - heap.warpKTopRDist) *
abs(heap.warpKTopRDist - cur_candidate_dist) -
heap.warpKTop * cur_candidate_dist) /
heap.warpKTopRDist;
z = isnan(z) || isinf(z) ? 0.0 : z;
value_t dist = std::numeric_limits<value_t>::max();
if (z <= heap.warpKTop) {
const value_t* y_ptr = X_index + (n_cols * cur_candidate_ind);
value_t local_y_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_y_ptr[j] = y_ptr[j];
}
dist = dfunc(local_x_ptr, local_y_ptr, n_cols);
++n_dists_computed;
}
heap.add(dist, cur_candidate_dist, cur_candidate_ind);
}
if (i < R_size) {
value_idx cur_candidate_ind = R_1nn_cols[R_start_offset + i];
value_t cur_candidate_dist = R_1nn_dists[R_start_offset + i];
value_t z = heap.warpKTopRDist == 0.0 ? 0.0
: (abs(heap.warpKTop - heap.warpKTopRDist) *
abs(heap.warpKTopRDist - cur_candidate_dist) -
heap.warpKTop * cur_candidate_dist) /
heap.warpKTopRDist;
z = isnan(z) || isinf(z) ? 0.0 : z;
value_t dist = std::numeric_limits<value_t>::max();
if (z <= heap.warpKTop) {
const value_t* y_ptr = X_index + (n_cols * cur_candidate_ind);
value_t local_y_ptr[col_q];
for (value_int j = 0; j < n_cols; ++j) {
local_y_ptr[j] = y_ptr[j];
}
dist = dfunc(local_x_ptr, local_y_ptr, n_cols);
++n_dists_computed;
}
heap.addThreadQ(dist, cur_candidate_dist, cur_candidate_ind);
}
heap.checkThreadQ();
}
heap.reduce();
for (int i = threadIdx.x; i < k; i += tpb) {
out_dists[blockIdx.x * k + i] = shared_memK[i];
out_inds[blockIdx.x * k + i] = shared_memV[i].value;
}
}
template <typename value_idx,
typename value_t,
typename value_int = std::uint32_t,
int dims = 2,
typename dist_func>
void rbc_low_dim_pass_one(const raft::handle_t& handle,
BallCoverIndex<value_idx, value_t, value_int>& index,
const value_t* query,
const value_int n_query_rows,
value_int k,
const value_idx* R_knn_inds,
const value_t* R_knn_dists,
dist_func& dfunc,
value_idx* inds,
value_t* dists,
float weight,
value_int* dists_counter)
{
if (k <= 32)
block_rbc_kernel_registers<value_idx, value_t, 32, 2, 128, dims, value_int>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
else if (k <= 64)
block_rbc_kernel_registers<value_idx, value_t, 64, 3, 128, 2, value_int>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
else if (k <= 128)
block_rbc_kernel_registers<value_idx, value_t, 128, 3, 128, dims, value_int>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
else if (k <= 256)
block_rbc_kernel_registers<value_idx, value_t, 256, 4, 128, dims, value_int>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
else if (k <= 512)
block_rbc_kernel_registers<value_idx, value_t, 512, 8, 64, dims, value_int>
<<<n_query_rows, 64, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
else if (k <= 1024)
block_rbc_kernel_registers<value_idx, value_t, 1024, 8, 64, dims, value_int>
<<<n_query_rows, 64, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
R_knn_inds,
R_knn_dists,
index.m,
k,
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
dists_counter,
index.get_R_radius(),
dfunc,
weight);
}
template <typename value_idx,
typename value_t,
typename value_int = std::uint32_t,
int dims = 2,
typename dist_func>
void rbc_low_dim_pass_two(const raft::handle_t& handle,
BallCoverIndex<value_idx, value_t, value_int>& index,
const value_t* query,
const value_int n_query_rows,
value_int k,
const value_idx* R_knn_inds,
const value_t* R_knn_dists,
dist_func& dfunc,
value_idx* inds,
value_t* dists,
float weight,
value_int* post_dists_counter)
{
const value_int bitset_size = ceil(index.n_landmarks / 32.0);
rmm::device_uvector<std::uint32_t> bitset(bitset_size * n_query_rows, handle.get_stream());
thrust::fill(handle.get_thrust_policy(), bitset.data(), bitset.data() + bitset.size(), 0);
perform_post_filter_registers<value_idx, value_t, value_int, dims, 128>
<<<n_query_rows, 128, bitset_size * sizeof(std::uint32_t), handle.get_stream()>>>(
query,
index.n,
R_knn_inds,
R_knn_dists,
index.get_R_radius(),
index.get_R(),
index.n_landmarks,
bitset_size,
k,
dfunc,
bitset.data(),
weight);
if (k <= 32)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
32,
2,
128,
dims>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
else if (k <= 64)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
64,
3,
128,
dims>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
else if (k <= 128)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
128,
3,
128,
dims>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
else if (k <= 256)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
256,
4,
128,
dims>
<<<n_query_rows, 128, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
else if (k <= 512)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
512,
8,
64,
dims>
<<<n_query_rows, 64, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
else if (k <= 1024)
compute_final_dists_registers<value_idx,
value_t,
value_int,
std::uint32_t,
dist_func,
1024,
8,
64,
dims>
<<<n_query_rows, 64, 0, handle.get_stream()>>>(index.get_X(),
query,
index.n,
bitset.data(),
bitset_size,
index.get_R_closest_landmark_dists(),
index.get_R_indptr(),
index.get_R_1nn_cols(),
index.get_R_1nn_dists(),
inds,
dists,
index.n_landmarks,
k,
dfunc,
post_dists_counter);
}
}; // namespace detail
}; // namespace knn
}; // namespace spatial
}; // namespace raft