11 #include "Float16.cuh"
14 namespace faiss {
namespace gpu {
22 __global__
void warpSelect(Tensor<K, 2, true> in,
23 Tensor<K, 2, true> outK,
24 Tensor<IndexType, 2, true> outV,
28 constexpr
int kNumWarps = ThreadsPerBlock / kWarpSize;
30 WarpSelect<K, IndexType, Dir, Comparator<K>,
31 NumWarpQ, NumThreadQ, ThreadsPerBlock>
32 heap(initK, initV, k);
34 int warpId = threadIdx.x / kWarpSize;
35 int row = blockIdx.x * kNumWarps + warpId;
37 if (row >= in.getSize(0)) {
42 K* inStart = in[row][i].data();
45 int limit = utils::roundDown(in.getSize(1), kWarpSize);
47 for (; i < limit; i += kWarpSize) {
48 heap.add(*inStart, (IndexType) i);
53 if (i < in.getSize(1)) {
54 heap.addThreadQ(*inStart, (IndexType) i);
58 heap.writeOut(outK[row].data(),
62 void runWarpSelect(Tensor<float, 2, true>& in,
63 Tensor<float, 2, true>& outKeys,
64 Tensor<int, 2, true>& outIndices,
65 bool dir,
int k, cudaStream_t stream);
67 #ifdef FAISS_USE_FLOAT16
68 void runWarpSelect(Tensor<half, 2, true>& in,
69 Tensor<half, 2, true>& outKeys,
70 Tensor<int, 2, true>& outIndices,
71 bool dir,
int k, cudaStream_t stream);