20 #ifndef RAJA_LAYOUT_HPP
21 #define RAJA_LAYOUT_HPP
23 #include "RAJA/config.hpp"
43 template<
typename Range,
45 ptrdiff_t StrideOneDim = -1>
52 template<
size_t j,
size_t n_dims,
typename IdxLin = Index_type>
57 IdxLin
const (&sizes)[n_dims])
const
60 cur_stride * (sizes[j] ? sizes[j] : 1), sizes);
64 template<
size_t n_dims,
typename IdxLin>
69 IdxLin
const (&)[n_dims])
const
75 template<camp::idx_t... RangeInts,
typename IdxLin, ptrdiff_t StrideOneDim>
80 using IndexRange = camp::make_idx_seq_t<
sizeof...(RangeInts)>;
82 static inline constexpr
size_t n_dims =
sizeof...(RangeInts);
84 static inline constexpr ptrdiff_t stride_one_dim = StrideOneDim;
86 IdxLin sizes[n_dims] = {0};
87 IdxLin strides[n_dims] = {0};
88 IdxLin inv_strides[n_dims] = {0};
89 IdxLin inv_mods[n_dims] = {0};
105 template<
typename... Types>
109 sizes[RangeInts] ? IdxLin(1) : IdxLin(0),
111 inv_strides {(strides[RangeInts] ? strides[RangeInts] : IdxLin(1))...},
112 inv_mods {(sizes[RangeInts] ? sizes[RangeInts] : IdxLin(1))...}
114 static_assert(n_dims ==
sizeof...(Types),
115 "number of dimensions must match");
121 template<
typename CIdxLin, ptrdiff_t CStr
ideOneDim>
126 : sizes {static_cast<IdxLin>(rhs.sizes[RangeInts])...},
127 strides {static_cast<IdxLin>(rhs.strides[RangeInts])...},
128 inv_strides {static_cast<IdxLin>(rhs.inv_strides[RangeInts])...},
129 inv_mods {static_cast<IdxLin>(rhs.inv_mods[RangeInts])...}
135 template<
typename... Types>
137 const std::array<IdxLin, n_dims>& sizes_in,
138 const std::array<IdxLin, n_dims>& strides_in)
139 : sizes {sizes_in[RangeInts]...},
140 strides {strides_in[RangeInts]...},
141 inv_strides {(strides[RangeInts] ? strides[RangeInts] : IdxLin(1))...},
142 inv_mods {(sizes[RangeInts] ? sizes[RangeInts] : IdxLin(1))...}
148 template<camp::
idx_t N,
typename Idx>
151 printf(
"Error at index %d, value %ld is not within bounds [0, %ld] \n",
152 static_cast<int>(N),
static_cast<long int>(idx),
153 static_cast<long int>(sizes[N] - 1));
157 template<camp::
idx_t N>
161 template<camp::idx_t N,
typename Idx,
typename... Indices>
163 Indices... indices)
const
165 if (sizes[N] > 0 && !(0 <= idx && idx <
static_cast<Idx
>(sizes[N])))
167 BoundsCheckError<N>(idx);
170 BoundsCheck<N + 1>(indices...);
181 template<
typename... Indices>
185 #if defined(RAJA_BOUNDS_CHECK_INTERNAL)
186 BoundsCheck<0>(indices...);
189 return sum<IdxLin>((RangeInts == stride_one_dim
193 strides[RangeInts] * indices
207 template<
typename... Indices>
209 Indices&&... indices)
const
211 #if defined(RAJA_BOUNDS_CHECK_INTERNAL)
212 IdxLin totSize = size_noproj();
213 if (totSize > 0 && (linear_index < 0 || linear_index >= totSize))
215 printf(
"Error! Linear index %ld is not within bounds [0, %ld]. \n",
216 static_cast<long int>(linear_index),
217 static_cast<long int>(totSize - 1));
222 camp::sink((indices = (camp::decay<Indices>)((linear_index /
223 inv_strides[RangeInts]) %
224 inv_mods[RangeInts]))...);
239 (sizes[RangeInts] == IdxLin(0) ? IdxLin(1) : sizes[RangeInts])...);
254 template<camp::
idx_t DIM>
260 template<camp::
idx_t DIM>
266 template<camp::
idx_t DIM>
324 template<
size_t n_dims,
typename IdxLin =
Index_type, ptrdiff_t StrideOne = -1>
328 template<
typename IdxLin,
typename DimTuple, ptrdiff_t StrideOne = -1>
331 template<
typename IdxLin,
typename... DimTypes, ptrdiff_t StrideOne>
333 :
public Layout<sizeof...(DimTypes), strip_index_type_t<IdxLin>, StrideOne>
352 DimTypes... indices)
const
368 DimTypes&... indices)
const
370 toIndicesHelper(camp::make_idx_seq_t<
sizeof...(DimTypes)> {},
371 std::forward<IdxLin>(linear_index),
372 std::forward<DimTypes&>(indices)...);
383 template<
typename... Indices, camp::idx_t... RangeInts>
384 RAJA_INLINE
RAJA_HOST_DEVICE void toIndicesHelper(camp::idx_seq<RangeInts...>,
386 Indices&... indices)
const
388 StrippedIdxLin locals[
sizeof...(DimTypes)];
389 Base::toIndices(
stripIndexType(linear_index), locals[RangeInts]...);
391 (indices = Indices {
static_cast<Indices
>(locals[RangeInts])})...);
399 template<ptrdiff_t s1_dim,
size_t n_dims,
typename IdxLin>
410 template<ptrdiff_t s1_dim,
typename IdxLin,
typename IdxTuple>
411 RAJA_INLINE
RAJA_HOST_DEVICE constexpr TypedLayout<IdxLin, IdxTuple, s1_dim>
416 Base
const& b = (Base
const&)l;
RAJA header file for strongly-typed integer class.
Header file for RAJA operator definitions.
RAJA header file defining permutations.
Header file with support for pre-C++14 compilers.
RAJA_HOST_DEVICE RAJA_INLINE void RAJA_UNUSED_VAR(T &&...) noexcept
Definition: macros.hpp:120
RAJA_HOST_DEVICE void RAJA_ABORT_OR_THROW(const char *str)
Definition: macros.hpp:143
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
std::ptrdiff_t Index_type
Definition: types.hpp:226
RAJA_HOST_DEVICE constexpr RAJA_INLINE auto foldl(Op &&RAJA_UNUSED_ARG(operation), Arg1 &&arg) -> typename detail::foldl_impl< Op, Arg1 >::Ret
Definition: foldl.hpp:104
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
RAJA_INLINE constexpr RAJA_HOST_DEVICE Layout< n_dims, IdxLin, s1_dim > make_stride_one(Layout< n_dims, IdxLin > const &l)
Definition: Layout.hpp:401
RAJA_HOST_DEVICE constexpr RAJA_INLINE Result max(Args... args)
Definition: foldl.hpp:155
Definition: Layout.hpp:334
strip_index_type_t< IdxLin > StrippedIdxLin
Definition: Layout.hpp:336
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin operator()(DimTypes... indices) const
Definition: Layout.hpp:351
RAJA_INLINE RAJA_HOST_DEVICE void toIndices(IdxLin linear_index, DimTypes &... indices) const
Definition: Layout.hpp:367
std::array< StrippedIdxLin, sizeof...(DimTypes)> DimArr
Definition: Layout.hpp:339
Definition: Layout.hpp:329
constexpr RAJA_INLINE LayoutBase_impl(const std::array< IdxLin, n_dims > &sizes_in, const std::array< IdxLin, n_dims > &strides_in)
Definition: Layout.hpp:136
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_stride() const
Definition: Layout.hpp:255
RAJA_INLINE constexpr RAJA_HOST_DEVICE LayoutBase_impl(const LayoutBase_impl< camp::idx_seq< RangeInts... >, CIdxLin, CStrideOneDim > &rhs)
Definition: Layout.hpp:122
IdxLin IndexLinear
Definition: Layout.hpp:79
constexpr RAJA_INLINE LayoutBase_impl & operator=(LayoutBase_impl const &)=default
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheck() const
Definition: Layout.hpp:158
constexpr RAJA_INLINE LayoutBase_impl()=default
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_size() const
Definition: Layout.hpp:261
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_begin() const
Definition: Layout.hpp:267
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheckError(Idx idx) const
Definition: Layout.hpp:149
camp::make_idx_seq_t< sizeof...(RangeInts)> IndexRange
Definition: Layout.hpp:80
constexpr RAJA_INLINE LayoutBase_impl(LayoutBase_impl const &)=default
constexpr RAJA_INLINE LayoutBase_impl & operator=(LayoutBase_impl &&)=default
RAJA_INLINE constexpr RAJA_HOST_DEVICE LayoutBase_impl(Types... ns)
Definition: Layout.hpp:106
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin size_noproj() const
Definition: Layout.hpp:248
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin size() const
Definition: Layout.hpp:233
RAJA_INLINE RAJA_HOST_DEVICE RAJA_BOUNDS_CHECK_constexpr IdxLin operator()(Indices... indices) const
Definition: Layout.hpp:183
RAJA_INLINE RAJA_HOST_DEVICE void toIndices(IdxLin linear_index, Indices &&... indices) const
Definition: Layout.hpp:208
constexpr RAJA_INLINE LayoutBase_impl(LayoutBase_impl &&)=default
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheck(Idx idx, Indices... indices) const
Definition: Layout.hpp:162
Definition: Layout.hpp:46
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin operator()(IdxLin cur_stride, IdxLin const (&)[n_dims]) const
Definition: Layout.hpp:67
Definition: Layout.hpp:54
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin operator()(IdxLin cur_stride, IdxLin const (&sizes)[n_dims]) const
Definition: Layout.hpp:55
Definition: Operators.hpp:400