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_policy_cuda_kernel_Hyperplane_HPP
21 #define RAJA_policy_cuda_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 
32 #include "RAJA/util/macros.hpp"
33 #include "RAJA/util/types.hpp"
34 
35 namespace RAJA
36 {
37 namespace internal
38 {
39 
40 
41 template<typename Data,
42  camp::idx_t HpArgumentId,
43  camp::idx_t... Args,
44  typename... EnclosedStmts,
45  typename Types>
46 struct CudaStatementExecutor<
47  Data,
48  statement::
49  Hyperplane<HpArgumentId, seq_exec, ArgList<Args...>, EnclosedStmts...>,
50  Types>
51 {
52 
53  using stmt_list_t = StatementList<EnclosedStmts...>;
54 
55  // Set the argument type for this loop
57 
59  CudaStatementListExecutor<Data, stmt_list_t, NewTypes>;
60 
61  static inline RAJA_DEVICE void exec(Data& data, bool thread_active)
62  {
63  // compute Manhattan distance of iteration space to determine
64  // as: hp_len = l0 + l1 + l2 + ...
65  int hp_len =
66  segment_length<HpArgumentId>(data) +
67  foldl(RAJA::operators::plus<int>(), segment_length<Args>(data)...);
68 
69  int h_args = foldl(RAJA::operators::plus<idx_t>(),
70  camp::get<Args>(data.offset_tuple)...);
71 
72  // get length of i dimension
73  auto i_len = segment_length<HpArgumentId>(data);
74 
75 
76  /*
77  * Execute the loop over hyperplanes
78  *
79  * We reject the iterations that lie outside of the specified rectangular
80  * region we are sweeping.
81  */
82  for (int h = 0; h < hp_len; ++h)
83  {
84 
85  // compute actual iterate for HpArgumentId
86  // as: i0 = h - (i1 + i2 + i3 + ...)
87  idx_t i = h - h_args;
88 
89  // execute enclosed statements, masking off threads that are out of
90  // bounds
91  data.template assign_offset<HpArgumentId>(i);
92  enclosed_stmts_t::exec(data, thread_active && (i >= 0 && i < i_len));
93  }
94  }
95 
96  static inline LaunchDims calculateDimensions(Data const& data)
97  {
98  return enclosed_stmts_t::calculateDimensions(data);
99  }
100 };
101 
102 
103 } // end namespace internal
104 
105 } // end namespace RAJA
106 
107 #endif /* RAJA_pattern_kernel_HPP */
Header file for common RAJA internal macro definitions.
#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
Definition: AlignedRangeIndexSetBuilders.cpp:35
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 hyperplane patern executor.
Definition: Operators.hpp:367
Header file for RAJA type definitions.