RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
TensorBlock.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 #if 0
21 #ifndef RAJA_pattern_tensor_TensorBlock_HPP
22 #define RAJA_pattern_tensor_TensorBlock_HPP
23 
24 #include "RAJA/config.hpp"
25 
26 #include "RAJA/util/macros.hpp"
27 
28 #include "camp/camp.hpp"
31 
32 namespace RAJA
33 {
34 namespace expt
35 {
36  template<camp::idx_t ... IDX>
37  struct GetSeqValue;
38 
39  template<camp::idx_t IDX0, camp::idx_t ... IDX_REST>
40  struct GetSeqValue<IDX0, IDX_REST...>
41  {
43  RAJA_INLINE
44  static
45  constexpr
46  camp::idx_t get(camp::idx_t idx){
47  return idx == 0 ? IDX0 : GetSeqValue<IDX_REST...>::get(idx-1);
48  }
49  };
50  template<>
51  struct GetSeqValue<>
52  {
54  RAJA_INLINE
55  static
56  constexpr
57  camp::idx_t get(camp::idx_t ){
58  return 0;
59  }
60  };
61 
62  template <typename IdxLin,
63  IdxLin... RangeInts,
64  IdxLin... Sizes,
65  IdxLin... Strides>
67  RAJA_INLINE
68  constexpr
69  RAJA::internal::TensorTile<IdxLin, RAJA::internal::TENSOR_FULL, sizeof...(RangeInts)>
70  get_layout_default_tile(
72  camp::int_seq<IdxLin, RangeInts...>,
73  camp::int_seq<IdxLin, Sizes...>,
74  camp::int_seq<IdxLin, Strides...>> const &)
75  {
76  using tile_type = RAJA::internal::TensorTile<IdxLin, RAJA::internal::TENSOR_FULL, sizeof...(RangeInts)>;
77  return tile_type{ {IdxLin(0*Sizes)...}, {IdxLin(Sizes)...}};
78  }
79 
80 
81  template<typename STORAGE_POLICY, typename T, typename LAYOUT>
82  class TensorBlockStorage : public RAJA::internal::ViewBase<T, T*, LAYOUT>
83  {
84  public:
85  using self_type = TensorBlockStorage<STORAGE_POLICY, T, LAYOUT>;
87  using element_type = T;
88  using layout_type = LAYOUT;
89 
90  static constexpr camp::idx_t s_num_elem = LAYOUT::s_size;
91  using tile_type = decltype(get_layout_default_tile(layout_type{}));
92  using index_type = typename tile_type::index_type;
93  using ref_type = internal::TensorRef<T*, typename tile_type::index_type, tile_type::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
94  using const_ref_type = internal::TensorRef<T const *, typename tile_type::index_type, tile_type::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
95 
101  RAJA_INLINE
102  static
103  constexpr
104  decltype(get_layout_default_tile(layout_type{}))
105  s_get_default_tile()
106  {
107  return get_layout_default_tile(layout_type{});
108  }
109 
110 
112  RAJA_INLINE
113  constexpr
114  TensorBlockStorage() noexcept :
115  base_type(&m_data[0], layout_type{})
116  {
117  }
118 
119 
120  template<typename TILE_TYPE, camp::idx_t ... DIM_SEQ>
122  RAJA_INLINE
123  auto create_ref_expanded(TILE_TYPE const &tile, camp::idx_seq<DIM_SEQ...> const &) noexcept ->
124  internal::TensorRef<T*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>
125  {
126  using ref_t =
127  internal::TensorRef<T*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
128 
129  return ref_t{&m_data[0], {(typename TILE_TYPE::index_type)base_type::get_layout().template get_dim_stride<DIM_SEQ>()...}, tile};
130  }
131 
132  template<typename TILE_TYPE>
134  RAJA_INLINE
135  auto create_ref(TILE_TYPE const &tile) noexcept ->
136  decltype(create_ref_expanded(tile, camp::make_idx_seq_t<layout_type::n_dims>{}))
137  {
138  return create_ref_expanded(tile, camp::make_idx_seq_t<layout_type::n_dims>{});
139  }
140 
141  template<typename TILE_TYPE, camp::idx_t ... DIM_SEQ>
143  RAJA_INLINE
144  auto create_ref_expanded(TILE_TYPE const &tile, camp::idx_seq<DIM_SEQ...> const &) const noexcept ->
145  internal::TensorRef<T const*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>
146  {
147  using ref_t =
148  internal::TensorRef<T const*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
149 
150  return ref_t{&m_data[0], {(typename TILE_TYPE::index_type)base_type::get_layout().template get_dim_stride<DIM_SEQ>()...}, tile};
151  }
152 
153  template<typename TILE_TYPE>
155  RAJA_INLINE
156  auto create_ref(TILE_TYPE const &tile) const noexcept ->
157  decltype(create_ref_expanded(tile, camp::make_idx_seq_t<layout_type::n_dims>{}))
158  {
159  return create_ref_expanded(tile, camp::make_idx_seq_t<layout_type::n_dims>{});
160  }
161 
162 
163  template<camp::idx_t ... DIM_SEQ>
165  RAJA_INLINE
166  ref_type get_ref_expanded(camp::idx_seq<DIM_SEQ...> const &) noexcept
167  {
168  return ref_type{&m_data[0], {index_type(base_type::get_layout().template get_dim_stride<DIM_SEQ>())...},
169  {
170  {(0*DIM_SEQ)...},
171  {index_type(base_type::get_layout().template get_dim_size<DIM_SEQ>())...}
172  }};
173  }
174 
176  RAJA_INLINE
177  ref_type get_ref() noexcept
178  {
179  return get_ref_expanded(camp::make_idx_seq_t<layout_type::n_dims>{});
180  }
181 
182  template<camp::idx_t ... DIM_SEQ>
184  RAJA_INLINE
185  const_ref_type get_ref_expanded(camp::idx_seq<DIM_SEQ...> const &) const noexcept
186  {
187  return const_ref_type{&m_data[0], {index_type(base_type::get_layout().template get_dim_stride<DIM_SEQ>())...},
188  {
189  {(0*DIM_SEQ)...},
190  {index_type(base_type::get_layout().template get_dim_size<DIM_SEQ>())...}
191  }};
192  }
193 
195  RAJA_INLINE
196  const_ref_type get_ref() const noexcept
197  {
198  return get_ref_expanded(camp::make_idx_seq_t<layout_type::n_dims>{});
199  }
200 
201 
202  private:
203  T m_data[s_num_elem];
204  };
205 
206 
207  class TensorBlockConcreteBase{};
208 
209 
210  template<typename REGISTER_POLICY,
211  typename ELEMENT_TYPE,
212  typename LAYOUT,
213  typename SIZES,
214  typename STORAGE_POLICY>
215  class TensorBlock;
216 
217 
218 
219 
220 
221  template<typename REGISTER_POLICY,
222  typename ELEMENT_TYPE,
223  camp::idx_t ... LAYOUT,
224  camp::idx_t ... DIM_SIZES,
225  typename STORAGE_POLICY>
226 
227  class TensorBlock<REGISTER_POLICY,
228  ELEMENT_TYPE,
229  TensorLayout<LAYOUT...>,
230  camp::idx_seq<DIM_SIZES...>,
231  STORAGE_POLICY> : public TensorBlockConcreteBase
232  {
233 
234 
235  public:
236  using self_type = TensorBlock<REGISTER_POLICY, ELEMENT_TYPE,
237  TensorLayout<LAYOUT...>,
238  camp::idx_seq<DIM_SIZES...>,
239  STORAGE_POLICY>;
240  using element_type = camp::decay<ELEMENT_TYPE>;
241 
242  using layout_type = camp::idx_seq<LAYOUT...>;
243 
244  using register_type =
245  TensorRegister<REGISTER_POLICY,
246  ELEMENT_TYPE,
247  TensorLayout<LAYOUT...>,
248  camp::idx_seq<
249  (0*LAYOUT+RegisterTraits<REGISTER_POLICY,ELEMENT_TYPE>::s_num_elem)...>>;
250 
251  static constexpr camp::idx_t s_num_dims = sizeof...(DIM_SIZES);
252 
253  using storage_layout = RAJA::StaticLayout<camp::idx_seq<LAYOUT...>, DIM_SIZES...>;
254  //using storage_layout = RAJA::StaticLayout<camp::idx_seq<1,0>, DIM_SIZES...>;
255  using storage_type = TensorBlockStorage<STORAGE_POLICY, ELEMENT_TYPE, storage_layout>;
256 
257  using index_type = camp::idx_t;
258 
259  using tile_type = typename storage_type::tile_type;
260  using ref_type = internal::TensorRef<element_type *, typename tile_type::index_type, tile_type::s_tensor_size, storage_layout::n_dims, storage_layout::stride_one_dim>;
261 
262  // to masquerade as a ET node
263  using result_type = register_type;
264 
265 
266 
267  public:
268 
270  RAJA_INLINE
271  static
272  constexpr
273  bool is_root() {
274  return true;
275  }
276 
277 
283  RAJA_INLINE
284  static
285  constexpr int s_dim_elem(int dim){
286  return GetSeqValue<DIM_SIZES...>::get(dim);
287  }
288 
294  RAJA_INLINE
295  constexpr int getDimSize(int dim) const{
296  return GetSeqValue<DIM_SIZES...>::get(dim);
297  }
298 
304  RAJA_INLINE
305  constexpr
306  decltype(get_layout_default_tile(storage_layout{}))
307  get_default_tile() const
308  {
309  return get_layout_default_tile(storage_layout{});
310  }
311 
312 
314  RAJA_INLINE
315  static
316  constexpr
317  storage_type s_create_temporary() {
318  return storage_type();
319  }
320 
321  template<typename REF_TYPE>
323  RAJA_INLINE
324  static
325  internal::ET::TensorLoadStore<register_type, REF_TYPE>
326  create_et_store_ref(REF_TYPE const &ref) {
327  return internal::ET::TensorLoadStore<register_type, REF_TYPE>(ref);
328  }
329 
330  template<typename REF_TYPE>
332  RAJA_INLINE
333  static
334  internal::ET::TensorLoadStore<register_type, REF_TYPE>
335  s_load_ref(REF_TYPE const &ref) {
336  return internal::ET::TensorLoadStore<register_type, REF_TYPE>(ref);
337  }
338 
339 
340  TensorBlock() = default;
341  ~TensorBlock() = default;
342 
343  TensorBlock(TensorBlock const &) = default;
344 
345  self_type &operator=(self_type const &x) = default;
346 
347 
348 
349 
350  };
351 
352 
353 
354 namespace internal {
355 
356 namespace ET{
357 
358 
359 } // namespace ET
360 } // namespace internal
361 } // namespace expt
362 } // namespace RAJA
363 
364 
365 #endif
366 
367 #endif
RAJA header file defining Layout, a N-dimensional index calculator with compile-time defined sizes an...
RAJA header file defining SIMD/SIMT register operations.
Definition: TypedViewBase.hpp:569
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
RAJA_HOST_DEVICE RAJA_INLINE void tile(CONTEXT const &ctx, TILE_T tile_size0, TILE_T tile_size1, SEGMENT const &segment0, SEGMENT const &segment1, BODY const &body)
Definition: launch_core.hpp:621
@ TENSOR_FULL
Definition: TensorRef.hpp:236
Definition: AlignedRangeIndexSetBuilders.cpp:35
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
StaticLayoutT< Perm, camp::idx_t, Sizes... > StaticLayout
Definition: StaticLayout.hpp:309
Definition: StaticLayout.hpp:48