21 #ifndef RAJA_policy_hip_kernel_For_HPP
22 #define RAJA_policy_hip_kernel_For_HPP
24 #include "RAJA/config.hpp"
40 template<
typename Data,
41 camp::idx_t ArgumentId,
44 typename... EnclosedStmts,
46 struct HipStatementExecutor<
51 hip_indexer<iteration_mapping::DirectUnchecked, sync, IndexMapper>,
62 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
68 hip_indexer<iteration_mapping::DirectUnchecked, sync, IndexMapper>>;
72 const diff_t i = IndexMapper::template index<diff_t>();
75 data.template assign_offset<ArgumentId>(i);
78 enclosed_stmts_t::exec(data, thread_active);
83 const diff_t len = segment_length<ArgumentId>(data);
85 LaunchDims dims = DimensionCalculator::get_dimensions(len);
87 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
89 return combine(dims, enclosed_dims);
99 template<
typename Data,
100 camp::idx_t ArgumentId,
101 typename IndexMapper,
103 typename... EnclosedStmts,
105 struct HipStatementExecutor<
107 statement::For<ArgumentId,
108 RAJA::policy::hip::hip_indexer<iteration_mapping::Direct,
121 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
127 hip_indexer<iteration_mapping::Direct, sync, IndexMapper>>;
131 const diff_t len = segment_length<ArgumentId>(data);
132 const diff_t i = IndexMapper::template index<diff_t>();
136 const bool have_work = (i < len);
139 data.template assign_offset<ArgumentId>(i);
142 enclosed_stmts_t::exec(data, thread_active && have_work);
147 const diff_t len = segment_length<ArgumentId>(data);
149 LaunchDims dims = DimensionCalculator::get_dimensions(len);
151 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
153 return combine(dims, enclosed_dims);
163 template<
typename Data,
164 camp::idx_t ArgumentId,
165 typename IndexMapper,
166 typename... EnclosedStmts,
168 struct HipStatementExecutor<
170 statement::For<ArgumentId,
171 RAJA::policy::hip::hip_indexer<
172 iteration_mapping::StridedLoop<named_usage::unspecified>,
173 kernel_sync_requirement::sync,
185 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
190 RAJA::internal::KernelDimensionCalculator<RAJA::policy::hip::hip_indexer<
198 const diff_t len = segment_length<ArgumentId>(data);
199 const diff_t i_init = IndexMapper::template index<diff_t>();
200 const diff_t i_stride = IndexMapper::template size<diff_t>();
204 for (
diff_t ii = 0; ii < len; ii += i_stride)
206 const diff_t i = ii + i_init;
210 const bool have_work = (i < len);
213 data.template assign_offset<ArgumentId>(i);
216 enclosed_stmts_t::exec(data, thread_active && have_work);
222 diff_t len = segment_length<ArgumentId>(data);
224 LaunchDims dims = DimensionCalculator::get_dimensions(len);
226 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
228 return combine(dims, enclosed_dims);
238 template<
typename Data,
239 camp::idx_t ArgumentId,
240 typename IndexMapper,
241 typename... EnclosedStmts,
243 struct HipStatementExecutor<
245 statement::For<ArgumentId,
246 RAJA::policy::hip::hip_indexer<
247 iteration_mapping::StridedLoop<named_usage::unspecified>,
248 kernel_sync_requirement::none,
260 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
265 RAJA::internal::KernelDimensionCalculator<RAJA::policy::hip::hip_indexer<
273 const diff_t len = segment_length<ArgumentId>(data);
274 const diff_t i_init = IndexMapper::template index<diff_t>();
275 const diff_t i_stride = IndexMapper::template size<diff_t>();
279 for (
diff_t i = i_init; i < len; i += i_stride)
283 data.template assign_offset<ArgumentId>(i);
286 enclosed_stmts_t::exec(data, thread_active);
292 const diff_t len = segment_length<ArgumentId>(data);
294 LaunchDims dims = DimensionCalculator::get_dimensions(len);
296 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
298 return combine(dims, enclosed_dims);
305 template<
typename Data,
306 camp::idx_t ArgumentId,
307 typename... EnclosedStmts,
309 struct HipStatementExecutor<
311 statement::For<ArgumentId, seq_exec, EnclosedStmts...>,
313 : HipStatementExecutor<
317 RAJA::policy::hip::hip_indexer<
318 iteration_mapping::StridedLoop<named_usage::unspecified>,
319 kernel_sync_requirement::none,
320 hip::IndexGlobal<named_dim::x,
321 named_usage::ignored,
322 named_usage::ignored>>,
332 template<
typename Data,
333 camp::idx_t ArgumentId,
335 typename... EnclosedStmts,
337 struct HipStatementExecutor<Data,
338 statement::For<ArgumentId,
339 RAJA::hip_warp_masked_direct<Mask>,
350 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
357 RAJA::internal::KernelDimensionCalculator<hip_warp_direct>;
359 static_assert(mask_t::max_masked_size <=
360 RAJA::policy::hip::device_constants.WARP_SIZE,
361 "BitMask is too large for HIP warp size");
365 const diff_t len = segment_length<ArgumentId>(data);
367 const diff_t i = mask_t::maskValue((
diff_t)threadIdx.x);
370 data.template assign_offset<ArgumentId>(i);
373 enclosed_stmts_t::exec(data, thread_active && (i < len));
378 diff_t len = segment_length<ArgumentId>(data);
380 LaunchDims dims = DimensionCalculator::get_dimensions(len);
382 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
384 return combine(dims, enclosed_dims);
393 template<
typename Data,
394 camp::idx_t ArgumentId,
396 typename... EnclosedStmts,
398 struct HipStatementExecutor<Data,
399 statement::For<ArgumentId,
400 RAJA::hip_warp_masked_loop<Mask>,
411 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
418 RAJA::internal::KernelDimensionCalculator<hip_warp_loop>;
420 static_assert(mask_t::max_masked_size <=
421 RAJA::policy::hip::device_constants.WARP_SIZE,
422 "BitMask is too large for HIP warp size");
427 const diff_t len = segment_length<ArgumentId>(data);
428 const diff_t i_init = mask_t::maskValue((
diff_t)threadIdx.x);
429 const diff_t i_stride = (
diff_t)mask_t::max_masked_size;
432 for (
diff_t ii = 0; ii < len; ii += i_stride)
434 const diff_t i = ii + i_init;
438 bool have_work = i < len;
441 data.template assign_offset<ArgumentId>(i);
444 enclosed_stmts_t::exec(data, thread_active && have_work);
450 diff_t len = segment_length<ArgumentId>(data);
452 LaunchDims dims = DimensionCalculator::get_dimensions(len);
454 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
456 return combine(dims, enclosed_dims);
465 template<
typename Data,
466 camp::idx_t ArgumentId,
468 typename... EnclosedStmts,
470 struct HipStatementExecutor<Data,
471 statement::For<ArgumentId,
472 RAJA::hip_thread_masked_direct<Mask>,
483 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
490 hip_thread_size_x_direct<mask_t::max_input_size>>;
494 const diff_t len = segment_length<ArgumentId>(data);
496 const diff_t i = mask_t::maskValue((
diff_t)threadIdx.x);
499 data.template assign_offset<ArgumentId>(i);
502 enclosed_stmts_t::exec(data, thread_active && (i < len));
507 const diff_t len = segment_length<ArgumentId>(data);
509 LaunchDims dims = DimensionCalculator::get_dimensions(len);
511 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
513 return combine(dims, enclosed_dims);
522 template<
typename Data,
523 camp::idx_t ArgumentId,
525 typename... EnclosedStmts,
527 struct HipStatementExecutor<Data,
528 statement::For<ArgumentId,
529 RAJA::hip_thread_masked_loop<Mask>,
540 HipStatementListExecutor<Data, stmt_list_t, NewTypes>;
547 hip_thread_size_x_loop<mask_t::max_input_size>>;
552 const diff_t len = segment_length<ArgumentId>(data);
553 const diff_t i_init = mask_t::maskValue((
diff_t)threadIdx.x);
554 const diff_t i_stride = (
diff_t)mask_t::max_masked_size;
557 for (
diff_t ii = 0; ii < len; ii += i_stride)
559 const diff_t i = ii + i_init;
563 bool have_work = i < len;
566 data.template assign_offset<ArgumentId>(i);
569 enclosed_stmts_t::exec(data, thread_active && have_work);
575 diff_t len = segment_length<ArgumentId>(data);
577 LaunchDims dims = DimensionCalculator::get_dimensions(len);
579 LaunchDims enclosed_dims = enclosed_stmts_t::calculateDimensions(data);
581 return combine(dims, enclosed_dims);
#define RAJA_DEVICE
Definition: macros.hpp:66
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
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
Definition: AlignedRangeIndexSetBuilders.cpp:35
kernel_sync_requirement
Definition: types.hpp:63
RAJA header file containing constructs used to run kernel traversals on GPU with HIP.
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:534
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:573
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:540
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:544
Mask mask_t
Definition: For.hpp:542
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:537
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:549
RAJA::internal::KernelDimensionCalculator< hip_thread_size_x_loop< mask_t::max_input_size > > DimensionCalculator
Definition: For.hpp:547
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:505
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:483
RAJA::internal::KernelDimensionCalculator< hip_thread_size_x_direct< mask_t::max_input_size > > DimensionCalculator
Definition: For.hpp:490
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:492
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:480
Mask mask_t
Definition: For.hpp:485
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:487
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:477
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:290
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:270
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:254
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:262
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:260
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:257
RAJA::internal::KernelDimensionCalculator< RAJA::policy::hip::hip_indexer< iteration_mapping::StridedLoop< named_usage::unspecified >, kernel_sync_requirement::none, IndexMapper > > DimensionCalculator
Definition: For.hpp:268
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:415
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:405
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:448
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:424
Mask mask_t
Definition: For.hpp:413
RAJA::internal::KernelDimensionCalculator< hip_warp_loop > DimensionCalculator
Definition: For.hpp:418
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:408
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:411
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:179
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:195
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:220
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:185
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:182
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:187
RAJA::internal::KernelDimensionCalculator< RAJA::policy::hip::hip_indexer< iteration_mapping::StridedLoop< named_usage::unspecified >, kernel_sync_requirement::sync, IndexMapper > > DimensionCalculator
Definition: For.hpp:193
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:70
RAJA::internal::KernelDimensionCalculator< RAJA::policy::hip::hip_indexer< iteration_mapping::DirectUnchecked, sync, IndexMapper > > DimensionCalculator
Definition: For.hpp:68
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:59
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:62
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:64
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:81
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:56
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:145
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:129
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:118
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:115
RAJA::internal::KernelDimensionCalculator< RAJA::policy::hip::hip_indexer< iteration_mapping::Direct, sync, IndexMapper > > DimensionCalculator
Definition: For.hpp:127
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:121
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:123
static LaunchDims calculateDimensions(Data const &data)
Definition: For.hpp:376
RAJA::internal::KernelDimensionCalculator< hip_warp_direct > DimensionCalculator
Definition: For.hpp:357
StatementList< EnclosedStmts... > stmt_list_t
Definition: For.hpp:344
HipStatementListExecutor< Data, stmt_list_t, NewTypes > enclosed_stmts_t
Definition: For.hpp:350
static RAJA_DEVICE void exec(Data &data, bool thread_active)
Definition: For.hpp:363
segment_diff_type< ArgumentId, Data > diff_t
Definition: For.hpp:354
setSegmentTypeFromData< Types, ArgumentId, Data > NewTypes
Definition: For.hpp:347
Mask mask_t
Definition: For.hpp:352
Definition: types.hpp:209