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 //
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 #include <stdexcept>
46 
47 #include "Kokkos_View.hpp"
48 
49 namespace Kokkos {
50 
51 namespace Impl {
52 
53 KOKKOS_INLINE_FUNCTION
54 void raise_error(const char *msg)
55 {
56 #if defined(__CUDACC__) && defined(__CUDA_ARCH__)
57  Kokkos::abort(msg);
58 #else
59  throw std::runtime_error(msg);
60 #endif
61 }
62 
63 template< class T , class Device > struct RebindStokhosStorageDevice ;
64 
65 template< class T , class Device >
66 struct RebindStokhosStorageDevice< T * , Device >
67 {
69 };
70 
71 template< class T , class Device >
72 struct RebindStokhosStorageDevice< T [] , Device >
73 {
75 };
76 
77 template< class T , unsigned N , class Device >
78 struct RebindStokhosStorageDevice< T[N] , Device >
79 {
81 };
82 
83 // Get Sacado size from a list of dimensions
84 template <unsigned Rank> struct GetSacadoSize {};
85 template <> struct GetSacadoSize<0> {
86  KOKKOS_INLINE_FUNCTION
87  static size_t eval( const size_t n0 ,
88  const size_t n1 = 0 ,
89  const size_t n2 = 0 ,
90  const size_t n3 = 0 ,
91  const size_t n4 = 0 ,
92  const size_t n5 = 0 ,
93  const size_t n6 = 0 ,
94  const size_t n7 = 0 ) {
95  return n0;
96  }
97 
98  template <typename Layout>
99  KOKKOS_INLINE_FUNCTION
100  static size_t eval( const Layout& layout ) {
101  return layout.dimension[0];
102  }
103 };
104 template <> struct GetSacadoSize<1> {
105  KOKKOS_INLINE_FUNCTION
106  static size_t eval( const size_t n0 ,
107  const size_t n1 ,
108  const size_t n2 = 0 ,
109  const size_t n3 = 0 ,
110  const size_t n4 = 0 ,
111  const size_t n5 = 0 ,
112  const size_t n6 = 0 ,
113  const size_t n7 = 0 ) {
114  return n1;
115  }
116 
117  template <typename Layout>
118  KOKKOS_INLINE_FUNCTION
119  static size_t eval( const Layout& layout ) {
120  return layout.dimension[1];
121  }
122 };
123 template <> struct GetSacadoSize<2> {
124  KOKKOS_INLINE_FUNCTION
125  static size_t eval( const size_t n0 ,
126  const size_t n1 ,
127  const size_t n2 ,
128  const size_t n3 = 0 ,
129  const size_t n4 = 0 ,
130  const size_t n5 = 0 ,
131  const size_t n6 = 0 ,
132  const size_t n7 = 0 ) {
133  return n2;
134  }
135 
136  template <typename Layout>
137  KOKKOS_INLINE_FUNCTION
138  static size_t eval( const Layout& layout ) {
139  return layout.dimension[2];
140  }
141 };
142 template <> struct GetSacadoSize<3> {
143  KOKKOS_INLINE_FUNCTION
144  static size_t eval( const size_t n0 ,
145  const size_t n1 ,
146  const size_t n2 ,
147  const size_t n3 ,
148  const size_t n4 = 0 ,
149  const size_t n5 = 0 ,
150  const size_t n6 = 0 ,
151  const size_t n7 = 0 ) {
152  return n3;
153  }
154 
155  template <typename Layout>
156  KOKKOS_INLINE_FUNCTION
157  static size_t eval( const Layout& layout ) {
158  return layout.dimension[3];
159  }
160 };
161 template <> struct GetSacadoSize<4> {
162  KOKKOS_INLINE_FUNCTION
163  static size_t eval( const size_t n0 ,
164  const size_t n1 ,
165  const size_t n2 ,
166  const size_t n3 ,
167  const size_t n4 ,
168  const size_t n5 = 0 ,
169  const size_t n6 = 0 ,
170  const size_t n7 = 0 ) {
171  return n4;
172  }
173 
174  template <typename Layout>
175  KOKKOS_INLINE_FUNCTION
176  static size_t eval( const Layout& layout ) {
177  return layout.dimension[4];
178  }
179 };
180 template <> struct GetSacadoSize<5> {
181  KOKKOS_INLINE_FUNCTION
182  static size_t eval( const size_t n0 ,
183  const size_t n1 ,
184  const size_t n2 ,
185  const size_t n3 ,
186  const size_t n4 ,
187  const size_t n5 ,
188  const size_t n6 = 0 ,
189  const size_t n7 = 0 ) {
190  return n5;
191  }
192 
193  template <typename Layout>
194  KOKKOS_INLINE_FUNCTION
195  static size_t eval( const Layout& layout ) {
196  return layout.dimension[5];
197  }
198 };
199 template <> struct GetSacadoSize<6> {
200  KOKKOS_INLINE_FUNCTION
201  static size_t eval( const size_t n0 ,
202  const size_t n1 ,
203  const size_t n2 ,
204  const size_t n3 ,
205  const size_t n4 ,
206  const size_t n5 ,
207  const size_t n6 ,
208  const size_t n7 = 0 ) {
209  return n6;
210  }
211 
212  template <typename Layout>
213  KOKKOS_INLINE_FUNCTION
214  static size_t eval( const Layout& layout ) {
215  return layout.dimension[6];
216  }
217 };
218 template <> struct GetSacadoSize<7> {
219  KOKKOS_INLINE_FUNCTION
220  static size_t eval( const size_t n0 ,
221  const size_t n1 ,
222  const size_t n2 ,
223  const size_t n3 ,
224  const size_t n4 ,
225  const size_t n5 ,
226  const size_t n6 ,
227  const size_t n7 ) {
228  return n7;
229  }
230 
231  template <typename Layout>
232  KOKKOS_INLINE_FUNCTION
233  static size_t eval( const Layout& layout ) {
234  return layout.dimension[7];
235  }
236 };
237 
238 } // namespace Impl
239 
240 // Typename of flat array where sacado dimension is folded into neighbor
241 template <typename view_type, typename Enabled = void>
243  typedef view_type type;
244 };
245 
246 // Typename of the intrinsic scalar type in a view
247 template <typename view_type, typename Enabled = void>
249  typedef typename view_type::array_type::non_const_value_type type;
250 };
251 
252 template <typename ViewType>
253 ViewType
254 make_view(const std::string& label,
255  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
256  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
257 {
258  return ViewType(label, N0, N1, N2, N3, N4, N5, N6, N7);
259 }
260 
261 template <typename ViewType>
262 ViewType
263 make_view(const ViewAllocateWithoutInitializing& init,
264  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
265  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
266 {
267  return ViewType(init, N0, N1, N2, N3, N4, N5, N6, N7);
268 }
269 
270 template <typename ViewType>
271 ViewType
272 make_view(typename ViewType::pointer_type ptr,
273  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
274  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
275 {
276  return ViewType(ptr, N0, N1, N2, N3, N4, N5, N6, N7);
277 }
278 
279 template <typename ViewType>
280 ViewType
281 make_view(const std::string& label,
282  const Impl::WithoutInitializing_t& init,
283  size_t N0 = 0, size_t N1 = 0, size_t N2 = 0, size_t N3 = 0,
284  size_t N4 = 0, size_t N5 = 0, size_t N6 = 0, size_t N7 = 0)
285 {
286  return ViewType(view_alloc(label,init),
287  N0, N1, N2, N3, N4, N5, N6, N7);
288 }
289 
290 namespace Impl {
291 
292 // Specialization for deep_copy( view, view::value_type ) for Cuda
293 
294 template <class OutputView, typename Enabled = void>
296 
297 } // namespace Impl
298 
299 } // namespace Kokkos
300 
301 #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)