Faiss

- Main Page
- Namespaces
- Classes
- Files

- File List

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
Pair.cuh
1
2 /**
3 * Copyright (c) 2015-present, Facebook, Inc.
4 * All rights reserved.
5 *
6 * This source code is licensed under the CC-by-NC license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10 // Copyright 2004-present Facebook. All Rights Reserved.
11
12 #pragma once
13
14 #include <cuda.h>
15 #include "MathOperators.cuh"
16 #include "WarpShuffles.cuh"
17
18 namespace faiss { namespace gpu {
19
20 /// A simple pair type for CUDA device usage
21 template <typename K, typename V>
22 struct Pair {
23 constexpr __device__ inline Pair() {
24 }
25
26 constexpr __device__ inline Pair(K key, V value)
27 : k(key), v(value) {
28 }
29
30 __device__ inline bool
31 operator==(const Pair<K, V>& rhs) const {
32 return Math<K>::eq(k, rhs.k) && Math<V>::eq(v, rhs.v);
33 }
34
35 __device__ inline bool
36 operator!=(const Pair<K, V>& rhs) const {
37 return !operator==(rhs);
38 }
39
40 __device__ inline bool
41 operator<(const Pair<K, V>& rhs) const {
42 return Math<K>::lt(k, rhs.k) ||
43 (Math<K>::eq(k, rhs.k) && Math<V>::lt(v, rhs.v));
44 }
45
46 __device__ inline bool
47 operator>(const Pair<K, V>& rhs) const {
48 return Math<K>::gt(k, rhs.k) ||
49 (Math<K>::eq(k, rhs.k) && Math<V>::gt(v, rhs.v));
50 }
51
52 K k;
53 V v;
54 };
55
56 template <typename T, typename U>
57 inline __device__ Pair<T, U> shfl_up(const Pair<T, U>& pair,
58 unsigned int delta,
59 int width = kWarpSize) {
60 return Pair<T, U>(shfl_up(pair.k, delta, width),
61 shfl_up(pair.v, delta, width));
62 }
63
64 template <typename T, typename U>
65 inline __device__ Pair<T, U> shfl_xor(const Pair<T, U>& pair,
66 int laneMask,
67 int width = kWarpSize) {
68 return Pair<T, U>(shfl_xor(pair.k, laneMask, width),
69 shfl_xor(pair.v, laneMask, width));
70 }
71
72 } } // namespace
faiss::gpu::Math
Definition: MathOperators.cuh:25
faiss::gpu::Pair
A simple pair type for CUDA device usage.
Definition: Pair.cuh:22