RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
TensorIndex.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_TensorIndex_HPP
21 #define RAJA_pattern_tensor_TensorIndex_HPP
22 
23 #include "RAJA/config.hpp"
24 #include "RAJA/util/macros.hpp"
26 
27 namespace RAJA
28 {
29 namespace expt
30 {
31 
32 
33 template<typename IDX,
34  typename TENSOR_TYPE,
35  camp::idx_t DIM,
36  strip_index_type_t<IDX> INDEX_VALUE,
37  strip_index_type_t<IDX> LENGTH_VALUE>
39 
40 template<typename INNER_TYPE>
42 
43 template<typename IDX, typename TENSOR_TYPE, camp::idx_t DIM>
45 {
46 public:
49  using index_type = IDX;
50  using tensor_type = TENSOR_TYPE;
51 
52  RAJA_INLINE
53 
55  static constexpr self_type all()
56  {
57  return self_type(index_type(-1), value_type(-1));
58  }
59 
60  RAJA_INLINE
61 
63  static constexpr StaticTensorIndex<StaticTensorIndexInner<IDX,
64  TENSOR_TYPE,
65  DIM,
66  value_type(-1),
67  value_type(-1)>>
69  {
71  IDX, TENSOR_TYPE, DIM, value_type(-1), value_type(-1)>>();
72  }
73 
74  RAJA_INLINE
75 
77  static constexpr self_type range(index_type begin, index_type end)
78  {
80  }
81 
82  template<value_type TBEGIN, value_type TEND>
83  RAJA_INLINE RAJA_HOST_DEVICE static constexpr StaticTensorIndex<
84  StaticTensorIndexInner<IDX, TENSOR_TYPE, DIM, TBEGIN, TEND - TBEGIN>>
86  {
87  return StaticTensorIndex<
88  StaticTensorIndexInner<IDX, TENSOR_TYPE, DIM, TBEGIN, TEND - TBEGIN>>();
89  }
90 
91  RAJA_INLINE
92 
94  constexpr TensorIndex() : m_index(index_type(0)), m_length(0) {}
95 
96  RAJA_INLINE
97 
100  : m_index(*seg.begin()),
101  m_length(seg.size())
102  {}
103 
104  RAJA_INLINE
105 
107  constexpr TensorIndex(index_type value, value_type length)
108  : m_index(value),
109  m_length(length)
110  {}
111 
112  template<typename T, camp::idx_t D>
113  RAJA_INLINE RAJA_HOST_DEVICE constexpr TensorIndex(
114  TensorIndex<IDX, T, D> const& c)
115  : m_index(*c),
116  m_length(c.size())
117  {}
118 
119  template<value_type IDX_VAL, value_type LEN_VAL>
120  RAJA_INLINE RAJA_HOST_DEVICE constexpr TensorIndex(
123  RAJA_UNUSED_ARG(&c))
124  : m_index(IDX_VAL),
125  m_length(LEN_VAL)
126  {}
127 
128  RAJA_INLINE
129 
131  constexpr index_type const& operator*() const { return m_index; }
132 
133  // used in strip_by_value as a static cast
134  RAJA_INLINE
135 
137  constexpr explicit operator index_type() const
138  {
139  // return does not matter, but suppresses no-return warnings
140  return m_index;
141  }
142 
143  RAJA_INLINE
144 
146  constexpr index_type begin() const { return m_index; }
147 
148  RAJA_INLINE
149 
151  constexpr value_type size() const { return m_length; }
152 
153  RAJA_INLINE
154 
156  constexpr value_type dim() const { return DIM; }
157 
158 private:
159  index_type m_index;
160  value_type m_length;
161 };
162 
163 template<typename IDX,
164  typename TENSOR_TYPE,
165  camp::idx_t DIM,
166  strip_index_type_t<IDX> INDEX_VALUE,
167  strip_index_type_t<IDX> LENGTH_VALUE>
169  StaticTensorIndexInner<IDX, TENSOR_TYPE, DIM, INDEX_VALUE, LENGTH_VALUE>>
170 {
171 
174  using index_type = IDX;
175  using tensor_type = TENSOR_TYPE;
176 
177  static const index_type s_index = INDEX_VALUE;
178  static const index_type s_length = LENGTH_VALUE;
179 
180  RAJA_INLINE
181 
183  constexpr operator base_type() { return base_type(s_index, s_length); }
184 };
185 
189 template<typename IDX, typename VECTOR_TYPE>
191 
195 template<typename IDX, typename MATRIX_TYPE>
197 
201 template<typename IDX, typename MATRIX_TYPE>
203 
207 template<typename IDX, typename MATRIX_TYPE>
210 {
211  return ColIndex<IDX, MATRIX_TYPE>(*r, r.size());
212 }
213 
217 template<typename IDX, typename MATRIX_TYPE>
220 {
221  return RowIndex<IDX, MATRIX_TYPE>(*c, c.size());
222 }
223 
224 } // namespace expt
225 } // namespace RAJA
226 
228 
229 #endif
RAJA header file for strongly-typed integer class.
RAJA header file defining SIMD/SIMT register operations.
Definition: TensorIndex.hpp:45
RAJA_INLINE static constexpr RAJA_HOST_DEVICE self_type all()
Definition: TensorIndex.hpp:55
RAJA_INLINE static constexpr RAJA_HOST_DEVICE StaticTensorIndex< StaticTensorIndexInner< IDX, TENSOR_TYPE, DIM, value_type(-1), value_type(-1)> > static_all()
Definition: TensorIndex.hpp:68
RAJA_INLINE constexpr RAJA_HOST_DEVICE TensorIndex(StaticTensorIndex< StaticTensorIndexInner< IDX, TENSOR_TYPE, DIM, IDX_VAL, LEN_VAL >> const RAJA_UNUSED_ARG(&c))
Definition: TensorIndex.hpp:120
RAJA_INLINE constexpr RAJA_HOST_DEVICE TensorIndex(TensorIndex< IDX, T, D > const &c)
Definition: TensorIndex.hpp:113
RAJA_INLINE constexpr RAJA_HOST_DEVICE index_type const & operator*() const
Definition: TensorIndex.hpp:131
RAJA_INLINE static constexpr RAJA_HOST_DEVICE self_type range(index_type begin, index_type end)
Definition: TensorIndex.hpp:77
RAJA_INLINE static constexpr RAJA_HOST_DEVICE StaticTensorIndex< StaticTensorIndexInner< IDX, TENSOR_TYPE, DIM, TBEGIN, TEND - TBEGIN > > static_range()
Definition: TensorIndex.hpp:85
RAJA_INLINE constexpr RAJA_HOST_DEVICE value_type size() const
Definition: TensorIndex.hpp:151
strip_index_type_t< IDX > value_type
Definition: TensorIndex.hpp:48
RAJA_INLINE constexpr RAJA_HOST_DEVICE TensorIndex(index_type value, value_type length)
Definition: TensorIndex.hpp:107
RAJA_INLINE constexpr RAJA_HOST_DEVICE value_type dim() const
Definition: TensorIndex.hpp:156
RAJA_INLINE constexpr RAJA_HOST_DEVICE index_type begin() const
Definition: TensorIndex.hpp:146
RAJA_INLINE constexpr RAJA_HOST_DEVICE TensorIndex()
Definition: TensorIndex.hpp:94
IDX index_type
Definition: TensorIndex.hpp:49
RAJA_INLINE constexpr RAJA_HOST_DEVICE TensorIndex(RAJA::TypedRangeSegment< IDX > const &seg)
Definition: TensorIndex.hpp:99
TENSOR_TYPE tensor_type
Definition: TensorIndex.hpp:50
TensorIndex< IDX, TENSOR_TYPE, DIM > self_type
Definition: TensorIndex.hpp:47
Header file for common RAJA internal macro definitions.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
#define RAJA_UNUSED_ARG(x)
Definition: macros.hpp:97
RAJA_HOST_DEVICE constexpr RAJA_INLINE ColIndex< IDX, MATRIX_TYPE > toColIndex(RowIndex< IDX, MATRIX_TYPE > const &r)
Definition: TensorIndex.hpp:208
RAJA_HOST_DEVICE constexpr RAJA_INLINE RowIndex< IDX, MATRIX_TYPE > toRowIndex(ColIndex< IDX, MATRIX_TYPE > const &c)
Definition: TensorIndex.hpp:218
Definition: AlignedRangeIndexSetBuilders.cpp:35
typename internal::StripIndexTypeT< FROM >::type strip_index_type_t
Strips a strongly typed index to its underlying type In the case of a non-strongly typed index,...
Definition: IndexValue.hpp:364
constexpr RAJA_HOST_DEVICE RAJA_INLINE std::enable_if< std::is_base_of< IndexValueBase, FROM >::value, typename FROM::value_type >::type stripIndexType(FROM const val)
Function that strips the strongly typed Index<> and returns its underlying value_type value.
Definition: IndexValue.hpp:323
Segment class representing a contiguous range of typed indices.
Definition: RangeSegment.hpp:100
Definition: TensorIndex.hpp:38
Definition: TensorIndex.hpp:41