12 #include "Float16.cuh"
15 namespace faiss {
namespace gpu {
23 __global__
void warpSelect(Tensor<K, 2, true> in,
24 Tensor<K, 2, true> outK,
25 Tensor<IndexType, 2, true> outV,
29 constexpr
int kNumWarps = ThreadsPerBlock / kWarpSize;
31 WarpSelect<K, IndexType, Dir, Comparator<K>,
32 NumWarpQ, NumThreadQ, ThreadsPerBlock>
33 heap(initK, initV, k);
35 int warpId = threadIdx.x / kWarpSize;
36 int row = blockIdx.x * kNumWarps + warpId;
38 if (row >= in.getSize(0)) {
43 K* inStart = in[row][i].data();
46 int limit = utils::roundDown(in.getSize(1), kWarpSize);
48 for (; i < limit; i += kWarpSize) {
49 heap.add(*inStart, (IndexType) i);
54 if (i < in.getSize(1)) {
55 heap.addThreadQ(*inStart, (IndexType) i);
59 heap.writeOut(outK[row].data(),
63 void runWarpSelect(Tensor<float, 2, true>& in,
64 Tensor<float, 2, true>& outKeys,
65 Tensor<int, 2, true>& outIndices,
66 bool dir,
int k, cudaStream_t stream);
68 #ifdef FAISS_USE_FLOAT16
69 void runWarpSelect(Tensor<half, 2, true>& in,
70 Tensor<half, 2, true>& outKeys,
71 Tensor<int, 2, true>& outIndices,
72 bool dir,
int k, cudaStream_t stream);