21 #ifndef RAJA_pattern_tensor_TensorBlock_HPP
22 #define RAJA_pattern_tensor_TensorBlock_HPP
24 #include "RAJA/config.hpp"
28 #include "camp/camp.hpp"
36 template<camp::idx_t ... IDX>
39 template<camp::idx_t IDX0, camp::idx_t ... IDX_REST>
40 struct GetSeqValue<IDX0, IDX_REST...>
46 camp::idx_t
get(camp::idx_t idx){
57 camp::idx_t
get(camp::idx_t ){
62 template <
typename IdxLin,
70 get_layout_default_tile(
72 camp::int_seq<IdxLin, RangeInts...>,
73 camp::int_seq<IdxLin, Sizes...>,
74 camp::int_seq<IdxLin, Strides...>>
const &)
77 return tile_type{ {IdxLin(0*Sizes)...}, {IdxLin(Sizes)...}};
81 template<
typename STORAGE_POLICY,
typename T,
typename LAYOUT>
85 using self_type = TensorBlockStorage<STORAGE_POLICY, T, LAYOUT>;
87 using element_type = T;
88 using layout_type = LAYOUT;
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>;
104 decltype(get_layout_default_tile(layout_type{}))
107 return get_layout_default_tile(layout_type{});
114 TensorBlockStorage() noexcept :
115 base_type(&m_data[0], layout_type{})
120 template<
typename TILE_TYPE, camp::idx_t ... DIM_SEQ>
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>
127 internal::TensorRef<T*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
129 return ref_t{&m_data[0], {(
typename TILE_TYPE::index_type)base_type::get_layout().template get_dim_stride<DIM_SEQ>()...},
tile};
132 template<
typename TILE_TYPE>
135 auto create_ref(TILE_TYPE
const &
tile) noexcept ->
136 decltype(create_ref_expanded(
tile, camp::make_idx_seq_t<layout_type::n_dims>{}))
138 return create_ref_expanded(
tile, camp::make_idx_seq_t<layout_type::n_dims>{});
141 template<
typename TILE_TYPE, camp::idx_t ... DIM_SEQ>
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>
148 internal::TensorRef<T const*, typename TILE_TYPE::index_type, TILE_TYPE::s_tensor_size, layout_type::n_dims, layout_type::stride_one_dim>;
150 return ref_t{&m_data[0], {(
typename TILE_TYPE::index_type)base_type::get_layout().template get_dim_stride<DIM_SEQ>()...},
tile};
153 template<
typename TILE_TYPE>
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>{}))
159 return create_ref_expanded(
tile, camp::make_idx_seq_t<layout_type::n_dims>{});
163 template<camp::idx_t ... DIM_SEQ>
166 ref_type get_ref_expanded(camp::idx_seq<DIM_SEQ...>
const &) noexcept
168 return ref_type{&m_data[0], {index_type(base_type::get_layout().
template get_dim_stride<DIM_SEQ>())...},
171 {index_type(base_type::get_layout().
template get_dim_size<DIM_SEQ>())...}
177 ref_type get_ref() noexcept
179 return get_ref_expanded(camp::make_idx_seq_t<layout_type::n_dims>{});
182 template<camp::idx_t ... DIM_SEQ>
185 const_ref_type get_ref_expanded(camp::idx_seq<DIM_SEQ...>
const &)
const noexcept
187 return const_ref_type{&m_data[0], {index_type(base_type::get_layout().
template get_dim_stride<DIM_SEQ>())...},
190 {index_type(base_type::get_layout().
template get_dim_size<DIM_SEQ>())...}
196 const_ref_type get_ref() const noexcept
198 return get_ref_expanded(camp::make_idx_seq_t<layout_type::n_dims>{});
203 T m_data[s_num_elem];
207 class TensorBlockConcreteBase{};
210 template<
typename REGISTER_POLICY,
211 typename ELEMENT_TYPE,
214 typename STORAGE_POLICY>
221 template<
typename REGISTER_POLICY,
222 typename ELEMENT_TYPE,
223 camp::idx_t ... LAYOUT,
224 camp::idx_t ... DIM_SIZES,
225 typename STORAGE_POLICY>
227 class TensorBlock<REGISTER_POLICY,
229 TensorLayout<LAYOUT...>,
230 camp::idx_seq<DIM_SIZES...>,
231 STORAGE_POLICY> :
public TensorBlockConcreteBase
236 using self_type = TensorBlock<REGISTER_POLICY, ELEMENT_TYPE,
237 TensorLayout<LAYOUT...>,
238 camp::idx_seq<DIM_SIZES...>,
240 using element_type = camp::decay<ELEMENT_TYPE>;
242 using layout_type = camp::idx_seq<LAYOUT...>;
244 using register_type =
245 TensorRegister<REGISTER_POLICY,
247 TensorLayout<LAYOUT...>,
249 (0*LAYOUT+RegisterTraits<REGISTER_POLICY,ELEMENT_TYPE>::s_num_elem)...>>;
251 static constexpr camp::idx_t s_num_dims =
sizeof...(DIM_SIZES);
255 using storage_type = TensorBlockStorage<STORAGE_POLICY, ELEMENT_TYPE, storage_layout>;
257 using index_type = camp::idx_t;
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>;
263 using result_type = register_type;
285 constexpr
int s_dim_elem(
int dim){
295 constexpr
int getDimSize(
int dim)
const{
306 decltype(get_layout_default_tile(storage_layout{}))
307 get_default_tile()
const
309 return get_layout_default_tile(storage_layout{});
317 storage_type s_create_temporary() {
318 return storage_type();
321 template<
typename REF_TYPE>
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);
330 template<
typename REF_TYPE>
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);
340 TensorBlock() =
default;
341 ~TensorBlock() =
default;
343 TensorBlock(TensorBlock
const &) =
default;
345 self_type &operator=(self_type
const &x) =
default;
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