RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
algorithm.hpp
Go to the documentation of this file.
1 
13 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
14 // Copyright (c) Lawrence Livermore National Security, LLC and other
15 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
16 // files for dates and other details. No copyright assignment is required
17 // to contribute to RAJA.
18 //
19 // SPDX-License-Identifier: (BSD-3-Clause)
20 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
21 
22 #ifndef RAJA_pattern_detail_algorithm_HPP
23 #define RAJA_pattern_detail_algorithm_HPP
24 
25 #include "RAJA/config.hpp"
26 #include "RAJA/util/macros.hpp"
27 #include "camp/helpers.hpp"
28 
29 #include <iterator>
30 
31 namespace RAJA
32 {
33 
34 namespace detail
35 {
36 
37 template<typename Iter>
38 using IterVal = typename ::std::iterator_traits<Iter>::value_type;
39 
40 template<typename Iter>
41 using IterRef = typename ::std::iterator_traits<Iter>::reference;
42 
43 template<typename Iter>
44 using IterDiff = typename ::std::iterator_traits<Iter>::difference_type;
45 
46 template<typename Container>
47 using ContainerIter = camp::iterator_from<Container>;
48 
49 template<typename Container>
50 using ContainerVal =
51  camp::decay<decltype(*camp::val<camp::iterator_from<Container>>())>;
52 
53 template<typename Container>
54 using ContainerRef = decltype(*camp::val<camp::iterator_from<Container>>());
55 
56 template<typename Container>
58  camp::decay<decltype(camp::val<camp::iterator_from<Container>>() -
59  camp::val<camp::iterator_from<Container>>())>;
60 
61 template<typename DiffType, typename CountType>
62 RAJA_INLINE DiffType firstIndex(DiffType n,
63  CountType num_threads,
64  CountType thread_id)
65 {
66  return (static_cast<size_t>(n) * thread_id) / num_threads;
67 }
68 
69 } // end namespace detail
70 
74 template<typename Iter>
75 RAJA_HOST_DEVICE RAJA_INLINE void safe_iter_swap(Iter lhs, Iter rhs)
76 {
77 #ifdef RAJA_GPU_DEVICE_COMPILE_PASS_ACTIVE
78  using camp::safe_swap;
79  safe_swap(*lhs, *rhs);
80 #else
81  using std::iter_swap;
82  iter_swap(lhs, rhs);
83 #endif
84 }
85 
89 template<typename Iter>
90 RAJA_HOST_DEVICE RAJA_INLINE Iter next(Iter it)
91 {
92  ++it;
93  return it;
94 }
95 
99 template<typename Iter>
100 RAJA_HOST_DEVICE RAJA_INLINE Iter prev(Iter it)
101 {
102  --it;
103  return it;
104 }
105 
106 } // end namespace RAJA
107 
108 #endif
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
camp::decay< decltype(*camp::val< camp::iterator_from< Container > >())> ContainerVal
Definition: algorithm.hpp:51
camp::iterator_from< Container > ContainerIter
Definition: algorithm.hpp:47
camp::decay< decltype(camp::val< camp::iterator_from< Container > >() - camp::val< camp::iterator_from< Container > >())> ContainerDiff
Definition: algorithm.hpp:59
decltype(*camp::val< camp::iterator_from< Container > >()) ContainerRef
Definition: algorithm.hpp:54
typename ::std::iterator_traits< Iter >::reference IterRef
Definition: algorithm.hpp:41
typename ::std::iterator_traits< Iter >::difference_type IterDiff
Definition: algorithm.hpp:44
typename ::std::iterator_traits< Iter >::value_type IterVal
Definition: algorithm.hpp:38
RAJA_INLINE DiffType firstIndex(DiffType n, CountType num_threads, CountType thread_id)
Definition: algorithm.hpp:62
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE RAJA_INLINE Iter next(Iter it)
returns iterator to next item
Definition: algorithm.hpp:90
RAJA_HOST_DEVICE RAJA_INLINE void safe_iter_swap(Iter lhs, Iter rhs)
swap values at iterators lhs and rhs
Definition: algorithm.hpp:75
RAJA_HOST_DEVICE RAJA_INLINE Iter prev(Iter it)
returns iterator to next item
Definition: algorithm.hpp:100