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()
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()
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 );
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() ))))))))
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 };
1443 enum { is_assignable_data_type =
true };
1445 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1446 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1447 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1449 template<
class DstType >
1451 void assign( DstType & dst
1452 ,
const SrcFadType & src
1453 ,
const TrackType & )
1457 std::is_same<
typename DstTraits::array_layout
1458 , Kokkos::LayoutLeft >::value ||
1459 std::is_same<
typename DstTraits::array_layout
1460 , Kokkos::LayoutRight >::value ||
1461 std::is_same<
typename DstTraits::array_layout
1462 , Kokkos::LayoutStride >::value
1466 std::is_same<
typename SrcTraits::array_layout
1467 , Kokkos::LayoutLeft >::value ||
1468 std::is_same<
typename SrcTraits::array_layout
1469 , Kokkos::LayoutRight >::value ||
1470 std::is_same<
typename SrcTraits::array_layout
1471 , Kokkos::LayoutStride >::value
1473 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1476 std::is_same<
typename DstTraits::array_layout
1477 ,
typename SrcTraits::array_layout >::value ||
1478 std::is_same<
typename DstTraits::array_layout
1479 , Kokkos::LayoutStride >::value ,
1480 "View assignment must have compatible layout" );
1483 std::is_same<
typename DstTraits::scalar_array_type
1484 ,
typename SrcTraits::scalar_array_type >::value ||
1485 std::is_same<
typename DstTraits::scalar_array_type
1486 ,
typename SrcTraits::const_scalar_array_type >::value ,
1487 "View assignment must have same value type or const = non-const" );
1490 ViewDimensionAssignable
1491 <
typename DstType::offset_type::dimension_type
1492 ,
typename SrcFadType::offset_type::dimension_type >::value ,
1493 "View assignment must have compatible dimensions" );
1496 ViewDimensionAssignable
1497 <
typename DstType::array_offset_type::dimension_type
1498 ,
typename SrcFadType::array_offset_type::dimension_type >::value ,
1499 "View assignment must have compatible dimensions" );
1501 typedef typename DstType::offset_type dst_offset_type ;
1502 typedef typename DstType::array_offset_type dst_array_offset_type ;
1504 dst.m_impl_handle = src.m_impl_handle ;
1505 dst.m_impl_offset = dst_offset_type( src.m_impl_offset );
1506 dst.m_array_offset = dst_array_offset_type( src.m_array_offset );
1507 dst.m_fad_size = src.m_fad_size.value ;
1508 dst.m_fad_stride = src.m_fad_stride.value ;
1518 template<
class DstTraits ,
class SrcTraits >
1519 class ViewMapping< DstTraits , SrcTraits ,
1520 typename std::enable_if<(
1521 Kokkos::Impl::MemorySpaceAccess
1522 < typename DstTraits::memory_space
1523 , typename SrcTraits::memory_space >::assignable
1526 std::is_same< typename DstTraits::specialize , void >::value
1529 std::is_same< typename SrcTraits::specialize
1530 , ViewSpecializeSacadoFad >::value
1532 , typename DstTraits::specialize
1537 enum { is_assignable =
true };
1538 enum { is_assignable_data_type =
true };
1541 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1542 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1543 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1548 template <
class DstType,
class SrcFadType,
class Truth =
void >
1549 struct AssignOffset;
1551 template <
class DstType,
class SrcFadType >
1552 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank != (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1556 static void assign( DstType & dst,
const SrcFadType & src )
1558 typedef typename SrcTraits::value_type TraitsValueType;
1564 typedef typename DstType::offset_type::array_layout DstLayoutType;
1566 typedef typename SrcFadType::array_offset_type::dimension_type SrcViewDimension;
1571 static constexpr
bool is_layout_left =
1572 std::is_same< DstLayoutType, Kokkos::LayoutLeft>::value;
1574 typedef typename std::conditional< is_layout_left,
1575 typename SrcViewDimension:: template prepend< InnerStaticDim+1 >::type,
1576 typename SrcViewDimension:: template append < InnerStaticDim+1 >::type
1577 >::type SrcViewDimensionAppended;
1579 typedef std::integral_constant< unsigned , 0 > padding ;
1581 typedef ViewOffset< SrcViewDimensionAppended, DstLayoutType > TmpOffsetType;
1583 auto src_layout = src.m_array_offset.layout();
1585 if ( is_layout_left ) {
1586 auto prepend_layout = Kokkos::Impl::prependFadToLayout< DstLayoutType >::returnNewLayoutPlusFad(src_layout, InnerStaticDim+1);
1587 TmpOffsetType offset_tmp( padding(), prepend_layout );
1588 dst.m_impl_offset = offset_tmp;
1591 TmpOffsetType offset_tmp( padding(), src_layout );
1592 dst.m_impl_offset = offset_tmp;
1596 Kokkos::abort(
"Sacado error: Applying AssignOffset for case with nested Fads, but without nested Fads - something went wrong");
1601 template <
class DstType,
class SrcFadType >
1602 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank == (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1605 static void assign( DstType & dst,
const SrcFadType & src )
1608 typedef typename DstType::offset_type dst_offset_type ;
1609 dst.m_impl_offset = dst_offset_type( src.m_array_offset );
1621 template <
class DstType >
1624 assign( DstType & dst
1625 ,
const SrcFadType & src
1632 std::is_same<
typename DstTraits::array_layout
1633 , Kokkos::LayoutLeft >::value ||
1634 std::is_same<
typename DstTraits::array_layout
1635 , Kokkos::LayoutRight >::value ||
1636 std::is_same<
typename DstTraits::array_layout
1637 , Kokkos::LayoutStride >::value
1641 std::is_same<
typename SrcTraits::array_layout
1642 , Kokkos::LayoutLeft >::value ||
1643 std::is_same<
typename SrcTraits::array_layout
1644 , Kokkos::LayoutRight >::value ||
1645 std::is_same<
typename SrcTraits::array_layout
1646 , Kokkos::LayoutStride >::value
1648 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1651 std::is_same<
typename DstTraits::array_layout
1652 ,
typename SrcTraits::array_layout >::value ||
1653 std::is_same<
typename DstTraits::array_layout
1654 , Kokkos::LayoutStride >::value ,
1655 "View assignment must have compatible layout" );
1658 std::is_same<
typename DstTraits::scalar_array_type
1659 ,
typename SrcTraits::scalar_array_type >::value ||
1660 std::is_same<
typename DstTraits::scalar_array_type
1661 ,
typename SrcTraits::const_scalar_array_type >::value ,
1662 "View assignment must have same value type or const = non-const" );
1665 AssignOffset< DstType, SrcFadType >::assign( dst, src );
1667 dst.m_impl_handle =
reinterpret_cast< typename DstType::handle_type
>(src.m_impl_handle) ;
1681 template<
class SrcTraits ,
class ... Args >
1683 < typename std::enable_if<(
1685 std::is_same< typename SrcTraits::specialize
1686 , ViewSpecializeSacadoFad >::value
1689 std::is_same< typename SrcTraits::array_layout
1690 , Kokkos::LayoutLeft >::value ||
1691 std::is_same< typename SrcTraits::array_layout
1692 , Kokkos::LayoutRight >::value ||
1693 std::is_same< typename SrcTraits::array_layout
1694 , Kokkos::LayoutStride >::value
1703 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
1707 , R0 = bool(is_integral_extent<0,Args...>::value)
1708 , R1 = bool(is_integral_extent<1,Args...>::value)
1709 , R2 = bool(is_integral_extent<2,Args...>::value)
1710 , R3 = bool(is_integral_extent<3,Args...>::value)
1711 , R4 = bool(is_integral_extent<4,Args...>::value)
1712 , R5 = bool(is_integral_extent<5,Args...>::value)
1713 , R6 = bool(is_integral_extent<6,Args...>::value)
1717 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1718 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1721 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1722 1 == SrcTraits::rank ? R0 : (
1723 2 == SrcTraits::rank ? R1 : (
1724 3 == SrcTraits::rank ? R2 : (
1725 4 == SrcTraits::rank ? R3 : (
1726 5 == SrcTraits::rank ? R4 : (
1727 6 == SrcTraits::rank ? R5 : R6 ))))))) };
1734 typedef typename std::conditional<
1738 ( std::is_same<
typename SrcTraits::array_layout
1739 , Kokkos::LayoutRight >::value
1741 ( rank == 1 ) && R0_rev
1744 ( std::is_same<
typename SrcTraits::array_layout
1745 , Kokkos::LayoutLeft >::value
1747 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
1749 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
1750 >::type array_layout ;
1752 typedef typename SrcTraits::value_type fad_type ;
1754 typedef typename std::conditional< rank == 0 , fad_type ,
1755 typename std::conditional< rank == 1 , fad_type * ,
1756 typename std::conditional< rank == 2 , fad_type ** ,
1757 typename std::conditional< rank == 3 , fad_type *** ,
1758 typename std::conditional< rank == 4 , fad_type **** ,
1759 typename std::conditional< rank == 5 , fad_type ***** ,
1760 typename std::conditional< rank == 6 , fad_type ****** ,
1762 >::type >::type >::type >::type >::type >::type >::type
1767 typedef Kokkos::ViewTraits
1770 ,
typename SrcTraits::device_type
1771 ,
typename SrcTraits::memory_traits > traits_type ;
1773 typedef Kokkos::View
1776 ,
typename SrcTraits::device_type
1777 ,
typename SrcTraits::memory_traits > type ;
1781 static void assign( ViewMapping< traits_type , typename traits_type::specialize > & dst
1782 , ViewMapping< SrcTraits ,typename SrcTraits::specialize >
const & src
1785 typedef ViewMapping< traits_type , typename traits_type::specialize > DstType ;
1786 typedef typename DstType::offset_type dst_offset_type ;
1787 typedef typename DstType::array_offset_type dst_array_offset_type ;
1788 typedef typename DstType::handle_type dst_handle_type ;
1790 const SubviewExtents< SrcTraits::rank , rank >
1791 extents( src.m_impl_offset.m_dim , args... );
1792 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
1793 array_extents( src.m_array_offset.m_dim , args... , Kokkos::ALL() );
1795 dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1796 dst.m_array_offset = dst_array_offset_type( src.m_array_offset , array_extents );
1798 dst_handle_type( src.m_impl_handle +
1799 src.m_array_offset( array_extents.domain_offset(0)
1800 , array_extents.domain_offset(1)
1801 , array_extents.domain_offset(2)
1802 , array_extents.domain_offset(3)
1803 , array_extents.domain_offset(4)
1804 , array_extents.domain_offset(5)
1805 , array_extents.domain_offset(6)
1806 , array_extents.domain_offset(7) ) );
1807 dst.m_fad_size = src.m_fad_size;
1808 dst.m_fad_stride = src.m_fad_stride.value;
1819 #if defined(HAVE_SACADO_KOKKOSCORE) && \
1820 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \
1821 defined(HAVE_SACADO_VIEW_SPEC) && \
1822 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1824 #include "Kokkos_TeuchosCommAdapters.hpp"
1828 template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
1829 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1830 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1833 (
const Comm<Ordinal>& comm,
1834 const EReductionType reductType ,
1836 const Kokkos::View<SD,SP...> & sendBuffer ,
1837 const Kokkos::View<RD,RP...> & recvBuffer )
1844 typedef Kokkos::View<SD,SP...> SendViewType;
1845 typedef Kokkos::View<RD,RP...> RecvViewType;
1846 typedef typename SendViewType::value_type send_value_type;
1847 typedef typename RecvViewType::value_type recv_value_type;
1850 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1851 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
1852 "The send View's rank is " << SendViewType::rank <<
" and the receive "
1853 "View's rank is " << RecvViewType::rank <<
".");
1857 typename SendViewType::HostMirror hostSendBuffer =
1858 Kokkos::create_mirror_view(sendBuffer);
1859 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1860 for (
Ordinal i=0; i<count; ++i)
1861 localSendBuffer[i] = hostSendBuffer(i);
1866 typename RecvViewType::HostMirror hostRecvBuffer =
1867 Kokkos::create_mirror_view(recvBuffer);
1868 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1869 for (
Ordinal i=0; i<count; ++i)
1870 localRecvBuffer[i] = hostRecvBuffer(i);
1873 reduceAll(comm, reductType, count,
1874 localSendBuffer.getRawPtr(),
1875 localRecvBuffer.getRawPtr());
1878 for (
Ordinal i=0; i<count; ++i)
1879 hostRecvBuffer(i) = localRecvBuffer[i];
1880 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1884 template<
typename Ordinal ,
typename Serializer ,
1885 class SD ,
class ... SP ,
class RD ,
class ... RP >
1886 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1887 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1890 (
const Comm<Ordinal>& comm,
1891 const Serializer& serializer,
1892 const EReductionType reductType ,
1894 const Kokkos::View<SD,SP...> & sendBuffer ,
1895 const Kokkos::View<RD,RP...> & recvBuffer )
1902 typedef Kokkos::View<SD,SP...> SendViewType;
1903 typedef Kokkos::View<RD,RP...> RecvViewType;
1904 typedef typename SendViewType::value_type send_value_type;
1905 typedef typename RecvViewType::value_type recv_value_type;
1908 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1909 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
1910 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
1914 typename SendViewType::HostMirror hostSendBuffer =
1915 Kokkos::create_mirror_view(sendBuffer);
1916 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
1917 for (
Ordinal i=0; i<count; ++i)
1918 localSendBuffer[i] = hostSendBuffer(i);
1923 typename RecvViewType::HostMirror hostRecvBuffer =
1924 Kokkos::create_mirror_view(recvBuffer);
1925 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
1926 for (
Ordinal i=0; i<count; ++i)
1927 localRecvBuffer[i] = hostRecvBuffer(i);
1930 reduceAll(comm, serializer, reductType, count,
1931 localSendBuffer.getRawPtr(),
1932 localRecvBuffer.getRawPtr());
1935 for (
Ordinal i=0; i<count; ++i)
1936 hostRecvBuffer(i) = localRecvBuffer[i];
1937 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
1941 template<
typename Ordinal,
class D,
class ... P >
1942 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1944 (
const Comm<Ordinal>& comm,
1945 const int rootRank ,
1947 const Kokkos::View<D,P...>& buffer)
1949 typedef Kokkos::View<
D,P...> view_type;
1950 typename view_type::array_type array_buffer = buffer;
1951 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
1952 broadcast( comm, rootRank, array_count, array_buffer );
1956 typename Serializer ,
1957 class D,
class ... P >
1958 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
1960 (
const Comm<Ordinal>& comm,
1961 const Serializer& serializer,
1962 const int rootRank ,
1964 const Kokkos::View<D,P...>& buffer)
1966 typedef Kokkos::View<
D,P...> view_type;
1967 typename view_type::array_type array_buffer = buffer;
1968 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
1969 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
1970 array_count, array_buffer );
1979 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1981 #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
#define KOKKOS_DEFAULTED_FUNCTION
GeneralFad< DynamicStorage< T > > DFad
#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.