Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
Kokkos_DynRankView_Fad.hpp
Go to the documentation of this file.
1// @HEADER
2// ***********************************************************************
3//
4// Sacado Package
5// Copyright (2006) Sandia Corporation
6//
7// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8// the U.S. Government retains certain rights in this software.
9//
10// This library is free software; you can redistribute it and/or modify
11// it under the terms of the GNU Lesser General Public License as
12// published by the Free Software Foundation; either version 2.1 of the
13// License, or (at your option) any later version.
14//
15// This library is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18// Lesser General Public License for more details.
19//
20// You should have received a copy of the GNU Lesser General Public
21// License along with this library; if not, write to the Free Software
22// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23// USA
24// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25// (etphipp@sandia.gov).
26//
27// ***********************************************************************
28// @HEADER
29
30#ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
31#define KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
32
33#include "Sacado_ConfigDefs.h"
34
35// This file is setup to always work even when KokkosContainers (which contains
36// Kokkos::DynRankView) isn't enabled.
37
38#if defined(HAVE_SACADO_KOKKOSCONTAINERS)
39
40// We are hooking into Kokkos Core internals here
41// Need to define this macro since we include non-public headers
42#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
43#define KOKKOS_IMPL_PUBLIC_INCLUDE
44#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
45#endif
46// Only include forward declarations so any overloads appear before they
47// might be used inside Kokkos
48#include "Kokkos_Core_fwd.hpp"
49#include "Kokkos_Layout.hpp"
50//#include "Kokkos_DynRankView.hpp"
51#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
52#undef KOKKOS_IMPL_PUBLIC_INCLUDE
53#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
54#endif
55
56namespace Kokkos {
57
58template< class DataType , class ... Properties >
59struct ViewTraits ;
60
61template< class DataType , class ... Properties >
62class DynRankView ;
63
64namespace Impl {
65
66template<class Space, class T, class ... P>
67struct MirrorDRVType;
68
69}
70
71template <typename view_type>
72struct is_dynrankview_fad { static const bool value = false; };
73
74template <typename view_type>
75struct is_dynrankview_fad_contiguous { static const bool value = false; };
76
77}
78
79#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
80
81#include "Kokkos_View_Fad.hpp"
82
83namespace Kokkos {
84
85// Declare overloads of create_mirror() so they are in scope
86// Kokkos_DynRankView.hpp is included below
87
88template< class T , class ... P >
89inline
90typename Kokkos::DynRankView<T,P...>::HostMirror
91create_mirror(
92 const Kokkos::DynRankView<T,P...> & src,
93 typename std::enable_if<
94 ( std::is_same< typename ViewTraits<T,P...>::specialize ,
95 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
96 std::is_same< typename ViewTraits<T,P...>::specialize ,
97 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
98 !std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
99 Kokkos::LayoutStride >::value >::type * = 0);
100
101
102template< class T , class ... P >
103inline
104typename Kokkos::DynRankView<T,P...>::HostMirror
105create_mirror(
106 const Kokkos::DynRankView<T,P...> & src,
107 typename std::enable_if<
108 ( std::is_same< typename ViewTraits<T,P...>::specialize ,
109 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
110 std::is_same< typename ViewTraits<T,P...>::specialize ,
111 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
112 std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
113 Kokkos::LayoutStride >::value >::type * = 0);
114
115template<class Space, class T, class ... P>
116typename Impl::MirrorDRVType<Space,T,P ...>::view_type
117create_mirror(
118 const Space&,
119 const Kokkos::DynRankView<T,P...> & src,
120 typename std::enable_if<
121 std::is_same< typename ViewTraits<T,P...>::specialize ,
122 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
123 std::is_same< typename ViewTraits<T,P...>::specialize ,
124 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
125
126namespace Impl {
127
128template <unsigned N, typename T, typename... Args>
129KOKKOS_FUNCTION auto as_view_of_rank_n(
130 DynRankView<T, Args...> v,
131 typename std::enable_if<
132 ( std::is_same< typename ViewTraits<T,Args...>::specialize,
133 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
134 std::is_same< typename ViewTraits<T,Args...>::specialize ,
135 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
136 >::type * = 0 );
137
138}
139
140} // namespace Kokkos
141
142#include "Kokkos_DynRankView.hpp"
143
144namespace Kokkos {
145namespace Impl {
146
147template <>
148struct DynRankDimTraits<Kokkos::Impl::ViewSpecializeSacadoFad> {
149
150 enum : size_t{unspecified = ~size_t(0)};
151
152 // Compute the rank of the view from the nonzero dimension arguments.
153 // For views of Fad, the rank is one less than the rank determined by the nonzero dimension args
154 KOKKOS_INLINE_FUNCTION
155 static size_t computeRank( const size_t N0
156 , const size_t N1
157 , const size_t N2
158 , const size_t N3
159 , const size_t N4
160 , const size_t N5
161 , const size_t N6
162 , const size_t N7 )
163 {
164 return
165 ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
166 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 0
167 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 1
168 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 2
169 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 3
170 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified) ? 4
171 : ( (N7 == unspecified && N6 == unspecified) ? 5
172 : ( (N7 == unspecified) ? 6
173 : 7 ) ) ) ) ) ) ) );
174 }
175
176 // Compute the rank of the view from the nonzero layout arguments.
177 template <typename Layout>
178 KOKKOS_INLINE_FUNCTION
179 static size_t computeRank( const Layout& layout )
180 {
181 return computeRank( layout.dimension[0]
182 , layout.dimension[1]
183 , layout.dimension[2]
184 , layout.dimension[3]
185 , layout.dimension[4]
186 , layout.dimension[5]
187 , layout.dimension[6]
188 , layout.dimension[7] );
189 }
190
191 // Compute the rank of the view from the nonzero layout arguments and possible hidden dim
192 template <typename Layout, typename ... P>
193 KOKKOS_INLINE_FUNCTION
194 static size_t computeRank( const ViewCtorProp<P...>& /* prop */, const Layout& layout )
195 {
196 size_t rank = computeRank( layout.dimension[0]
197 , layout.dimension[1]
198 , layout.dimension[2]
199 , layout.dimension[3]
200 , layout.dimension[4]
201 , layout.dimension[5]
202 , layout.dimension[6]
203 , layout.dimension[7] );
204
205 // Check if has_common_view_alloc_prop; if so, return rank+1, else rank
206 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
207 return (test_traits_check == true) ? rank+1 : rank;
208 }
209
210 // Create the layout for the rank-7 view.
211 // For Fad we have to move the fad dimension to the last (rank 8 since the DynRankView is rank-7)
212 // LayoutLeft or LayoutRight
213 template <typename Layout>
214 KOKKOS_INLINE_FUNCTION
215 static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutRight>::value || std::is_same<Layout , Kokkos::LayoutLeft>::value) , Layout >::type createLayout( const Layout& layout )
216 {
217 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
218 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
219 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
220 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
221 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
222 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
223 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
224 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
225 const unsigned fad_dim = computeRank(layout);
226 const size_t fad_size = layout.dimension[fad_dim];
227 l.dimension[fad_dim] = 1;
228 l.dimension[7] = fad_size;
229
230 return l;
231 }
232
233 //LayoutStride
234 template <typename Layout>
235 KOKKOS_INLINE_FUNCTION
236 static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout( const Layout& layout )
237 {
238 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
239 , layout.stride[0]
240 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
241 , layout.stride[1]
242 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
243 , layout.stride[2]
244 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
245 , layout.stride[3]
246 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
247 , layout.stride[4]
248 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
249 , layout.stride[5]
250 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
251 , layout.stride[6]
252 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
253 , layout.stride[7]
254 );
255 const unsigned fad_dim = computeRank(layout);
256 const size_t fad_size = layout.dimension[fad_dim];
257 l.dimension[fad_dim] = 1;
258 l.dimension[7] = fad_size;
259 const size_t fad_stride = layout.stride[fad_dim];
260 l.stride[fad_dim] = 0;
261 l.stride[7] = fad_stride;
262
263 return l;
264 }
265
266 // If fad_dim is stored in ViewCtorProp
267 // LayoutLeft or LayoutRight
268 template <typename Traits, typename ... P>
269 KOKKOS_INLINE_FUNCTION
270 static typename std::enable_if< (std::is_same<typename Traits::array_layout , Kokkos::LayoutRight>::value || std::is_same<typename Traits::array_layout , Kokkos::LayoutLeft>::value) , typename Traits::array_layout >::type createLayout( const ViewCtorProp<P...> & arg_prop, const typename Traits::array_layout& layout )
271 {
272 using Layout = typename Traits::array_layout;
273
274 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
275 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
276 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
277 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
278 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
279 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
280 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
281 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
282
283 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
284 if (test_traits_check == true) {
285 l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
286 }
287 else {
288 const unsigned fad_dim = computeRank(layout);
289 const size_t fad_size = layout.dimension[fad_dim];
290 l.dimension[fad_dim] = 1;
291 l.dimension[7] = fad_size;
292 }
293
294 return l;
295 }
296
297 // If fad_dim is stored in ViewCtorProp
298 //LayoutStride
299 template <typename Traits, typename ... P>
300 KOKKOS_INLINE_FUNCTION
301 static typename std::enable_if< (std::is_same<typename Traits::array_layout , Kokkos::LayoutStride>::value) , typename Traits::array_layout>::type createLayout( const ViewCtorProp<P...> & arg_prop, const typename Traits::array_layout& layout )
302 {
303 using Layout = typename Traits::array_layout;
304
305 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
306 , layout.stride[0]
307 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
308 , layout.stride[1]
309 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
310 , layout.stride[2]
311 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
312 , layout.stride[3]
313 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
314 , layout.stride[4]
315 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
316 , layout.stride[5]
317 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
318 , layout.stride[6]
319 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
320 , layout.stride[7]
321 );
322
323 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
324 const unsigned fad_dim = computeRank(layout);
325 if (test_traits_check == true) {
326 l.dimension[fad_dim] = 1;
327 l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
328 }
329 else {
330 const size_t fad_size = layout.dimension[fad_dim];
331 l.dimension[fad_dim] = 1;
332 l.dimension[7] = fad_size;
333 }
334 const size_t fad_stride = layout.stride[fad_dim];
335 l.stride[fad_dim] = 0;
336 l.stride[7] = fad_stride;
337
338 return l;
339 }
340
341 // Create a view from the given dimension arguments.
342 // This is only necessary because the shmem constructor doesn't take a layout.
343 template <typename ViewType, typename ViewArg>
344 static ViewType createView( const ViewArg& arg
345 , const size_t N0
346 , const size_t N1
347 , const size_t N2
348 , const size_t N3
349 , const size_t N4
350 , const size_t N5
351 , const size_t N6
352 , const size_t N7 )
353 {
354 typename ViewType::array_layout l( N0, N1, N2, N3, N4, N5, N6, N7 );
355 typename ViewType::array_layout l_fad = createLayout(l);
356 return ViewType( arg
357 , l_fad.dimension[0]
358 , l_fad.dimension[1]
359 , l_fad.dimension[2]
360 , l_fad.dimension[3]
361 , l_fad.dimension[4]
362 , l_fad.dimension[5]
363 , l_fad.dimension[6]
364 , l_fad.dimension[7] );
365 }
366
367};
368
369}} // namespace Kokkos::Impl
370
371namespace Kokkos {
372namespace Impl {
373
374template <unsigned> struct AssignDim7 {
375 template <typename Dst>
376 KOKKOS_INLINE_FUNCTION
377 static void eval(Dst& dst, const size_t src_dim) {}
378};
379template <> struct AssignDim7<0u> {
380 template <typename Dst>
381 KOKKOS_INLINE_FUNCTION
382 static void eval(Dst& dst, const size_t src_dim) {
383 dst.N7 = src_dim;
384 }
385};
386
387// Utility class that handles calculation of the stride in Fad subview
388template <unsigned,unsigned> struct AssignFadDimStride {};
389template <unsigned StaticDim> struct AssignFadDimStride<0u,StaticDim> {
390 template <typename Src, typename Dst>
391 KOKKOS_INLINE_FUNCTION
392 static void eval(Dst& dst, const Src& src) {
393 dst.m_stride.S0 = 0 ;
394 dst.m_stride.S1 = 0 ;
395 dst.m_stride.S2 = 0 ;
396 dst.m_stride.S3 = 0 ;
397 dst.m_stride.S4 = 0 ;
398 dst.m_stride.S5 = 0 ;
399 dst.m_stride.S6 = 0 ;
400 dst.m_stride.S7 = src.m_stride.S0 ;
401
402 dst.m_dim.N0 = 1 ;
403 dst.m_dim.N1 = 1 ;
404 dst.m_dim.N2 = 1 ;
405 dst.m_dim.N3 = 1 ;
406 dst.m_dim.N4 = 1 ;
407 dst.m_dim.N5 = 1 ;
408 dst.m_dim.N6 = 1 ;
409 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N0 );
410 }
411};
412template <unsigned StaticDim> struct AssignFadDimStride<1u,StaticDim> {
413 template <typename Src, typename Dst>
414 KOKKOS_INLINE_FUNCTION
415 static void eval(Dst& dst, const Src& src) {
416 dst.m_stride.S0 = src.m_stride.S0 ;
417 dst.m_stride.S1 = 0 ;
418 dst.m_stride.S2 = 0 ;
419 dst.m_stride.S3 = 0 ;
420 dst.m_stride.S4 = 0 ;
421 dst.m_stride.S5 = 0 ;
422 dst.m_stride.S6 = 0 ;
423 dst.m_stride.S7 = src.m_stride.S1 ;
424
425 dst.m_dim.N0 = src.m_dim.N0 ;
426 dst.m_dim.N1 = 1 ;
427 dst.m_dim.N2 = 1 ;
428 dst.m_dim.N3 = 1 ;
429 dst.m_dim.N4 = 1 ;
430 dst.m_dim.N5 = 1 ;
431 dst.m_dim.N6 = 1 ;
432 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N1 );
433 }
434};
435template <unsigned StaticDim> struct AssignFadDimStride<2u,StaticDim> {
436 template <typename Src, typename Dst>
437 KOKKOS_INLINE_FUNCTION
438 static void eval(Dst& dst, const Src& src) {
439 dst.m_stride.S0 = src.m_stride.S0 ;
440 dst.m_stride.S1 = src.m_stride.S1 ;
441 dst.m_stride.S2 = 0 ;
442 dst.m_stride.S3 = 0 ;
443 dst.m_stride.S4 = 0 ;
444 dst.m_stride.S5 = 0 ;
445 dst.m_stride.S6 = 0 ;
446 dst.m_stride.S7 = src.m_stride.S2 ;
447
448 dst.m_dim.N0 = src.m_dim.N0 ;
449 dst.m_dim.N1 = src.m_dim.N1 ;
450 dst.m_dim.N2 = 1 ;
451 dst.m_dim.N3 = 1 ;
452 dst.m_dim.N4 = 1 ;
453 dst.m_dim.N5 = 1 ;
454 dst.m_dim.N6 = 1 ;
455 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N2 );
456 }
457};
458template <unsigned StaticDim> struct AssignFadDimStride<3u,StaticDim> {
459 template <typename Src, typename Dst>
460 KOKKOS_INLINE_FUNCTION
461 static void eval(Dst& dst, const Src& src) {
462 dst.m_stride.S0 = src.m_stride.S0 ;
463 dst.m_stride.S1 = src.m_stride.S1 ;
464 dst.m_stride.S2 = src.m_stride.S2 ;
465 dst.m_stride.S3 = 0 ;
466 dst.m_stride.S4 = 0 ;
467 dst.m_stride.S5 = 0 ;
468 dst.m_stride.S6 = 0 ;
469 dst.m_stride.S7 = src.m_stride.S3 ;
470
471 dst.m_dim.N0 = src.m_dim.N0 ;
472 dst.m_dim.N1 = src.m_dim.N1 ;
473 dst.m_dim.N2 = src.m_dim.N2 ;
474 dst.m_dim.N3 = 1 ;
475 dst.m_dim.N4 = 1 ;
476 dst.m_dim.N5 = 1 ;
477 dst.m_dim.N6 = 1 ;
478 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N3 );
479 }
480};
481template <unsigned StaticDim> struct AssignFadDimStride<4u,StaticDim> {
482 template <typename Src, typename Dst>
483 KOKKOS_INLINE_FUNCTION
484 static void eval(Dst& dst, const Src& src) {
485 dst.m_stride.S0 = src.m_stride.S0 ;
486 dst.m_stride.S1 = src.m_stride.S1 ;
487 dst.m_stride.S2 = src.m_stride.S2 ;
488 dst.m_stride.S3 = src.m_stride.S3 ;
489 dst.m_stride.S4 = 0 ;
490 dst.m_stride.S5 = 0 ;
491 dst.m_stride.S6 = 0 ;
492 dst.m_stride.S7 = src.m_stride.S4 ;
493
494 dst.m_dim.N0 = src.m_dim.N0 ;
495 dst.m_dim.N1 = src.m_dim.N1 ;
496 dst.m_dim.N2 = src.m_dim.N2 ;
497 dst.m_dim.N3 = src.m_dim.N3 ;
498 dst.m_dim.N4 = 1 ;
499 dst.m_dim.N5 = 1 ;
500 dst.m_dim.N6 = 1 ;
501 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N4 );
502 }
503};
504template <unsigned StaticDim> struct AssignFadDimStride<5u,StaticDim> {
505 template <typename Src, typename Dst>
506 KOKKOS_INLINE_FUNCTION
507 static void eval(Dst& dst, const Src& src) {
508 dst.m_stride.S0 = src.m_stride.S0 ;
509 dst.m_stride.S1 = src.m_stride.S1 ;
510 dst.m_stride.S2 = src.m_stride.S2 ;
511 dst.m_stride.S3 = src.m_stride.S3 ;
512 dst.m_stride.S4 = src.m_stride.S4 ;
513 dst.m_stride.S5 = 0 ;
514 dst.m_stride.S6 = 0 ;
515 dst.m_stride.S7 = src.m_stride.S5 ;
516
517 dst.m_dim.N0 = src.m_dim.N0 ;
518 dst.m_dim.N1 = src.m_dim.N1 ;
519 dst.m_dim.N2 = src.m_dim.N2 ;
520 dst.m_dim.N3 = src.m_dim.N3 ;
521 dst.m_dim.N4 = src.m_dim.N4 ;
522 dst.m_dim.N5 = 1 ;
523 dst.m_dim.N6 = 1 ;
524 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N5 );
525 }
526};
527template <unsigned StaticDim> struct AssignFadDimStride<6u,StaticDim> {
528 template <typename Src, typename Dst>
529 KOKKOS_INLINE_FUNCTION
530 static void eval(Dst& dst, const Src& src) {
531 dst.m_stride.S0 = src.m_stride.S0 ;
532 dst.m_stride.S1 = src.m_stride.S1 ;
533 dst.m_stride.S2 = src.m_stride.S2 ;
534 dst.m_stride.S3 = src.m_stride.S3 ;
535 dst.m_stride.S4 = src.m_stride.S4 ;
536 dst.m_stride.S5 = src.m_stride.S5 ;
537 dst.m_stride.S6 = 0 ;
538 dst.m_stride.S7 = src.m_stride.S6 ;
539
540 dst.m_dim.N0 = src.m_dim.N0 ;
541 dst.m_dim.N1 = src.m_dim.N1 ;
542 dst.m_dim.N2 = src.m_dim.N2 ;
543 dst.m_dim.N3 = src.m_dim.N3 ;
544 dst.m_dim.N4 = src.m_dim.N4 ;
545 dst.m_dim.N5 = src.m_dim.N5 ;
546 dst.m_dim.N6 = 1 ;
547 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N6 );
548 }
549};
550template <unsigned StaticDim> struct AssignFadDimStride<7u,StaticDim> {
551 template <typename Src, typename Dst>
552 KOKKOS_INLINE_FUNCTION
553 static void eval(Dst& dst, const Src& src) {
554 dst.m_stride.S0 = src.m_stride.S0 ;
555 dst.m_stride.S1 = src.m_stride.S1 ;
556 dst.m_stride.S2 = src.m_stride.S2 ;
557 dst.m_stride.S3 = src.m_stride.S3 ;
558 dst.m_stride.S4 = src.m_stride.S4 ;
559 dst.m_stride.S5 = src.m_stride.S5 ;
560 dst.m_stride.S6 = src.m_stride.S6 ;
561 dst.m_stride.S7 = src.m_stride.S7 ;
562
563 dst.m_dim.N0 = src.m_dim.N0 ;
564 dst.m_dim.N1 = src.m_dim.N1 ;
565 dst.m_dim.N2 = src.m_dim.N2 ;
566 dst.m_dim.N3 = src.m_dim.N3 ;
567 dst.m_dim.N4 = src.m_dim.N4 ;
568 dst.m_dim.N5 = src.m_dim.N5 ;
569 dst.m_dim.N6 = src.m_dim.N6 ;
570 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N7 );
571 }
572};
573
574// Specializations for subdynrankview
575template< class SrcTraits , class ... Args >
576struct ViewMapping
577 < typename std::enable_if<(
578 std::is_same< typename SrcTraits::specialize ,
579 Kokkos::Impl::ViewSpecializeSacadoFad >::value
580 &&
581 (
582 std::is_same< typename SrcTraits::array_layout
583 , Kokkos::LayoutLeft >::value ||
584 std::is_same< typename SrcTraits::array_layout
585 , Kokkos::LayoutRight >::value ||
586 std::is_same< typename SrcTraits::array_layout
587 , Kokkos::LayoutStride >::value
588 )
589 ), Kokkos::Impl::DynRankSubviewTag >::type
590 , SrcTraits
591 , Args ... >
592{
593private:
594
595 enum
596 { RZ = false
597 , R0 = bool(is_integral_extent<0,Args...>::value)
598 , R1 = bool(is_integral_extent<1,Args...>::value)
599 , R2 = bool(is_integral_extent<2,Args...>::value)
600 , R3 = bool(is_integral_extent<3,Args...>::value)
601 , R4 = bool(is_integral_extent<4,Args...>::value)
602 , R5 = bool(is_integral_extent<5,Args...>::value)
603 , R6 = bool(is_integral_extent<6,Args...>::value)
604 };
605
606 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
607 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
608
609 typedef Kokkos::LayoutStride array_layout ;
610
611 typedef typename SrcTraits::value_type value_type ;
612
613 typedef value_type******* data_type ;
614
615public:
616
617 typedef Kokkos::ViewTraits
618 < data_type
619 , array_layout
620 , typename SrcTraits::device_type
621 , typename SrcTraits::memory_traits > traits_type ;
622
623 typedef Kokkos::View
624 < data_type
625 , array_layout
626 , typename SrcTraits::device_type
627 , typename SrcTraits::memory_traits > type ;
628
629
630 template< class MemoryTraits >
631 struct apply {
632
633 static_assert( Kokkos::is_memory_traits< MemoryTraits >::value , "" );
634
635 typedef Kokkos::ViewTraits
636 < data_type
637 , array_layout
638 , typename SrcTraits::device_type
639 , MemoryTraits > traits_type ;
640
641 typedef Kokkos::View
642 < data_type
643 , array_layout
644 , typename SrcTraits::device_type
645 , MemoryTraits > type ;
646 };
647
648 template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
649 struct ExtentGenerator {
650 template <typename dimension>
651 KOKKOS_INLINE_FUNCTION
652 static SubviewExtents< 7 , rank > generator ( const dimension & dim , Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(), Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(), Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6() )
653 {
654 return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
655 arg4 , arg5 , arg6 );
656 }
657 };
658
659 template < class Arg0 = int, class Arg1 = int, class Arg2 = int, class Arg3 = int, class Arg4 = int, class Arg5 = int, class Arg6 = int >
660 struct ArrayExtentGenerator {
661 template <typename dimension>
662 KOKKOS_INLINE_FUNCTION
663 static SubviewExtents< 8 , rank+1 > generator ( const dimension & dim , Arg0 arg0 = Arg0(), Arg1 arg1 = Arg1(), Arg2 arg2 = Arg2(), Arg3 arg3 = Arg3(), Arg4 arg4 = Arg4(), Arg5 arg5 = Arg5(), Arg6 arg6 = Arg6() )
664 {
665 return SubviewExtents< 8 , rank+1 >( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , Kokkos::ALL() );
666 }
667 };
668
669 typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
670
671 template < typename T , class ... P >
672 KOKKOS_INLINE_FUNCTION
673 static ret_type subview( const unsigned src_rank , Kokkos::DynRankView< T , P...> const & src , Args ... args )
674 {
675
676 typedef ViewMapping< traits_type, typename traits_type::specialize> DstType ;
677 typedef ViewMapping< SrcTraits, typename SrcTraits::specialize> SrcType;
678 enum { FadStaticDim = SrcType::FadStaticDimension };
679 typedef typename std::conditional< (rank==0) , ViewDimension<>
680 , typename std::conditional< (rank==1) , ViewDimension<0>
681 , typename std::conditional< (rank==2) , ViewDimension<0,0>
682 , typename std::conditional< (rank==3) , ViewDimension<0,0,0>
683 , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
684 , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
685 , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
686 , ViewDimension<0,0,0,0,0,0,0>
687 >::type >::type >::type >::type >::type >::type >::type DstDimType ;
688 typedef typename std::conditional< (rank==0) , ViewDimension<FadStaticDim>
689 , typename std::conditional< (rank==1) , ViewDimension<0,FadStaticDim>
690 , typename std::conditional< (rank==2) , ViewDimension<0,0,FadStaticDim>
691 , typename std::conditional< (rank==3) , ViewDimension<0,0,0,FadStaticDim>
692 , typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,FadStaticDim>
693 , typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,FadStaticDim>
694 , typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,FadStaticDim>
695 , ViewDimension<0,0,0,0,0,0,0,FadStaticDim>
696 >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
697
698 typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
699 typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
700 typedef typename DstType::handle_type dst_handle_type ;
701
702 ret_type dst ;
703
704 const SubviewExtents< 7 , rank > extents =
705 ExtentGenerator< Args ... >::generator(
706 src.m_map.m_impl_offset.m_dim , args... ) ;
707 const SubviewExtents< 8 , rank+1 > array_extents =
708 ArrayExtentGenerator< Args ... >::generator(
709 src.m_map.m_array_offset.m_dim , args... ) ;
710
711 dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
712 dst_array_offset_type temparraydst(
713 src.m_map.m_array_offset , array_extents ) ;
714
715 dst.m_track = src.m_track ;
716
717 dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
718 dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
719 dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
720 dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
721 dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
722 dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
723 dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
724
725 dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
726 dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
727 dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
728 dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
729 dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
730 dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
731 dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
732
733 // Move last non-unit dim and stride to N7/S7 since subview collapses
734 // out all singleton dimensions between the last rank and the fad
735 // dimension. Equivalent to:
736 // dst.m_map.m_impl_offset.m_dim.N* = tempdst.m_dim.N*
737 // dst.m_map.m_impl_offset.m_dim.N7 = tempdst.m_dim.N{rank}
738 // dst.m_map.m_impl_offset.m_stride.S* = tempdst.m_stride.S*
739 // dst.m_map.m_impl_offset.m_stride.S7 = tempdst.m_stride.S{rank}
740 AssignFadDimStride<rank,FadStaticDim>::eval( dst.m_map.m_array_offset, temparraydst );
741
742 dst.m_track = src.m_track ;
743
744 dst.m_map.m_impl_handle =
745 dst_handle_type(
746 src.m_map.m_impl_handle +
747 src.m_map.m_array_offset( array_extents.domain_offset(0)
748 , array_extents.domain_offset(1)
749 , array_extents.domain_offset(2)
750 , array_extents.domain_offset(3)
751 , array_extents.domain_offset(4)
752 , array_extents.domain_offset(5)
753 , array_extents.domain_offset(6)
754 , array_extents.domain_offset(7)
755 ) );
756
757 dst.m_map.m_fad_size = src.m_map.m_fad_size;
758 dst.m_map.m_fad_stride = src.m_map.m_fad_stride.value;
759
760 dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
761 + ( src_rank > 1 ? unsigned(R1) : 0 )
762 + ( src_rank > 2 ? unsigned(R2) : 0 )
763 + ( src_rank > 3 ? unsigned(R3) : 0 )
764 + ( src_rank > 4 ? unsigned(R4) : 0 )
765 + ( src_rank > 5 ? unsigned(R5) : 0 )
766 + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
767
768 return dst ;
769 }
770};
771
772// ViewMapping for copy and copy-assign from View to DynRankView
773template <unsigned> struct AssignFadDim7 {
774 template <typename Src, typename Dst>
775 KOKKOS_INLINE_FUNCTION
776 static void eval(Dst& dst, const Src& src , const unsigned dim ) {}
777};
778
779template <> struct AssignFadDim7<0u> {
780 template <typename Src, typename Dst>
781 KOKKOS_INLINE_FUNCTION
782 static void eval(Dst& dst, const Src& src , const unsigned dim ) {
783 dst.m_dim.N7 = src.m_dim.extent(dim);
784 }
785};
786
787// Copy a layout, moving the Fad dimension to the last
788template <typename Layout>
789KOKKOS_INLINE_FUNCTION
790static Layout
791permute_fad_layout(const Layout& src, const unsigned rank) {
792 Layout dst = src;
793 dst.dimension[rank] = 1;
794 dst.dimension[7] = src.dimension[rank];
795 return dst;
796}
797KOKKOS_INLINE_FUNCTION
798static LayoutStride
799permute_fad_layout(const LayoutStride& src, const unsigned rank) {
800 LayoutStride dst = src;
801 dst.dimension[rank] = 1;
802 dst.stride[rank] = 1;
803 dst.dimension[7] = src.dimension[rank];
804 dst.stride[7] = src.stride[rank];
805 return dst;
806}
807
812template< class DstTraits , class SrcTraits >
813class ViewMapping< DstTraits , SrcTraits ,
814 typename std::enable_if<(
815 Kokkos::Impl::MemorySpaceAccess
816 < typename DstTraits::memory_space
817 , typename SrcTraits::memory_space >::assignable
818 &&
819 // Destination view has FAD only
820 std::is_same< typename DstTraits::specialize
821 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
822 &&
823 // Source view has FAD only
824 std::is_same< typename SrcTraits::specialize
825 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
826 ), Kokkos::Impl::ViewToDynRankViewTag >::type >
827{
828public:
829
830 enum { is_assignable = true };
831 enum { is_assignable_data_type = true };
832
833 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
834 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
835 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
836
837 template < typename DT , typename ... DP , typename ST , typename ... SP >
838 KOKKOS_INLINE_FUNCTION static
839 void assign( Kokkos::DynRankView< DT , DP... > & dst
840 , const Kokkos::View< ST , SP... >& src )
841 {
842 static_assert(
843 (
844 std::is_same< typename DstTraits::array_layout
845 , Kokkos::LayoutLeft >::value ||
846 std::is_same< typename DstTraits::array_layout
847 , Kokkos::LayoutRight >::value ||
848 std::is_same< typename DstTraits::array_layout
849 , Kokkos::LayoutStride >::value
850 )
851 &&
852 (
853 std::is_same< typename SrcTraits::array_layout
854 , Kokkos::LayoutLeft >::value ||
855 std::is_same< typename SrcTraits::array_layout
856 , Kokkos::LayoutRight >::value ||
857 std::is_same< typename SrcTraits::array_layout
858 , Kokkos::LayoutStride >::value
859 )
860 , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
861
862 static_assert(
863 std::is_same< typename DstTraits::value_type
864 , typename SrcTraits::value_type >::value ||
865 std::is_same< typename DstTraits::value_type
866 , typename SrcTraits::const_value_type >::value ,
867 "View assignment must have same value type or const = non-const" );
868
869 typedef typename DstType::offset_type dst_offset_type;
870 typedef typename DstType::array_offset_type dst_array_offset_type;
871 dst.m_map.m_array_offset =
872 dst_array_offset_type(std::integral_constant<unsigned,0>(),
873 permute_fad_layout(src.m_map.m_array_offset.layout(),
874 SrcTraits::rank) );
875 dst.m_map.m_impl_offset =
876 dst_offset_type(std::integral_constant<unsigned,0>(),
877 src.m_map.m_impl_offset.layout() );
878
879 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
880 dst.m_rank = src.Rank ;
881
882 dst.m_map.m_fad_size = src.m_map.m_fad_size ;
883 dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
884 }
885};
886
891template< class DstTraits , class SrcTraits >
892class ViewMapping< DstTraits , SrcTraits ,
893 typename std::enable_if<(
894 Kokkos::Impl::MemorySpaceAccess
895 < typename DstTraits::memory_space
896 , typename SrcTraits::memory_space >::assignable
897 &&
898 // Destination view has ordinary
899 std::is_same< typename DstTraits::specialize , void >::value
900 &&
901 // Source view has FAD only
902 std::is_same< typename SrcTraits::specialize
903 , ViewSpecializeSacadoFad >::value
904 ), Kokkos::Impl::ViewToDynRankViewTag >::type >
905{
906public:
907
908 enum { is_assignable = true };
909 enum { is_assignable_data_type = true };
910
911 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
912 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
913 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
914
915 template < typename DT , typename ... DP , typename ST , typename ... SP >
916 KOKKOS_INLINE_FUNCTION static
917 void assign( Kokkos::DynRankView< DT , DP... > & dst
918 , const Kokkos::View< ST , SP... >& src )
919 {
920 static_assert(
921 (
922 std::is_same< typename DstTraits::array_layout
923 , Kokkos::LayoutLeft >::value ||
924 std::is_same< typename DstTraits::array_layout
925 , Kokkos::LayoutRight >::value ||
926 std::is_same< typename DstTraits::array_layout
927 , Kokkos::LayoutStride >::value
928 )
929 &&
930 (
931 std::is_same< typename SrcTraits::array_layout
932 , Kokkos::LayoutLeft >::value ||
933 std::is_same< typename SrcTraits::array_layout
934 , Kokkos::LayoutRight >::value ||
935 std::is_same< typename SrcTraits::array_layout
936 , Kokkos::LayoutStride >::value
937 )
938 , "View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
939
940 static_assert(
941 std::is_same< typename DstTraits::value_type
942 , typename SrcTraits::value_type >::value ||
943 std::is_same< typename DstTraits::value_type
944 , typename SrcTraits::const_value_type >::value ,
945 "View assignment must have same value type or const = non-const" );
946
947 typedef typename DstType::offset_type dst_offset_type;
948 dst.m_map.m_impl_offset =
949 dst_offset_type(std::integral_constant<unsigned,0>(),
950 permute_fad_layout(src.m_map.m_array_offset.layout(),
951 SrcTraits::rank));
952
953 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
954 dst.m_rank = src.Rank ;
955 }
956};
957
958}} //end Kokkos::Impl
959
960namespace Kokkos {
961
962template <typename T, typename ... P>
963struct is_dynrankview_fad< DynRankView<T,P...> > {
964 typedef DynRankView<T,P...> view_type;
965 static const bool value =
966 std::is_same< typename view_type::specialize,
967 Impl::ViewSpecializeSacadoFad >::value ||
968 std::is_same< typename view_type::specialize,
969 Impl::ViewSpecializeSacadoFadContiguous >::value;
970};
971
972template <typename T, typename ... P>
973struct is_dynrankview_fad_contiguous< DynRankView<T,P...> > {
974 typedef DynRankView<T,P...> view_type;
975 static const bool value =
976 std::is_same< typename view_type::specialize,
977 Impl::ViewSpecializeSacadoFadContiguous >::value;
978};
979
980template <typename T, typename ... P>
981KOKKOS_INLINE_FUNCTION
982constexpr typename
983std::enable_if< is_dynrankview_fad< DynRankView<T,P...> >::value, unsigned >::type
984dimension_scalar(const DynRankView<T,P...>& view) {
985#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
986 return view.implementation_map().dimension_scalar();
987#else
988 return view.impl_map().dimension_scalar();
989#endif
990}
991
992
993// Overload of deep_copy for Fad views intializing to a constant scalar
994
995template< class DT, class ... DP >
996void deep_copy(
997 const DynRankView<DT,DP...> & view ,
998 const typename Sacado::ScalarType< typename DynRankView<DT,DP...>::value_type >::type & value
999 , typename std::enable_if<(
1000 std::is_same< typename ViewTraits<DT,DP...>::specialize
1001 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1002 std::is_same< typename ViewTraits<DT,DP...>::specialize
1003 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1004 )>::type * = 0 )
1005{
1006 static_assert(
1007 std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1008 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1009 , "Can only deep copy into non-const type" );
1010
1011 Kokkos::fence();
1012 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
1013 Kokkos::fence();
1014}
1015
1016// Overload of deep_copy for Fad views intializing to a constant Fad
1017template< class DT, class ... DP >
1018void deep_copy(
1019 const DynRankView<DT,DP...> & view ,
1020 const typename DynRankView<DT,DP...>::value_type & value
1021 , typename std::enable_if<(
1022 std::is_same< typename ViewTraits<DT,DP...>::specialize
1023 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1024 std::is_same< typename ViewTraits<DT,DP...>::specialize
1025 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1026 )>::type * = 0 )
1027{
1028 static_assert(
1029 std::is_same< typename ViewTraits<DT,DP...>::value_type ,
1030 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1031 , "Can only deep copy into non-const type" );
1032
1033 Kokkos::fence();
1034 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
1035 Kokkos::fence();
1036}
1037
1038template< class DstType , class SrcType >
1039inline
1040void deep_copy
1041 ( const DstType & dst
1042 , const SrcType & src
1043 , typename std::enable_if<(
1044 ( std::is_same< typename DstType::traits::specialize
1045 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1046 std::is_same< typename DstType::traits::specialize
1047 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1048 &&
1049 ( std::is_same< typename SrcType::traits::specialize
1050 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1051 std::is_same< typename SrcType::traits::specialize
1052 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1053 &&
1054 ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType
1055>::value )
1056 )>::type * = 0 )
1057{
1058 static_assert(
1059 std::is_same< typename DstType::traits::value_type ,
1060 typename DstType::traits::non_const_value_type >::value
1061 , "deep_copy requires non-const destination type" );
1062
1063 typedef DstType dst_type ;
1064 typedef SrcType src_type ;
1065
1066 typedef typename dst_type::execution_space dst_execution_space ;
1067 typedef typename src_type::execution_space src_execution_space ;
1068 typedef typename dst_type::memory_space dst_memory_space ;
1069 typedef typename src_type::memory_space src_memory_space ;
1070
1071 enum { DstExecCanAccessSrc =
1072 Kokkos::SpaceAccessibility< typename dst_execution_space::memory_space, src_memory_space >::accessible };
1073
1074 enum { SrcExecCanAccessDst =
1075 Kokkos::SpaceAccessibility< typename src_execution_space::memory_space, dst_memory_space >::accessible };
1076
1077 if ( (void *) dst.data() != (void*) src.data() ) {
1078
1079 // Concern: If overlapping views then a parallel copy will be erroneous.
1080 // ...
1081
1082 // If same type, equal layout, equal dimensions, equal span, and contiguous memory then can byte-wise copy
1083 if ( rank(src) == 0 && rank(dst) == 0 )
1084 {
1085 typedef typename dst_type::value_type::value_type value_type ;
1086 const size_t nbytes = sizeof(value_type) * dst.span() ;
1087 Kokkos::fence();
1088 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1089 Kokkos::fence();
1090 }
1091 else if ( std::is_same< typename DstType::traits::value_type ,
1092 typename SrcType::traits::non_const_value_type >::value &&
1093 (
1094 ( std::is_same< typename DstType::traits::array_layout ,
1095 typename SrcType::traits::array_layout >::value
1096 &&
1097 ( std::is_same< typename DstType::traits::array_layout ,
1098 typename Kokkos::LayoutLeft>::value
1099 ||
1100 std::is_same< typename DstType::traits::array_layout ,
1101 typename Kokkos::LayoutRight>::value
1102 )
1103 )
1104 ||
1105 (
1106 rank(dst) == 1
1107 &&
1108 rank(src) == 1
1109 )
1110 ) &&
1111 dst.span_is_contiguous() &&
1112 src.span_is_contiguous() &&
1113 dst.span() == src.span() &&
1114 dst.extent(0) == src.extent(0) &&
1115 dst.extent(1) == src.extent(1) &&
1116 dst.extent(2) == src.extent(2) &&
1117 dst.extent(3) == src.extent(3) &&
1118 dst.extent(4) == src.extent(4) &&
1119 dst.extent(5) == src.extent(5) &&
1120 dst.extent(6) == src.extent(6) &&
1121 dst.extent(7) == src.extent(7) ) {
1122
1123// const size_t nbytes = sizeof(typename dst_type::value_type) * dst.span() * dimension_scalar(dst) ;
1124 //const size_t nbytes = sizeof(typename dst_type::scalar_array_type) * dst.span() ;
1125 const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1126 //dst_type::value_type is outer FAD type, dst_type::value_type::value_type is inner FAD type
1127 Kokkos::fence();
1128 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1129 Kokkos::fence();
1130 }
1131 else if ( std::is_same< typename DstType::traits::value_type ,
1132 typename SrcType::traits::non_const_value_type >::value &&
1133 (
1134 ( std::is_same< typename DstType::traits::array_layout ,
1135 typename SrcType::traits::array_layout >::value
1136 &&
1137 std::is_same< typename DstType::traits::array_layout ,
1138 typename Kokkos::LayoutStride>::value
1139 )
1140 ||
1141 (
1142 rank(dst) == 1
1143 &&
1144 rank(src) == 1
1145 )
1146 ) &&
1147 dst.span_is_contiguous() &&
1148 src.span_is_contiguous() &&
1149 dst.span() == src.span() &&
1150 dst.extent(0) == src.extent(0) &&
1151 dst.extent(1) == src.extent(1) &&
1152 dst.extent(2) == src.extent(2) &&
1153 dst.extent(3) == src.extent(3) &&
1154 dst.extent(4) == src.extent(4) &&
1155 dst.extent(5) == src.extent(5) &&
1156 dst.extent(6) == src.extent(6) &&
1157 dst.extent(7) == src.extent(7) &&
1158 dst.stride_0() == src.stride_0() &&
1159 dst.stride_1() == src.stride_1() &&
1160 dst.stride_2() == src.stride_2() &&
1161 dst.stride_3() == src.stride_3() &&
1162 dst.stride_4() == src.stride_4() &&
1163 dst.stride_5() == src.stride_5() &&
1164 dst.stride_6() == src.stride_6() &&
1165 dst.stride_7() == src.stride_7()
1166 ) {
1167
1168 const size_t nbytes = sizeof(typename dst_type::value_type::value_type) * dst.span() ;
1169 Kokkos::fence();
1170 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1171 Kokkos::fence();
1172 }
1173 else if ( DstExecCanAccessSrc ) {
1174 // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1175 Kokkos::fence();
1176 Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1177 Kokkos::fence();
1178 }
1179 else if ( SrcExecCanAccessDst ) {
1180 // Copying data between views in accessible memory spaces and either non-contiguous or incompatible shape.
1181 Kokkos::fence();
1182 Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1183 Kokkos::fence();
1184 }
1185 else {
1186 Kokkos::Impl::throw_runtime_exception("deep_copy given views that would require a temporary allocation");
1187 }
1188 }
1189 else {
1190 Kokkos::fence();
1191 }
1192}
1193
1194template< class T , class ... P >
1195inline
1196typename Kokkos::DynRankView<T,P...>::HostMirror
1197create_mirror( const Kokkos::DynRankView<T,P...> & src
1198 , typename std::enable_if<
1199 ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1200 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1201 std::is_same< typename ViewTraits<T,P...>::specialize ,
1202 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1203 &&
1204 ! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1205 , Kokkos::LayoutStride >::value
1206 >::type *
1207 )
1208{
1209 typedef DynRankView<T,P...> src_type ;
1210 typedef typename src_type::HostMirror dst_type ;
1211
1212 typename src_type::array_layout layout = src.layout();
1213 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1214
1215 return dst_type(std::string(src.label()).append("_mirror"),
1216 Impl::reconstructLayout(layout, src.rank()+1));
1217}
1218
1219template< class T , class ... P >
1220inline
1221typename Kokkos::DynRankView<T,P...>::HostMirror
1222create_mirror( const Kokkos::DynRankView<T,P...> & src
1223 , typename std::enable_if<
1224 ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1225 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1226 std::is_same< typename ViewTraits<T,P...>::specialize ,
1227 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1228 &&
1229 std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
1230 , Kokkos::LayoutStride >::value
1231 >::type *
1232 )
1233{
1234 typedef DynRankView<T,P...> src_type ;
1235 typedef typename src_type::HostMirror dst_type ;
1236
1237 Kokkos::LayoutStride layout ;
1238
1239 layout.dimension[0] = src.extent(0);
1240 layout.dimension[1] = src.extent(1);
1241 layout.dimension[2] = src.extent(2);
1242 layout.dimension[3] = src.extent(3);
1243 layout.dimension[4] = src.extent(4);
1244 layout.dimension[5] = src.extent(5);
1245 layout.dimension[6] = src.extent(6);
1246 layout.dimension[7] = src.extent(7);
1247
1248 layout.stride[0] = src.stride_0();
1249 layout.stride[1] = src.stride_1();
1250 layout.stride[2] = src.stride_2();
1251 layout.stride[3] = src.stride_3();
1252 layout.stride[4] = src.stride_4();
1253 layout.stride[5] = src.stride_5();
1254 layout.stride[6] = src.stride_6();
1255 layout.stride[7] = src.stride_7();
1256
1257 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1258#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1259 layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1260#else
1261 layout.stride[src.rank()] = src.impl_map().stride_scalar();
1262#endif
1263
1264 return dst_type(std::string(src.label()).append("_mirror"),
1265 Impl::reconstructLayout(layout, src.rank()+1));
1266}
1267
1268template<class Space, class T, class ... P>
1269typename Impl::MirrorDRVType<Space,T,P ...>::view_type
1270create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
1271 , typename std::enable_if<
1272 ( std::is_same< typename ViewTraits<T,P...>::specialize ,
1273 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1274 std::is_same< typename ViewTraits<T,P...>::specialize ,
1275 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1276 >::type *) {
1277 typedef DynRankView<T,P...> src_type ;
1278 typename src_type::array_layout layout = src.layout();
1279 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1280 return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(
1281 src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1282}
1283
1284namespace Impl {
1285
1286template <unsigned N, typename T, typename... Args>
1287KOKKOS_FUNCTION auto as_view_of_rank_n(
1288 DynRankView<T, Args...> v,
1289 typename std::enable_if<
1290 ( std::is_same< typename ViewTraits<T,Args...>::specialize,
1291 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1292 std::is_same< typename ViewTraits<T,Args...>::specialize ,
1293 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1294 >::type*)
1295{
1296 if (v.rank() != N) {
1297 KOKKOS_IF_ON_HOST(
1298 const std::string message =
1299 "Converting DynRankView of rank " + std::to_string(v.rank()) +
1300 " to a View of mis-matched rank " + std::to_string(N) + "!";
1301 Kokkos::abort(message.c_str());)
1302 KOKKOS_IF_ON_DEVICE(
1303 Kokkos::abort("Converting DynRankView to a View of mis-matched rank!");)
1304 }
1305
1306 auto layout = v.impl_map().layout();
1307 layout.dimension[v.rank()] = Kokkos::dimension_scalar(v);
1308 return View<typename RankDataType<T, N>::type, Args...>(
1309 v.data(), Impl::reconstructLayout(layout, v.rank()+1));
1310}
1311
1312}
1313
1314} // end Kokkos
1315
1316#endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1317
1318#endif // defined(HAVE_SACADO_KOKKOSCONTAINERS)
1319
1321
1322#endif /* #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP */
expr expr expr bar false
#define T
Definition: Sacado_rad.hpp:573
const int N
const int fad_dim
int value
Base template specification for ScalarType.