Stokhos Package Browser (Single Doxygen Collection)  Version of the Day
Kokkos_View_Utils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Stokhos Package
5 // Copyright (2009) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Eric T. Phipps (etphipp@sandia.gov).
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef KOKKOS_VIEW_UTILS_HPP
43 #define KOKKOS_VIEW_UTILS_HPP
44 
45 namespace Kokkos {
46 
47 namespace Impl {
48 
49 KOKKOS_INLINE_FUNCTION
50 void raise_error(const char *msg)
51 {
52 #if defined(__CUDACC__) && defined(__CUDA_ARCH__)
53  Kokkos::abort(msg);
54 #else
55  throw std::runtime_error(msg);
56 #endif
57 }
58 
59 template< class T , class Device > struct RebindStokhosStorageDevice ;
60 
61 template< class T , class Device >
62 struct RebindStokhosStorageDevice< T * , Device >
63 {
65 };
66 
67 template< class T , class Device >
68 struct RebindStokhosStorageDevice< T [] , Device >
69 {
71 };
72 
73 template< class T , unsigned N , class Device >
74 struct RebindStokhosStorageDevice< T[N] , Device >
75 {
77 };
78 
79 // Get Sacado size from a list of dimensions
80 template <unsigned Rank> struct GetSacadoSize {};
81 template <> struct GetSacadoSize<0> {
82  KOKKOS_INLINE_FUNCTION
83  static size_t eval( const size_t n0 ,
84  const size_t n1 = 0 ,
85  const size_t n2 = 0 ,
86  const size_t n3 = 0 ,
87  const size_t n4 = 0 ,
88  const size_t n5 = 0 ,
89  const size_t n6 = 0 ,
90  const size_t n7 = 0 ) {
91  return n0;
92  }
93 
94  template <typename Layout>
95  KOKKOS_INLINE_FUNCTION
96  static size_t eval( const Layout& layout ) {
97  return layout.dimension[0];
98  }
99 };
100 template <> struct GetSacadoSize<1> {
101  KOKKOS_INLINE_FUNCTION
102  static size_t eval( const size_t n0 ,
103  const size_t n1 ,
104  const size_t n2 = 0 ,
105  const size_t n3 = 0 ,
106  const size_t n4 = 0 ,
107  const size_t n5 = 0 ,
108  const size_t n6 = 0 ,
109  const size_t n7 = 0 ) {
110  return n1;
111  }
112 
113  template <typename Layout>
114  KOKKOS_INLINE_FUNCTION
115  static size_t eval( const Layout& layout ) {
116  return layout.dimension[1];
117  }
118 };
119 template <> struct GetSacadoSize<2> {
120  KOKKOS_INLINE_FUNCTION
121  static size_t eval( const size_t n0 ,
122  const size_t n1 ,
123  const size_t n2 ,
124  const size_t n3 = 0 ,
125  const size_t n4 = 0 ,
126  const size_t n5 = 0 ,
127  const size_t n6 = 0 ,
128  const size_t n7 = 0 ) {
129  return n2;
130  }
131 
132  template <typename Layout>
133  KOKKOS_INLINE_FUNCTION
134  static size_t eval( const Layout& layout ) {
135  return layout.dimension[2];
136  }
137 };
138 template <> struct GetSacadoSize<3> {
139  KOKKOS_INLINE_FUNCTION
140  static size_t eval( const size_t n0 ,
141  const size_t n1 ,
142  const size_t n2 ,
143  const size_t n3 ,
144  const size_t n4 = 0 ,
145  const size_t n5 = 0 ,
146  const size_t n6 = 0 ,
147  const size_t n7 = 0 ) {
148  return n3;
149  }
150 
151  template <typename Layout>
152  KOKKOS_INLINE_FUNCTION
153  static size_t eval( const Layout& layout ) {
154  return layout.dimension[3];
155  }
156 };
157 template <> struct GetSacadoSize<4> {
158  KOKKOS_INLINE_FUNCTION
159  static size_t eval( const size_t n0 ,
160  const size_t n1 ,
161  const size_t n2 ,
162  const size_t n3 ,
163  const size_t n4 ,
164  const size_t n5 = 0 ,
165  const size_t n6 = 0 ,
166  const size_t n7 = 0 ) {
167  return n4;
168  }
169 
170  template <typename Layout>
171  KOKKOS_INLINE_FUNCTION
172  static size_t eval( const Layout& layout ) {
173  return layout.dimension[4];
174  }
175 };
176 template <> struct GetSacadoSize<5> {
177  KOKKOS_INLINE_FUNCTION
178  static size_t eval( const size_t n0 ,
179  const size_t n1 ,
180  const size_t n2 ,
181  const size_t n3 ,
182  const size_t n4 ,
183  const size_t n5 ,
184  const size_t n6 = 0 ,
185  const size_t n7 = 0 ) {
186  return n5;
187  }
188 
189  template <typename Layout>
190  KOKKOS_INLINE_FUNCTION
191  static size_t eval( const Layout& layout ) {
192  return layout.dimension[5];
193  }
194 };
195 template <> struct GetSacadoSize<6> {
196  KOKKOS_INLINE_FUNCTION
197  static size_t eval( const size_t n0 ,
198  const size_t n1 ,
199  const size_t n2 ,
200  const size_t n3 ,
201  const size_t n4 ,
202  const size_t n5 ,
203  const size_t n6 ,
204  const size_t n7 = 0 ) {
205  return n6;
206  }
207 
208  template <typename Layout>
209  KOKKOS_INLINE_FUNCTION
210  static size_t eval( const Layout& layout ) {
211  return layout.dimension[6];
212  }
213 };
214 template <> struct GetSacadoSize<7> {
215  KOKKOS_INLINE_FUNCTION
216  static size_t eval( const size_t n0 ,
217  const size_t n1 ,
218  const size_t n2 ,
219  const size_t n3 ,
220  const size_t n4 ,
221  const size_t n5 ,
222  const size_t n6 ,
223  const size_t n7 ) {
224  return n7;
225  }
226 
227  template <typename Layout>
228  KOKKOS_INLINE_FUNCTION
229  static size_t eval( const Layout& layout ) {
230  return layout.dimension[7];
231  }
232 };
233 
234 } // namespace Impl
235 
236 // Typename of flat array where sacado dimension is folded into neighbor
237 template <typename view_type, typename Enabled = void>
239  typedef view_type type;
240 };
241 
242 // Typename of the intrinsic scalar type in a view
243 template <typename view_type, typename Enabled = void>
245  typedef typename view_type::array_type::non_const_value_type type;
246 };
247 
248 template <typename ViewType>
249 ViewType
250 make_view(const std::string& label,
251  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
252  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
253 {
254  return ViewType(label, N0, N1, N2, N3, N4, N5, N6, N7);
255 }
256 
257 template <typename ViewType>
258 ViewType
259 make_view(const ViewAllocateWithoutInitializing& init,
260  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
261  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
262 {
263  return ViewType(init, N0, N1, N2, N3, N4, N5, N6, N7);
264 }
265 
266 template <typename ViewType>
267 ViewType
268 make_view(typename ViewType::pointer_type ptr,
269  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
270  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
271 {
272  return ViewType(ptr, N0, N1, N2, N3, N4, N5, N6, N7);
273 }
274 
275 template <typename ViewType>
276 ViewType
277 make_view(const std::string& label,
278  const Experimental::Impl::WithoutInitializing_t& init,
279  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
280  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
281 {
282  return ViewType(Experimental::view_alloc(label,init),
283  N0, N1, N2, N3, N4, N5, N6, N7);
284 }
285 
286 } // namespace Kokkos
287 
288 #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)
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=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)
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)