Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Kokkos_View_Utils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Stokhos Package
4 //
5 // Copyright 2009 NTESS and the Stokhos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef KOKKOS_VIEW_UTILS_HPP
11 #define KOKKOS_VIEW_UTILS_HPP
12 
13 #include <stdexcept>
14 
15 // We are hooking into Kokkos Core internals here
16 // Need to define this macro since we include non-public headers
17 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
18 #define KOKKOS_IMPL_PUBLIC_INCLUDE
19 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
20 #endif
21 #include "Kokkos_View.hpp"
22 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
23 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
24 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
25 #endif
26 
27 namespace Kokkos {
28 
29 namespace Impl {
30 
31 KOKKOS_INLINE_FUNCTION
32 void raise_error(const char *msg)
33 {
34  KOKKOS_IF_ON_HOST(throw std::runtime_error(msg);)
35 
36  KOKKOS_IF_ON_DEVICE(Kokkos::abort(msg);)
37 }
38 
39 template< class T , class Device > struct RebindStokhosStorageDevice ;
40 
41 template< class T , class Device >
42 struct RebindStokhosStorageDevice< T * , Device >
43 {
45 };
46 
47 template< class T , class Device >
48 struct RebindStokhosStorageDevice< T [] , Device >
49 {
51 };
52 
53 template< class T , unsigned N , class Device >
54 struct RebindStokhosStorageDevice< T[N] , Device >
55 {
57 };
58 
59 // Get Sacado size from a list of dimensions
60 template <unsigned Rank> struct GetSacadoSize {};
61 template <> struct GetSacadoSize<0> {
62  KOKKOS_INLINE_FUNCTION
63  static size_t eval( const size_t n0 ,
64  const size_t n1 = 0 ,
65  const size_t n2 = 0 ,
66  const size_t n3 = 0 ,
67  const size_t n4 = 0 ,
68  const size_t n5 = 0 ,
69  const size_t n6 = 0 ,
70  const size_t n7 = 0 ) {
71  return n0;
72  }
73 
74  template <typename Layout>
75  KOKKOS_INLINE_FUNCTION
76  static size_t eval( const Layout& layout ) {
77  return layout.dimension[0];
78  }
79 };
80 template <> struct GetSacadoSize<1> {
81  KOKKOS_INLINE_FUNCTION
82  static size_t eval( const size_t n0 ,
83  const size_t n1 ,
84  const size_t n2 = 0 ,
85  const size_t n3 = 0 ,
86  const size_t n4 = 0 ,
87  const size_t n5 = 0 ,
88  const size_t n6 = 0 ,
89  const size_t n7 = 0 ) {
90  return n1;
91  }
92 
93  template <typename Layout>
94  KOKKOS_INLINE_FUNCTION
95  static size_t eval( const Layout& layout ) {
96  return layout.dimension[1];
97  }
98 };
99 template <> struct GetSacadoSize<2> {
100  KOKKOS_INLINE_FUNCTION
101  static size_t eval( const size_t n0 ,
102  const size_t n1 ,
103  const size_t n2 ,
104  const size_t n3 = 0 ,
105  const size_t n4 = 0 ,
106  const size_t n5 = 0 ,
107  const size_t n6 = 0 ,
108  const size_t n7 = 0 ) {
109  return n2;
110  }
111 
112  template <typename Layout>
113  KOKKOS_INLINE_FUNCTION
114  static size_t eval( const Layout& layout ) {
115  return layout.dimension[2];
116  }
117 };
118 template <> struct GetSacadoSize<3> {
119  KOKKOS_INLINE_FUNCTION
120  static size_t eval( const size_t n0 ,
121  const size_t n1 ,
122  const size_t n2 ,
123  const size_t n3 ,
124  const size_t n4 = 0 ,
125  const size_t n5 = 0 ,
126  const size_t n6 = 0 ,
127  const size_t n7 = 0 ) {
128  return n3;
129  }
130 
131  template <typename Layout>
132  KOKKOS_INLINE_FUNCTION
133  static size_t eval( const Layout& layout ) {
134  return layout.dimension[3];
135  }
136 };
137 template <> struct GetSacadoSize<4> {
138  KOKKOS_INLINE_FUNCTION
139  static size_t eval( const size_t n0 ,
140  const size_t n1 ,
141  const size_t n2 ,
142  const size_t n3 ,
143  const size_t n4 ,
144  const size_t n5 = 0 ,
145  const size_t n6 = 0 ,
146  const size_t n7 = 0 ) {
147  return n4;
148  }
149 
150  template <typename Layout>
151  KOKKOS_INLINE_FUNCTION
152  static size_t eval( const Layout& layout ) {
153  return layout.dimension[4];
154  }
155 };
156 template <> struct GetSacadoSize<5> {
157  KOKKOS_INLINE_FUNCTION
158  static size_t eval( const size_t n0 ,
159  const size_t n1 ,
160  const size_t n2 ,
161  const size_t n3 ,
162  const size_t n4 ,
163  const size_t n5 ,
164  const size_t n6 = 0 ,
165  const size_t n7 = 0 ) {
166  return n5;
167  }
168 
169  template <typename Layout>
170  KOKKOS_INLINE_FUNCTION
171  static size_t eval( const Layout& layout ) {
172  return layout.dimension[5];
173  }
174 };
175 template <> struct GetSacadoSize<6> {
176  KOKKOS_INLINE_FUNCTION
177  static size_t eval( const size_t n0 ,
178  const size_t n1 ,
179  const size_t n2 ,
180  const size_t n3 ,
181  const size_t n4 ,
182  const size_t n5 ,
183  const size_t n6 ,
184  const size_t n7 = 0 ) {
185  return n6;
186  }
187 
188  template <typename Layout>
189  KOKKOS_INLINE_FUNCTION
190  static size_t eval( const Layout& layout ) {
191  return layout.dimension[6];
192  }
193 };
194 template <> struct GetSacadoSize<7> {
195  KOKKOS_INLINE_FUNCTION
196  static size_t eval( const size_t n0 ,
197  const size_t n1 ,
198  const size_t n2 ,
199  const size_t n3 ,
200  const size_t n4 ,
201  const size_t n5 ,
202  const size_t n6 ,
203  const size_t n7 ) {
204  return n7;
205  }
206 
207  template <typename Layout>
208  KOKKOS_INLINE_FUNCTION
209  static size_t eval( const Layout& layout ) {
210  return layout.dimension[7];
211  }
212 };
213 
214 } // namespace Impl
215 
216 // Typename of flat array where sacado dimension is folded into neighbor
217 template <typename view_type, typename Enabled = void>
219  typedef view_type type;
220 };
221 
222 // Typename of the intrinsic scalar type in a view
223 template <typename view_type, typename Enabled = void>
225  typedef typename view_type::array_type::non_const_value_type type;
226 };
227 
228 template <typename ViewType>
229 ViewType
230 make_view(const std::string& label,
231  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
232  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
233 {
234  return ViewType(label, N0, N1, N2, N3, N4, N5, N6, N7);
235 }
236 
237 template <typename ViewType>
238 ViewType
239 make_view(const ViewAllocateWithoutInitializing& init,
240  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
241  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
242 {
243  return ViewType(init, N0, N1, N2, N3, N4, N5, N6, N7);
244 }
245 
246 template <typename ViewType>
247 ViewType
248 make_view(typename ViewType::pointer_type ptr,
249  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
250  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
251 {
252  return ViewType(ptr, N0, N1, N2, N3, N4, N5, N6, N7);
253 }
254 
255 template <typename ViewType>
256 ViewType
257 make_view(const std::string& label,
258  const Impl::WithoutInitializing_t& init,
259  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
260  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
261 {
262  return ViewType(view_alloc(label,init),
263  N0, N1, N2, N3, N4, N5, N6, N7);
264 }
265 
266 namespace Impl {
267 
268 // Specialization for deep_copy( view, view::value_type ) for Cuda
269 
270 template <class OutputView, typename Enabled = void>
272 
273 } // namespace Impl
274 
275 } // namespace Kokkos
276 
277 #endif // KOKKOS_VIEW_UTILS_HPP
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const size_t n4, const size_t n5, const size_t n6, const size_t n7)
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const size_t n4, const size_t n5, const size_t n6, const size_t n7=0)
RebindStokhosStorageDevice< T, Device >::type * type
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const size_t n4, const size_t n5=0, const size_t n6=0, const size_t n7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1=0, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
KOKKOS_INLINE_FUNCTION void raise_error(const char *msg)
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const size_t n4, const size_t n5, const size_t n6=0, const size_t n7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
ViewType make_view(const std::string &label, size_t N0=0, size_t N1=0, size_t N2=0, size_t N3=0, size_t N4=0, size_t N5=0, size_t N6=0, size_t N7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2, const size_t n3, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
view_type::array_type::non_const_value_type type
static KOKKOS_INLINE_FUNCTION size_t eval(const size_t n0, const size_t n1, const size_t n2=0, const size_t n3=0, const size_t n4=0, const size_t n5=0, const size_t n6=0, const size_t n7=0)
RebindStokhosStorageDevice< T, Device >::type * type
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)
static KOKKOS_INLINE_FUNCTION size_t eval(const Layout &layout)