30 #ifndef KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
31 #define KOKKOS_DYN_RANK_VIEW_SACADO_FAD_HPP
38 #if defined(HAVE_SACADO_KOKKOSCONTAINERS)
42 #include "Kokkos_Core_fwd.hpp"
43 #include "Kokkos_Layout.hpp"
48 template<
class DataType ,
class ... Properties >
51 template<
class DataType ,
class ... Properties >
56 template<
class Space,
class T,
class ... P>
61 template <
typename view_type>
62 struct is_dynrankview_fad {
static const bool value =
false; };
64 template <
typename view_type>
65 struct is_dynrankview_fad_contiguous {
static const bool value =
false; };
69 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
78 template<
class T ,
class ... P >
80 typename Kokkos::DynRankView<
T,P...>::HostMirror
82 const Kokkos::DynRankView<T,P...> & src,
83 typename std::enable_if<
84 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
85 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
86 std::is_same<
typename ViewTraits<T,P...>::specialize ,
87 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
88 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
89 Kokkos::LayoutStride >::value >::type * = 0);
92 template<
class T ,
class ... P >
94 typename Kokkos::DynRankView<
T,P...>::HostMirror
96 const Kokkos::DynRankView<T,P...> & src,
97 typename std::enable_if<
98 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
99 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
100 std::is_same<
typename ViewTraits<T,P...>::specialize ,
101 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
102 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
103 Kokkos::LayoutStride >::value >::type * = 0);
105 template<
class Space,
class T,
class ... P>
106 typename Impl::MirrorDRVType<Space,
T,P ...>::view_type
109 const Kokkos::DynRankView<T,P...> & src,
110 typename std::enable_if<
111 std::is_same<
typename ViewTraits<T,P...>::specialize ,
112 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
113 std::is_same<
typename ViewTraits<T,P...>::specialize ,
114 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
118 #include "Kokkos_DynRankView.hpp"
124 struct DynRankDimTraits<Kokkos::Impl::ViewSpecializeSacadoFad> {
126 enum :
size_t{unspecified = ~size_t(0)};
131 static size_t computeRank(
const size_t N0
141 ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified && N0 == unspecified) ? 0
142 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified && N1 == unspecified) ? 0
143 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified && N2 == unspecified) ? 1
144 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified && N3 == unspecified) ? 2
145 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified && N4 == unspecified) ? 3
146 : ( (N7 == unspecified && N6 == unspecified && N5 == unspecified) ? 4
147 : ( (N7 == unspecified && N6 == unspecified) ? 5
148 : ( (N7 == unspecified) ? 6
153 template <
typename Layout>
155 static size_t computeRank(
const Layout& layout )
157 return computeRank( layout.dimension[0]
158 , layout.dimension[1]
159 , layout.dimension[2]
160 , layout.dimension[3]
161 , layout.dimension[4]
162 , layout.dimension[5]
163 , layout.dimension[6]
164 , layout.dimension[7] );
168 template <
typename Layout,
typename ... P>
170 static size_t computeRank(
const ViewCtorProp<P...>& ,
const Layout& layout )
172 size_t rank = computeRank( layout.dimension[0]
173 , layout.dimension[1]
174 , layout.dimension[2]
175 , layout.dimension[3]
176 , layout.dimension[4]
177 , layout.dimension[5]
178 , layout.dimension[6]
179 , layout.dimension[7] );
182 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
183 return (test_traits_check ==
true) ? rank+1 : rank;
189 template <
typename Layout>
191 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 )
193 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
194 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
195 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
196 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
197 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
198 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
199 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
200 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
201 const unsigned fad_dim = computeRank(layout);
202 const size_t fad_size = layout.dimension[fad_dim];
203 l.dimension[fad_dim] = 1;
204 l.dimension[7] = fad_size;
210 template <
typename Layout>
212 static typename std::enable_if< (std::is_same<Layout , Kokkos::LayoutStride>::value) , Layout>::type createLayout(
const Layout& layout )
214 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
216 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
218 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
220 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
222 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
224 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
226 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
228 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
231 const unsigned fad_dim = computeRank(layout);
232 const size_t fad_size = layout.dimension[fad_dim];
233 l.dimension[fad_dim] = 1;
234 l.dimension[7] = fad_size;
235 const size_t fad_stride = layout.stride[fad_dim];
236 l.stride[fad_dim] = 0;
237 l.stride[7] = fad_stride;
244 template <
typename Traits,
typename ... P>
246 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 )
248 using Layout =
typename Traits::array_layout;
250 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
251 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
252 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
253 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
254 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
255 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
256 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
257 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1 );
259 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
260 if (test_traits_check ==
true) {
261 l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
264 const unsigned fad_dim = computeRank(layout);
265 const size_t fad_size = layout.dimension[fad_dim];
266 l.dimension[fad_dim] = 1;
267 l.dimension[7] = fad_size;
275 template <
typename Traits,
typename ... P>
277 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 )
279 using Layout =
typename Traits::array_layout;
281 Layout l( layout.dimension[0] != unspecified ? layout.dimension[0] : 1
283 , layout.dimension[1] != unspecified ? layout.dimension[1] : 1
285 , layout.dimension[2] != unspecified ? layout.dimension[2] : 1
287 , layout.dimension[3] != unspecified ? layout.dimension[3] : 1
289 , layout.dimension[4] != unspecified ? layout.dimension[4] : 1
291 , layout.dimension[5] != unspecified ? layout.dimension[5] : 1
293 , layout.dimension[6] != unspecified ? layout.dimension[6] : 1
295 , layout.dimension[7] != unspecified ? layout.dimension[7] : 1
299 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
300 const unsigned fad_dim = computeRank(layout);
301 if (test_traits_check ==
true) {
302 l.dimension[fad_dim] = 1;
303 l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
306 const size_t fad_size = layout.dimension[fad_dim];
307 l.dimension[fad_dim] = 1;
308 l.dimension[7] = fad_size;
310 const size_t fad_stride = layout.stride[fad_dim];
311 l.stride[fad_dim] = 0;
312 l.stride[7] = fad_stride;
319 template <
typename ViewType,
typename ViewArg>
320 static ViewType createView(
const ViewArg& arg
330 typename ViewType::array_layout l( N0, N1, N2, N3, N4, N5, N6, N7 );
331 typename ViewType::array_layout l_fad = createLayout(l);
340 , l_fad.dimension[7] );
350 template <
unsigned>
struct AssignDim7 {
351 template <
typename Dst>
353 static void eval(Dst& dst,
const size_t& src_dim) {}
355 template <>
struct AssignDim7<0u> {
356 template <
typename Dst>
358 static void eval(Dst& dst,
const size_t& src_dim) {
364 template <
unsigned,
unsigned>
struct AssignFadDimStride {};
365 template <
unsigned StaticDim>
struct AssignFadDimStride<0u,StaticDim> {
366 template <
typename Src,
typename Dst>
368 static void eval(Dst& dst,
const Src& src) {
369 dst.m_stride.S0 = 0 ;
370 dst.m_stride.S1 = 0 ;
371 dst.m_stride.S2 = 0 ;
372 dst.m_stride.S3 = 0 ;
373 dst.m_stride.S4 = 0 ;
374 dst.m_stride.S5 = 0 ;
375 dst.m_stride.S6 = 0 ;
376 dst.m_stride.S7 = src.m_stride.S0 ;
385 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N0 );
388 template <
unsigned StaticDim>
struct AssignFadDimStride<1u,StaticDim> {
389 template <
typename Src,
typename Dst>
391 static void eval(Dst& dst,
const Src& src) {
392 dst.m_stride.S0 = src.m_stride.S0 ;
393 dst.m_stride.S1 = 0 ;
394 dst.m_stride.S2 = 0 ;
395 dst.m_stride.S3 = 0 ;
396 dst.m_stride.S4 = 0 ;
397 dst.m_stride.S5 = 0 ;
398 dst.m_stride.S6 = 0 ;
399 dst.m_stride.S7 = src.m_stride.S1 ;
401 dst.m_dim.N0 = src.m_dim.N0 ;
408 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N1 );
411 template <
unsigned StaticDim>
struct AssignFadDimStride<2u,StaticDim> {
412 template <
typename Src,
typename Dst>
414 static void eval(Dst& dst,
const Src& src) {
415 dst.m_stride.S0 = src.m_stride.S0 ;
416 dst.m_stride.S1 = src.m_stride.S1 ;
417 dst.m_stride.S2 = 0 ;
418 dst.m_stride.S3 = 0 ;
419 dst.m_stride.S4 = 0 ;
420 dst.m_stride.S5 = 0 ;
421 dst.m_stride.S6 = 0 ;
422 dst.m_stride.S7 = src.m_stride.S2 ;
424 dst.m_dim.N0 = src.m_dim.N0 ;
425 dst.m_dim.N1 = src.m_dim.N1 ;
431 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N2 );
434 template <
unsigned StaticDim>
struct AssignFadDimStride<3u,StaticDim> {
435 template <
typename Src,
typename Dst>
437 static void eval(Dst& dst,
const Src& src) {
438 dst.m_stride.S0 = src.m_stride.S0 ;
439 dst.m_stride.S1 = src.m_stride.S1 ;
440 dst.m_stride.S2 = src.m_stride.S2 ;
441 dst.m_stride.S3 = 0 ;
442 dst.m_stride.S4 = 0 ;
443 dst.m_stride.S5 = 0 ;
444 dst.m_stride.S6 = 0 ;
445 dst.m_stride.S7 = src.m_stride.S3 ;
447 dst.m_dim.N0 = src.m_dim.N0 ;
448 dst.m_dim.N1 = src.m_dim.N1 ;
449 dst.m_dim.N2 = src.m_dim.N2 ;
454 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N3 );
457 template <
unsigned StaticDim>
struct AssignFadDimStride<4u,StaticDim> {
458 template <
typename Src,
typename Dst>
460 static void eval(Dst& dst,
const Src& src) {
461 dst.m_stride.S0 = src.m_stride.S0 ;
462 dst.m_stride.S1 = src.m_stride.S1 ;
463 dst.m_stride.S2 = src.m_stride.S2 ;
464 dst.m_stride.S3 = src.m_stride.S3 ;
465 dst.m_stride.S4 = 0 ;
466 dst.m_stride.S5 = 0 ;
467 dst.m_stride.S6 = 0 ;
468 dst.m_stride.S7 = src.m_stride.S4 ;
470 dst.m_dim.N0 = src.m_dim.N0 ;
471 dst.m_dim.N1 = src.m_dim.N1 ;
472 dst.m_dim.N2 = src.m_dim.N2 ;
473 dst.m_dim.N3 = src.m_dim.N3 ;
477 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N4 );
480 template <
unsigned StaticDim>
struct AssignFadDimStride<5u,StaticDim> {
481 template <
typename Src,
typename Dst>
483 static void eval(Dst& dst,
const Src& src) {
484 dst.m_stride.S0 = src.m_stride.S0 ;
485 dst.m_stride.S1 = src.m_stride.S1 ;
486 dst.m_stride.S2 = src.m_stride.S2 ;
487 dst.m_stride.S3 = src.m_stride.S3 ;
488 dst.m_stride.S4 = src.m_stride.S4 ;
489 dst.m_stride.S5 = 0 ;
490 dst.m_stride.S6 = 0 ;
491 dst.m_stride.S7 = src.m_stride.S5 ;
493 dst.m_dim.N0 = src.m_dim.N0 ;
494 dst.m_dim.N1 = src.m_dim.N1 ;
495 dst.m_dim.N2 = src.m_dim.N2 ;
496 dst.m_dim.N3 = src.m_dim.N3 ;
497 dst.m_dim.N4 = src.m_dim.N4 ;
500 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N5 );
503 template <
unsigned StaticDim>
struct AssignFadDimStride<6u,StaticDim> {
504 template <
typename Src,
typename Dst>
506 static void eval(Dst& dst,
const Src& src) {
507 dst.m_stride.S0 = src.m_stride.S0 ;
508 dst.m_stride.S1 = src.m_stride.S1 ;
509 dst.m_stride.S2 = src.m_stride.S2 ;
510 dst.m_stride.S3 = src.m_stride.S3 ;
511 dst.m_stride.S4 = src.m_stride.S4 ;
512 dst.m_stride.S5 = src.m_stride.S5 ;
513 dst.m_stride.S6 = 0 ;
514 dst.m_stride.S7 = src.m_stride.S6 ;
516 dst.m_dim.N0 = src.m_dim.N0 ;
517 dst.m_dim.N1 = src.m_dim.N1 ;
518 dst.m_dim.N2 = src.m_dim.N2 ;
519 dst.m_dim.N3 = src.m_dim.N3 ;
520 dst.m_dim.N4 = src.m_dim.N4 ;
521 dst.m_dim.N5 = src.m_dim.N5 ;
523 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N6 );
526 template <
unsigned StaticDim>
struct AssignFadDimStride<7u,StaticDim> {
527 template <
typename Src,
typename Dst>
529 static void eval(Dst& dst,
const Src& src) {
530 dst.m_stride.S0 = src.m_stride.S0 ;
531 dst.m_stride.S1 = src.m_stride.S1 ;
532 dst.m_stride.S2 = src.m_stride.S2 ;
533 dst.m_stride.S3 = src.m_stride.S3 ;
534 dst.m_stride.S4 = src.m_stride.S4 ;
535 dst.m_stride.S5 = src.m_stride.S5 ;
536 dst.m_stride.S6 = src.m_stride.S6 ;
537 dst.m_stride.S7 = src.m_stride.S7 ;
539 dst.m_dim.N0 = src.m_dim.N0 ;
540 dst.m_dim.N1 = src.m_dim.N1 ;
541 dst.m_dim.N2 = src.m_dim.N2 ;
542 dst.m_dim.N3 = src.m_dim.N3 ;
543 dst.m_dim.N4 = src.m_dim.N4 ;
544 dst.m_dim.N5 = src.m_dim.N5 ;
545 dst.m_dim.N6 = src.m_dim.N6 ;
546 AssignDim7<StaticDim>::eval( dst.m_dim, src.m_dim.N7 );
551 template<
class SrcTraits ,
class ... Args >
553 < typename std::enable_if<(
554 std::is_same< typename SrcTraits::specialize ,
555 Kokkos::Impl::ViewSpecializeSacadoFad >::value
558 std::is_same< typename SrcTraits::array_layout
559 , Kokkos::LayoutLeft >::value ||
560 std::is_same< typename SrcTraits::array_layout
561 , Kokkos::LayoutRight >::value ||
562 std::is_same< typename SrcTraits::array_layout
563 , Kokkos::LayoutStride >::value
565 ), Kokkos::Impl::DynRankSubviewTag >::type
573 , R0 = bool(is_integral_extent<0,Args...>::value)
574 , R1 = bool(is_integral_extent<1,Args...>::value)
575 , R2 = bool(is_integral_extent<2,Args...>::value)
576 , R3 = bool(is_integral_extent<3,Args...>::value)
577 , R4 = bool(is_integral_extent<4,Args...>::value)
578 , R5 = bool(is_integral_extent<5,Args...>::value)
579 , R6 = bool(is_integral_extent<6,Args...>::value)
582 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
583 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
585 typedef Kokkos::LayoutStride array_layout ;
587 typedef typename SrcTraits::value_type value_type ;
589 typedef value_type******* data_type ;
593 typedef Kokkos::ViewTraits
596 ,
typename SrcTraits::device_type
597 ,
typename SrcTraits::memory_traits > traits_type ;
602 ,
typename SrcTraits::device_type
603 ,
typename SrcTraits::memory_traits > type ;
606 template<
class MemoryTraits >
609 static_assert( Kokkos::Impl::is_memory_traits< MemoryTraits >::value ,
"" );
611 typedef Kokkos::ViewTraits
614 ,
typename SrcTraits::device_type
615 , MemoryTraits > traits_type ;
620 ,
typename SrcTraits::device_type
621 , MemoryTraits > type ;
624 template <
class Arg0 =
int,
class Arg1 =
int,
class Arg2 =
int,
class Arg3 =
int,
class Arg4 =
int,
class Arg5 =
int,
class Arg6 =
int >
625 struct ExtentGenerator {
626 template <
typename dimension>
628 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() )
630 return SubviewExtents< 7 , rank >( dim , arg0 , arg1 , arg2 , arg3 ,
631 arg4 , arg5 , arg6 );
635 template <
class Arg0 =
int,
class Arg1 =
int,
class Arg2 =
int,
class Arg3 =
int,
class Arg4 =
int,
class Arg5 =
int,
class Arg6 =
int >
636 struct ArrayExtentGenerator {
637 template <
typename dimension>
639 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() )
641 return SubviewExtents< 8 , rank+1 >( dim , arg0 , arg1 , arg2 , arg3 , arg4 , arg5 , arg6 , Kokkos::ALL() );
645 typedef DynRankView< value_type , array_layout , typename SrcTraits::device_type , typename SrcTraits::memory_traits > ret_type;
647 template <
typename T ,
class ... P >
649 static ret_type subview(
const unsigned src_rank , Kokkos::DynRankView< T , P...>
const & src , Args ... args )
652 typedef ViewMapping< traits_type, typename traits_type::specialize> DstType ;
653 typedef ViewMapping< SrcTraits, typename SrcTraits::specialize> SrcType;
654 enum { FadStaticDim = SrcType::FadStaticDimension };
655 typedef typename std::conditional< (rank==0) , ViewDimension<>
656 ,
typename std::conditional< (rank==1) , ViewDimension<0>
657 ,
typename std::conditional< (rank==2) , ViewDimension<0,0>
658 ,
typename std::conditional< (rank==3) , ViewDimension<0,0,0>
659 ,
typename std::conditional< (rank==4) , ViewDimension<0,0,0,0>
660 ,
typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0>
661 ,
typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0>
662 , ViewDimension<0,0,0,0,0,0,0>
663 >::type >::type >::type >::type >::type >::type >::type DstDimType ;
664 typedef typename std::conditional< (rank==0) , ViewDimension<FadStaticDim>
665 ,
typename std::conditional< (rank==1) , ViewDimension<0,FadStaticDim>
666 ,
typename std::conditional< (rank==2) , ViewDimension<0,0,FadStaticDim>
667 ,
typename std::conditional< (rank==3) , ViewDimension<0,0,0,FadStaticDim>
668 ,
typename std::conditional< (rank==4) , ViewDimension<0,0,0,0,FadStaticDim>
669 ,
typename std::conditional< (rank==5) , ViewDimension<0,0,0,0,0,FadStaticDim>
670 ,
typename std::conditional< (rank==6) , ViewDimension<0,0,0,0,0,0,FadStaticDim>
671 , ViewDimension<0,0,0,0,0,0,0,FadStaticDim>
672 >::type >::type >::type >::type >::type >::type >::type DstArrayDimType ;
674 typedef ViewOffset< DstDimType , Kokkos::LayoutStride > dst_offset_type ;
675 typedef ViewOffset< DstArrayDimType , Kokkos::LayoutStride > dst_array_offset_type ;
676 typedef typename DstType::handle_type dst_handle_type ;
680 const SubviewExtents< 7 , rank > extents =
681 ExtentGenerator< Args ... >::generator(
682 src.m_map.m_impl_offset.m_dim , args... ) ;
683 const SubviewExtents< 8 , rank+1 > array_extents =
684 ArrayExtentGenerator< Args ... >::generator(
685 src.m_map.m_array_offset.m_dim , args... ) ;
687 dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
688 dst_array_offset_type temparraydst(
689 src.m_map.m_array_offset , array_extents ) ;
691 dst.m_track = src.m_track ;
693 dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
694 dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
695 dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
696 dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
697 dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
698 dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
699 dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
701 dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0;
702 dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1;
703 dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2;
704 dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3;
705 dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4;
706 dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5;
707 dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6;
716 AssignFadDimStride<rank,FadStaticDim>::eval( dst.m_map.m_array_offset, temparraydst );
718 dst.m_track = src.m_track ;
720 dst.m_map.m_impl_handle =
722 src.m_map.m_impl_handle +
723 src.m_map.m_array_offset( array_extents.domain_offset(0)
724 , array_extents.domain_offset(1)
725 , array_extents.domain_offset(2)
726 , array_extents.domain_offset(3)
727 , array_extents.domain_offset(4)
728 , array_extents.domain_offset(5)
729 , array_extents.domain_offset(6)
730 , array_extents.domain_offset(7)
733 dst.m_map.m_fad_size = src.m_map.m_fad_size;
734 dst.m_map.m_fad_stride = src.m_map.m_fad_stride.value;
736 dst.m_rank = ( src_rank > 0 ? unsigned(R0) : 0 )
737 + ( src_rank > 1 ? unsigned(R1) : 0 )
738 + ( src_rank > 2 ? unsigned(R2) : 0 )
739 + ( src_rank > 3 ? unsigned(R3) : 0 )
740 + ( src_rank > 4 ? unsigned(R4) : 0 )
741 + ( src_rank > 5 ? unsigned(R5) : 0 )
742 + ( src_rank > 6 ? unsigned(R6) : 0 ) ;
749 template <
unsigned>
struct AssignFadDim7 {
750 template <
typename Src,
typename Dst>
752 static void eval(Dst& dst,
const Src& src ,
const unsigned dim ) {}
755 template <>
struct AssignFadDim7<0u> {
756 template <
typename Src,
typename Dst>
758 static void eval(Dst& dst,
const Src& src ,
const unsigned dim ) {
759 dst.m_dim.N7 = src.m_dim.extent(dim);
764 template <
typename Layout>
767 permute_fad_layout(
const Layout& src,
const unsigned rank) {
769 dst.dimension[rank] = 1;
770 dst.dimension[7] = src.dimension[rank];
775 permute_fad_layout(
const LayoutStride& src,
const unsigned rank) {
776 LayoutStride dst = src;
777 dst.dimension[rank] = 1;
778 dst.stride[rank] = 1;
779 dst.dimension[7] = src.dimension[rank];
780 dst.stride[7] = src.stride[rank];
788 template<
class DstTraits ,
class SrcTraits >
789 class ViewMapping< DstTraits , SrcTraits ,
790 typename std::enable_if<(
791 Kokkos::Impl::MemorySpaceAccess
792 < typename DstTraits::memory_space
793 , typename SrcTraits::memory_space >::assignable
796 std::is_same< typename DstTraits::specialize
797 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
800 std::is_same< typename SrcTraits::specialize
801 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
802 ), Kokkos::Impl::ViewToDynRankViewTag >::type >
806 enum { is_assignable =
true };
808 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
809 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
810 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
812 template <
typename DT ,
typename ... DP ,
typename ST ,
typename ... SP >
814 void assign( Kokkos::DynRankView< DT , DP... > & dst
815 ,
const Kokkos::View< ST , SP... >& src )
819 std::is_same<
typename DstTraits::array_layout
820 , Kokkos::LayoutLeft >::value ||
821 std::is_same<
typename DstTraits::array_layout
822 , Kokkos::LayoutRight >::value ||
823 std::is_same<
typename DstTraits::array_layout
824 , Kokkos::LayoutStride >::value
828 std::is_same<
typename SrcTraits::array_layout
829 , Kokkos::LayoutLeft >::value ||
830 std::is_same<
typename SrcTraits::array_layout
831 , Kokkos::LayoutRight >::value ||
832 std::is_same<
typename SrcTraits::array_layout
833 , Kokkos::LayoutStride >::value
835 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
838 std::is_same<
typename DstTraits::value_type
839 ,
typename SrcTraits::value_type >::value ||
840 std::is_same<
typename DstTraits::value_type
841 ,
typename SrcTraits::const_value_type >::value ,
842 "View assignment must have same value type or const = non-const" );
844 typedef typename DstType::offset_type dst_offset_type;
845 typedef typename DstType::array_offset_type dst_array_offset_type;
846 dst.m_map.m_array_offset =
847 dst_array_offset_type(std::integral_constant<unsigned,0>(),
848 permute_fad_layout(src.m_map.m_array_offset.layout(),
850 dst.m_map.m_impl_offset =
851 dst_offset_type(std::integral_constant<unsigned,0>(),
852 src.m_map.m_impl_offset.layout() );
854 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
855 dst.m_rank = src.Rank ;
857 dst.m_map.m_fad_size = src.m_map.m_fad_size ;
858 dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
866 template<
class DstTraits ,
class SrcTraits >
867 class ViewMapping< DstTraits , SrcTraits ,
868 typename std::enable_if<(
869 Kokkos::Impl::MemorySpaceAccess
870 < typename DstTraits::memory_space
871 , typename SrcTraits::memory_space >::assignable
874 std::is_same< typename DstTraits::specialize , void >::value
877 std::is_same< typename SrcTraits::specialize
878 , ViewSpecializeSacadoFad >::value
879 ), Kokkos::Impl::ViewToDynRankViewTag >::type >
883 enum { is_assignable =
true };
885 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
886 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
887 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
889 template <
typename DT ,
typename ... DP ,
typename ST ,
typename ... SP >
891 void assign( Kokkos::DynRankView< DT , DP... > & dst
892 ,
const Kokkos::View< ST , SP... >& src )
896 std::is_same<
typename DstTraits::array_layout
897 , Kokkos::LayoutLeft >::value ||
898 std::is_same<
typename DstTraits::array_layout
899 , Kokkos::LayoutRight >::value ||
900 std::is_same<
typename DstTraits::array_layout
901 , Kokkos::LayoutStride >::value
905 std::is_same<
typename SrcTraits::array_layout
906 , Kokkos::LayoutLeft >::value ||
907 std::is_same<
typename SrcTraits::array_layout
908 , Kokkos::LayoutRight >::value ||
909 std::is_same<
typename SrcTraits::array_layout
910 , Kokkos::LayoutStride >::value
912 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
915 std::is_same<
typename DstTraits::value_type
916 ,
typename SrcTraits::value_type >::value ||
917 std::is_same<
typename DstTraits::value_type
918 ,
typename SrcTraits::const_value_type >::value ,
919 "View assignment must have same value type or const = non-const" );
921 typedef typename DstType::offset_type dst_offset_type;
922 dst.m_map.m_impl_offset =
923 dst_offset_type(std::integral_constant<unsigned,0>(),
924 permute_fad_layout(src.m_map.m_array_offset.layout(),
927 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
928 dst.m_rank = src.Rank ;
936 template <
typename T,
typename ... P>
937 struct is_dynrankview_fad< DynRankView<
T,P...> > {
938 typedef DynRankView<
T,P...> view_type;
939 static const bool value =
940 std::is_same<
typename view_type::specialize,
941 Impl::ViewSpecializeSacadoFad >::value ||
942 std::is_same<
typename view_type::specialize,
943 Impl::ViewSpecializeSacadoFadContiguous >::value;
946 template <
typename T,
typename ... P>
947 struct is_dynrankview_fad_contiguous< DynRankView<
T,P...> > {
948 typedef DynRankView<
T,P...> view_type;
949 static const bool value =
950 std::is_same<
typename view_type::specialize,
951 Impl::ViewSpecializeSacadoFadContiguous >::value;
954 template <
typename T,
typename ... P>
957 std::enable_if< is_dynrankview_fad< DynRankView<
T,P...> >::value,
unsigned >::type
958 dimension_scalar(
const DynRankView<T,P...>& view) {
959 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
960 return view.implementation_map().dimension_scalar();
962 return view.impl_map().dimension_scalar();
969 template<
class DT,
class ... DP >
971 const DynRankView<DT,DP...> & view ,
972 const typename Sacado::ScalarType<
typename DynRankView<DT,DP...>::value_type >::type & value
973 ,
typename std::enable_if<(
974 std::is_same<
typename ViewTraits<DT,DP...>::specialize
975 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
976 std::is_same<
typename ViewTraits<DT,DP...>::specialize
977 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
981 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
982 typename ViewTraits<DT,DP...>::non_const_value_type >::value
983 ,
"Can only deep copy into non-const type" );
985 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
989 template<
class DT,
class ... DP >
991 const DynRankView<DT,DP...> & view ,
992 const typename DynRankView<DT,DP...>::value_type & value
993 ,
typename std::enable_if<(
994 std::is_same<
typename ViewTraits<DT,DP...>::specialize
995 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
996 std::is_same<
typename ViewTraits<DT,DP...>::specialize
997 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1001 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1002 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1003 ,
"Can only deep copy into non-const type" );
1005 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
1008 template<
class DstType ,
class SrcType >
1011 (
const DstType & dst
1012 ,
const SrcType & src
1013 ,
typename std::enable_if<(
1014 ( std::is_same<
typename DstType::traits::specialize
1015 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1016 std::is_same<
typename DstType::traits::specialize
1017 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1019 ( std::is_same<
typename SrcType::traits::specialize
1020 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1021 std::is_same<
typename SrcType::traits::specialize
1022 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1024 ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType
1029 std::is_same<
typename DstType::traits::value_type ,
1030 typename DstType::traits::non_const_value_type >::value
1031 ,
"deep_copy requires non-const destination type" );
1033 typedef DstType dst_type ;
1034 typedef SrcType src_type ;
1036 typedef typename dst_type::execution_space dst_execution_space ;
1037 typedef typename src_type::execution_space src_execution_space ;
1038 typedef typename dst_type::memory_space dst_memory_space ;
1039 typedef typename src_type::memory_space src_memory_space ;
1041 enum { DstExecCanAccessSrc =
1042 Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
1044 enum { SrcExecCanAccessDst =
1045 Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename src_execution_space::memory_space , dst_memory_space >::value };
1047 if ( (
void *) dst.data() != (
void*) src.data() ) {
1053 if ( rank(src) == 0 && rank(dst) == 0 )
1055 typedef typename dst_type::value_type::value_type value_type ;
1056 const size_t nbytes =
sizeof(value_type) * dst.span() ;
1057 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1059 else if ( std::is_same<
typename DstType::traits::value_type ,
1060 typename SrcType::traits::non_const_value_type >::value &&
1062 ( std::is_same<
typename DstType::traits::array_layout ,
1063 typename SrcType::traits::array_layout >::value
1065 ( std::is_same<
typename DstType::traits::array_layout ,
1066 typename Kokkos::LayoutLeft>::value
1068 std::is_same<
typename DstType::traits::array_layout ,
1069 typename Kokkos::LayoutRight>::value
1079 dst.span_is_contiguous() &&
1080 src.span_is_contiguous() &&
1081 dst.span() == src.span() &&
1082 dst.extent(0) == src.extent(0) &&
1083 dst.extent(1) == src.extent(1) &&
1084 dst.extent(2) == src.extent(2) &&
1085 dst.extent(3) == src.extent(3) &&
1086 dst.extent(4) == src.extent(4) &&
1087 dst.extent(5) == src.extent(5) &&
1088 dst.extent(6) == src.extent(6) &&
1089 dst.extent(7) == src.extent(7) ) {
1093 const size_t nbytes =
sizeof(
typename dst_type::value_type::value_type) * dst.span() ;
1096 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1098 else if ( std::is_same<
typename DstType::traits::value_type ,
1099 typename SrcType::traits::non_const_value_type >::value &&
1101 ( std::is_same<
typename DstType::traits::array_layout ,
1102 typename SrcType::traits::array_layout >::value
1104 std::is_same<
typename DstType::traits::array_layout ,
1105 typename Kokkos::LayoutStride>::value
1114 dst.span_is_contiguous() &&
1115 src.span_is_contiguous() &&
1116 dst.span() == src.span() &&
1117 dst.extent(0) == src.extent(0) &&
1118 dst.extent(1) == src.extent(1) &&
1119 dst.extent(2) == src.extent(2) &&
1120 dst.extent(3) == src.extent(3) &&
1121 dst.extent(4) == src.extent(4) &&
1122 dst.extent(5) == src.extent(5) &&
1123 dst.extent(6) == src.extent(6) &&
1124 dst.extent(7) == src.extent(7) &&
1125 dst.stride_0() == src.stride_0() &&
1126 dst.stride_1() == src.stride_1() &&
1127 dst.stride_2() == src.stride_2() &&
1128 dst.stride_3() == src.stride_3() &&
1129 dst.stride_4() == src.stride_4() &&
1130 dst.stride_5() == src.stride_5() &&
1131 dst.stride_6() == src.stride_6() &&
1132 dst.stride_7() == src.stride_7()
1135 const size_t nbytes =
sizeof(
typename dst_type::value_type::value_type) * dst.span() ;
1137 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1139 else if ( DstExecCanAccessSrc ) {
1141 Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1143 else if ( SrcExecCanAccessDst ) {
1145 Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1148 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
1153 template<
class T ,
class ... P >
1155 typename Kokkos::DynRankView<
T,P...>::HostMirror
1156 create_mirror(
const Kokkos::DynRankView<T,P...> & src
1157 ,
typename std::enable_if<
1158 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1159 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1160 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1161 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1163 ! std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
1164 , Kokkos::LayoutStride >::value
1168 typedef DynRankView<
T,P...> src_type ;
1169 typedef typename src_type::HostMirror dst_type ;
1171 typename src_type::array_layout layout = src.layout();
1172 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1174 return dst_type(std::string(src.label()).append(
"_mirror"),
1175 Impl::reconstructLayout(layout, src.rank()+1));
1178 template<
class T ,
class ... P >
1180 typename Kokkos::DynRankView<
T,P...>::HostMirror
1181 create_mirror(
const Kokkos::DynRankView<T,P...> & src
1182 ,
typename std::enable_if<
1183 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1184 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1185 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1186 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1188 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
1189 , Kokkos::LayoutStride >::value
1193 typedef DynRankView<
T,P...> src_type ;
1194 typedef typename src_type::HostMirror dst_type ;
1196 Kokkos::LayoutStride layout ;
1198 layout.dimension[0] = src.extent(0);
1199 layout.dimension[1] = src.extent(1);
1200 layout.dimension[2] = src.extent(2);
1201 layout.dimension[3] = src.extent(3);
1202 layout.dimension[4] = src.extent(4);
1203 layout.dimension[5] = src.extent(5);
1204 layout.dimension[6] = src.extent(6);
1205 layout.dimension[7] = src.extent(7);
1207 layout.stride[0] = src.stride_0();
1208 layout.stride[1] = src.stride_1();
1209 layout.stride[2] = src.stride_2();
1210 layout.stride[3] = src.stride_3();
1211 layout.stride[4] = src.stride_4();
1212 layout.stride[5] = src.stride_5();
1213 layout.stride[6] = src.stride_6();
1214 layout.stride[7] = src.stride_7();
1216 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1217 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1218 layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1220 layout.stride[src.rank()] = src.impl_map().stride_scalar();
1223 return dst_type(std::string(src.label()).append(
"_mirror"),
1224 Impl::reconstructLayout(layout, src.rank()+1));
1227 template<
class Space,
class T,
class ... P>
1228 typename Impl::MirrorDRVType<Space,
T,P ...>::view_type
1229 create_mirror(
const Space& ,
const Kokkos::DynRankView<T,P...> & src
1230 ,
typename std::enable_if<
1231 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1232 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1233 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1234 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1236 typedef DynRankView<
T,P...> src_type ;
1237 typename src_type::array_layout layout = src.layout();
1238 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1239 return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(
1240 src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1245 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1247 #endif // defined(HAVE_SACADO_KOKKOSCONTAINERS)
Base template specification for ScalarType.
#define KOKKOS_INLINE_FUNCTION