RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
Hyperplane.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_pattern_kernel_Hyperplane_HPP
21 #define RAJA_pattern_kernel_Hyperplane_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <iostream>
26 #include <type_traits>
27 
28 #include "camp/camp.hpp"
29 
31 #include "RAJA/util/macros.hpp"
32 #include "RAJA/util/types.hpp"
33 
34 namespace RAJA
35 {
36 namespace statement
37 {
38 
39 
81 template<camp::idx_t HpArgumentId,
82  typename HpExecPolicy,
83  typename ArgList,
84  typename ExecPolicy,
85  typename... EnclosedStmts>
86 struct Hyperplane : public internal::Statement<ExecPolicy, EnclosedStmts...>
87 {};
88 
89 } // end namespace statement
90 
91 namespace internal
92 {
93 
94 
95 template<camp::idx_t HpArgumentId, typename ArgList, typename... EnclosedStmts>
96 struct HyperplaneInner : public internal::Statement<camp::nil, EnclosedStmts...>
97 {};
98 
99 template<camp::idx_t HpArgumentId,
100  typename HpExecPolicy,
101  camp::idx_t... Args,
102  typename ExecPolicy,
103  typename... EnclosedStmts,
104  typename Types>
105 struct StatementExecutor<statement::Hyperplane<HpArgumentId,
106  HpExecPolicy,
107  ArgList<Args...>,
108  ExecPolicy,
109  EnclosedStmts...>,
110  Types>
111 {
112 
113 
114  template<typename Data>
115  static RAJA_INLINE void exec(Data& data)
116  {
117 
118  // get type of Hp arguments index
119  using data_t = camp::decay<Data>;
120  using idx_t =
121  camp::tuple_element_t<HpArgumentId, typename data_t::offset_tuple_t>;
122 
123  // Set the argument type for this loop
125 
126  // Add a Collapse policy around our enclosed statements that will handle
127  // the inner hyperplane loop's execution
128  using kernel_policy = statement::Collapse<
129  ExecPolicy, ArgList<Args...>,
130  HyperplaneInner<HpArgumentId, ArgList<Args...>, EnclosedStmts...>>;
131 
132  // Create a For-loop wrapper for the outer loop
134 
135  // compute manhattan distance of iteration space to determine
136  // as: hp_len = l0 + l1 + l2 + ...
137  idx_t hp_len =
138  segment_length<HpArgumentId>(data) +
139  foldl(RAJA::operators::plus<idx_t>(), segment_length<Args>(data)...);
140 
141  /* Execute the outer loop over hyperplanes
142  *
143  * This will store h in the index_tuple as argument HpArgumentId, so that
144  * later, the HyperplaneInner executor can pull it out, and calculate that
145  * arguments actual value (and restrict to valid hyperplane indices)
146  */
148  forall_impl(r, HpExecPolicy {}, TypedRangeSegment<idx_t>(0, hp_len),
149  outer_wrapper, RAJA::expt::get_empty_forall_param_pack());
150  }
151 };
152 
153 template<camp::idx_t HpArgumentId,
154  camp::idx_t... Args,
155  typename... EnclosedStmts,
156  typename Types>
158  HyperplaneInner<HpArgumentId, ArgList<Args...>, EnclosedStmts...>,
159  Types>
160 {
161 
162 
163  template<typename Data>
164  static RAJA_INLINE void exec(Data& data)
165  {
166 
167  // get h value
168  auto h = camp::get<HpArgumentId>(data.offset_tuple);
169  using idx_t = decltype(h);
170 
171  // compute actual iterate for HpArgumentId
172  // as: i0 = h - (i1 + i2 + i3 + ...)
173  idx_t i = h - foldl(RAJA::operators::plus<idx_t>(),
174  camp::get<Args>(data.offset_tuple)...);
175 
176  // get length of Hp indexed argument
177  auto len = segment_length<HpArgumentId>(data);
178 
179  // check bounds
180  if (i >= 0 && i < len)
181  {
182 
183  // store in tuple
184  data.template assign_offset<HpArgumentId>(i);
185 
186  // execute enclosed statements
187  execute_statement_list<StatementList<EnclosedStmts...>, Types>(data);
188 
189  // reset h for next iteration
190  data.template assign_offset<HpArgumentId>(h);
191  }
192  }
193 };
194 
195 
196 } // end namespace internal
197 
198 } // end namespace RAJA
199 
200 #endif /* RAJA_pattern_kernel_HPP */
Header file for common RAJA internal macro definitions.
setSegmentType< Types, Segment, camp::at_v< typename camp::decay< Data >::index_types_t, Segment > > setSegmentTypeFromData
Definition: LoopTypes.hpp:95
camp::list< Stmts... > StatementList
Definition: StatementList.hpp:41
RAJA_INLINE void execute_statement_list(Data &&data)
Definition: StatementList.hpp:84
RAJA_INLINE void forall_impl(MultiPolicy< Selector, Policies... > p, Iterable &&iter, Body &&body)
Definition: MultiPolicy.hpp:96
Definition: AlignedRangeIndexSetBuilders.cpp:35
camp::idx_seq< ArgumentId... > ArgList
Definition: kernel.hpp:53
RAJA_HOST_DEVICE constexpr RAJA_INLINE auto foldl(Op &&RAJA_UNUSED_ARG(operation), Arg1 &&arg) -> typename detail::foldl_impl< Op, Arg1 >::Ret
Definition: foldl.hpp:104
Header file for statement wrappers and executors.
Segment class representing a contiguous range of typed indices.
Definition: RangeSegment.hpp:100
Definition: For.hpp:71
Definition: Hyperplane.hpp:97
Definition: Statement.hpp:48
Definition: Statement.hpp:35
Definition: Operators.hpp:367
Definition: IndexSet.hpp:70
Definition: resource.hpp:48
Definition: Collapse.hpp:35
Definition: Hyperplane.hpp:87
Header file for RAJA type definitions.