Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Pair.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
10 #pragma once
11
12 #include <cuda.h>
13 #include "MathOperators.cuh"
14 #include "WarpShuffles.cuh"
15
16 namespace faiss { namespace gpu {
17
18 /// A simple pair type for CUDA device usage
19 template <typename K, typename V>
20 struct Pair {
21 constexpr __device__ inline Pair() {
22 }
23
24 constexpr __device__ inline Pair(K key, V value)
25 : k(key), v(value) {
26 }
27
28 __device__ inline bool
29 operator==(const Pair<K, V>& rhs) const {
30 return Math<K>::eq(k, rhs.k) && Math<V>::eq(v, rhs.v);
31 }
32
33 __device__ inline bool
34 operator!=(const Pair<K, V>& rhs) const {
35 return !operator==(rhs);
36 }
37
38 __device__ inline bool
39 operator<(const Pair<K, V>& rhs) const {
40 return Math<K>::lt(k, rhs.k) ||
41 (Math<K>::eq(k, rhs.k) && Math<V>::lt(v, rhs.v));
42 }
43
44 __device__ inline bool
45 operator>(const Pair<K, V>& rhs) const {
46 return Math<K>::gt(k, rhs.k) ||
47 (Math<K>::eq(k, rhs.k) && Math<V>::gt(v, rhs.v));
48 }
49
50 K k;
51 V v;
52 };
53
54 template <typename T, typename U>
55 inline __device__ Pair<T, U> shfl_up(const Pair<T, U>& pair,
56 unsigned int delta,
57 int width = kWarpSize) {
58 return Pair<T, U>(shfl_up(pair.k, delta, width),
59 shfl_up(pair.v, delta, width));
60 }
61
62 template <typename T, typename U>
63 inline __device__ Pair<T, U> shfl_xor(const Pair<T, U>& pair,
64 int laneMask,
65 int width = kWarpSize) {
66 return Pair<T, U>(shfl_xor(pair.k, laneMask, width),
67 shfl_xor(pair.v, laneMask, width));
68 }
69
70 } } // namespace
faiss::gpu::Math
Definition: MathOperators.cuh:23
faiss::gpu::Pair
A simple pair type for CUDA device usage.
Definition: Pair.cuh:20