30 #ifndef KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
31 #define KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
34 #if defined(HAVE_SACADO_KOKKOSCORE)
38 #include "Kokkos_Core_fwd.hpp"
39 #include "Kokkos_Layout.hpp"
40 #include "Kokkos_View.hpp"
47 template <
typename view_type>
48 struct is_view_fad {
static const bool value =
false; };
52 template <
typename view_type>
53 struct is_view_fad_contiguous {
static const bool value =
false; };
56 template <
typename view_type>
59 dimension_scalar(
const view_type& ) {
64 template <
typename view_type>
67 dimension_scalar_aligned(
const view_type& view) {
68 return dimension_scalar(view);
74 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
81 struct ViewSpecializeSacadoFad {};
82 struct ViewSpecializeSacadoFadContiguous {};
84 template<
class ... Args >
85 struct is_ViewSpecializeSacadoFad {
enum { value =
false }; };
87 template<
class D ,
class ... P ,
class ... Args >
88 struct is_ViewSpecializeSacadoFad< Kokkos::
View<D,P...> , Args... > {
90 std::is_same<
typename Kokkos::ViewTraits<
D,P...>::specialize
91 , ViewSpecializeSacadoFad >::value
93 ( (
sizeof...(Args) == 0 ) ||
94 is_ViewSpecializeSacadoFad< Args... >::value ) };
102 template <
typename T,
typename ... P>
103 struct is_view_fad<
View<
T,P...> > {
104 typedef View<
T,P...> view_type;
105 static const bool value =
106 std::is_same<
typename view_type::specialize,
107 Impl::ViewSpecializeSacadoFad >::value ||
108 std::is_same<
typename view_type::specialize,
109 Impl::ViewSpecializeSacadoFadContiguous >::value;
112 template <
typename T,
typename ... P>
113 struct is_view_fad_contiguous<
View<
T,P...> > {
114 typedef View<
T,P...> view_type;
115 static const bool value =
116 std::is_same<
typename view_type::specialize,
117 Impl::ViewSpecializeSacadoFadContiguous >::value;
133 template<
class DT,
class ... DP,
134 class ST,
class ... SP>
135 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
136 is_view_fad< Kokkos::View<ST,SP...> >::value
138 view_copy(
const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src);
140 template<
class Space,
class T,
class ... P>
148 template<
class T ,
class ... P >
150 typename Kokkos::View<
T,P...>::HostMirror
152 const Kokkos::View<T,P...> & src,
153 typename std::enable_if<
154 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
155 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
156 std::is_same<
typename ViewTraits<T,P...>::specialize ,
157 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
158 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
159 Kokkos::LayoutStride >::value >::type * = 0);
162 template<
class T ,
class ... P >
164 typename Kokkos::View<
T,P...>::HostMirror
166 const Kokkos::View<T,P...> & src,
167 typename std::enable_if<
168 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
169 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
170 std::is_same<
typename ViewTraits<T,P...>::specialize ,
171 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
172 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
173 Kokkos::LayoutStride >::value >::type * = 0);
175 template<
class Space,
class T,
class ... P>
176 typename Impl::MirrorType<Space,
T,P ...>::view_type
179 const Kokkos::View<T,P...> & src,
180 typename std::enable_if<
181 std::is_same<
typename ViewTraits<T,P...>::specialize ,
182 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
183 std::is_same<
typename ViewTraits<T,P...>::specialize ,
184 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
189 #include "Kokkos_Core.hpp"
198 template<
class DT,
class ... DP,
199 class ST,
class ... SP>
200 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
201 is_view_fad< Kokkos::View<ST,SP...> >::value
203 view_copy(
const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
205 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
206 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
207 view_copy( dst_array_type(dst) , src_array_type(src) );
215 template <
typename T,
typename ... P>
218 std::enable_if< is_view_fad<
View<
T,P...> >::value,
unsigned >::type
219 dimension_scalar(
const View<T,P...>& view) {
220 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
221 return view.implementation_map().dimension_scalar();
223 return view.impl_map().dimension_scalar();
227 template <
typename Layout>
228 struct ApplyNatural {
229 typedef LayoutNatural<Layout> type;
232 template <
typename Layout>
233 struct ApplyNatural< LayoutNatural<Layout> > {
234 typedef LayoutNatural<Layout> type;
237 template <
typename T,
typename Enable =
void >
240 template <
typename T >
241 struct ArrayScalar<
T, typename std::enable_if< !Sacado::IsFad<T>::value >::type > {
245 template <
typename T >
246 struct ArrayScalar<
T, typename std::enable_if< Sacado::IsFad<T>::value >::type > {
247 typedef typename ArrayScalar< typename Sacado::ValueType<T>::type >::type* type;
251 template <
typename DataType,
int Rank >
252 struct AppendRankToConvertedFad {
253 static_assert( Rank > -1,
"Sacado AppendRankToConvertedFad Error: Rank < 0" );
254 typedef typename AppendRankToConvertedFad<DataType,Rank-1>::type* type;
258 template <
typename DataType >
259 struct AppendRankToConvertedFad< DataType, 0 > {
260 typedef DataType type;
264 template <
class ArrayLayout,
class Enable =
void >
265 struct ViewArrayLayoutSelector;
267 template <
class ArrayLayout >
268 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutLeft>::value >::type >
270 using type = Kokkos::LayoutLeft;
273 template <
class ArrayLayout >
274 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutRight>::value >::type >
276 using type = Kokkos::LayoutRight;
279 template <
class ArrayLayout >
280 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutStride>::value >::type >
282 using type = Kokkos::LayoutStride;
285 template <
typename ViewType,
typename Enable =
void >
286 struct PODViewDeepCopyType;
288 template <
typename ViewType >
289 struct PODViewDeepCopyType< ViewType, typename std::enable_if< is_view_fad<ViewType>::value >::type >
292 typedef ViewType view_type;
293 typedef typename ArrayScalar< typename view_type::value_type >::type fad_converted_type;
294 typedef typename AppendRankToConvertedFad< fad_converted_type, view_type::Rank >::type new_data_type;
296 typedef typename ViewArrayLayoutSelector<typename view_type::array_layout>::type layout;
298 typedef typename view_type::device_type device;
299 typedef typename view_type::memory_traits memory;
301 typedef Kokkos::View< new_data_type, layout, device, memory > type;
305 template <
typename ViewType >
306 struct PODViewDeepCopyType< ViewType, typename std::enable_if< !is_view_fad<ViewType>::value >::type >
308 typedef ViewType type;
312 template <
typename ViewType,
typename Enabled =
void>
313 struct NaturalArrayType {
314 typedef ViewType type;
317 template <
typename D,
typename ... P>
318 struct NaturalArrayType<
View<
D,P...>,
319 typename std::enable_if< is_view_fad< View<D,P...> >::value >::type > {
320 typedef View<
D,P...> view_type;
321 typedef typename view_type::data_type data_type;
322 typedef typename view_type::array_layout layout;
323 typedef typename view_type::device_type device;
324 typedef typename view_type::memory_traits memory;
326 typedef typename ViewArrayLayoutSelector<layout>::type natural_layout;
327 typedef View<data_type,natural_layout,device,memory> type;
332 template <
class OutputView,
typename Enabled =
void>
333 struct SacadoViewFill
335 typedef typename OutputView::const_value_type const_value_type ;
336 typedef typename OutputView::execution_space execution_space ;
338 const OutputView output ;
339 const_value_type input ;
342 void operator()(
const size_t i0 )
const
344 const size_t n1 = output.extent(1);
345 const size_t n2 = output.extent(2);
346 const size_t n3 = output.extent(3);
347 const size_t n4 = output.extent(4);
348 const size_t n5 = output.extent(5);
349 const size_t n6 = output.extent(6);
350 const size_t n7 = output.extent(7);
352 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
353 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
354 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
355 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
356 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
357 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
358 for (
size_t i7 = 0 ; i7 < n7 ; ++i7 ) {
359 output.access(i0,i1,i2,i3,i4,i5,i6,i7) = input ;
363 SacadoViewFill(
const OutputView & arg_out , const_value_type & arg_in )
364 : output( arg_out ), input( arg_in )
366 const size_t n0 = output.extent(0);
367 Kokkos::RangePolicy<execution_space> policy( 0, n0 );
368 Kokkos::parallel_for( policy, *
this );
369 execution_space::fence();
376 template<
class DT,
class ... DP >
378 const View<DT,DP...> & view ,
379 const typename Sacado::ScalarType<
typename View<DT,DP...>::value_type >::type & value
380 ,
typename std::enable_if<(
381 std::is_same<
typename ViewTraits<DT,DP...>::specialize
382 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
383 std::is_same<
typename ViewTraits<DT,DP...>::specialize
384 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
388 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
389 typename ViewTraits<DT,DP...>::non_const_value_type >::value
390 ,
"Can only deep copy into non-const type" );
392 Impl::SacadoViewFill<
View<DT,DP...> >( view , value );
397 template<
class DT,
class ... DP >
399 const View<DT,DP...> & view ,
400 const typename View<DT,DP...>::value_type & value
401 ,
typename std::enable_if<(
402 std::is_same<
typename ViewTraits<DT,DP...>::specialize
403 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
404 std::is_same<
typename ViewTraits<DT,DP...>::specialize
405 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
409 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
410 typename ViewTraits<DT,DP...>::non_const_value_type >::value
411 ,
"Can only deep copy into non-const type" );
413 Impl::SacadoViewFill<
View<DT,DP...> >( view , value );
418 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
420 void deep_copy(
const View<DT,DP...> & dst ,
421 const View<ST,SP...> & src
422 ,
typename std::enable_if<(
423 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
424 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
426 std::is_same<
typename ViewTraits<DT,DP...>::specialize
427 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
429 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
430 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
432 std::is_same<
typename ViewTraits<ST,SP...>::specialize
433 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
437 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
438 typename ViewTraits<DT,DP...>::non_const_value_type >::value
439 ,
"Deep copy destination must be non-const" );
442 (
unsigned(ViewTraits<DT,DP...>::rank) ==
443 unsigned(ViewTraits<ST,SP...>::rank) )
444 ,
"Deep copy destination and source must have same rank" );
448 typedef typename View<DT,DP...>::array_type dst_array_type;
449 typedef typename View<ST,SP...>::array_type src_array_type;
450 typename NaturalArrayType< dst_array_type >::type dst_array( dst );
451 typename NaturalArrayType< src_array_type >::type src_array( src );
454 typename PODViewDeepCopyType<
View<DT,DP...> >::type dst_array( dst );
455 typename PODViewDeepCopyType<
View<ST,SP...> >::type src_array( src );
457 Kokkos::deep_copy( dst_array , src_array );
460 template<
class T ,
class ... P >
462 typename Kokkos::View<
T,P...>::HostMirror
463 create_mirror(
const Kokkos::View<T,P...> & src
464 ,
typename std::enable_if<
465 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
466 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
467 std::is_same<
typename ViewTraits<T,P...>::specialize ,
468 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
470 ! std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
471 , Kokkos::LayoutStride >::value
475 typedef View<
T,P...> src_type ;
476 typedef typename src_type::HostMirror dst_type ;
478 typename src_type::array_layout layout = src.layout();
479 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
481 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
484 template<
class T ,
class ... P >
486 typename Kokkos::View<
T,P...>::HostMirror
487 create_mirror(
const Kokkos::View<T,P...> & src
488 ,
typename std::enable_if<
489 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
490 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
491 std::is_same<
typename ViewTraits<T,P...>::specialize ,
492 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
494 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout
495 , Kokkos::LayoutStride >::value
499 typedef View<
T,P...> src_type ;
500 typedef typename src_type::HostMirror dst_type ;
502 Kokkos::LayoutStride layout ;
504 layout.dimension[0] = src.extent(0);
505 layout.dimension[1] = src.extent(1);
506 layout.dimension[2] = src.extent(2);
507 layout.dimension[3] = src.extent(3);
508 layout.dimension[4] = src.extent(4);
509 layout.dimension[5] = src.extent(5);
510 layout.dimension[6] = src.extent(6);
511 layout.dimension[7] = src.extent(7);
513 layout.stride[0] = src.stride_0();
514 layout.stride[1] = src.stride_1();
515 layout.stride[2] = src.stride_2();
516 layout.stride[3] = src.stride_3();
517 layout.stride[4] = src.stride_4();
518 layout.stride[5] = src.stride_5();
519 layout.stride[6] = src.stride_6();
520 layout.stride[7] = src.stride_7();
522 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
524 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
527 template<
class Space,
class T,
class ... P>
528 typename Impl::MirrorType<Space,
T,P ...>::view_type
529 create_mirror(
const Space& ,
const Kokkos::View<T,P...> & src
530 ,
typename std::enable_if<
531 ( std::is_same<
typename ViewTraits<T,P...>::specialize ,
532 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
533 std::is_same<
typename ViewTraits<T,P...>::specialize ,
534 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
536 typedef View<
T,P...> src_type ;
537 typename src_type::array_layout layout = src.layout();
538 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
539 return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),layout);
549 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
550 struct FadViewDataAnalysis
554 typedef ViewArrayAnalysis< DataType > array_analysis ;
559 typedef ViewSpecializeSacadoFad specialize ;
561 typedef typename array_analysis::dimension dimension ;
562 typedef typename array_analysis::value_type value_type ;
563 typedef typename array_analysis::const_value_type const_value_type ;
564 typedef typename array_analysis::non_const_value_type non_const_value_type ;
568 ViewDataType< value_type , dimension >::type type ;
570 ViewDataType< const_value_type , dimension >::type const_type ;
572 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
577 enum { is_const = std::is_same< value_type , const_value_type >::value };
581 std::conditional< is_const , const ScalarType , ScalarType >::type
584 typedef ScalarType non_const_scalar_type ;
585 typedef const ScalarType const_scalar_type ;
588 typedef typename array_analysis::dimension::
589 template append<( DimFad ? DimFad + 1 : 0 )>::type
596 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
599 ViewDataType< const_scalar_type , scalar_dimension >::type
600 const_scalar_array_type ;
603 ViewDataType< non_const_scalar_type , scalar_dimension >::type
604 non_const_scalar_array_type ;
609 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad,
unsigned Str
ide >
610 struct FadViewDataAnalysis<DataType, LayoutContiguous<ArrayLayout,Stride>, ScalarType, DimFad>
614 typedef ViewArrayAnalysis< DataType > array_analysis ;
619 typedef ViewSpecializeSacadoFadContiguous specialize ;
621 typedef typename array_analysis::dimension dimension ;
622 typedef typename array_analysis::value_type value_type ;
623 typedef typename array_analysis::const_value_type const_value_type ;
624 typedef typename array_analysis::non_const_value_type non_const_value_type ;
628 ViewDataType< value_type , dimension >::type type ;
630 ViewDataType< const_value_type , dimension >::type const_type ;
632 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
637 enum { is_const = std::is_same< value_type , const_value_type >::value };
641 std::conditional< is_const , const ScalarType , ScalarType >::type
644 typedef ScalarType non_const_scalar_type ;
645 typedef const ScalarType const_scalar_type ;
648 typedef typename std::conditional<
649 std::is_same< ArrayLayout, Kokkos::LayoutLeft >::value,
650 typename array_analysis::dimension::
651 template prepend<0>::type,
652 typename array_analysis::dimension::
653 template append<0>::type >::type
660 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
663 ViewDataType< const_scalar_type , scalar_dimension >::type
664 const_scalar_array_type ;
667 ViewDataType< non_const_scalar_type , scalar_dimension >::type
668 non_const_scalar_array_type ;
677 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
678 struct FadViewDataAnalysis<DataType, LayoutNatural<ArrayLayout>, ScalarType, DimFad>
682 typedef ViewArrayAnalysis< DataType > array_analysis ;
687 typedef void specialize ;
689 typedef typename array_analysis::dimension dimension ;
690 typedef typename array_analysis::value_type value_type ;
691 typedef typename array_analysis::const_value_type const_value_type ;
692 typedef typename array_analysis::non_const_value_type non_const_value_type ;
696 ViewDataType< value_type , dimension >::type type ;
698 ViewDataType< const_value_type , dimension >::type const_type ;
700 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
703 typedef type scalar_array_type ;
704 typedef const_type const_scalar_array_type ;
705 typedef non_const_type non_const_scalar_array_type ;
716 namespace Fad {
namespace Exp {
template<
typename >
class GeneralFad ; } }
718 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
719 namespace Fad {
template<
typename >
class DFad ; }
720 namespace Fad {
template<
typename ,
int >
class SFad ; }
721 namespace Fad {
template<
typename ,
int >
class SLFad ; }
724 namespace CacheFad {
template<
typename >
class DFad ; }
725 namespace ELRFad {
template<
typename >
class DFad ; }
726 namespace ELRCacheFad {
template<
typename >
class DFad ; }
728 namespace CacheFad {
template<
typename ,
int >
class SFad ; }
729 namespace ELRFad {
template<
typename ,
int >
class SFad ; }
730 namespace ELRCacheFad {
template<
typename ,
int >
class SFad ; }
733 namespace CacheFad {
template<
typename ,
int >
class SLFad ; }
734 namespace ELRFad {
template<
typename ,
int >
class SLFad ; }
735 namespace ELRCacheFad {
template<
typename ,
int >
class SLFad ; }
741 #define KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( NS ) \
742 template< class DataType , class ArrayLayout , typename ScalarType > \
743 struct ViewDataAnalysis \
746 , Sacado:: NS ::DFad< ScalarType > \
747 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , 0 > {}; \
749 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
750 struct ViewDataAnalysis \
753 , Sacado:: NS ::SFad< ScalarType , N > \
754 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
755 int(Sacado::StaticSize< Sacado:: NS ::SFad< ScalarType , N > >::value) \
758 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
759 struct ViewDataAnalysis \
762 , Sacado:: NS ::SLFad< ScalarType , N > \
763 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
764 int(Sacado::StaticSize< Sacado:: NS ::SLFad< ScalarType , N > >::value) \
767 template<
class DataType ,
class ArrayLayout ,
typename StorageType >
768 struct ViewDataAnalysis
771 , Sacado::Fad::Exp::GeneralFad< StorageType >
772 > :
public FadViewDataAnalysis< DataType, ArrayLayout, typename StorageType::value_type , 0 > {};
774 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
775 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( Fad )
778 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( CacheFad )
779 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRFad )
780 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRCacheFad )
782 #undef KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD
792 template <
class View,
class ... ViewPack>
794 unsigned dimension_scalar(
const View& v,
const ViewPack&... views) {
795 const unsigned dim0 = dimension_scalar(v);
796 const unsigned dim1 = dimension_scalar(views...);
797 return dim0 >= dim1 ? dim0 : dim1 ;
804 namespace Kokkos {
namespace Impl {
806 template <
typename Specialize,
typename A,
typename B >
807 struct CommonViewValueType;
809 template <
typename A,
typename B >
810 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFad,
A,
B >
815 template <
typename A,
typename B >
816 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFadContiguous,
A,
B >
822 template <
class Specialize,
class ValueType >
823 struct CommonViewAllocProp;
825 template <
class ValueType >
826 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFad, ValueType >
828 using value_type = ValueType;
834 CommonViewAllocProp()
835 : fad_dim(0) , is_view_type(
false) {}
839 template <
class View >
841 CommonViewAllocProp(
const View & view )
842 : fad_dim ( dimension_scalar(view) )
844 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
848 template <
class View,
class ... Views >
850 CommonViewAllocProp(
const View & view,
const Views & ... views )
851 : fad_dim ( dimension_scalar(view, views... ) )
853 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
858 template <
class ValueType >
859 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFadContiguous, ValueType >
861 using value_type = ValueType;
867 CommonViewAllocProp()
868 : fad_dim(0) , is_view_type(
false) {}
872 template <
class View >
874 CommonViewAllocProp(
const View & view )
875 : fad_dim ( dimension_scalar(view) )
877 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
881 template <
class View,
class ... Views >
883 CommonViewAllocProp(
const View & view,
const Views & ... views )
884 : fad_dim ( dimension_scalar(view, views... ) )
886 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
891 template <
typename ... P >
892 struct has_common_view_alloc_prop :
public std::false_type {};
894 template <
class Specialize,
class ValueType >
895 struct has_common_view_alloc_prop< CommonViewAllocProp<Specialize, ValueType> > :
public std::true_type {};
899 template <
typename ... >
900 struct check_has_common_view_alloc_prop;
903 struct check_has_common_view_alloc_prop<>
905 enum { value =
false };
908 template <
typename P >
909 struct check_has_common_view_alloc_prop<P>
911 enum { value = has_common_view_alloc_prop< P >::value };
914 template <
typename P0,
typename ... P >
915 struct check_has_common_view_alloc_prop<P0, P...>
917 enum { value = ( (has_common_view_alloc_prop<P0>::value ==
true) ?
true : check_has_common_view_alloc_prop<P...>::value ) };
920 template <
typename ... >
921 struct compute_fad_dim_from_alloc_prop;
924 struct compute_fad_dim_from_alloc_prop<> {
925 template <
typename CtorProp>
927 static unsigned eval(
const CtorProp&) {
return 0; }
930 template <
typename P >
931 struct compute_fad_dim_from_alloc_prop<P> {
932 template <
typename CtorProp>
934 static unsigned eval(
const CtorProp&) {
return 0; }
937 template <
typename P0,
typename ... P >
938 struct compute_fad_dim_from_alloc_prop<P0,P...> {
939 template <
typename CtorProp>
941 static unsigned eval(
const CtorProp& prop) {
942 unsigned d1 = compute_fad_dim_from_alloc_prop<P0>::eval(prop);
943 unsigned d2 = compute_fad_dim_from_alloc_prop<P...>::eval(prop);
944 return d1 > d2 ? d1 : d2;
948 template <
class ValueType >
949 struct compute_fad_dim_from_alloc_prop<
950 CommonViewAllocProp<ViewSpecializeSacadoFad, ValueType>
952 template <
typename CtorProp>
954 static unsigned eval(
const CtorProp& prop) {
955 using specialize = ViewSpecializeSacadoFad;
956 using CVAP = CommonViewAllocProp< specialize, ValueType >;
957 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
958 return cast_prop.fad_dim;
962 template <
class ValueType >
963 struct compute_fad_dim_from_alloc_prop<
964 CommonViewAllocProp<ViewSpecializeSacadoFadContiguous, ValueType>
966 template <
typename CtorProp>
968 static unsigned eval(
const CtorProp& prop) {
969 using specialize = ViewSpecializeSacadoFadContiguous;
970 using CVAP = CommonViewAllocProp< specialize, ValueType >;
971 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
972 return cast_prop.fad_dim;
976 template <
typename Traits,
typename ... P >
977 struct appendFadToLayoutViewAllocHelper
979 using layout_type =
typename Traits::array_layout;
980 using specialize =
typename Traits::specialize;
981 using CtorProp = ViewCtorProp< P... >;
984 static layout_type returnNewLayoutPlusFad(
const CtorProp & arg_prop,
const layout_type & arg_layout ) {
986 layout_type appended_layout( arg_layout );
990 const unsigned fad_dim =
991 compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
992 appended_layout.dimension[ Traits::rank ] = (fad_dim > 0) ? fad_dim : 1;
994 return appended_layout;
998 template <
typename Layout>
999 struct prependFadToLayout
1001 using layout_type = Layout;
1003 template <
typename FadSizeType >
1005 static layout_type returnNewLayoutPlusFad(
const layout_type & arg_layout,
const FadSizeType fad_dim ) {
1007 layout_type prepended_layout(0,0,0,0,0,0,0,0);
1009 prepended_layout.dimension[0] = fad_dim;
1011 for (
int i = 1; i < ARRAY_LAYOUT_MAX_RANK; ++i ) {
1012 prepended_layout.dimension[i] = arg_layout.dimension[i-1];
1015 return prepended_layout;
1028 template<
class Traits >
1029 class ViewMapping< Traits ,
1030 typename std::enable_if<
1031 ( std::is_same< typename Traits::specialize
1032 , ViewSpecializeSacadoFad >::value
1034 ( std::is_same< typename Traits::array_layout
1035 , Kokkos::LayoutLeft >::value
1037 std::is_same< typename Traits::array_layout
1038 , Kokkos::LayoutRight >::value
1040 std::is_same< typename Traits::array_layout
1041 , Kokkos::LayoutStride >::value
1044 , typename Traits::specialize
1049 template< class ,
class ... >
friend class ViewMapping ;
1050 template< class ,
class ... >
friend class Kokkos::View ;
1052 typedef typename Traits::value_type fad_type ;
1055 std::add_const< fad_value_type >::type const_fad_value_type ;
1061 enum { FadStaticStride =
1062 std::is_same<
typename Traits::array_layout
1063 , Kokkos::LayoutRight >::value ? 1 : 0 };
1067 typedef fad_value_type * handle_type ;
1069 typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1072 typedef ViewOffset<
typename Traits::dimension
1073 ,
typename Traits::array_layout
1079 <
typename array_analysis::dimension::
1080 template append<( unsigned(FadStaticDimension) > 0 ? unsigned(FadStaticDimension) + 1 : 0 )>::type
1081 ,
typename Traits::array_layout
1083 > array_offset_type ;
1085 handle_type m_impl_handle ;
1086 offset_type m_impl_offset ;
1087 array_offset_type m_array_offset ;
1088 sacado_size_type m_fad_size ;
1089 sacado_stride_type m_fad_stride ;
1096 enum { Rank = Traits::dimension::rank };
1099 template<
typename iType >
1101 {
return m_impl_offset.m_dim.extent(r) ; }
1104 typename Traits::array_layout layout()
const
1105 {
return m_impl_offset.layout(); }
1108 {
return m_impl_offset.dimension_0(); }
1110 {
return m_impl_offset.dimension_1(); }
1112 {
return m_impl_offset.dimension_2(); }
1114 {
return m_impl_offset.dimension_3(); }
1116 {
return m_impl_offset.dimension_4(); }
1118 {
return m_impl_offset.dimension_5(); }
1120 {
return m_impl_offset.dimension_6(); }
1122 {
return m_impl_offset.dimension_7(); }
1126 using is_regular = std::false_type ;
1129 {
return m_impl_offset.stride_0(); }
1131 {
return m_impl_offset.stride_1(); }
1133 {
return m_impl_offset.stride_2(); }
1135 {
return m_impl_offset.stride_3(); }
1137 {
return m_impl_offset.stride_4(); }
1139 {
return m_impl_offset.stride_5(); }
1141 {
return m_impl_offset.stride_6(); }
1143 {
return m_impl_offset.stride_7(); }
1145 template<
typename iType >
1147 { m_impl_offset.stride(s) ; }
1151 {
return m_fad_size.value+1; }
1155 {
return m_fad_stride.value; }
1165 typedef fad_value_type * pointer_type ;
1169 {
return m_array_offset.span(); }
1173 {
return m_array_offset.span_is_contiguous() ; }
1177 {
return m_impl_handle ; }
1182 reference_type reference()
const
1183 {
return reference_type( m_impl_handle
1185 , m_fad_stride.value ); }
1187 template<
typename I0 >
1190 reference(
const I0 & i0 )
const
1191 {
return reference_type( m_impl_handle + m_array_offset(i0,0)
1193 , m_fad_stride.value ); }
1195 template<
typename I0 ,
typename I1 >
1197 reference_type reference(
const I0 & i0 ,
const I1 & i1 )
const
1198 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,0)
1200 , m_fad_stride.value ); }
1203 template<
typename I0 ,
typename I1 ,
typename I2 >
1205 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 )
const
1206 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,0)
1208 , m_fad_stride.value ); }
1210 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3 >
1212 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3 )
const
1213 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,0)
1215 , m_fad_stride.value ); }
1217 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1220 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1221 ,
const I4 & i4 )
const
1222 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,0)
1224 , m_fad_stride.value ); }
1226 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1227 ,
typename I4 ,
typename I5 >
1229 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1230 ,
const I4 & i4 ,
const I5 & i5 )
const
1231 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,0)
1233 , m_fad_stride.value ); }
1236 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1237 ,
typename I4 ,
typename I5 ,
typename I6 >
1239 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1240 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 )
const
1241 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,i6,0)
1243 , m_fad_stride.value ); }
1249 static size_t memory_span(
typename Traits::array_layout
const & layout )
1252 for (
int i=0; i<8; ++i)
1253 dims[i] = layout.dimension[i];
1254 if (
unsigned(FadStaticDimension) > 0)
1255 dims[unsigned(Rank)] = FadStaticDimension+1;
1257 typename Traits::array_layout alayout(
1258 dims[0], dims[1], dims[2], dims[3],
1259 dims[4], dims[5], dims[6], dims[7] );
1262 typedef std::integral_constant< unsigned , 0 > padding ;
1263 return array_offset_type( padding() , alayout ).span() *
sizeof(fad_value_type);
1269 KOKKOS_INLINE_FUNCTION ViewMapping() : m_impl_handle(0) , m_impl_offset() , m_array_offset() , m_fad_size(0) , m_fad_stride(0) {}
1277 template<
class ... P >
1280 ( ViewCtorProp< P ... >
const & prop
1281 ,
typename Traits::array_layout
const & local_layout
1283 : m_impl_handle( ( (ViewCtorProp<
void,pointer_type> const &) prop ).value )
1284 , m_impl_offset( std::integral_constant< unsigned , 0 >()
1286 , m_array_offset( std::integral_constant< unsigned , 0 >()
1290 ( Rank == 0 ? m_array_offset.dimension_0() :
1291 ( Rank == 1 ? m_array_offset.dimension_1() :
1292 ( Rank == 2 ? m_array_offset.dimension_2() :
1293 ( Rank == 3 ? m_array_offset.dimension_3() :
1294 ( Rank == 4 ? m_array_offset.dimension_4() :
1295 ( Rank == 5 ? m_array_offset.dimension_5() :
1296 ( Rank == 6 ? m_array_offset.dimension_6() :
1297 m_array_offset.dimension_7() ))))))) - 1 )
1299 ( Rank == 0 ? m_array_offset.stride_0() :
1300 ( Rank == 1 ? m_array_offset.stride_1() :
1301 ( Rank == 2 ? m_array_offset.stride_2() :
1302 ( Rank == 3 ? m_array_offset.stride_3() :
1303 ( Rank == 4 ? m_array_offset.stride_4() :
1304 ( Rank == 5 ? m_array_offset.stride_5() :
1305 ( Rank == 6 ? m_array_offset.stride_6() :
1306 m_array_offset.stride_7() ))))))))
1309 const unsigned fad_dim =
1310 ( Rank == 0 ? m_array_offset.dimension_0() :
1311 ( Rank == 1 ? m_array_offset.dimension_1() :
1312 ( Rank == 2 ? m_array_offset.dimension_2() :
1313 ( Rank == 3 ? m_array_offset.dimension_3() :
1314 ( Rank == 4 ? m_array_offset.dimension_4() :
1315 ( Rank == 5 ? m_array_offset.dimension_5() :
1316 ( Rank == 6 ? m_array_offset.dimension_6() :
1317 m_array_offset.dimension_7() )))))));
1318 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1319 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1327 template<
class ... P >
1328 SharedAllocationRecord<> *
1329 allocate_shared( ViewCtorProp< P... >
const & prop
1330 ,
typename Traits::array_layout
const & local_layout )
1332 typedef ViewCtorProp< P... > ctor_prop ;
1334 typedef typename ctor_prop::execution_space execution_space ;
1335 typedef typename Traits::memory_space memory_space ;
1336 typedef ViewValueFunctor< execution_space , fad_value_type > functor_type ;
1337 typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1340 typedef std::integral_constant< unsigned , 0 > padding ;
1343 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
1345 m_impl_offset = offset_type( padding(), local_layout );
1347 typename Traits::array_layout internal_layout =
1348 (test_traits_check ==
true)
1349 ? Kokkos::Impl::appendFadToLayoutViewAllocHelper< Traits, P... >::returnNewLayoutPlusFad(prop, local_layout)
1352 m_array_offset = array_offset_type( padding(), internal_layout );
1354 const unsigned fad_dim =
1355 ( Rank == 0 ? m_array_offset.dimension_0() :
1356 ( Rank == 1 ? m_array_offset.dimension_1() :
1357 ( Rank == 2 ? m_array_offset.dimension_2() :
1358 ( Rank == 3 ? m_array_offset.dimension_3() :
1359 ( Rank == 4 ? m_array_offset.dimension_4() :
1360 ( Rank == 5 ? m_array_offset.dimension_5() :
1361 ( Rank == 6 ? m_array_offset.dimension_6() :
1362 m_array_offset.dimension_7() )))))));
1363 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1364 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1365 m_fad_size = fad_dim - 1 ;
1368 ( Rank == 0 ? m_array_offset.stride_0() :
1369 ( Rank == 1 ? m_array_offset.stride_1() :
1370 ( Rank == 2 ? m_array_offset.stride_2() :
1371 ( Rank == 3 ? m_array_offset.stride_3() :
1372 ( Rank == 4 ? m_array_offset.stride_4() :
1373 ( Rank == 5 ? m_array_offset.stride_5() :
1374 ( Rank == 6 ? m_array_offset.stride_6() :
1375 m_array_offset.stride_7() )))))));
1377 const size_t alloc_size = m_array_offset.span() *
sizeof(fad_value_type);
1380 record_type *
const record =
1381 record_type::allocate( ( (ViewCtorProp<void,memory_space>
const &) prop ).value
1382 , ( (ViewCtorProp<void,std::string>
const &) prop ).value
1389 m_impl_handle = handle_type( reinterpret_cast< pointer_type >( record->data() ) );
1391 if ( ctor_prop::initialize ) {
1394 record->m_destroy = functor_type( ( (ViewCtorProp<void,execution_space>
const &) prop).value
1395 , (fad_value_type *) m_impl_handle
1396 , m_array_offset.span()
1400 record->m_destroy.construct_shared_allocation();
1421 template<
class DstTraits ,
class SrcTraits >
1422 class ViewMapping< DstTraits , SrcTraits ,
1423 typename std::enable_if<(
1424 Kokkos::Impl::MemorySpaceAccess
1425 < typename DstTraits::memory_space
1426 , typename SrcTraits::memory_space >::assignable
1429 std::is_same< typename DstTraits::specialize
1430 , ViewSpecializeSacadoFad >::value
1433 std::is_same< typename SrcTraits::specialize
1434 , ViewSpecializeSacadoFad >::value
1437 , typename DstTraits::specialize
1442 enum { is_assignable =
true };
1444 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1445 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1446 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1448 template<
class DstType >
1450 void assign( DstType & dst
1451 ,
const SrcFadType & src
1452 ,
const TrackType & )
1456 std::is_same<
typename DstTraits::array_layout
1457 , Kokkos::LayoutLeft >::value ||
1458 std::is_same<
typename DstTraits::array_layout
1459 , Kokkos::LayoutRight >::value ||
1460 std::is_same<
typename DstTraits::array_layout
1461 , Kokkos::LayoutStride >::value
1465 std::is_same<
typename SrcTraits::array_layout
1466 , Kokkos::LayoutLeft >::value ||
1467 std::is_same<
typename SrcTraits::array_layout
1468 , Kokkos::LayoutRight >::value ||
1469 std::is_same<
typename SrcTraits::array_layout
1470 , Kokkos::LayoutStride >::value
1472 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1475 std::is_same<
typename DstTraits::array_layout
1476 ,
typename SrcTraits::array_layout >::value ||
1477 std::is_same<
typename DstTraits::array_layout
1478 , Kokkos::LayoutStride >::value ,
1479 "View assignment must have compatible layout" );
1482 std::is_same<
typename DstTraits::scalar_array_type
1483 ,
typename SrcTraits::scalar_array_type >::value ||
1484 std::is_same<
typename DstTraits::scalar_array_type
1485 ,
typename SrcTraits::const_scalar_array_type >::value ,
1486 "View assignment must have same value type or const = non-const" );
1489 ViewDimensionAssignable
1490 <
typename DstType::offset_type::dimension_type
1491 ,
typename SrcFadType::offset_type::dimension_type >::value ,
1492 "View assignment must have compatible dimensions" );
1495 ViewDimensionAssignable
1496 <
typename DstType::array_offset_type::dimension_type
1497 ,
typename SrcFadType::array_offset_type::dimension_type >::value ,
1498 "View assignment must have compatible dimensions" );
1500 typedef typename DstType::offset_type dst_offset_type ;
1501 typedef typename DstType::array_offset_type dst_array_offset_type ;
1503 dst.m_impl_handle = src.m_impl_handle ;
1504 dst.m_impl_offset = dst_offset_type( src.m_impl_offset );
1505 dst.m_array_offset = dst_array_offset_type( src.m_array_offset );
1506 dst.m_fad_size = src.m_fad_size.value ;
1507 dst.m_fad_stride = src.m_fad_stride.value ;
1517 template<
class DstTraits ,
class SrcTraits >
1518 class ViewMapping< DstTraits , SrcTraits ,
1519 typename std::enable_if<(
1520 Kokkos::Impl::MemorySpaceAccess
1521 < typename DstTraits::memory_space
1522 , typename SrcTraits::memory_space >::assignable
1525 std::is_same< typename DstTraits::specialize , void >::value
1528 std::is_same< typename SrcTraits::specialize
1529 , ViewSpecializeSacadoFad >::value
1531 , typename DstTraits::specialize
1536 enum { is_assignable =
true };
1539 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1540 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1541 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1546 template <
class DstType,
class SrcFadType,
class Truth =
void >
1547 struct AssignOffset;
1549 template <
class DstType,
class SrcFadType >
1550 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank != (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1554 static void assign( DstType & dst,
const SrcFadType & src )
1556 typedef typename SrcTraits::value_type TraitsValueType;
1562 typedef typename DstType::offset_type::array_layout DstLayoutType;
1564 typedef typename SrcFadType::array_offset_type::dimension_type SrcViewDimension;
1569 static constexpr
bool is_layout_left =
1570 std::is_same< DstLayoutType, Kokkos::LayoutLeft>::value;
1572 typedef typename std::conditional< is_layout_left,
1573 typename SrcViewDimension:: template prepend< InnerStaticDim+1 >::type,
1574 typename SrcViewDimension:: template append < InnerStaticDim+1 >::type
1575 >::type SrcViewDimensionAppended;
1577 typedef std::integral_constant< unsigned , 0 > padding ;
1579 typedef ViewOffset< SrcViewDimensionAppended, DstLayoutType > TmpOffsetType;
1581 auto src_layout = src.m_array_offset.layout();
1583 if ( is_layout_left ) {
1584 auto prepend_layout = Kokkos::Impl::prependFadToLayout< DstLayoutType >::returnNewLayoutPlusFad(src_layout, InnerStaticDim+1);
1585 TmpOffsetType offset_tmp( padding(), prepend_layout );
1586 dst.m_impl_offset = offset_tmp;
1589 TmpOffsetType offset_tmp( padding(), src_layout );
1590 dst.m_impl_offset = offset_tmp;
1594 Kokkos::abort(
"Sacado error: Applying AssignOffset for case with nested Fads, but without nested Fads - something went wrong");
1599 template <
class DstType,
class SrcFadType >
1600 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank == (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1603 static void assign( DstType & dst,
const SrcFadType & src )
1606 typedef typename DstType::offset_type dst_offset_type ;
1607 dst.m_impl_offset = dst_offset_type( src.m_array_offset );
1619 template <
class DstType >
1622 assign( DstType & dst
1623 ,
const SrcFadType & src
1630 std::is_same<
typename DstTraits::array_layout
1631 , Kokkos::LayoutLeft >::value ||
1632 std::is_same<
typename DstTraits::array_layout
1633 , Kokkos::LayoutRight >::value ||
1634 std::is_same<
typename DstTraits::array_layout
1635 , Kokkos::LayoutStride >::value
1639 std::is_same<
typename SrcTraits::array_layout
1640 , Kokkos::LayoutLeft >::value ||
1641 std::is_same<
typename SrcTraits::array_layout
1642 , Kokkos::LayoutRight >::value ||
1643 std::is_same<
typename SrcTraits::array_layout
1644 , Kokkos::LayoutStride >::value
1646 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1649 std::is_same<
typename DstTraits::array_layout
1650 ,
typename SrcTraits::array_layout >::value ||
1651 std::is_same<
typename DstTraits::array_layout
1652 , Kokkos::LayoutStride >::value ,
1653 "View assignment must have compatible layout" );
1656 std::is_same<
typename DstTraits::scalar_array_type
1657 ,
typename SrcTraits::scalar_array_type >::value ||
1658 std::is_same<
typename DstTraits::scalar_array_type
1659 ,
typename SrcTraits::const_scalar_array_type >::value ,
1660 "View assignment must have same value type or const = non-const" );
1663 AssignOffset< DstType, SrcFadType >::assign( dst, src );
1665 dst.m_impl_handle =
reinterpret_cast< typename DstType::handle_type
>(src.m_impl_handle) ;
1679 template<
class SrcTraits ,
class ... Args >
1681 < typename std::enable_if<(
1683 std::is_same< typename SrcTraits::specialize
1684 , ViewSpecializeSacadoFad >::value
1687 std::is_same< typename SrcTraits::array_layout
1688 , Kokkos::LayoutLeft >::value ||
1689 std::is_same< typename SrcTraits::array_layout
1690 , Kokkos::LayoutRight >::value ||
1691 std::is_same< typename SrcTraits::array_layout
1692 , Kokkos::LayoutStride >::value
1701 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
1705 , R0 = bool(is_integral_extent<0,Args...>::value)
1706 , R1 = bool(is_integral_extent<1,Args...>::value)
1707 , R2 = bool(is_integral_extent<2,Args...>::value)
1708 , R3 = bool(is_integral_extent<3,Args...>::value)
1709 , R4 = bool(is_integral_extent<4,Args...>::value)
1710 , R5 = bool(is_integral_extent<5,Args...>::value)
1711 , R6 = bool(is_integral_extent<6,Args...>::value)
1715 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1716 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1719 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1720 1 == SrcTraits::rank ? R0 : (
1721 2 == SrcTraits::rank ? R1 : (
1722 3 == SrcTraits::rank ? R2 : (
1723 4 == SrcTraits::rank ? R3 : (
1724 5 == SrcTraits::rank ? R4 : (
1725 6 == SrcTraits::rank ? R5 : R6 ))))))) };
1732 typedef typename std::conditional<
1736 ( std::is_same<
typename SrcTraits::array_layout
1737 , Kokkos::LayoutRight >::value
1739 ( rank == 1 ) && R0_rev
1742 ( std::is_same<
typename SrcTraits::array_layout
1743 , Kokkos::LayoutLeft >::value
1745 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
1747 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
1748 >::type array_layout ;
1750 typedef typename SrcTraits::value_type fad_type ;
1752 typedef typename std::conditional< rank == 0 , fad_type ,
1753 typename std::conditional< rank == 1 , fad_type * ,
1754 typename std::conditional< rank == 2 , fad_type ** ,
1755 typename std::conditional< rank == 3 , fad_type *** ,
1756 typename std::conditional< rank == 4 , fad_type **** ,
1757 typename std::conditional< rank == 5 , fad_type ***** ,
1758 typename std::conditional< rank == 6 , fad_type ****** ,
1760 >::type >::type >::type >::type >::type >::type >::type
1765 typedef Kokkos::ViewTraits
1768 ,
typename SrcTraits::device_type
1769 ,
typename SrcTraits::memory_traits > traits_type ;
1771 typedef Kokkos::View
1774 ,
typename SrcTraits::device_type
1775 ,
typename SrcTraits::memory_traits > type ;
1779 static void assign( ViewMapping< traits_type , typename traits_type::specialize > & dst
1780 , ViewMapping< SrcTraits ,typename SrcTraits::specialize >
const & src
1783 typedef ViewMapping< traits_type , typename traits_type::specialize > DstType ;
1784 typedef typename DstType::offset_type dst_offset_type ;
1785 typedef typename DstType::array_offset_type dst_array_offset_type ;
1786 typedef typename DstType::handle_type dst_handle_type ;
1788 const SubviewExtents< SrcTraits::rank , rank >
1789 extents( src.m_impl_offset.m_dim , args... );
1790 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
1791 array_extents( src.m_array_offset.m_dim , args... , Kokkos::ALL() );
1793 dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1794 dst.m_array_offset = dst_array_offset_type( src.m_array_offset , array_extents );
1796 dst_handle_type( src.m_impl_handle +
1797 src.m_array_offset( array_extents.domain_offset(0)
1798 , array_extents.domain_offset(1)
1799 , array_extents.domain_offset(2)
1800 , array_extents.domain_offset(3)
1801 , array_extents.domain_offset(4)
1802 , array_extents.domain_offset(5)
1803 , array_extents.domain_offset(6)
1804 , array_extents.domain_offset(7) ) );
1805 dst.m_fad_size = src.m_fad_size;
1806 dst.m_fad_stride = src.m_fad_stride.value;
1817 #if defined(HAVE_SACADO_KOKKOSCORE) && \
1818 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \
1819 defined(HAVE_SACADO_VIEW_SPEC) && \
1820 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1822 #include "Kokkos_TeuchosCommAdapters.hpp"
1826 template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
1827 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1828 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1831 (
const Comm<Ordinal>& comm,
1832 const EReductionType reductType ,
1834 const Kokkos::View<SD,SP...> & sendBuffer ,
1835 const Kokkos::View<RD,RP...> & recvBuffer )
1842 typedef Kokkos::View<SD,SP...> SendViewType;
1843 typedef Kokkos::View<RD,RP...> RecvViewType;
1844 typedef typename SendViewType::value_type send_value_type;
1845 typedef typename RecvViewType::value_type recv_value_type;
1848 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1849 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
1850 "The send View's rank is " << SendViewType::rank <<
" and the receive "
1851 "View's rank is " << RecvViewType::rank <<
".");
1855 typename SendViewType::HostMirror hostSendBuffer =
1856 Kokkos::create_mirror_view(sendBuffer);
1857 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1858 for (
Ordinal i=0; i<count; ++i)
1859 localSendBuffer[i] = hostSendBuffer(i);
1864 typename RecvViewType::HostMirror hostRecvBuffer =
1865 Kokkos::create_mirror_view(recvBuffer);
1866 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1867 for (
Ordinal i=0; i<count; ++i)
1868 localRecvBuffer[i] = hostRecvBuffer(i);
1872 localSendBuffer.getRawPtr(),
1873 localRecvBuffer.getRawPtr());
1876 for (
Ordinal i=0; i<count; ++i)
1877 hostRecvBuffer(i) = localRecvBuffer[i];
1878 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1882 template<
typename Ordinal ,
typename Serializer ,
1883 class SD ,
class ... SP ,
class RD ,
class ... RP >
1884 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1885 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1888 (
const Comm<Ordinal>& comm,
1889 const Serializer& serializer,
1890 const EReductionType reductType ,
1892 const Kokkos::View<SD,SP...> & sendBuffer ,
1893 const Kokkos::View<RD,RP...> & recvBuffer )
1900 typedef Kokkos::View<SD,SP...> SendViewType;
1901 typedef Kokkos::View<RD,RP...> RecvViewType;
1902 typedef typename SendViewType::value_type send_value_type;
1903 typedef typename RecvViewType::value_type recv_value_type;
1906 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1907 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
1908 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
1912 typename SendViewType::HostMirror hostSendBuffer =
1913 Kokkos::create_mirror_view(sendBuffer);
1914 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1915 for (
Ordinal i=0; i<count; ++i)
1916 localSendBuffer[i] = hostSendBuffer(i);
1921 typename RecvViewType::HostMirror hostRecvBuffer =
1922 Kokkos::create_mirror_view(recvBuffer);
1923 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1924 for (
Ordinal i=0; i<count; ++i)
1925 localRecvBuffer[i] = hostRecvBuffer(i);
1928 reduceAll(comm, serializer, reductType, count,
1929 localSendBuffer.getRawPtr(),
1930 localRecvBuffer.getRawPtr());
1933 for (
Ordinal i=0; i<count; ++i)
1934 hostRecvBuffer(i) = localRecvBuffer[i];
1935 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1939 template<
typename Ordinal,
class D,
class ... P >
1940 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1942 (
const Comm<Ordinal>& comm,
1943 const int rootRank ,
1945 const Kokkos::View<D,P...>& buffer)
1947 typedef Kokkos::View<
D,P...> view_type;
1948 typename view_type::array_type array_buffer = buffer;
1949 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
1950 broadcast( comm, rootRank, array_count, array_buffer );
1954 typename Serializer ,
1955 class D,
class ... P >
1956 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1958 (
const Comm<Ordinal>& comm,
1959 const Serializer& serializer,
1960 const int rootRank ,
1962 const Kokkos::View<D,P...>& buffer)
1964 typedef Kokkos::View<
D,P...> view_type;
1965 typename view_type::array_type array_buffer = buffer;
1966 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
1967 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
1968 array_count, array_buffer );
1977 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1979 #endif // defined(HAVE_SACADO_KOKKOSCORE)
Base template specification for ScalarType.
Base template specification for whether a type is a Fad type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
GeneralFad< StaticStorage< T, Num > > SLFad
Base template specification for static size.
#define KOKKOS_INLINE_FUNCTION
GeneralFad< DynamicStorage< T > > DFad
TEUCHOS_DEPRECATED void reduceAll(const Comm< Ordinal > &comm, const EReductionType reductType, const Packet &send, Packet *globalReduct)
#define KOKKOS_FORCEINLINE_FUNCTION
GeneralFad< StaticFixedStorage< T, Num > > SFad
Base template specification for testing whether type is statically sized.
Get view type for any Fad type.