ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Pair.cuh
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <cuda.h>
11 
12 #include "core/nns/kernel/PtxUtils.cuh"
13 #include "core/nns/kernel/WarpShuffle.cuh"
14 
15 namespace cloudViewer {
16 namespace core {
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  constexpr __device__ inline Pair(K key, V value) : k(key), v(value) {}
24 
25  __device__ inline bool operator==(const Pair<K, V>& rhs) const {
26  return k == rhs.k && v == rhs.v;
27  }
28 
29  __device__ inline bool operator!=(const Pair<K, V>& rhs) const {
30  return !operator==(rhs);
31  }
32 
33  __device__ inline bool operator<(const Pair<K, V>& rhs) const {
34  return k < rhs.k || (k == rhs.k && v < rhs.v);
35  }
36 
37  __device__ inline bool operator>(const Pair<K, V>& rhs) const {
38  return k > rhs.k || (k == rhs.k && v > rhs.v);
39  }
40 
41  K k;
42  V v;
43 };
44 
45 template <typename T, typename U>
46 inline __device__ Pair<T, U> shfl_up(const Pair<T, U>& pair,
47  unsigned int delta,
48  int width = kWarpSize) {
49  return Pair<T, U>(shfl_up(pair.k, delta, width),
50  shfl_up(pair.v, delta, width));
51 }
52 
53 template <typename T, typename U>
54 inline __device__ Pair<T, U> shfl_xor(const Pair<T, U>& pair,
55  int laneMask,
56  int width = kWarpSize) {
57  return Pair<T, U>(shfl_xor(pair.k, laneMask, width),
58  shfl_xor(pair.v, laneMask, width));
59 }
60 
61 } // namespace core
62 } // namespace cloudViewer