1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
12 #include "core/nns/kernel/Limits.cuh"
13 #include "core/nns/kernel/Pair.cuh"
15 namespace cloudViewer {
20 __device__ inline T operator()(T a, T b) const { return a + b; }
22 inline __device__ T identity() const { return 0.0; }
27 __device__ inline T operator()(T a, T b) const { return a < b ? a : b; }
29 inline __device__ T identity() const { return Limits<T>::getMax(); }
34 __device__ inline T operator()(T a, T b) const { return a > b ? a : b; }
36 inline __device__ T identity() const { return Limits<T>::getMin(); }
39 /// Used for producing segmented prefix scans; the value of the Pair
40 /// denotes the start of a new segment for the scan
41 template <typename T, typename ReduceOp>
42 struct SegmentedReduce {
43 inline __device__ SegmentedReduce(const ReduceOp& o) : op(o) {}
45 __device__ inline Pair<T, bool> operator()(const Pair<T, bool>& a,
46 const Pair<T, bool>& b) const {
47 return Pair<T, bool>(b.v ? b.k : op(a.k, b.k), a.v || b.v);
50 inline __device__ Pair<T, bool> identity() const {
51 return Pair<T, bool>(op.identity(), false);
58 } // namespace cloudViewer