RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
PolicyBase.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_POLICYBASE_HPP
21 #define RAJA_POLICYBASE_HPP
22 
24 #include "RAJA/util/concepts.hpp"
25 
26 #include <cstddef>
27 
28 namespace RAJA
29 {
30 
31 enum class Policy
32 {
33  undefined,
34  sequential,
35  simd,
36  openmp,
38  cuda,
39  hip,
40  sycl
41 };
42 
43 enum class Pattern
44 {
45  undefined,
46  forall,
47  region,
48  reduce,
50  taskgraph,
52  workgroup,
57 };
58 
59 enum class Launch
60 {
61  undefined,
62  sync,
63  async
64 };
65 
66 struct PolicyBase
67 {};
68 
69 template<Policy Policy_,
70  Pattern Pattern_,
71  Launch Launch_,
72  Platform Platform_,
73  typename... Traits>
75 {
76  static constexpr Policy policy = Policy_;
77  static constexpr Pattern pattern = Pattern_;
78  static constexpr Launch launch = Launch_;
79  static constexpr Platform platform = Platform_;
80 };
81 
82 template<typename PolicyType>
83 struct policy_of
84 {
85  static constexpr Policy value = PolicyType::policy;
86 };
87 
88 template<typename PolicyType>
89 struct pattern_of
90 {
91  static constexpr Pattern value = PolicyType::pattern;
92 };
93 
94 template<typename PolicyType>
95 struct launch_of
96 {
97  static constexpr Launch value = PolicyType::launch;
98 };
99 
100 template<typename PolicyType>
102 {
103  static constexpr Platform value = PolicyType::platform;
104 };
105 
106 template<typename PolicyType, RAJA::Policy P_>
107 struct policy_is : camp::num<policy_of<camp::decay<PolicyType>>::value == P_>
108 {};
109 
110 template<typename PolicyType, RAJA::Policy... Ps_>
112  : camp::num<camp::concepts::any_of<policy_is<PolicyType, Ps_>...>::value>
113 {};
114 
115 template<typename PolicyType, RAJA::Pattern P_>
116 struct pattern_is : camp::num<pattern_of<camp::decay<PolicyType>>::value == P_>
117 {};
118 
119 template<typename PolicyType, RAJA::Launch L_>
120 struct launch_is : camp::num<launch_of<camp::decay<PolicyType>>::value == L_>
121 {};
122 
123 template<typename PolicyType, RAJA::Platform P_>
125  : camp::num<platform_of<camp::decay<PolicyType>>::value == P_>
126 {};
127 
128 template<typename PolicyType, typename Trait>
129 struct policy_has_trait_impl : camp::num<false>
130 {};
131 
133 template<typename Trait,
134  Policy Policy_,
135  Pattern Pattern_,
136  Launch Launch_,
137  Platform Platform_,
138  typename... Traits>
140  PolicyBaseT<Policy_, Pattern_, Launch_, Platform_, Traits...>,
141  Trait>
142  : camp::num<camp::concepts::any_of<std::is_same<Trait, Traits>...>::value>
143 {};
144 
146 template<typename PolicyType, typename Trait>
148 
149 template<typename Inner>
150 struct wrapper
151 {
152  using inner = Inner;
153 };
154 
155 namespace reduce
156 {
157 
158 struct ordered
159 {};
160 
161 struct unordered
162 {};
163 
164 } // namespace reduce
165 
166 template<Policy Pol, Pattern Pat, typename... Args>
168  PolicyBaseT<Pol, Pat, Launch::undefined, Platform::undefined, Args...>;
169 
170 template<Policy Policy_,
171  Pattern Pattern_,
172  Launch Launch_,
173  Platform Platform_,
174  typename... Args>
176  PolicyBaseT<Policy_, Pattern_, Launch_, Platform_, Args...>;
177 
178 template<Policy Policy_, Pattern Pattern_, Launch Launch_, typename... Args>
180  PolicyBaseT<Policy_, Pattern_, Launch_, Platform::undefined, Args...>;
181 
182 template<Policy Policy_, Pattern Pattern_, Platform Platform_, typename... Args>
184  PolicyBaseT<Policy_, Pattern_, Launch::undefined, Platform_, Args...>;
185 
186 namespace concepts
187 {
188 
189 template<typename Pol>
191  : DefineConcept(::RAJA::concepts::has_type<::RAJA::Policy>(
192  camp::decay<decltype(Pol::policy)>()),
193  ::RAJA::concepts::has_type<::RAJA::Pattern>(
194  camp::decay<decltype(Pol::pattern)>()),
195  ::RAJA::concepts::has_type<::RAJA::Launch>(
196  camp::decay<decltype(Pol::launch)>()),
197  ::RAJA::concepts::has_type<::RAJA::Platform>(
198  camp::decay<decltype(Pol::platform)>())) {};
199 
200 } // end namespace concepts
201 
202 namespace type_traits
203 {
204 
205 template<typename Pol>
206 struct is_sequential_policy : RAJA::policy_is<Pol, RAJA::Policy::sequential>
207 {};
208 
209 template<typename Pol>
210 struct is_simd_policy : RAJA::policy_is<Pol, RAJA::Policy::simd>
211 {};
212 
213 template<typename Pol>
214 struct is_openmp_policy : RAJA::policy_is<Pol, RAJA::Policy::openmp>
215 {};
216 
217 template<typename Pol>
219  : RAJA::policy_is<Pol, RAJA::Policy::target_openmp>
220 {};
221 
222 template<typename Pol>
223 struct is_cuda_policy : RAJA::policy_is<Pol, RAJA::Policy::cuda>
224 {};
225 
226 template<typename Pol>
227 struct is_hip_policy : RAJA::policy_is<Pol, RAJA::Policy::hip>
228 {};
229 
230 template<typename Pol>
231 struct is_sycl_policy : RAJA::policy_is<Pol, RAJA::Policy::sycl>
232 {};
233 
234 template<typename Pol>
236  : RAJA::policy_any_of<Pol, RAJA::Policy::cuda, RAJA::Policy::hip>
237 {};
238 
239 DefineTypeTraitFromConcept(is_execution_policy,
241 
242 template<typename Pol>
243 struct is_reduce_policy : RAJA::pattern_is<Pol, RAJA::Pattern::reduce>
244 {};
245 
246 template<typename Pol>
248  : RAJA::pattern_is<Pol, RAJA::Pattern::multi_reduce>
249 {};
250 
251 } // end namespace type_traits
252 
253 } // end namespace RAJA
254 
255 #endif /* RAJA_POLICYBASE_HPP */
Header file with aliases to camp types.
Header file for RAJA concept definitions.
DefineTypeTraitFromConcept(is_range_constructible, RAJA::concepts::RangeConstructible)
Definition: AlignedRangeIndexSetBuilders.cpp:35
Launch
Definition: PolicyBase.hpp:60
Policy
Definition: PolicyBase.hpp:32
void launch(LaunchParams const &launch_params, ReduceParams &&... rest_of_launch_args)
Definition: launch_core.hpp:268
Pattern
Definition: PolicyBase.hpp:44
Definition: PolicyBase.hpp:75
static constexpr Platform platform
Definition: PolicyBase.hpp:79
static constexpr Pattern pattern
Definition: PolicyBase.hpp:77
static constexpr Launch launch
Definition: PolicyBase.hpp:78
static constexpr Policy policy
Definition: PolicyBase.hpp:76
Definition: PolicyBase.hpp:67
Definition: PolicyBase.hpp:198
Definition: PolicyBase.hpp:121
Definition: PolicyBase.hpp:96
static constexpr Launch value
Definition: PolicyBase.hpp:97
Definition: PolicyBase.hpp:117
Definition: PolicyBase.hpp:90
static constexpr Pattern value
Definition: PolicyBase.hpp:91
Definition: PolicyBase.hpp:126
Definition: PolicyBase.hpp:102
static constexpr Platform value
Definition: PolicyBase.hpp:103
Definition: PolicyBase.hpp:113
Definition: PolicyBase.hpp:130
Definition: PolicyBase.hpp:108
Definition: PolicyBase.hpp:84
static constexpr Policy value
Definition: PolicyBase.hpp:85
Definition: PolicyBase.hpp:159
Definition: PolicyBase.hpp:162
Definition: PolicyBase.hpp:224
Definition: PolicyBase.hpp:237
Definition: PolicyBase.hpp:228
Definition: PolicyBase.hpp:249
Definition: PolicyBase.hpp:215
Definition: PolicyBase.hpp:244
Definition: PolicyBase.hpp:207
Definition: PolicyBase.hpp:211
Definition: PolicyBase.hpp:232
Definition: PolicyBase.hpp:220
Definition: PolicyBase.hpp:151
Inner inner
Definition: PolicyBase.hpp:152