21 #ifndef RAJA_OFFSETLAYOUT_HPP
22 #define RAJA_OFFSETLAYOUT_HPP
24 #include "RAJA/config.hpp"
29 #include "camp/camp.hpp"
42 template<
typename Range,
typename IdxLin>
45 template<camp::idx_t... RangeInts,
typename IdxLin>
54 static inline constexpr camp::idx_t stride_one_dim = Base::stride_one_dim;
56 static inline constexpr
size_t n_dims =
sizeof...(RangeInts);
57 IdxLin offsets[n_dims] = {0};
61 std::array<IdxLin,
sizeof...(RangeInts)> end)
62 : base_ {(end[RangeInts] - begin[RangeInts])...},
63 offsets {begin[RangeInts]...}
68 offsets {c.offsets[RangeInts]...}
72 std::array<IdxLin,
sizeof...(RangeInts)> shift)
74 for (
size_t i = 0; i < n_dims; ++i)
75 offsets[i] += shift[i];
78 template<camp::
idx_t N,
typename Idx>
81 printf(
"Error at index %d, value %ld is not within bounds [%ld, %ld] \n",
82 static_cast<int>(N),
static_cast<long int>(idx),
83 static_cast<long int>(offsets[N]),
84 static_cast<long int>(offsets[N] + base_.sizes[N] - 1));
88 template<camp::
idx_t N>
92 template<camp::idx_t N,
typename Idx,
typename... Indices>
94 Indices... indices)
const
96 if (!(offsets[N] <= idx && idx < offsets[N] + base_.sizes[N]))
98 BoundsCheckError<N>(idx);
101 BoundsCheck<N + 1>(indices...);
104 template<
typename... Indices>
108 #if defined(RAJA_BOUNDS_CHECK_INTERNAL)
109 BoundsCheck<0>(indices...);
111 return base_((indices - offsets[RangeInts])...);
114 template<
typename... Indices>
116 Indices&&... indices)
const
118 base_.toIndices(linear_index, std::forward<Indices>(indices)...);
119 camp::sink((indices = (offsets[RangeInts] + indices))...);
125 const std::array<IdxLin,
sizeof...(RangeInts)>& offsets_in,
126 const Layout<
sizeof...(RangeInts), IdxLin>& rhs)
129 camp::sink((ret.offsets[RangeInts] = offsets_in[RangeInts])...);
145 return base_.size_noproj();
148 template<camp::
idx_t DIM>
151 return base_.get_dim_stride();
154 template<camp::
idx_t DIM>
157 return base_.get_dim_size();
160 template<camp::
idx_t DIM>
169 template<
size_t n_dims = 1,
typename IdxLin = Index_type>
177 IdxLin>::OffsetLayout_impl;
187 template<
typename IdxLin,
typename DimTuple>
190 template<
typename IdxLin,
typename... DimTypes>
192 :
public OffsetLayout<sizeof...(DimTypes), strip_index_type_t<IdxLin>>
216 DimTypes&... indices)
const
218 toIndicesHelper(camp::make_idx_seq_t<
sizeof...(DimTypes)> {},
219 std::forward<IdxLin>(linear_index),
220 std::forward<DimTypes&>(indices)...);
224 template<
typename... Indices, camp::idx_t... RangeInts>
225 RAJA_INLINE
RAJA_HOST_DEVICE void toIndicesHelper(camp::idx_seq<RangeInts...>,
227 Indices&... indices)
const
229 StrippedIdxLin locals[
sizeof...(DimTypes)];
230 Base::toIndices(
stripIndexType(linear_index), locals[RangeInts]...);
232 (indices = Indices {
static_cast<Indices
>(locals[RangeInts])})...);
236 template<
size_t n_dims,
typename IdxLin = Index_type>
238 const std::array<IdxLin, n_dims>& begin,
244 template<
size_t Rank,
typename IdxLin = Index_type>
246 const std::array<IdxLin, Rank>& begin,
247 const std::array<IdxLin, Rank>& end,
248 const std::array<IdxLin, Rank>& permutation)
249 -> decltype(make_offset_layout<Rank, IdxLin>(begin, end))
251 std::array<IdxLin, Rank> sizes;
252 for (
size_t i = 0; i < Rank; ++i)
254 sizes[i] = end[i] - begin[i];
RAJA header file for strongly-typed integer class.
RAJA header file defining permutations.
RAJA header file defining Layout, a N-dimensional index calculator with permuted stride orderings.
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
RAJA_INLINE constexpr RAJA_HOST_DEVICE auto make_permuted_offset_layout(const std::array< IdxLin, Rank > &begin, const std::array< IdxLin, Rank > &end, const std::array< IdxLin, Rank > &permutation) -> decltype(make_offset_layout< Rank, IdxLin >(begin, end))
Definition: OffsetLayout.hpp:245
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
RAJA_INLINE constexpr RAJA_HOST_DEVICE auto make_offset_layout(const std::array< IdxLin, n_dims > &begin, const std::array< IdxLin, n_dims > &end) -> OffsetLayout< n_dims, IdxLin >
Definition: OffsetLayout.hpp:237
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
constexpr RAJA_INLINE RAJA_HOST_DEVICE auto make_permuted_layout(std::array< IdxLin, Rank > sizes, std::array< camp::idx_t, Rank > permutation) -> Layout< Rank, IdxLin >
Creates a permuted Layout object.
Definition: PermutedLayout.hpp:66
Definition: OffsetLayout.hpp:172
constexpr RAJA_INLINE RAJA_HOST_DEVICE OffsetLayout(const internal::OffsetLayout_impl< camp::make_idx_seq_t< n_dims >, IdxLin > &rhs)
Definition: OffsetLayout.hpp:179
Definition: OffsetLayout.hpp:193
std::array< StrippedIdxLin, sizeof...(DimTypes)> DimArr
Definition: OffsetLayout.hpp:197
RAJA_INLINE RAJA_HOST_DEVICE RAJA_BOUNDS_CHECK_constexpr IdxLin operator()(DimTypes... indices) const
Definition: OffsetLayout.hpp:210
RAJA_INLINE RAJA_HOST_DEVICE void toIndices(IdxLin linear_index, DimTypes &... indices) const
Definition: OffsetLayout.hpp:215
camp::tuple< DimTypes... > DimTuple
Definition: OffsetLayout.hpp:198
IdxLin IndexLinear
Definition: OffsetLayout.hpp:199
strip_index_type_t< IdxLin > StrippedIdxLin
Definition: OffsetLayout.hpp:194
Definition: OffsetLayout.hpp:188
Definition: OffsetLayout.hpp:47
constexpr RAJA_INLINE RAJA_HOST_DEVICE void shift(std::array< IdxLin, sizeof...(RangeInts)> shift)
Definition: OffsetLayout.hpp:71
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheck(Idx idx, Indices... indices) const
Definition: OffsetLayout.hpp:93
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin size() const
Definition: OffsetLayout.hpp:138
constexpr RAJA_INLINE RAJA_HOST_DEVICE OffsetLayout_impl(const Layout< sizeof...(RangeInts), IdxLin > &rhs)
Definition: OffsetLayout.hpp:134
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin size_noproj() const
Definition: OffsetLayout.hpp:143
Base base_
Definition: OffsetLayout.hpp:52
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheck() const
Definition: OffsetLayout.hpp:89
RAJA_INLINE RAJA_HOST_DEVICE RAJA_BOUNDS_CHECK_constexpr IdxLin operator()(Indices... indices) const
Definition: OffsetLayout.hpp:106
constexpr RAJA_INLINE RAJA_HOST_DEVICE OffsetLayout_impl(Self const &c)
Definition: OffsetLayout.hpp:66
IdxLin IndexLinear
Definition: OffsetLayout.hpp:50
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_size() const
Definition: OffsetLayout.hpp:155
static constexpr RAJA_INLINE RAJA_HOST_DEVICE OffsetLayout_impl< IndexRange, IdxLin > from_layout_and_offsets(const std::array< IdxLin, sizeof...(RangeInts)> &offsets_in, const Layout< sizeof...(RangeInts), IdxLin > &rhs)
Definition: OffsetLayout.hpp:124
constexpr RAJA_INLINE RAJA_HOST_DEVICE OffsetLayout_impl(std::array< IdxLin, sizeof...(RangeInts)> begin, std::array< IdxLin, sizeof...(RangeInts)> end)
Definition: OffsetLayout.hpp:60
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_begin() const
Definition: OffsetLayout.hpp:161
RAJA_INLINE RAJA_HOST_DEVICE void toIndices(IdxLin linear_index, Indices &&... indices) const
Definition: OffsetLayout.hpp:115
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_stride() const
Definition: OffsetLayout.hpp:149
camp::idx_seq< RangeInts... > IndexRange
Definition: OffsetLayout.hpp:49
RAJA_INLINE RAJA_HOST_DEVICE void BoundsCheckError(Idx idx) const
Definition: OffsetLayout.hpp:79
Definition: OffsetLayout.hpp:43