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];
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];
234 l.dimension[7] = fad_size;
235 const size_t fad_stride = layout.stride[
fad_dim];
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];
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) {
303 l.dimension[7] = compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
306 const size_t fad_size = layout.dimension[
fad_dim];
308 l.dimension[7] = fad_size;
310 const size_t fad_stride = layout.stride[
fad_dim];
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 };
807 enum { is_assignable_data_type =
true };
809 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
810 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
811 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
813 template <
typename DT ,
typename ... DP ,
typename ST ,
typename ... SP >
815 void assign( Kokkos::DynRankView< DT , DP... > & dst
816 ,
const Kokkos::View< ST , SP... >& src )
820 std::is_same<
typename DstTraits::array_layout
821 , Kokkos::LayoutLeft >::value ||
822 std::is_same<
typename DstTraits::array_layout
823 , Kokkos::LayoutRight >::value ||
824 std::is_same<
typename DstTraits::array_layout
825 , Kokkos::LayoutStride >::value
829 std::is_same<
typename SrcTraits::array_layout
830 , Kokkos::LayoutLeft >::value ||
831 std::is_same<
typename SrcTraits::array_layout
832 , Kokkos::LayoutRight >::value ||
833 std::is_same<
typename SrcTraits::array_layout
834 , Kokkos::LayoutStride >::value
836 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
839 std::is_same<
typename DstTraits::value_type
840 ,
typename SrcTraits::value_type >::value ||
841 std::is_same<
typename DstTraits::value_type
842 ,
typename SrcTraits::const_value_type >::value ,
843 "View assignment must have same value type or const = non-const" );
845 typedef typename DstType::offset_type dst_offset_type;
846 typedef typename DstType::array_offset_type dst_array_offset_type;
847 dst.m_map.m_array_offset =
848 dst_array_offset_type(std::integral_constant<unsigned,0>(),
849 permute_fad_layout(src.m_map.m_array_offset.layout(),
851 dst.m_map.m_impl_offset =
852 dst_offset_type(std::integral_constant<unsigned,0>(),
853 src.m_map.m_impl_offset.layout() );
855 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
856 dst.m_rank = src.Rank ;
858 dst.m_map.m_fad_size = src.m_map.m_fad_size ;
859 dst.m_map.m_fad_stride = src.m_map.m_fad_stride ;
867 template<
class DstTraits ,
class SrcTraits >
868 class ViewMapping< DstTraits , SrcTraits ,
869 typename std::enable_if<(
870 Kokkos::Impl::MemorySpaceAccess
871 < typename DstTraits::memory_space
872 , typename SrcTraits::memory_space >::assignable
875 std::is_same< typename DstTraits::specialize , void >::value
878 std::is_same< typename SrcTraits::specialize
879 , ViewSpecializeSacadoFad >::value
880 ), Kokkos::Impl::ViewToDynRankViewTag >::type >
884 enum { is_assignable =
true };
885 enum { is_assignable_data_type =
true };
887 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
888 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
889 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
891 template <
typename DT ,
typename ... DP ,
typename ST ,
typename ... SP >
893 void assign( Kokkos::DynRankView< DT , DP... > & dst
894 ,
const Kokkos::View< ST , SP... >& src )
898 std::is_same<
typename DstTraits::array_layout
899 , Kokkos::LayoutLeft >::value ||
900 std::is_same<
typename DstTraits::array_layout
901 , Kokkos::LayoutRight >::value ||
902 std::is_same<
typename DstTraits::array_layout
903 , Kokkos::LayoutStride >::value
907 std::is_same<
typename SrcTraits::array_layout
908 , Kokkos::LayoutLeft >::value ||
909 std::is_same<
typename SrcTraits::array_layout
910 , Kokkos::LayoutRight >::value ||
911 std::is_same<
typename SrcTraits::array_layout
912 , Kokkos::LayoutStride >::value
914 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
917 std::is_same<
typename DstTraits::value_type
918 ,
typename SrcTraits::value_type >::value ||
919 std::is_same<
typename DstTraits::value_type
920 ,
typename SrcTraits::const_value_type >::value ,
921 "View assignment must have same value type or const = non-const" );
923 typedef typename DstType::offset_type dst_offset_type;
924 dst.m_map.m_impl_offset =
925 dst_offset_type(std::integral_constant<unsigned,0>(),
926 permute_fad_layout(src.m_map.m_array_offset.layout(),
929 dst.m_map.m_impl_handle = src.m_map.m_impl_handle ;
930 dst.m_rank = src.Rank ;
938 template <
typename T,
typename ... P>
939 struct is_dynrankview_fad< DynRankView<
T,P...> > {
940 typedef DynRankView<
T,P...> view_type;
941 static const bool value =
942 std::is_same<
typename view_type::specialize,
943 Impl::ViewSpecializeSacadoFad >::value ||
944 std::is_same<
typename view_type::specialize,
945 Impl::ViewSpecializeSacadoFadContiguous >::value;
948 template <
typename T,
typename ... P>
949 struct is_dynrankview_fad_contiguous< DynRankView<
T,P...> > {
950 typedef DynRankView<
T,P...> view_type;
951 static const bool value =
952 std::is_same<
typename view_type::specialize,
953 Impl::ViewSpecializeSacadoFadContiguous >::value;
956 template <
typename T,
typename ... P>
959 std::enable_if< is_dynrankview_fad< DynRankView<
T,P...> >::value,
unsigned >::type
960 dimension_scalar(
const DynRankView<T,P...>& view) {
961 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
962 return view.implementation_map().dimension_scalar();
964 return view.impl_map().dimension_scalar();
971 template<
class DT,
class ... DP >
973 const DynRankView<DT,DP...> & view ,
974 const typename Sacado::ScalarType<
typename DynRankView<DT,DP...>::value_type >::type & value
975 ,
typename std::enable_if<(
976 std::is_same<
typename ViewTraits<DT,DP...>::specialize
977 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
978 std::is_same<
typename ViewTraits<DT,DP...>::specialize
979 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
983 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
984 typename ViewTraits<DT,DP...>::non_const_value_type >::value
985 ,
"Can only deep copy into non-const type" );
987 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
991 template<
class DT,
class ... DP >
993 const DynRankView<DT,DP...> & view ,
994 const typename DynRankView<DT,DP...>::value_type & value
995 ,
typename std::enable_if<(
996 std::is_same<
typename ViewTraits<DT,DP...>::specialize
997 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
998 std::is_same<
typename ViewTraits<DT,DP...>::specialize
999 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
1003 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
1004 typename ViewTraits<DT,DP...>::non_const_value_type >::value
1005 ,
"Can only deep copy into non-const type" );
1007 Kokkos::Impl::DynRankViewFill< DynRankView<DT,DP...> >( view , value );
1010 template<
class DstType ,
class SrcType >
1013 (
const DstType & dst
1014 ,
const SrcType & src
1015 ,
typename std::enable_if<(
1016 ( std::is_same<
typename DstType::traits::specialize
1017 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1018 std::is_same<
typename DstType::traits::specialize
1019 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1021 ( std::is_same<
typename SrcType::traits::specialize
1022 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1023 std::is_same<
typename SrcType::traits::specialize
1024 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1026 ( Kokkos::is_dyn_rank_view<DstType>::value || Kokkos::is_dyn_rank_view<SrcType
1031 std::is_same<
typename DstType::traits::value_type ,
1032 typename DstType::traits::non_const_value_type >::value
1033 ,
"deep_copy requires non-const destination type" );
1035 typedef DstType dst_type ;
1036 typedef SrcType src_type ;
1038 typedef typename dst_type::execution_space dst_execution_space ;
1039 typedef typename src_type::execution_space src_execution_space ;
1040 typedef typename dst_type::memory_space dst_memory_space ;
1041 typedef typename src_type::memory_space src_memory_space ;
1043 enum { DstExecCanAccessSrc =
1044 Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename dst_execution_space::memory_space , src_memory_space >::value };
1046 enum { SrcExecCanAccessDst =
1047 Kokkos::Impl::VerifyExecutionCanAccessMemorySpace< typename src_execution_space::memory_space , dst_memory_space >::value };
1049 if ( (
void *) dst.data() != (
void*) src.data() ) {
1055 if ( rank(src) == 0 && rank(dst) == 0 )
1057 typedef typename dst_type::value_type::value_type value_type ;
1058 const size_t nbytes =
sizeof(value_type) * dst.span() ;
1059 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1061 else if ( std::is_same<
typename DstType::traits::value_type ,
1062 typename SrcType::traits::non_const_value_type >::value &&
1064 ( std::is_same<
typename DstType::traits::array_layout ,
1065 typename SrcType::traits::array_layout >::value
1067 ( std::is_same<
typename DstType::traits::array_layout ,
1068 typename Kokkos::LayoutLeft>::value
1070 std::is_same<
typename DstType::traits::array_layout ,
1071 typename Kokkos::LayoutRight>::value
1081 dst.span_is_contiguous() &&
1082 src.span_is_contiguous() &&
1083 dst.span() == src.span() &&
1084 dst.extent(0) == src.extent(0) &&
1085 dst.extent(1) == src.extent(1) &&
1086 dst.extent(2) == src.extent(2) &&
1087 dst.extent(3) == src.extent(3) &&
1088 dst.extent(4) == src.extent(4) &&
1089 dst.extent(5) == src.extent(5) &&
1090 dst.extent(6) == src.extent(6) &&
1091 dst.extent(7) == src.extent(7) ) {
1095 const size_t nbytes =
sizeof(
typename dst_type::value_type::value_type) * dst.span() ;
1098 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1100 else if ( std::is_same<
typename DstType::traits::value_type ,
1101 typename SrcType::traits::non_const_value_type >::value &&
1103 ( std::is_same<
typename DstType::traits::array_layout ,
1104 typename SrcType::traits::array_layout >::value
1106 std::is_same<
typename DstType::traits::array_layout ,
1107 typename Kokkos::LayoutStride>::value
1116 dst.span_is_contiguous() &&
1117 src.span_is_contiguous() &&
1118 dst.span() == src.span() &&
1119 dst.extent(0) == src.extent(0) &&
1120 dst.extent(1) == src.extent(1) &&
1121 dst.extent(2) == src.extent(2) &&
1122 dst.extent(3) == src.extent(3) &&
1123 dst.extent(4) == src.extent(4) &&
1124 dst.extent(5) == src.extent(5) &&
1125 dst.extent(6) == src.extent(6) &&
1126 dst.extent(7) == src.extent(7) &&
1127 dst.stride_0() == src.stride_0() &&
1128 dst.stride_1() == src.stride_1() &&
1129 dst.stride_2() == src.stride_2() &&
1130 dst.stride_3() == src.stride_3() &&
1131 dst.stride_4() == src.stride_4() &&
1132 dst.stride_5() == src.stride_5() &&
1133 dst.stride_6() == src.stride_6() &&
1134 dst.stride_7() == src.stride_7()
1137 const size_t nbytes =
sizeof(
typename dst_type::value_type::value_type) * dst.span() ;
1139 Kokkos::Impl::DeepCopy< dst_memory_space , src_memory_space >( dst.data() , src.data() , nbytes );
1141 else if ( DstExecCanAccessSrc ) {
1143 Kokkos::Impl::DynRankViewRemap< dst_type , src_type >( dst , src );
1145 else if ( SrcExecCanAccessDst ) {
1147 Kokkos::Impl::DynRankViewRemap< dst_type , src_type , src_execution_space >( dst , src );
1150 Kokkos::Impl::throw_runtime_exception(
"deep_copy given views that would require a temporary allocation");
1155 template<
class T ,
class ... P >
1157 typename Kokkos::DynRankView<
T,P...>::HostMirror
1158 create_mirror(
const Kokkos::DynRankView<T,P...> & src
1159 ,
typename std::enable_if<
1160 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1161 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1162 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1163 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1165 ! std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
1166 , Kokkos::LayoutStride >::value
1170 typedef DynRankView<
T,P...> src_type ;
1171 typedef typename src_type::HostMirror dst_type ;
1173 typename src_type::array_layout layout = src.layout();
1174 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1176 return dst_type(std::string(src.label()).append(
"_mirror"),
1177 Impl::reconstructLayout(layout, src.rank()+1));
1180 template<
class T ,
class ... P >
1182 typename Kokkos::DynRankView<
T,P...>::HostMirror
1183 create_mirror(
const Kokkos::DynRankView<T,P...> & src
1184 ,
typename std::enable_if<
1185 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1186 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1187 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1188 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1190 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
1191 , Kokkos::LayoutStride >::value
1195 typedef DynRankView<
T,P...> src_type ;
1196 typedef typename src_type::HostMirror dst_type ;
1198 Kokkos::LayoutStride layout ;
1200 layout.dimension[0] = src.extent(0);
1201 layout.dimension[1] = src.extent(1);
1202 layout.dimension[2] = src.extent(2);
1203 layout.dimension[3] = src.extent(3);
1204 layout.dimension[4] = src.extent(4);
1205 layout.dimension[5] = src.extent(5);
1206 layout.dimension[6] = src.extent(6);
1207 layout.dimension[7] = src.extent(7);
1209 layout.stride[0] = src.stride_0();
1210 layout.stride[1] = src.stride_1();
1211 layout.stride[2] = src.stride_2();
1212 layout.stride[3] = src.stride_3();
1213 layout.stride[4] = src.stride_4();
1214 layout.stride[5] = src.stride_5();
1215 layout.stride[6] = src.stride_6();
1216 layout.stride[7] = src.stride_7();
1218 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1219 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
1220 layout.stride[src.rank()] = src.implementation_map().stride_scalar();
1222 layout.stride[src.rank()] = src.impl_map().stride_scalar();
1225 return dst_type(std::string(src.label()).append(
"_mirror"),
1226 Impl::reconstructLayout(layout, src.rank()+1));
1229 template<
class Space,
class T,
class ... P>
1230 typename Impl::MirrorDRVType<Space,
T,P ...>::view_type
1231 create_mirror(
const Space& ,
const Kokkos::DynRankView<T,P...> & src
1232 ,
typename std::enable_if<
1233 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
1234 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
1235 std::is_same<
typename ViewTraits<T,P...>::specialize ,
1236 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1238 typedef DynRankView<
T,P...> src_type ;
1239 typename src_type::array_layout layout = src.layout();
1240 layout.dimension[src.rank()] = Kokkos::dimension_scalar(src);
1241 return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(
1242 src.label(),Impl::reconstructLayout(layout, src.rank()+1));
1247 #endif //defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1249 #endif // defined(HAVE_SACADO_KOKKOSCONTAINERS)
Base template specification for ScalarType.
#define KOKKOS_INLINE_FUNCTION