RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
TensorLoadStore.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_pattern_tensor_ET_TensorLoadStore_HPP
21 #define RAJA_pattern_tensor_ET_TensorLoadStore_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include "RAJA/util/macros.hpp"
26 
29 
30 namespace RAJA
31 {
32 namespace internal
33 {
34 namespace expt
35 {
36 
37 
38 namespace ET
39 {
40 
41 
42 template<typename STORAGE, typename LHS_TYPE, typename RHS_TYPE>
44 {
45  LHS_TYPE const& m_lhs;
46  RHS_TYPE const& m_rhs;
47 
48  template<typename TILE_TYPE>
49  RAJA_HOST_DEVICE RAJA_INLINE void operator()(TILE_TYPE const& tile) const
50  {
51 
52 
53  /*
54  *
55  * For recursive ET types, eval() produces a new ET, and
56  * eval_lhs() produces a new TensorLoadStore.
57  *
58  */
59 
60  m_lhs.eval_lhs(tile) = m_rhs.eval(tile);
61  }
62 };
63 
64 template<typename STORAGE, typename LHS_TYPE, typename RHS_TYPE>
65 RAJA_HOST_DEVICE RAJA_INLINE constexpr auto makeTensorStoreFunctor(
66  LHS_TYPE const& lhs,
68 {
70 }
71 
72 template<typename TENSOR_TYPE, typename REF_TYPE>
74  : public TensorExpressionBase<TensorLoadStore<TENSOR_TYPE, REF_TYPE>>
75 {
76 public:
78  using tensor_type = TENSOR_TYPE;
79  using element_type = typename TENSOR_TYPE::element_type;
80  using index_type = typename REF_TYPE::index_type;
81  using ref_type = REF_TYPE;
82  using tile_type = typename REF_TYPE::tile_type;
83  using result_type = TENSOR_TYPE;
84 
85  static constexpr camp::idx_t s_num_dims = result_type::s_num_dims;
86 
87 
88 private:
89  ref_type m_ref;
90 
91 
92 public:
93  RAJA_INLINE
94 
96  explicit TensorLoadStore(ref_type const& ref) : m_ref {ref} {}
97 
98  RAJA_INLINE
99 
101  TensorLoadStore(self_type const& rhs) : m_ref(rhs.m_ref) {}
102 
103  RAJA_INLINE
104 
106  void print() const
107  {
108  printf("TensorLoadStore: ");
109  m_ref.m_tile.print();
110  }
111 
112  // RAJA_SUPPRESS_HD_WARN
114 
115  RAJA_INLINE
117  {
118  store(rhs);
119  return *this;
120  }
121 
122  // RAJA_SUPPRESS_HD_WARN
123  template<typename RHS>
124  RAJA_HOST_DEVICE RAJA_INLINE self_type& operator=(RHS const& rhs)
125  {
126 
127  store(normalizeOperand(rhs));
128 
129  return *this;
130  }
131 
133  template<typename RHS>
134  RAJA_HOST_DEVICE RAJA_INLINE self_type& operator+=(RHS const& rhs)
135  {
136  store(normalizeOperand(rhs) + (*this));
137  return *this;
138  }
139 
141  template<typename RHS>
142  RAJA_HOST_DEVICE RAJA_INLINE self_type& operator-=(RHS const& rhs)
143  {
145  return *this;
146  }
147 
149  template<typename RHS>
150  RAJA_HOST_DEVICE RAJA_INLINE self_type operator*=(RHS const& rhs)
151  {
153  return *this;
154  }
155 
157  template<typename RHS>
158  RAJA_HOST_DEVICE RAJA_INLINE self_type operator/=(RHS const& rhs)
159  {
161  return *this;
162  }
163 
165  template<typename TILE_TYPE>
166  RAJA_INLINE RAJA_HOST_DEVICE auto eval(TILE_TYPE const& tile) const
167  -> decltype(tensor_type::s_load_ref(merge_ref_tile(m_ref, tile)))
168  {
169  return tensor_type::s_load_ref(merge_ref_tile(m_ref, tile));
170  }
171 
173  template<typename TILE_TYPE>
174  RAJA_INLINE RAJA_HOST_DEVICE auto eval_lhs(TILE_TYPE const& tile) const
175  -> decltype(TENSOR_TYPE::create_et_store_ref(merge_ref_tile(this->m_ref,
176  tile)))
177  {
178  return TENSOR_TYPE::create_et_store_ref(merge_ref_tile(m_ref, tile));
179  }
180 
181  RAJA_INLINE
182 
184  constexpr index_type getDimSize(index_type dim) const
185  {
186  return m_ref.m_tile.m_size[dim];
187  }
188 
189  RAJA_INLINE
190 
192  void print_ast() const { printf("Load()"); }
193 
194 private:
195  RAJA_INLINE
196 
198  tile_type const& getTile() const { return m_ref.m_tile; }
199 
200  template<typename RHS>
201  RAJA_INLINE RAJA_HOST_DEVICE void store(RHS const& rhs)
202  {
203 #ifdef RAJA_DEBUG_PRINT_ET_AST
204  printf("Store(");
205  rhs.print_ast();
206  printf(")\n");
207 #endif
208 
209  tensorTileExec<tensor_type>(
210  m_ref.m_tile, makeTensorStoreFunctor<tensor_type>(*this, rhs));
211  }
212 };
213 
214 
215 } // namespace ET
216 
217 } // namespace expt
218 } // namespace internal
219 
220 } // namespace RAJA
221 
222 
223 #endif
RAJA header file defining SIMD/SIMT register operations.
RAJA header file defining SIMD/SIMT register operations.
Definition: BinaryOperator.hpp:46
Definition: TensorDivide.hpp:320
Definition: ExpressionTemplateBase.hpp:72
Definition: TensorLoadStore.hpp:75
RAJA_INLINE RAJA_HOST_DEVICE TensorLoadStore(ref_type const &ref)
Definition: TensorLoadStore.hpp:96
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE RAJA_INLINE self_type operator*=(RHS const &rhs)
Definition: TensorLoadStore.hpp:150
TENSOR_TYPE tensor_type
Definition: TensorLoadStore.hpp:78
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE RAJA_INLINE self_type & operator-=(RHS const &rhs)
Definition: TensorLoadStore.hpp:142
typename REF_TYPE::tile_type tile_type
Definition: TensorLoadStore.hpp:82
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE RAJA_INLINE self_type operator/=(RHS const &rhs)
Definition: TensorLoadStore.hpp:158
TENSOR_TYPE result_type
Definition: TensorLoadStore.hpp:83
static constexpr camp::idx_t s_num_dims
Definition: TensorLoadStore.hpp:85
typename TENSOR_TYPE::element_type element_type
Definition: TensorLoadStore.hpp:79
RAJA_HOST_DEVICE RAJA_INLINE self_type & operator=(RHS const &rhs)
Definition: TensorLoadStore.hpp:124
RAJA_INLINE RAJA_HOST_DEVICE void print() const
Definition: TensorLoadStore.hpp:106
typename REF_TYPE::index_type index_type
Definition: TensorLoadStore.hpp:80
RAJA_SUPPRESS_HD_WARN RAJA_INLINE RAJA_HOST_DEVICE auto eval(TILE_TYPE const &tile) const -> decltype(tensor_type::s_load_ref(merge_ref_tile(m_ref, tile)))
Definition: TensorLoadStore.hpp:166
RAJA_INLINE RAJA_HOST_DEVICE void print_ast() const
Definition: TensorLoadStore.hpp:192
RAJA_INLINE constexpr RAJA_HOST_DEVICE index_type getDimSize(index_type dim) const
Definition: TensorLoadStore.hpp:184
RAJA_SUPPRESS_HD_WARN RAJA_HOST_DEVICE RAJA_INLINE self_type & operator+=(RHS const &rhs)
Definition: TensorLoadStore.hpp:134
RAJA_SUPPRESS_HD_WARN RAJA_INLINE RAJA_HOST_DEVICE auto eval_lhs(TILE_TYPE const &tile) const -> decltype(TENSOR_TYPE::create_et_store_ref(merge_ref_tile(this->m_ref, tile)))
Definition: TensorLoadStore.hpp:174
REF_TYPE ref_type
Definition: TensorLoadStore.hpp:81
RAJA_HOST_DEVICE RAJA_INLINE self_type & operator=(self_type const &rhs)
Definition: TensorLoadStore.hpp:116
RAJA_INLINE RAJA_HOST_DEVICE TensorLoadStore(self_type const &rhs)
Definition: TensorLoadStore.hpp:101
Definition: TensorMultiply.hpp:50
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_SUPPRESS_HD_WARN
Definition: macros.hpp:68
RAJA_INLINE RAJA_HOST_DEVICE auto normalizeOperand(RHS const &rhs) -> typename NormalizeOperandHelper< RHS >::return_type
Definition: normalizeOperand.hpp:73
RAJA_HOST_DEVICE constexpr RAJA_INLINE auto makeTensorStoreFunctor(LHS_TYPE const &lhs, RHS_TYPE const &rhs) -> TensorStoreFunctor< STORAGE, LHS_TYPE, RHS_TYPE >
Definition: TensorLoadStore.hpp:65
RAJA_INLINE constexpr RAJA_HOST_DEVICE auto merge_ref_tile(REF_TYPE const &ref, TILE_TYPE const &tile) -> typename MergeRefTile< REF_TYPE, TILE_TYPE, camp::make_idx_seq_t< TILE_TYPE::s_num_dims >>::merge_type
Definition: TensorRef.hpp:682
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_HOST_DEVICE RAJA_INLINE void tile(CONTEXT const &ctx, TILE_T tile_size, SEGMENT const &segment, BODY const &body)
Definition: launch_core.hpp:589
Definition: TensorLoadStore.hpp:44
RHS_TYPE const & m_rhs
Definition: TensorLoadStore.hpp:46
RAJA_HOST_DEVICE RAJA_INLINE void operator()(TILE_TYPE const &tile) const
Definition: TensorLoadStore.hpp:49
LHS_TYPE const & m_lhs
Definition: TensorLoadStore.hpp:45