RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
IndexLayout.hpp
Go to the documentation of this file.
1 
12 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
13 // Copyright (c) Lawrence Livermore National Security, LLC and other
14 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
15 // files for dates and other details. No copyright assignment is required
16 // to contribute to RAJA.
17 //
18 // SPDX-License-Identifier: (BSD-3-Clause)
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 
21 #ifndef RAJA_INDEXLAYOUT_HPP
22 #define RAJA_INDEXLAYOUT_HPP
23 
24 #include "RAJA/util/Layout.hpp"
25 
26 namespace RAJA
27 {
28 
34 template<typename IdxLin = Index_type>
36 {
37 
38  IdxLin RAJA_INLINE RAJA_HOST_DEVICE constexpr operator()(
39  const IdxLin idx) const
40  {
41  return idx;
42  }
43 };
44 
51 template<typename IdxLin = Index_type>
52 struct IndexList
53 {
54 
55  IdxLin* index_list {nullptr};
56 
57  IdxLin RAJA_INLINE RAJA_HOST_DEVICE constexpr operator()(
58  const IdxLin idx) const
59  {
60  return index_list[idx];
61  }
62 };
63 
71 template<typename IdxLin = Index_type>
73 {
74 
75  IdxLin* index_list {nullptr};
76 
77  IdxLin RAJA_INLINE RAJA_HOST_DEVICE constexpr operator()(
78  const IdxLin idx) const
79  {
80  if (index_list)
81  {
82  return index_list[idx];
83  }
84  else
85  {
86  return idx;
87  }
88  }
89 };
90 
91 namespace internal
92 {
93 
94 template<typename Range, typename IdxLin, typename... IndexTypes>
96 
97 template<camp::idx_t... RangeInts, typename IdxLin, typename... IndexTypes>
98 struct IndexLayout_impl<camp::idx_seq<RangeInts...>, IdxLin, IndexTypes...>
99 {
100  using IndexRange = camp::idx_seq<RangeInts...>;
101  using IndexLinear = IdxLin;
104 
105  static constexpr size_t n_dims = sizeof...(RangeInts);
106 
107  camp::tuple<IndexTypes...> tuple;
108 
109  template<typename... Types>
110  constexpr RAJA_INLINE IndexLayout_impl(
111  camp::tuple<IndexTypes...> index_tuple_in,
112  Types... ns)
113  : base_ {(ns)...},
114  tuple(index_tuple_in)
115  {}
116 
124  template<typename... Indices>
125  RAJA_INLINE RAJA_HOST_DEVICE constexpr IdxLin operator()(
126  Indices... indices) const
127  {
128  return sum<IdxLin>(
129  (base_.strides[RangeInts] * camp::get<RangeInts>(tuple)(indices))...);
130  }
131 
132  RAJA_INLINE RAJA_HOST_DEVICE constexpr IndexLinear size() const
133  {
134  return base_.size();
135  }
136 
137  RAJA_INLINE RAJA_HOST_DEVICE constexpr IndexLinear size_noproj() const
138  {
139  return base_.size_noproj();
140  }
141 
142  template<camp::idx_t DIM>
143  RAJA_INLINE RAJA_HOST_DEVICE constexpr IndexLinear get_dim_stride() const
144  {
145  return base_.template get_dim_stride<DIM>();
146  }
147 
148  template<camp::idx_t DIM>
149  RAJA_INLINE RAJA_HOST_DEVICE constexpr IndexLinear get_dim_size() const
150  {
151  return base_.template get_dim_size<DIM>();
152  }
153 };
154 
155 } // namespace internal
156 
157 template<size_t n_dims = 1,
158  typename IdxLin = Index_type,
159  typename... IndexTypes>
161  : public internal::
162  IndexLayout_impl<camp::make_idx_seq_t<n_dims>, IdxLin, IndexTypes...>
163 {
164  using Base = internal::
165  IndexLayout_impl<camp::make_idx_seq_t<n_dims>, IdxLin, IndexTypes...>;
166 
168  IdxLin,
169  IndexTypes...>::IndexLayout_impl;
170 
171  constexpr RAJA_INLINE RAJA_HOST_DEVICE
172  IndexLayout(const internal::IndexLayout_impl<camp::make_idx_seq_t<n_dims>,
173  IdxLin,
174  IndexTypes...>& rhs)
175  : Base {rhs}
176  {}
177 };
178 
184 template<typename... IndexTypes>
185 RAJA_INLINE RAJA_HOST_DEVICE auto make_index_tuple(IndexTypes... it)
186  -> camp::tuple<IndexTypes...>
187 {
188  return camp::tuple<IndexTypes...>(it...);
189 }
190 
195 template<typename IdxLin = Index_type,
196  typename... Types,
197  typename... IndexTypes>
199  camp::tuple<IndexTypes...> index_tuple_in,
200  Types... ns) -> IndexLayout<sizeof...(Types), IdxLin, IndexTypes...>
201 {
202  static_assert(sizeof...(Types) == sizeof...(IndexTypes), "");
203  return IndexLayout<sizeof...(Types), IdxLin, IndexTypes...>(index_tuple_in,
204  ns...);
205 }
206 
207 } // namespace RAJA
208 
209 #endif
RAJA header file defining Layout, a N-dimensional index calculator.
#define RAJA_HOST_DEVICE
Definition: macros.hpp:65
Definition: AlignedRangeIndexSetBuilders.cpp:35
RAJA_INLINE RAJA_HOST_DEVICE auto make_index_tuple(IndexTypes... it) -> camp::tuple< IndexTypes... >
Definition: IndexLayout.hpp:185
std::ptrdiff_t Index_type
Definition: types.hpp:226
RAJA_INLINE RAJA_HOST_DEVICE auto make_index_layout(camp::tuple< IndexTypes... > index_tuple_in, Types... ns) -> IndexLayout< sizeof...(Types), IdxLin, IndexTypes... >
Definition: IndexLayout.hpp:198
Definition: IndexLayout.hpp:73
IdxLin * index_list
Definition: IndexLayout.hpp:75
IdxLin RAJA_INLINE constexpr RAJA_HOST_DEVICE operator()(const IdxLin idx) const
Definition: IndexLayout.hpp:77
Definition: IndexLayout.hpp:36
IdxLin RAJA_INLINE constexpr RAJA_HOST_DEVICE operator()(const IdxLin idx) const
Definition: IndexLayout.hpp:38
Definition: IndexLayout.hpp:163
constexpr RAJA_INLINE RAJA_HOST_DEVICE IndexLayout(const internal::IndexLayout_impl< camp::make_idx_seq_t< n_dims >, IdxLin, IndexTypes... > &rhs)
Definition: IndexLayout.hpp:172
Definition: IndexLayout.hpp:53
IdxLin * index_list
Definition: IndexLayout.hpp:55
IdxLin RAJA_INLINE constexpr RAJA_HOST_DEVICE operator()(const IdxLin idx) const
Definition: IndexLayout.hpp:57
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear size() const
Definition: IndexLayout.hpp:132
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear size_noproj() const
Definition: IndexLayout.hpp:137
camp::tuple< IndexTypes... > tuple
Definition: IndexLayout.hpp:107
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_size() const
Definition: IndexLayout.hpp:149
RAJA_INLINE constexpr RAJA_HOST_DEVICE IndexLinear get_dim_stride() const
Definition: IndexLayout.hpp:143
constexpr RAJA_INLINE IndexLayout_impl(camp::tuple< IndexTypes... > index_tuple_in, Types... ns)
Definition: IndexLayout.hpp:110
RAJA_INLINE constexpr RAJA_HOST_DEVICE IdxLin operator()(Indices... indices) const
Definition: IndexLayout.hpp:125
camp::idx_seq< RangeInts... > IndexRange
Definition: IndexLayout.hpp:100
Definition: IndexLayout.hpp:95