RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
LoopData.hpp
Go to the documentation of this file.
1 
12 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
13 // Copyright (c) Lawrence Livermore National Security, LLC and other
14 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
15 // files for dates and other details. No copyright assignment is required
16 // to contribute to RAJA.
17 //
18 // SPDX-License-Identifier: (BSD-3-Clause)
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 
21 #ifndef RAJA_pattern_kernel_internal_LoopData_HPP
22 #define RAJA_pattern_kernel_internal_LoopData_HPP
23 
24 #include "RAJA/config.hpp"
25 
26 #include "RAJA/index/IndexSet.hpp"
27 #include "RAJA/util/macros.hpp"
28 #include "RAJA/util/types.hpp"
29 
30 #include "camp/camp.hpp"
31 
36 
37 #include <iterator>
38 #include <type_traits>
39 
40 namespace RAJA
41 {
42 namespace internal
43 {
44 
45 
46 // Universal base of all For wrappers for type traits
47 struct ForList
48 {};
49 
50 struct ForBase
51 {};
52 
54 {};
55 
56 template<camp::idx_t ArgumentId, typename Policy>
57 struct ForTraitBase : public ForBase
58 {
59  constexpr static camp::idx_t index_val = ArgumentId;
60  using index = camp::num<ArgumentId>;
61  using index_type = camp::nil; // default to invalid type
63  using type = ForTraitBase; // make camp::value compatible
64 };
65 
66 template<typename Iterator>
68 {
69  using type = typename std::iterator_traits<
70  typename Iterator::iterator>::difference_type;
71 };
72 
73 template<typename Segments>
75  typename camp::transform<iterable_difftype_getter, Segments>::type;
76 
77 
78 template<typename Segments>
80  typename camp::apply_l<camp::lambda<camp::tuple>,
82 
83 template<typename Iterator>
85 {
86  using type =
87  typename std::iterator_traits<typename Iterator::iterator>::value_type;
88 };
89 
90 template<typename Segments>
92  typename camp::transform<iterable_value_type_getter, Segments>::type;
93 
94 
95 template<typename Segments>
97  typename camp::apply_l<camp::lambda<camp::tuple>,
99 
100 template<typename Segments>
102  typename camp::apply_l<camp::lambda<camp::list>,
104 
105 template<typename SegmentTuple,
106  typename ParamTuple,
107  typename Resource,
108  typename... Bodies>
109 struct LoopData
110 {
111 
112  using Self = LoopData<SegmentTuple, ParamTuple, Resource, Bodies...>;
113 
114  // Offset tuple holds offset from begin() for each of the segments
117 
118  // Used by LoopTypes and various execution policies to determine the
119  // index value type of each segment
121 
122  // Tuple of segments that can be iterated over
123  using segment_tuple_t = SegmentTuple;
124  SegmentTuple segment_tuple;
125 
126  // Tuple of parameters that are thread privatized
127  using param_tuple_t = ParamTuple;
128  using arg_tuple_t =
130  ParamTuple param_tuple;
131 
132  Resource res;
133 
134  // Lambdas that were passed into the kernel
135  using BodiesTuple = camp::tuple<Bodies...>;
138 
139  // Vector sizes of each segment. This is only used by the vector_exec
140  // policies
143 
144  RAJA_INLINE RAJA_HOST_DEVICE constexpr LoopData(SegmentTuple const& s,
145  ParamTuple const& p,
146  Resource r,
147  Bodies const&... b)
148  : segment_tuple(s),
149  param_tuple(p),
150  res(r),
151  bodies(b...)
152  {}
153 
154  constexpr LoopData(LoopData const&) = default;
155  constexpr LoopData(LoopData&&) = default;
156 
157  template<camp::idx_t Idx, typename IndexT>
158  RAJA_HOST_DEVICE RAJA_INLINE void assign_offset(IndexT const& i)
159  {
160  camp::get<Idx>(offset_tuple) = i;
161  }
162 
163  template<typename ParamId, typename IndexT>
164  RAJA_HOST_DEVICE RAJA_INLINE void assign_param(IndexT const& i)
165  {
166  using param_t =
167  camp::at_v<typename param_tuple_t::TList, ParamId::param_idx>;
168  camp::get<ParamId::param_idx>(param_tuple) = param_t(i);
169  }
170 
171  template<typename ParamId>
172  RAJA_HOST_DEVICE RAJA_INLINE auto get_param()
173  -> camp::at_v<typename param_tuple_t::TList, ParamId::param_idx>
174  {
175  return camp::get<ParamId::param_idx>(param_tuple);
176  }
177 
178  RAJA_HOST_DEVICE RAJA_INLINE Resource get_resource() { return res; }
179 };
180 
181 template<camp::idx_t ArgumentId, typename Data>
182 using segment_diff_type = typename std::iterator_traits<
183  typename camp::at_v<typename Data::segment_tuple_t::TList,
184  ArgumentId>::iterator>::difference_type;
185 
186 template<camp::idx_t ArgumentId, typename Data>
187 RAJA_INLINE RAJA_HOST_DEVICE auto segment_length(Data const& data)
189 {
190  return camp::get<ArgumentId>(data.segment_tuple).end() -
191  camp::get<ArgumentId>(data.segment_tuple).begin();
192 }
193 
194 template<typename Data, typename Types, typename... EnclosedStmts>
196 {
197  using data_t = camp::decay<Data>;
198 
200 
201  RAJA_INLINE
202  constexpr explicit GenericWrapper(data_t& d) : data {d} {}
203 
204  RAJA_INLINE
205  void exec()
206  {
207  execute_statement_list<camp::list<EnclosedStmts...>, Types>(data);
208  }
209 };
210 
214 template<typename T>
216 {
217  using data_t = typename T::data_t;
218  using value_type = camp::decay<T>;
220 
223 
224  RAJA_INLINE
225  constexpr NestedPrivatizer(const T& o)
226  : privatized_data {o.data},
228  {}
229 
230  RAJA_INLINE
232 };
233 
234 
235 } // end namespace internal
236 } // end namespace RAJA
237 
238 
239 #endif /* RAJA_pattern_kernel_internal_LoopData_HPP */
RAJA header file defining index set classes.
Header file for loop kernel internals.
Header file for loop kernel internals and helper functions.
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
typename camp::apply_l< camp::lambda< camp::list >, value_type_list_from_segments< Segments > >::type index_types_from_segments
Definition: LoopData.hpp:103
RAJA_INLINE void execute_statement_list(Data &&data)
Definition: StatementList.hpp:84
RAJA_INLINE RAJA_HOST_DEVICE auto segment_length(Data const &data) -> segment_diff_type< ArgumentId, Data >
Definition: LoopData.hpp:187
typename detail::TupleOfNHelper< T, camp::make_idx_seq_t< N > >::type tuple_of_n
Definition: Template.hpp:80
typename std::iterator_traits< typename camp::at_v< typename Data::segment_tuple_t::TList, ArgumentId >::iterator >::difference_type segment_diff_type
Definition: LoopData.hpp:184
typename camp::transform< iterable_value_type_getter, Segments >::type value_type_list_from_segments
Definition: LoopData.hpp:92
typename camp::transform< iterable_difftype_getter, Segments >::type difftype_list_from_segments
Definition: LoopData.hpp:75
typename camp::apply_l< camp::lambda< camp::tuple >, difftype_list_from_segments< Segments > >::type difftype_tuple_from_segments
Definition: LoopData.hpp:81
typename camp::apply_l< camp::lambda< camp::tuple >, value_type_list_from_segments< Segments > >::type index_tuple_from_segments
Definition: LoopData.hpp:98
Definition: AlignedRangeIndexSetBuilders.cpp:35
Policy
Definition: PolicyBase.hpp:32
Definition: params_base.hpp:288
Definition: LoopData.hpp:54
Definition: LoopData.hpp:51
Definition: LoopData.hpp:48
Definition: LoopData.hpp:58
camp::num< ArgumentId > index
Definition: LoopData.hpp:60
constexpr static camp::idx_t index_val
Definition: LoopData.hpp:59
camp::nil index_type
Definition: LoopData.hpp:61
Definition: privatizer.hpp:47
Definition: LoopData.hpp:196
constexpr RAJA_INLINE GenericWrapper(data_t &d)
Definition: LoopData.hpp:202
data_t & data
Definition: LoopData.hpp:199
camp::decay< Data > data_t
Definition: LoopData.hpp:197
RAJA_INLINE void exec()
Definition: LoopData.hpp:205
Definition: LoopData.hpp:110
RAJA_HOST_DEVICE RAJA_INLINE void assign_param(IndexT const &i)
Definition: LoopData.hpp:164
ParamTuple param_tuple_t
Definition: LoopData.hpp:127
vector_sizes_t vector_sizes
Definition: LoopData.hpp:142
RAJA_INLINE constexpr RAJA_HOST_DEVICE LoopData(SegmentTuple const &s, ParamTuple const &p, Resource r, Bodies const &... b)
Definition: LoopData.hpp:144
constexpr LoopData(LoopData &&)=default
SegmentTuple segment_tuple_t
Definition: LoopData.hpp:123
const BodiesTuple bodies
Definition: LoopData.hpp:136
offset_tuple_t offset_tuple
Definition: LoopData.hpp:137
difftype_tuple_from_segments< typename SegmentTuple::TList > offset_tuple_t
Definition: LoopData.hpp:116
RAJA_HOST_DEVICE RAJA_INLINE auto get_param() -> camp::at_v< typename param_tuple_t::TList, ParamId::param_idx >
Definition: LoopData.hpp:172
RAJA_HOST_DEVICE RAJA_INLINE Resource get_resource()
Definition: LoopData.hpp:178
ParamTuple param_tuple
Definition: LoopData.hpp:130
tuple_of_n< int, camp::tuple_size< SegmentTuple >::value > vector_sizes_t
Definition: LoopData.hpp:141
constexpr LoopData(LoopData const &)=default
typename RAJA::expt::detail::ParamToArgHelper< ParamTuple >::type arg_tuple_t
Definition: LoopData.hpp:129
RAJA_HOST_DEVICE RAJA_INLINE void assign_offset(IndexT const &i)
Definition: LoopData.hpp:158
SegmentTuple segment_tuple
Definition: LoopData.hpp:124
camp::tuple< Bodies... > BodiesTuple
Definition: LoopData.hpp:135
index_types_from_segments< typename SegmentTuple::TList > index_types_t
Definition: LoopData.hpp:120
Resource res
Definition: LoopData.hpp:132
Definition: LoopData.hpp:216
value_type privatized_wrapper
Definition: LoopData.hpp:222
data_t privatized_data
Definition: LoopData.hpp:221
constexpr RAJA_INLINE NestedPrivatizer(const T &o)
Definition: LoopData.hpp:225
typename T::data_t data_t
Definition: LoopData.hpp:217
value_type & reference_type
Definition: LoopData.hpp:219
camp::decay< T > value_type
Definition: LoopData.hpp:218
RAJA_INLINE reference_type get_priv()
Definition: LoopData.hpp:231
Definition: LoopData.hpp:68
typename std::iterator_traits< typename Iterator::iterator >::difference_type type
Definition: LoopData.hpp:70
typename std::iterator_traits< typename Iterator::iterator >::value_type type
Definition: LoopData.hpp:87
Header file for RAJA type definitions.