30 #ifndef KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP 31 #define KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP 34 #if defined(HAVE_SACADO_KOKKOSCORE) 36 #include "Kokkos_Core.hpp" 37 #include "Kokkos_Macros.hpp" 44 template <
typename view_type>
45 struct is_view_fad {
static const bool value =
false; };
48 template <
typename view_type>
58 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) 61 #include "impl/KokkosExp_ViewMapping.hpp" 64 #define SACADO_SUPPORT_RANK_8 0 69 namespace Experimental {
72 struct ViewSpecializeSacadoFad {};
74 template<
class ... Args >
75 struct is_ViewSpecializeSacadoFad {
enum { value =
false }; };
77 template<
class D ,
class ... P ,
class ... Args >
78 struct is_ViewSpecializeSacadoFad<
Kokkos::View<D,P...> , Args... > {
80 std::is_same<
typename Kokkos::ViewTraits<
D,P...>::specialize
81 , ViewSpecializeSacadoFad >::value
83 ( (
sizeof...(Args) == 0 ) ||
84 is_ViewSpecializeSacadoFad< Args... >::value ) };
93 template <
typename T,
typename ... P>
94 struct is_view_fad< View<
T,P...> > {
95 typedef View<
T,P...> view_type;
96 static const bool value =
97 std::is_same<
typename view_type::specialize,
98 Experimental::Impl::ViewSpecializeSacadoFad >::value;
101 template <
typename T,
typename ... P>
104 std::enable_if< is_view_fad< View<
T,P...> >::value,
unsigned >::type
106 return view.implementation_map().dimension_scalar();
109 template <
typename ViewType,
typename Enabled =
void>
110 struct ContiguousArrayType {
111 typedef ViewType type;
114 template <
typename D,
typename ... P>
115 struct ContiguousArrayType< View<
D,P...>,
116 typename
std::enable_if< is_view_fad< View<D,P...> >::value >::type > {
117 typedef View<
D,P...> view_type;
118 typedef typename view_type::data_type data_type;
119 typedef typename view_type::array_layout layout;
120 typedef typename view_type::device_type device;
121 typedef typename view_type::memory_traits memory;
122 typedef View<data_type,LayoutContiguous<layout>,device,memory> type;
126 template<
class DT,
class ... DP >
128 const View<DT,DP...> & view ,
129 const typename Sacado::ScalarType<
typename View<DT,DP...>::value_type >::type & value
130 ,
typename std::enable_if<(
131 std::is_same<
typename ViewTraits<DT,DP...>::specialize
132 , Kokkos::Experimental::Impl::ViewSpecializeSacadoFad >::value
136 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
137 typename ViewTraits<DT,DP...>::non_const_value_type >::value
138 ,
"Can only deep copy into non-const type" );
140 Kokkos::Experimental::Impl::ViewFill< View<DT,DP...> >( view , value );
144 template<
class DT,
class ... DP >
146 const View<DT,DP...> & view ,
147 const typename View<DT,DP...>::value_type & value
148 ,
typename std::enable_if<(
149 std::is_same<
typename ViewTraits<DT,DP...>::specialize
150 , Kokkos::Experimental::Impl::ViewSpecializeSacadoFad >::value
154 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
155 typename ViewTraits<DT,DP...>::non_const_value_type >::value
156 ,
"Can only deep copy into non-const type" );
158 Kokkos::Experimental::Impl::ViewFill< View<DT,DP...> >( view , value );
162 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
164 void deep_copy(
const View<DT,DP...> & dst ,
165 const View<ST,SP...> & src
166 ,
typename std::enable_if<(
167 std::is_same<
typename ViewTraits<DT,DP...>::specialize
168 , Kokkos::Experimental::Impl::ViewSpecializeSacadoFad >::value
170 std::is_same<
typename ViewTraits<ST,SP...>::specialize
171 , Kokkos::Experimental::Impl::ViewSpecializeSacadoFad >::value
175 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
176 typename ViewTraits<DT,DP...>::non_const_value_type >::value
177 ,
"Deep copy destination must be non-const" );
180 (
unsigned(ViewTraits<DT,DP...>::rank) ==
181 unsigned(ViewTraits<ST,SP...>::rank) )
182 ,
"Deep copy destination and source must have same rank" );
184 typedef typename View<DT,DP...>::array_type dst_array_type;
185 typedef typename View<ST,SP...>::array_type src_array_type;
187 typename ContiguousArrayType< dst_array_type >::type( dst ) ,
188 typename ContiguousArrayType< src_array_type >::type( src ) );
196 namespace Experimental {
199 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
200 struct FadViewDataAnalysis
204 typedef ViewArrayAnalysis< DataType > array_analysis ;
209 typedef ViewSpecializeSacadoFad specialize ;
211 typedef typename array_analysis::dimension dimension ;
212 typedef typename array_analysis::value_type value_type ;
213 typedef typename array_analysis::const_value_type const_value_type ;
214 typedef typename array_analysis::non_const_value_type non_const_value_type ;
218 ViewDataType< value_type , dimension >::type type ;
220 ViewDataType< const_value_type , dimension >::type const_type ;
222 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
227 enum { is_const = std::is_same< value_type , const_value_type >::value };
231 std::conditional< is_const , const ScalarType , ScalarType >::type
234 typedef ScalarType non_const_scalar_type ;
235 typedef const ScalarType const_scalar_type ;
237 #if SACADO_SUPPORT_RANK_8 243 unsigned(array_analysis::dimension::rank) == 8 ,
244 typename array_analysis::dimension,
245 typename array_analysis::dimension::
246 template append<( DimFad ? DimFad + 1 : 0 )>::type >::type
252 typedef typename array_analysis::dimension::
253 template append<( DimFad ? DimFad + 1 : 0 )>::type
262 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
265 ViewDataType< const_scalar_type , scalar_dimension >::type
266 const_scalar_array_type ;
269 ViewDataType< non_const_scalar_type , scalar_dimension >::type
270 non_const_scalar_array_type ;
278 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
279 struct FadViewDataAnalysis<DataType, LayoutContiguous<ArrayLayout>, ScalarType, DimFad>
283 typedef ViewArrayAnalysis< DataType > array_analysis ;
288 typedef void specialize ;
290 typedef typename array_analysis::dimension dimension ;
291 typedef typename array_analysis::value_type value_type ;
292 typedef typename array_analysis::const_value_type const_value_type ;
293 typedef typename array_analysis::non_const_value_type non_const_value_type ;
297 ViewDataType< value_type , dimension >::type type ;
299 ViewDataType< const_value_type , dimension >::type const_type ;
301 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
304 typedef type scalar_array_type ;
305 typedef const_type const_scalar_array_type ;
306 typedef non_const_type non_const_scalar_array_type ;
316 namespace Fad {
template<
typename >
class DFad ; }
317 namespace CacheFad {
template<
typename >
class DFad ; }
318 namespace ELRFad {
template<
typename >
class DFad ; }
319 namespace ELRCacheFad {
template<
typename >
class DFad ; }
321 namespace Fad {
template<
typename ,
int >
class SFad ; }
322 namespace CacheFad {
template<
typename ,
int >
class SFad ; }
323 namespace ELRFad {
template<
typename ,
int >
class SFad ; }
324 namespace ELRCacheFad {
template<
typename ,
int >
class SFad ; }
326 namespace Fad {
template<
typename ,
int >
class SLFad ; }
327 namespace CacheFad {
template<
typename ,
int >
class SLFad ; }
328 namespace ELRFad {
template<
typename ,
int >
class SLFad ; }
329 namespace ELRCacheFad {
template<
typename ,
int >
class SLFad ; }
333 namespace Experimental {
336 #define KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( NS ) \ 337 template< class DataType , class ArrayLayout , typename ScalarType > \ 338 struct ViewDataAnalysis \ 341 , Sacado:: NS ::DFad< ScalarType > \ 342 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , 0 > {}; \ 344 template< class DataType , class ArrayLayout , typename ScalarType , int N > \ 345 struct ViewDataAnalysis \ 348 , Sacado:: NS ::SFad< ScalarType , N > \ 349 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \ 350 int(Sacado::StaticSize< Sacado:: NS ::SFad< ScalarType , N > >::value) \ 353 template< class DataType , class ArrayLayout , typename ScalarType , int N > \ 354 struct ViewDataAnalysis \ 357 , Sacado:: NS ::SLFad< ScalarType , N > \ 358 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \ 359 int(Sacado::StaticSize< Sacado:: NS ::SLFad< ScalarType , N > >::value) \ 362 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( Fad )
363 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( CacheFad )
364 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRFad )
365 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRCacheFad )
367 #undef KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD 376 namespace Experimental {
379 template<
class Traits >
380 class ViewMapping< Traits ,
381 typename
std::enable_if<
382 ( std::is_same< typename Traits::specialize
383 , ViewSpecializeSacadoFad >::value
385 ( std::is_same< typename Traits::array_layout
386 , Kokkos::LayoutLeft >::value
388 std::is_same< typename Traits::array_layout
389 , Kokkos::LayoutRight >::value
391 std::is_same< typename Traits::array_layout
392 , Kokkos::LayoutStride >::value
398 template< class ,
class ... >
friend class ViewMapping ;
399 template< class ,
class ... >
friend class Kokkos::Experimental::View ;
401 typedef typename Traits::value_type fad_type ;
404 std::add_const< fad_value_type >::type const_fad_value_type ;
410 enum { FadStaticStride =
411 std::is_same<
typename Traits::array_layout
412 , Kokkos::LayoutRight >::value ? 1 : 0 };
416 typedef fad_value_type * handle_type ;
418 typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
420 #if SACADO_SUPPORT_RANK_8 425 <
typename std::conditional<
426 unsigned(array_analysis::dimension::rank) == 8,
427 typename array_analysis::dimension,
428 typename array_analysis::dimension::
429 template append<( FadStaticDimension ? FadStaticDimension + 1 : 0 )>::type >::type
430 ,
typename Traits::array_layout
438 <
typename array_analysis::dimension::
439 template append<( FadStaticDimension ? FadStaticDimension + 1 : 0 )>::type
440 ,
typename Traits::array_layout
446 handle_type m_handle ;
447 offset_type m_offset ;
448 sacado_size_type m_fad_size ;
449 sacado_stride_type m_fad_stride ;
456 enum { Rank = Traits::dimension::rank };
459 template<
typename iType >
461 {
return unsigned(r) < unsigned(Rank) ? m_offset.m_dim.extent(r) : 1 ; }
464 typename Traits::array_layout layout()
const 465 {
return typename Traits::array_layout(
466 0 <
unsigned(Rank) ? m_offset.dimension_0() : 0,
467 1 < unsigned(Rank) ? m_offset.dimension_1() : 0,
468 2 < unsigned(Rank) ? m_offset.dimension_2() : 0,
469 3 < unsigned(Rank) ? m_offset.dimension_3() : 0,
470 4 < unsigned(Rank) ? m_offset.dimension_4() : 0,
471 5 < unsigned(Rank) ? m_offset.dimension_5() : 0,
472 6 < unsigned(Rank) ? m_offset.dimension_6() : 0,
473 7 < unsigned(Rank) ? m_offset.dimension_7() : 0
478 {
return 0 < unsigned(Rank) ? m_offset.dimension_0() : 1 ; }
481 {
return 1 < unsigned(Rank) ? m_offset.dimension_1() : 1 ; }
484 {
return 2 < unsigned(Rank) ? m_offset.dimension_2() : 1 ; }
487 {
return 3 < unsigned(Rank) ? m_offset.dimension_3() : 1 ; }
490 {
return 4 < unsigned(Rank) ? m_offset.dimension_4() : 1 ; }
493 {
return 5 < unsigned(Rank) ? m_offset.dimension_5() : 1 ; }
496 {
return 6 < unsigned(Rank) ? m_offset.dimension_6() : 1 ; }
499 {
return 7 < unsigned(Rank) ? m_offset.dimension_7() : 1 ; }
503 using is_regular = std::false_type ;
516 {
return m_fad_size.value+1; }
526 typedef fad_value_type * pointer_type ;
530 {
return m_offset.span(); }
538 {
return m_handle ; }
543 reference_type reference()
const 544 {
return reference_type( m_handle
546 , m_fad_stride.value ); }
548 template<
typename I0 >
551 reference(
const I0 & i0 )
const 552 {
return reference_type( m_handle + m_offset(i0,0)
554 , m_fad_stride.value ); }
556 template<
typename I0 ,
typename I1 >
558 reference_type reference(
const I0 & i0 ,
const I1 & i1 )
const 559 {
return reference_type( m_handle + m_offset(i0,i1,0)
561 , m_fad_stride.value ); }
564 template<
typename I0 ,
typename I1 ,
typename I2 >
566 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 )
const 567 {
return reference_type( m_handle + m_offset(i0,i1,i2,0)
569 , m_fad_stride.value ); }
571 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3 >
573 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3 )
const 574 {
return reference_type( m_handle + m_offset(i0,i1,i2,i3,0)
576 , m_fad_stride.value ); }
578 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
581 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
582 ,
const I4 & i4 )
const 583 {
return reference_type( m_handle + m_offset(i0,i1,i2,i3,i4,0)
585 , m_fad_stride.value ); }
587 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
588 ,
typename I4 ,
typename I5 >
590 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
591 ,
const I4 & i4 ,
const I5 & i5 )
const 592 {
return reference_type( m_handle + m_offset(i0,i1,i2,i3,i4,i5,0)
594 , m_fad_stride.value ); }
597 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
598 ,
typename I4 ,
typename I5 ,
typename I6 >
600 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
601 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 )
const 602 {
return reference_type( m_handle + m_offset(i0,i1,i2,i3,i4,i5,i6,0)
604 , m_fad_stride.value ); }
606 #if SACADO_SUPPORT_RANK_8 609 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
610 ,
typename I4 ,
typename I5 ,
typename I6 ,
typename I7>
612 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
613 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 ,
const I7 & i7 )
const 614 {
return reference_type( m_handle + m_offset(i0,i1,i2,i3,i4,i5,i6,0)
616 , m_fad_stride.value ); }
624 static constexpr
size_t memory_span(
typename Traits::array_layout
const & layout )
627 typedef std::integral_constant< unsigned , 0 > padding ;
628 return offset_type( padding() , layout ).span() *
sizeof(fad_value_type);
642 template<
class ... P >
645 ( ViewCtorProp< P ... >
const & prop
646 ,
typename Traits::array_layout
const & local_layout
648 : m_handle( ( (ViewCtorProp<void,pointer_type> const &) prop ).value )
649 , m_offset(
std::integral_constant< unsigned , 0 >()
653 ( Rank == 0 ? m_offset.dimension_0() :
654 ( Rank == 1 ? m_offset.dimension_1() :
655 ( Rank == 2 ? m_offset.dimension_2() :
656 ( Rank == 3 ? m_offset.dimension_3() :
657 ( Rank == 4 ? m_offset.dimension_4() :
658 ( Rank == 5 ? m_offset.dimension_5() :
659 ( Rank == 6 ? m_offset.dimension_6() :
660 m_offset.dimension_7() ))))))) - 1 )
662 ( Rank == 0 ? m_offset.stride_0() :
663 ( Rank == 1 ? m_offset.stride_1() :
664 ( Rank == 2 ? m_offset.stride_2() :
665 ( Rank == 3 ? m_offset.stride_3() :
666 ( Rank == 4 ? m_offset.stride_4() :
667 ( Rank == 5 ? m_offset.stride_5() :
668 ( Rank == 6 ? m_offset.stride_6() :
669 m_offset.stride_7() ))))))))
672 const unsigned fad_dim =
673 ( Rank == 0 ? m_offset.dimension_0() :
674 ( Rank == 1 ? m_offset.dimension_1() :
675 ( Rank == 2 ? m_offset.dimension_2() :
676 ( Rank == 3 ? m_offset.dimension_3() :
677 ( Rank == 4 ? m_offset.dimension_4() :
678 ( Rank == 5 ? m_offset.dimension_5() :
679 ( Rank == 6 ? m_offset.dimension_6() :
680 m_offset.dimension_7() )))))));
681 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
682 Kokkos::abort(
"invalid fad dimension (0) supplied!");
690 template<
class ... P >
691 SharedAllocationRecord<> *
692 allocate_shared( ViewCtorProp< P... >
const & prop
693 ,
typename Traits::array_layout
const & local_layout )
695 typedef ViewCtorProp< P... > ctor_prop ;
697 typedef typename ctor_prop::execution_space execution_space ;
698 typedef typename Traits::memory_space memory_space ;
699 typedef ViewValueFunctor< execution_space , fad_value_type > functor_type ;
700 typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
703 typedef std::integral_constant< unsigned , 0 > padding ;
705 m_offset = offset_type( padding(), local_layout );
706 const unsigned fad_dim =
707 ( Rank == 0 ? m_offset.dimension_0() :
708 ( Rank == 1 ? m_offset.dimension_1() :
709 ( Rank == 2 ? m_offset.dimension_2() :
710 ( Rank == 3 ? m_offset.dimension_3() :
711 ( Rank == 4 ? m_offset.dimension_4() :
712 ( Rank == 5 ? m_offset.dimension_5() :
713 ( Rank == 6 ? m_offset.dimension_6() :
714 m_offset.dimension_7() )))))));
715 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
716 Kokkos::abort(
"invalid fad dimension (0) supplied!");
717 m_fad_size = fad_dim - 1 ;
720 ( Rank == 0 ? m_offset.stride_0() :
721 ( Rank == 1 ? m_offset.stride_1() :
722 ( Rank == 2 ? m_offset.stride_2() :
723 ( Rank == 3 ? m_offset.stride_3() :
724 ( Rank == 4 ? m_offset.stride_4() :
725 ( Rank == 5 ? m_offset.stride_5() :
726 ( Rank == 6 ? m_offset.stride_6() :
727 m_offset.stride_7() )))))));
729 const size_t alloc_size = m_offset.span() *
sizeof(fad_value_type);
732 record_type *
const record =
733 record_type::allocate( ( (ViewCtorProp<void,memory_space>
const &) prop ).value
734 , ( (ViewCtorProp<void,std::string>
const &) prop ).value
741 m_handle = handle_type( reinterpret_cast< pointer_type >( record->data() ) );
743 if ( ctor_prop::initialize ) {
746 record->m_destroy = functor_type( ( (ViewCtorProp<void,execution_space>
const &) prop).value
747 , (fad_value_type *) m_handle
752 record->m_destroy.construct_shared_allocation();
768 namespace Experimental {
777 template<
class DstTraits ,
class SrcTraits >
778 class ViewMapping< DstTraits , SrcTraits ,
779 typename
std::enable_if<(
780 std::is_same< typename DstTraits::memory_space
781 , typename SrcTraits::memory_space >::value
784 ( std::is_same< typename DstTraits::specialize
785 , ViewSpecializeSacadoFad >::value
787 std::is_same< typename DstTraits::specialize , void >::value
791 std::is_same< typename SrcTraits::specialize
792 , ViewSpecializeSacadoFad >::value
797 enum { is_assignable =
true };
799 typedef Kokkos::Experimental::Impl::SharedAllocationTracker TrackType ;
800 typedef ViewMapping< DstTraits , void > DstType ;
801 typedef ViewMapping< SrcTraits , void > SrcFadType ;
803 template<
class S ,
class D >
805 typename std::enable_if<(
806 std::is_same< S , ViewSpecializeSacadoFad >::value
808 assign_fad_size(
D & dst ,
const SrcFadType & src )
809 { dst.m_fad_size = src.m_fad_size.value ;
810 dst.m_fad_stride = src.m_fad_stride.value ;
813 template<
class S ,
class D >
815 typename std::enable_if<(
816 ! std::is_same< S , ViewSpecializeSacadoFad >::value
818 assign_fad_size(
D & ,
const SrcFadType & ) {}
820 template<
class DstType >
822 void assign( DstType & dst
823 ,
const SrcFadType & src
824 ,
const TrackType & )
828 std::is_same<
typename DstTraits::array_layout
829 , Kokkos::LayoutLeft >::value ||
830 std::is_same<
typename DstTraits::array_layout
831 , Kokkos::LayoutRight >::value ||
832 std::is_same<
typename DstTraits::array_layout
833 , Kokkos::LayoutStride >::value
837 std::is_same<
typename SrcTraits::array_layout
838 , Kokkos::LayoutLeft >::value ||
839 std::is_same<
typename SrcTraits::array_layout
840 , Kokkos::LayoutRight >::value ||
841 std::is_same<
typename SrcTraits::array_layout
842 , Kokkos::LayoutStride >::value
844 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
847 std::is_same<
typename DstTraits::array_layout
848 ,
typename SrcTraits::array_layout >::value ||
849 std::is_same<
typename DstTraits::array_layout
850 , Kokkos::LayoutStride >::value ,
851 "View assignment must have compatible layout" );
854 std::is_same<
typename DstTraits::scalar_array_type
855 ,
typename SrcTraits::scalar_array_type >::value ||
856 std::is_same<
typename DstTraits::scalar_array_type
857 ,
typename SrcTraits::const_scalar_array_type >::value ,
858 "View assignment must have same value type or const = non-const" );
861 ViewDimensionAssignable
862 <
typename DstType::offset_type::dimension_type
863 ,
typename SrcFadType::offset_type::dimension_type >::value ,
864 "View assignment must have compatible dimensions" );
866 typedef typename DstType::offset_type dst_offset_type ;
868 dst.m_offset = dst_offset_type( src.m_offset );
869 dst.m_handle = src.m_handle ;
871 ViewMapping::template assign_fad_size< typename DstTraits::specialize >( dst , src );
882 namespace Experimental {
887 template<
class SrcTraits ,
class ... Args >
889 < typename
std::enable_if<(
891 std::is_same< typename SrcTraits::specialize
892 , ViewSpecializeSacadoFad >::value
895 std::is_same< typename SrcTraits::array_layout
896 , Kokkos::LayoutLeft >::value ||
897 std::is_same< typename SrcTraits::array_layout
898 , Kokkos::LayoutRight >::value ||
899 std::is_same< typename SrcTraits::array_layout
900 , Kokkos::LayoutStride >::value
908 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
912 , R0 = bool(is_integral_extent<0,Args...>::value)
913 , R1 = bool(is_integral_extent<1,Args...>::value)
914 , R2 = bool(is_integral_extent<2,Args...>::value)
915 , R3 = bool(is_integral_extent<3,Args...>::value)
916 , R4 = bool(is_integral_extent<4,Args...>::value)
917 , R5 = bool(is_integral_extent<5,Args...>::value)
918 , R6 = bool(is_integral_extent<6,Args...>::value)
922 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
923 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
926 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
927 1 == SrcTraits::rank ? R0 : (
928 2 == SrcTraits::rank ? R1 : (
929 3 == SrcTraits::rank ? R2 : (
930 4 == SrcTraits::rank ? R3 : (
931 5 == SrcTraits::rank ? R4 : (
932 6 == SrcTraits::rank ? R5 : R6 ))))))) };
939 typedef typename std::conditional<
943 ( std::is_same<
typename SrcTraits::array_layout
944 , Kokkos::LayoutRight >::value
946 ( rank == 1 ) && R0_rev
949 ( std::is_same<
typename SrcTraits::array_layout
950 , Kokkos::LayoutLeft >::value
952 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
954 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
955 >::type array_layout ;
957 typedef typename SrcTraits::value_type fad_type ;
959 typedef typename std::conditional< rank == 0 , fad_type ,
960 typename std::conditional< rank == 1 , fad_type * ,
961 typename std::conditional< rank == 2 , fad_type ** ,
962 typename std::conditional< rank == 3 , fad_type *** ,
963 typename std::conditional< rank == 4 , fad_type **** ,
964 typename std::conditional< rank == 5 , fad_type ***** ,
965 typename std::conditional< rank == 6 , fad_type ****** ,
967 >::type >::type >::type >::type >::type >::type >::type
972 typedef Kokkos::Experimental::ViewTraits
975 ,
typename SrcTraits::device_type
976 ,
typename SrcTraits::memory_traits > traits_type ;
978 typedef Kokkos::Experimental::View
981 ,
typename SrcTraits::device_type
982 ,
typename SrcTraits::memory_traits > type ;
986 static void assign( ViewMapping< traits_type , void > & dst
987 , ViewMapping< SrcTraits , void >
const & src
990 typedef ViewMapping< traits_type , void > DstType ;
991 typedef typename DstType::offset_type dst_offset_type ;
992 typedef typename DstType::handle_type dst_handle_type ;
994 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
995 extents( src.m_offset.m_dim , args... , Kokkos::ALL() );
997 dst.m_offset = dst_offset_type( src.m_offset , extents );
998 dst.m_handle = dst_handle_type( src.m_handle +
999 src.m_offset( extents.domain_offset(0)
1000 , extents.domain_offset(1)
1001 , extents.domain_offset(2)
1002 , extents.domain_offset(3)
1003 , extents.domain_offset(4)
1004 , extents.domain_offset(5)
1005 , extents.domain_offset(6)
1006 , extents.domain_offset(7)
1008 dst.m_fad_size = src.m_fad_size;
1009 dst.m_fad_stride = src.m_fad_stride.value;
1021 #if defined(HAVE_SACADO_KOKKOSCORE) && \ 1022 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \ 1023 defined(HAVE_SACADO_VIEW_SPEC) && \ 1024 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC) 1026 #include "Kokkos_TeuchosCommAdapters.hpp" 1030 template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
1031 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1032 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1035 (
const Comm<Ordinal>& comm,
1036 const EReductionType reductType ,
1038 const Kokkos::View<SD,SP...> & sendBuffer ,
1039 const Kokkos::View<RD,RP...> & recvBuffer )
1046 typedef Kokkos::View<SD,SP...> SendViewType;
1047 typedef Kokkos::View<RD,RP...> RecvViewType;
1048 typedef typename SendViewType::value_type send_value_type;
1049 typedef typename RecvViewType::value_type recv_value_type;
1051 TEUCHOS_TEST_FOR_EXCEPTION(
1052 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1053 "Teuchos::reduceAll: Both send and receive Views must have rank 1. " 1054 "The send View's rank is " << SendViewType::rank <<
" and the receive " 1055 "View's rank is " << RecvViewType::rank <<
".");
1058 Teuchos::Array<send_value_type> localSendBuffer(count);
1059 typename SendViewType::HostMirror hostSendBuffer =
1060 Kokkos::create_mirror_view(sendBuffer);
1061 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1062 for (
Ordinal i=0; i<count; ++i)
1063 localSendBuffer[i] = hostSendBuffer(i);
1067 Teuchos::Array<recv_value_type> localRecvBuffer(count);
1068 typename RecvViewType::HostMirror hostRecvBuffer =
1069 Kokkos::create_mirror_view(recvBuffer);
1070 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1071 for (
Ordinal i=0; i<count; ++i)
1072 localRecvBuffer[i] = hostRecvBuffer(i);
1075 reduceAll(comm, reductType, count,
1076 localSendBuffer.getRawPtr(),
1077 localRecvBuffer.getRawPtr());
1080 for (
Ordinal i=0; i<count; ++i)
1081 hostRecvBuffer(i) = localRecvBuffer[i];
1082 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1086 template<
typename Ordinal ,
typename Serializer ,
1087 class SD ,
class ... SP ,
class RD ,
class ... RP >
1088 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1089 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1092 (
const Comm<Ordinal>& comm,
1093 const Serializer& serializer,
1094 const EReductionType reductType ,
1096 const Kokkos::View<SD,SP...> & sendBuffer ,
1097 const Kokkos::View<RD,RP...> & recvBuffer )
1104 typedef Kokkos::View<SD,SP...> SendViewType;
1105 typedef Kokkos::View<RD,RP...> RecvViewType;
1106 typedef typename SendViewType::value_type send_value_type;
1107 typedef typename RecvViewType::value_type recv_value_type;
1109 TEUCHOS_TEST_FOR_EXCEPTION(
1110 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1111 "Teuchos::reduceAll: Both send and receive Views must have rank 1. " 1112 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
1115 Teuchos::Array<send_value_type> localSendBuffer(count);
1116 typename SendViewType::HostMirror hostSendBuffer =
1117 Kokkos::create_mirror_view(sendBuffer);
1118 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1119 for (
Ordinal i=0; i<count; ++i)
1120 localSendBuffer[i] = hostSendBuffer(i);
1124 Teuchos::Array<recv_value_type> localRecvBuffer(count);
1125 typename RecvViewType::HostMirror hostRecvBuffer =
1126 Kokkos::create_mirror_view(recvBuffer);
1127 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1128 for (
Ordinal i=0; i<count; ++i)
1129 localRecvBuffer[i] = hostRecvBuffer(i);
1132 reduceAll(comm, serializer, reductType, count,
1133 localSendBuffer.getRawPtr(),
1134 localRecvBuffer.getRawPtr());
1137 for (
Ordinal i=0; i<count; ++i)
1138 hostRecvBuffer(i) = localRecvBuffer[i];
1139 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1143 template<
typename Ordinal,
class D,
class ... P >
1144 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1146 (
const Comm<Ordinal>& comm,
1147 const int rootRank ,
1149 const Kokkos::View<D,P...>& buffer)
1151 typedef Kokkos::View<
D,P...> view_type;
1152 typename view_type::array_type array_buffer = buffer;
1154 broadcast( comm, rootRank, array_count, array_buffer );
1158 typename Serializer ,
1159 class D,
class ... P >
1160 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1162 (
const Comm<Ordinal>& comm,
1163 const Serializer& serializer,
1164 const int rootRank ,
1166 const Kokkos::View<D,P...>& buffer)
1168 typedef Kokkos::View<
D,P...> view_type;
1169 typename view_type::array_type array_buffer = buffer;
1171 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
1172 array_count, array_buffer );
1181 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC) 1183 #endif // defined(HAVE_SACADO_KOKKOSCORE) Base template specification for ScalarType.
Base template specification for static size.
#define KOKKOS_INLINE_FUNCTION
#define KOKKOS_FORCEINLINE_FUNCTION
unsigned dimension_scalar(const View &v, const ViewPack &... views)
Get view type for any Fad type.