RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
launch.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_launch_sequential_HPP
21 #define RAJA_pattern_launch_sequential_HPP
22 
26 
27 namespace RAJA
28 {
29 
30 template<>
32 {
33  template<typename BODY>
34  static void exec(LaunchContext const& RAJA_UNUSED_ARG(ctx),
35  BODY const& RAJA_UNUSED_ARG(body))
36  {
37  RAJA_ABORT_OR_THROW("NULL Launch");
38  }
39 };
40 
41 template<>
43 {
44  template<typename BODY, typename ReduceParams>
45  static concepts::enable_if_t<
46  resources::EventProxy<resources::Resource>,
48  exec(RAJA::resources::Resource res,
49  LaunchParams const& launch_params,
50  BODY const& body,
51  ReduceParams& launch_reducers)
52  {
53  constexpr bool is_parampack_empty =
55  if constexpr (!is_parampack_empty)
56  {
57  using EXEC_POL = RAJA::seq_exec;
58  EXEC_POL pol {};
59  expt::ParamMultiplexer::parampack_init(pol, launch_reducers);
60  }
61 
62  using LaunchContextType =
64 
66  char* kernel_local_mem = new char[launch_params.shared_mem_size];
67  ctx.shared_mem_ptr = kernel_local_mem;
68 
69  if constexpr (!is_parampack_empty)
70  {
71  expt::invoke_body(launch_reducers, body, ctx);
72  }
73  else
74  {
75  body(ctx);
76  }
77 
78  delete[] kernel_local_mem;
79  ctx.shared_mem_ptr = nullptr;
80  if constexpr (!is_parampack_empty)
81  {
82  using EXEC_POL = RAJA::seq_exec;
83  EXEC_POL pol {};
84  expt::ParamMultiplexer::parampack_resolve(pol, launch_reducers);
85  }
86 
87  return resources::EventProxy<resources::Resource>(res);
88  }
89 };
90 
91 template<typename SEGMENT>
92 struct LoopExecute<seq_exec, SEGMENT>
93 {
94 
96  template<typename BODY>
97  static RAJA_INLINE RAJA_HOST_DEVICE void exec(SEGMENT const& segment,
98  BODY const& body)
99  {
100 
101  const int len = segment.end() - segment.begin();
102  for (int i = 0; i < len; i++)
103  {
104 
105  body(*(segment.begin() + i));
106  }
107  }
108 
109  template<typename LaunchContextPolicy, typename BODY>
110  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
112  SEGMENT const& segment,
113  BODY const& body)
114  {
115 
116  const int len = segment.end() - segment.begin();
117  for (int i = 0; i < len; i++)
118  {
119  body(*(segment.begin() + i));
120  }
121  }
122 
123  template<typename LaunchContextPolicy, typename BODY>
124  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
126  SEGMENT const& segment0,
127  SEGMENT const& segment1,
128  BODY const& body)
129  {
130 
131  // block stride loop
132  const int len1 = segment1.end() - segment1.begin();
133  const int len0 = segment0.end() - segment0.begin();
134 
135  for (int j = 0; j < len1; j++)
136  {
137  for (int i = 0; i < len0; i++)
138  {
139 
140  body(*(segment0.begin() + i), *(segment1.begin() + j));
141  }
142  }
143  }
144 
145  template<typename LaunchContextPolicy, typename BODY>
146  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
148  SEGMENT const& segment0,
149  SEGMENT const& segment1,
150  SEGMENT const& segment2,
151  BODY const& body)
152  {
153 
154  // block stride loop
155  const int len2 = segment2.end() - segment2.begin();
156  const int len1 = segment1.end() - segment1.begin();
157  const int len0 = segment0.end() - segment0.begin();
158 
159  for (int k = 0; k < len2; k++)
160  {
161  for (int j = 0; j < len1; j++)
162  {
163  for (int i = 0; i < len0; i++)
164  {
165  body(*(segment0.begin() + i), *(segment1.begin() + j),
166  *(segment2.begin() + k));
167  }
168  }
169  }
170  }
171 };
172 
173 template<typename SEGMENT>
174 struct LoopICountExecute<seq_exec, SEGMENT>
175 {
176 
177  template<typename LaunchContextPolicy, typename BODY>
178  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
180  SEGMENT const& segment,
181  BODY const& body)
182  {
183  const int len = segment.end() - segment.begin();
184  for (int i = 0; i < len; i++)
185  {
186  body(*(segment.begin() + i), i);
187  }
188  }
189 
190  template<typename LaunchContextPolicy, typename BODY>
191  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
193  SEGMENT const& segment0,
194  SEGMENT const& segment1,
195  BODY const& body)
196  {
197 
198  // block stride loop
199  const int len1 = segment1.end() - segment1.begin();
200  const int len0 = segment0.end() - segment0.begin();
201 
202  for (int j = 0; j < len1; j++)
203  {
204  for (int i = 0; i < len0; i++)
205  {
206 
207  body(*(segment0.begin() + i), *(segment1.begin() + j), i, j);
208  }
209  }
210  }
211 
212  template<typename LaunchContextPolicy, typename BODY>
213  static RAJA_INLINE RAJA_HOST_DEVICE void exec(
215  SEGMENT const& segment0,
216  SEGMENT const& segment1,
217  SEGMENT const& segment2,
218  BODY const& body)
219  {
220 
221  // block stride loop
222  const int len2 = segment2.end() - segment2.begin();
223  const int len1 = segment1.end() - segment1.begin();
224  const int len0 = segment0.end() - segment0.begin();
225 
226  for (int k = 0; k < len2; k++)
227  {
228  for (int j = 0; j < len1; j++)
229  {
230  for (int i = 0; i < len0; i++)
231  {
232  body(*(segment0.begin() + i), *(segment1.begin() + j),
233  *(segment2.begin() + k), i, j, k);
234  }
235  }
236  }
237  }
238 };
239 
240 // Tile Execute + variants
241 
242 template<typename SEGMENT>
243 struct TileExecute<seq_exec, SEGMENT>
244 {
245 
246  template<typename LaunchContextPolicy, typename TILE_T, typename BODY>
247  static RAJA_HOST_DEVICE RAJA_INLINE void exec(
249  TILE_T tile_size,
250  SEGMENT const& segment,
251  BODY const& body)
252  {
253 
254  const int len = segment.end() - segment.begin();
255 
256  for (int tx = 0; tx < len; tx += tile_size)
257  {
258  body(segment.slice(tx, tile_size));
259  }
260  }
261 };
262 
263 template<typename SEGMENT>
264 struct TileTCountExecute<seq_exec, SEGMENT>
265 {
266 
267  template<typename LaunchContextPolicy, typename TILE_T, typename BODY>
268  static RAJA_HOST_DEVICE RAJA_INLINE void exec(
270  TILE_T tile_size,
271  SEGMENT const& segment,
272  BODY const& body)
273  {
274 
275  const int len = segment.end() - segment.begin();
276 
277  for (int tx = 0, bx = 0; tx < len; tx += tile_size, bx++)
278  {
279  body(segment.slice(tx, tile_size), bx);
280  }
281  }
282 };
283 
284 } // namespace RAJA
285 #endif
Definition: launch_context_policy.hpp:30
RAJA header file containing the core components of RAJA::launch.
RAJA_HOST_DEVICE void RAJA_ABORT_OR_THROW(const char *str)
Definition: macros.hpp:143
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_SUPPRESS_HD_WARN
Definition: macros.hpp:68
#define RAJA_UNUSED_ARG(x)
Definition: macros.hpp:97
constexpr RAJA_HOST_DEVICE auto invoke_body(Params &&params, Fn &&f, Ts &&... extra)
Definition: forall.hpp:598
Definition: AlignedRangeIndexSetBuilders.cpp:35
LaunchContextType ctx
Definition: launch.hpp:185
auto & body
Definition: launch.hpp:177
typename RAJA::detail::launch_context_type< BODY >::type LaunchContextType
Definition: launch.hpp:183
Header file containing RAJA sequential policy definitions.
static void exec(LaunchContext const &RAJA_UNUSED_ARG(ctx), BODY const &RAJA_UNUSED_ARG(body))
Definition: launch.hpp:34
static concepts::enable_if_t< resources::EventProxy< resources::Resource >, RAJA::expt::type_traits::is_ForallParamPack< ReduceParams > > exec(RAJA::resources::Resource res, LaunchParams const &launch_params, BODY const &body, ReduceParams &launch_reducers)
Definition: launch.hpp:48
Definition: launch_core.hpp:263
Definition: launch_core.hpp:163
size_t shared_mem_size
Definition: launch_core.hpp:167
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:110
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:124
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:146
static RAJA_SUPPRESS_HD_WARN RAJA_INLINE RAJA_HOST_DEVICE void exec(SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:97
Definition: launch_core.hpp:480
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:178
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch.hpp:191
static RAJA_INLINE RAJA_HOST_DEVICE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), SEGMENT const &segment0, SEGMENT const &segment1, SEGMENT const &segment2, BODY const &body)
Definition: launch.hpp:213
Definition: launch_core.hpp:483
static RAJA_HOST_DEVICE RAJA_INLINE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:247
Definition: launch_core.hpp:579
static RAJA_HOST_DEVICE RAJA_INLINE void exec(LaunchContextT< LaunchContextPolicy > const RAJA_UNUSED_ARG(&ctx), TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch.hpp:268
Definition: launch_core.hpp:582
static constexpr void parampack_resolve(EXEC_POL const &pol, ForallParamPack< Params... > &f_params, Args &&... args)
Definition: forall.hpp:304
static constexpr void parampack_init(EXEC_POL const &pol, ForallParamPack< Params... > &f_params, Args &&... args)
Definition: forall.hpp:269
Definition: TypeTraits.hpp:59
Definition: launch_core.hpp:65
Definition: policy.hpp:78