RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
policy.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 policy_sycl_HPP
21 #define policy_sycl_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #if defined(RAJA_SYCL_ACTIVE)
26 
28 
31 
32 #include "RAJA/util/Operators.hpp"
33 #include "RAJA/util/types.hpp"
34 
35 #include <cstddef>
36 
37 namespace RAJA
38 {
39 
40 struct uint3
41 {
42  unsigned long x, y, z;
43 };
44 
45 using sycl_dim_t = ::sycl::range<1>;
46 
47 using sycl_dim_3_t = uint3;
48 
49 namespace detail
50 {
51 template<bool Async>
52 struct get_launch
53 {
54  static constexpr RAJA::Launch value = RAJA::Launch::async;
55 };
56 
57 template<>
58 struct get_launch<false>
59 {
60  static constexpr RAJA::Launch value = RAJA::Launch::sync;
61 };
62 } // end namespace detail
63 
64 namespace policy
65 {
66 namespace sycl
67 {
68 
69 //
71 //
72 // Execution policies
73 //
75 
76 template<size_t BLOCK_SIZE, bool Async = false>
77 struct sycl_exec : public RAJA::make_policy_pattern_launch_platform_t<
78  RAJA::Policy::sycl,
79  RAJA::Pattern::forall,
80  detail::get_launch<Async>::value,
81  RAJA::Platform::sycl>
82 {};
83 
84 template<bool Async, int num_threads = 0>
85 struct sycl_launch_t : public RAJA::make_policy_pattern_launch_platform_t<
86  RAJA::Policy::sycl,
87  RAJA::Pattern::region,
88  detail::get_launch<Async>::value,
89  RAJA::Platform::sycl>
90 {};
91 
92 struct sycl_reduce
93  : make_policy_pattern_t<RAJA::Policy::sycl, RAJA::Pattern::reduce>
94 {};
95 
96 //
97 // Sycl atomic policy for using sycl atomics on the device and
98 // the provided Policy on the host
99 //
100 template<typename host_policy>
101 struct sycl_atomic_explicit
102 {};
103 
104 //
105 // Default sycl atomic policy uses sycl atomics on the device and non-atomics
106 // on the host
107 //
108 using sycl_atomic = sycl_atomic_explicit<seq_atomic>;
109 
110 template<typename Mask>
111 struct sycl_local_masked_direct
112 {};
113 
114 template<typename Mask>
115 struct sycl_local_masked_loop
116 {};
117 
118 } // namespace sycl
119 } // namespace policy
120 
121 using policy::sycl::sycl_exec;
122 using policy::sycl::sycl_reduce;
123 
124 using policy::sycl::sycl_atomic;
125 using policy::sycl::sycl_atomic_explicit;
126 
127 using policy::sycl::sycl_local_masked_direct;
128 using policy::sycl::sycl_local_masked_loop;
129 
130 using policy::sycl::sycl_launch_t;
131 
136 template<int dim, int WORK_GROUP_SIZE = 1>
137 struct sycl_global_012
138 {};
139 
140 template<int WORK_GROUP_SIZE>
141 using sycl_global_0 = sycl_global_012<0, WORK_GROUP_SIZE>;
142 template<int WORK_GROUP_SIZE>
143 using sycl_global_1 = sycl_global_012<1, WORK_GROUP_SIZE>;
144 template<int WORK_GROUP_SIZE>
145 using sycl_global_2 = sycl_global_012<2, WORK_GROUP_SIZE>;
146 
151 template<int... dim>
152 struct sycl_group_012_loop
153 {};
154 
155 using sycl_group_0_loop = sycl_group_012_loop<0>;
156 using sycl_group_1_loop = sycl_group_012_loop<1>;
157 using sycl_group_2_loop = sycl_group_012_loop<2>;
158 
163 template<int... dim>
164 struct sycl_local_012_loop
165 {};
166 
167 using sycl_local_0_loop = sycl_local_012_loop<0>;
168 using sycl_local_1_loop = sycl_local_012_loop<1>;
169 using sycl_local_2_loop = sycl_local_012_loop<2>;
170 
174 template<int... dim>
175 struct sycl_group_012_direct
176 {};
177 
178 using sycl_group_0_direct = sycl_group_012_direct<0>;
179 using sycl_group_1_direct = sycl_group_012_direct<1>;
180 using sycl_group_2_direct = sycl_group_012_direct<2>;
181 
185 template<int... dim>
186 struct sycl_local_012_direct
187 {};
188 
189 using sycl_local_0_direct = sycl_local_012_direct<0>;
190 using sycl_local_1_direct = sycl_local_012_direct<1>;
191 using sycl_local_2_direct = sycl_local_012_direct<2>;
192 
193 namespace internal
194 {
195 
196 template<int dim>
197 struct SyclDimHelper;
198 
199 template<>
200 struct SyclDimHelper<0>
201 {
202 
203  template<typename dim_t>
204  inline static constexpr auto get(dim_t const& d) -> decltype(d.x)
205  {
206  return d.x;
207  }
208 
209  template<typename dim_t>
210  inline static void set(dim_t& d, int value)
211  {
212  d.x = value;
213  }
214 };
215 
216 template<>
217 struct SyclDimHelper<1>
218 {
219 
220  template<typename dim_t>
221  inline static constexpr auto get(dim_t const& d) -> decltype(d.x)
222  {
223  return d.y;
224  }
225 
226  template<typename dim_t>
227  inline static void set(dim_t& d, int value)
228  {
229  d.y = value;
230  }
231 };
232 
233 template<>
234 struct SyclDimHelper<2>
235 {
236 
237  template<typename dim_t>
238  inline static constexpr auto get(dim_t const& d) -> decltype(d.x)
239  {
240  return d.z;
241  }
242 
243  template<typename dim_t>
244  inline static void set(dim_t& d, int value)
245  {
246  d.z = value;
247  }
248 };
249 
250 template<int dim, typename dim_t>
251 constexpr auto get_sycl_dim(dim_t const& d) -> decltype(d.x)
252 {
253  return SyclDimHelper<dim>::get(d);
254 }
255 
256 template<int dim, typename dim_t>
257 void set_sycl_dim(dim_t& d, int value)
258 {
259  return SyclDimHelper<dim>::set(d, value);
260 }
261 } // namespace internal
262 
263 } // namespace RAJA
264 
265 #endif // RAJA_ENABLE_SYCL
266 
267 #endif
Header file for RAJA operator definitions.
Header file for basic RAJA policy mechanics.
Definition: AlignedRangeIndexSetBuilders.cpp:35
Launch
Definition: PolicyBase.hpp:60
RAJA_HOST_DEVICE constexpr RAJA_INLINE RAJA::zip_tuple_element_t< I, zip_tuple< is_val, Ts... > > & get(zip_tuple< is_val, Ts... > &z) noexcept
Definition: zip_tuple.hpp:56
PolicyBaseT< Pol, Pat, Launch::undefined, Platform::undefined, Args... > make_policy_pattern_t
Definition: PolicyBase.hpp:168
Header file containing RAJA sequential policy definitions.
Definition: PolicyBase.hpp:75
RAJA header file for handling different SYCL header include paths.
Header file for RAJA type definitions.