Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
WarpSelectImpl.cuh
1 /**
2 * Copyright (c) 2015-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD+Patents license found in the
6 * LICENSE file in the root directory of this source tree.
7 */
8
9 #include "../WarpSelectKernel.cuh"
10 #include "../Limits.cuh"
11
12 #define WARP_SELECT_DECL(TYPE, DIR, WARP_Q) \
13 extern void runWarpSelect_ ## TYPE ## _ ## DIR ## _ ## WARP_Q ## _( \
14 Tensor<TYPE, 2, true>& in, \
15 Tensor<TYPE, 2, true>& outK, \
16 Tensor<int, 2, true>& outV, \
17 bool dir, \
18 int k, \
19 cudaStream_t stream)
20
21 #define WARP_SELECT_IMPL(TYPE, DIR, WARP_Q, THREAD_Q) \
22 void runWarpSelect_ ## TYPE ## _ ## DIR ## _ ## WARP_Q ## _( \
23 Tensor<TYPE, 2, true>& in, \
24 Tensor<TYPE, 2, true>& outK, \
25 Tensor<int, 2, true>& outV, \
26 bool dir, \
27 int k, \
28 cudaStream_t stream) { \
29 \
30 constexpr int kWarpSelectNumThreads = 128; \
31 auto grid = dim3(utils::divUp(in.getSize(0), \
32 (kWarpSelectNumThreads / kWarpSize))); \
33 auto block = dim3(kWarpSelectNumThreads); \
34 \
35 FAISS_ASSERT(k <= WARP_Q); \
36 FAISS_ASSERT(dir == DIR); \
37 \
38 auto kInit = dir ? Limits<TYPE>::getMin() : Limits<TYPE>::getMax(); \
39 auto vInit = -1; \
40 \
41 warpSelect<TYPE, int, DIR, WARP_Q, THREAD_Q, kWarpSelectNumThreads> \
42 <<<grid, block, 0, stream>>>(in, outK, outV, kInit, vInit, k); \
43 CUDA_TEST_ERROR(); \
44 }
45
46 #define WARP_SELECT_CALL(TYPE, DIR, WARP_Q) \
47 runWarpSelect_ ## TYPE ## _ ## DIR ## _ ## WARP_Q ## _( \
48 in, outK, outV, dir, k, stream)