30#ifndef KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
31#define KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
34#if defined(HAVE_SACADO_KOKKOS)
41#ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
42#define KOKKOS_IMPL_PUBLIC_INCLUDE
43#define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
45#include "Kokkos_Layout.hpp"
46#ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
47#undef KOKKOS_IMPL_PUBLIC_INCLUDE
48#undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
56template <
typename view_type>
57struct is_view_fad {
static const bool value =
false; };
61template <
typename view_type>
62struct is_view_fad_contiguous {
static const bool value =
false; };
65template <
typename view_type>
68dimension_scalar(
const view_type& ) {
73template <
typename view_type>
76dimension_scalar_aligned(
const view_type& view) {
77 return dimension_scalar(view);
83#if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
90struct ViewSpecializeSacadoFad {};
91struct ViewSpecializeSacadoFadContiguous {};
93template<
class ... Args >
94struct is_ViewSpecializeSacadoFad {
enum { value =
false }; };
96template<
class D ,
class ... P ,
class ... Args >
97struct is_ViewSpecializeSacadoFad< Kokkos::
View<D,P...> , Args... > {
99 std::is_same<
typename Kokkos::ViewTraits<
D,P...>::specialize
100 , ViewSpecializeSacadoFad >::value
102 ( (
sizeof...(Args) == 0 ) ||
103 is_ViewSpecializeSacadoFad< Args... >::value ) };
111template <
typename T,
typename ... P>
112struct is_view_fad<
View<
T,P...> > {
113 typedef View<
T,P...> view_type;
114 static const bool value =
115 std::is_same<
typename view_type::specialize,
116 Impl::ViewSpecializeSacadoFad >::value ||
117 std::is_same<
typename view_type::specialize,
118 Impl::ViewSpecializeSacadoFadContiguous >::value;
121template <
typename T,
typename ... P>
122struct is_view_fad_contiguous<
View<
T,P...> > {
123 typedef View<
T,P...> view_type;
124 static const bool value =
125 std::is_same<
typename view_type::specialize,
126 Impl::ViewSpecializeSacadoFadContiguous >::value;
132#include "Kokkos_Core.hpp"
141template<
class DT,
class ... DP,
142 class ST,
class ... SP>
143typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
144 is_view_fad< Kokkos::View<ST,SP...> >::value
146view_copy(
const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
148 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
149 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
150 view_copy( dst_array_type(dst) , src_array_type(src) );
153template<
class ExecutionSpace,
154 class DT,
class ... DP,
155 class ST,
class ... SP>
156typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >::value &&
157 is_view_fad< Kokkos::View<ST,SP...> >::value
159view_copy(
const ExecutionSpace& space,
160 const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
162 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
163 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
164 view_copy( space, dst_array_type(dst) , src_array_type(src) );
172template <
typename T,
typename ... P>
173KOKKOS_INLINE_FUNCTION
175std::enable_if< is_view_fad<
View<
T,P...> >::value,
unsigned >::type
176dimension_scalar(
const View<T,P...>& view) {
177#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
178 return view.implementation_map().dimension_scalar();
180 return view.impl_map().dimension_scalar();
184template <
typename Layout>
186 typedef LayoutNatural<Layout> type;
189template <
typename Layout>
191 typedef LayoutNatural<Layout> type;
194template <
typename T,
typename Enable =
void >
197template <
typename T >
198struct ArrayScalar<
T, typename std::enable_if< !Sacado::IsFad<T>::value >::type > {
202template <
typename T >
203struct ArrayScalar<
T, typename std::enable_if< Sacado::IsFad<T>::value >::type > {
204 typedef typename ArrayScalar< typename Sacado::ValueType<T>::type >::type* type;
208template <
typename DataType,
int Rank >
209struct AppendRankToConvertedFad {
210 static_assert( Rank > -1,
"Sacado AppendRankToConvertedFad Error: Rank < 0" );
211 typedef typename AppendRankToConvertedFad<DataType,Rank-1>::type* type;
215template <
typename DataType >
216struct AppendRankToConvertedFad< DataType, 0 > {
217 typedef DataType type;
221template <
class ArrayLayout,
class Enable =
void >
222struct ViewArrayLayoutSelector;
224template <
class ArrayLayout >
225struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutLeft>::value >::type >
227 using type = Kokkos::LayoutLeft;
230template <
class ArrayLayout >
231struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutRight>::value >::type >
233 using type = Kokkos::LayoutRight;
236template <
class ArrayLayout >
237struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutStride>::value >::type >
239 using type = Kokkos::LayoutStride;
242template <
typename ViewType,
typename Enable =
void >
243struct PODViewDeepCopyType;
245template <
typename ViewType >
246struct PODViewDeepCopyType< ViewType, typename std::enable_if< is_view_fad<ViewType>::value >::type >
249 typedef ViewType view_type;
250 typedef typename ArrayScalar< typename view_type::value_type >::type fad_converted_type;
251 typedef typename AppendRankToConvertedFad< fad_converted_type, view_type::rank >::type new_data_type;
253 typedef typename ViewArrayLayoutSelector<typename view_type::array_layout>::type layout;
255 typedef typename view_type::device_type device;
256 typedef typename view_type::memory_traits memory;
258 typedef Kokkos::View< new_data_type, layout, device, memory > type;
262template <
typename ViewType >
263struct PODViewDeepCopyType< ViewType, typename std::enable_if< !is_view_fad<ViewType>::value >::type >
265 typedef ViewType type;
269template <
typename ViewType,
typename Enabled =
void>
270struct NaturalArrayType {
271 typedef ViewType type;
274template <
typename D,
typename ... P>
275struct NaturalArrayType<
View<
D,P...>,
276 typename std::enable_if< is_view_fad< View<D,P...> >::value >::type > {
277 typedef View<
D,P...> view_type;
278 typedef typename view_type::data_type data_type;
279 typedef typename view_type::array_layout layout;
280 typedef typename view_type::device_type device;
281 typedef typename view_type::memory_traits memory;
283 typedef typename ViewArrayLayoutSelector<layout>::type natural_layout;
284 typedef View<data_type,natural_layout,device,memory> type;
289template <
class OutputView,
typename Enabled =
void>
292 typedef typename OutputView::const_value_type const_value_type ;
293 typedef typename OutputView::execution_space execution_space ;
295 const OutputView output ;
296 const_value_type input ;
298 KOKKOS_INLINE_FUNCTION
299 void operator()(
const size_t i0 )
const
301 const size_t n1 = output.extent(1);
302 const size_t n2 = output.extent(2);
303 const size_t n3 = output.extent(3);
304 const size_t n4 = output.extent(4);
305 const size_t n5 = output.extent(5);
306 const size_t n6 = output.extent(6);
308 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
309 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
310 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
311 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
312 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
313 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
314 output.access(i0,i1,i2,i3,i4,i5,i6) = input ;
318 SacadoViewFill(
const OutputView & arg_out , const_value_type & arg_in )
319 : output( arg_out ), input( arg_in )
321 const size_t n0 = output.extent(0);
322 Kokkos::RangePolicy<execution_space> policy( 0, n0 );
323 Kokkos::parallel_for( policy, *
this );
330template<
class DT,
class ... DP >
332 const View<DT,DP...> & view ,
333 const typename Sacado::ScalarType<
typename View<DT,DP...>::value_type >::type & value
334 ,
typename std::enable_if<(
335 std::is_same<
typename ViewTraits<DT,DP...>::specialize
336 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
337 std::is_same<
typename ViewTraits<DT,DP...>::specialize
338 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
342 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
343 typename ViewTraits<DT,DP...>::non_const_value_type >::value
344 ,
"Can only deep copy into non-const type" );
346 Impl::SacadoViewFill<
View<DT,DP...> >( view , value );
351template<
class DT,
class ... DP >
353 const View<DT,DP...> & view ,
354 const typename View<DT,DP...>::value_type & value
355 ,
typename std::enable_if<(
356 std::is_same<
typename ViewTraits<DT,DP...>::specialize
357 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
358 std::is_same<
typename ViewTraits<DT,DP...>::specialize
359 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
363 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
364 typename ViewTraits<DT,DP...>::non_const_value_type >::value
365 ,
"Can only deep copy into non-const type" );
367 Impl::SacadoViewFill<
View<DT,DP...> >( view , value );
371template<
class ExecSpace,
class DT ,
class ... DP ,
class ST ,
class ... SP >
373void deep_copy(
const ExecSpace &,
374 const View<DT,DP...> & dst ,
375 const View<ST,SP...> & src
376 ,
typename std::enable_if<(
377 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
378 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
380 std::is_same<
typename ViewTraits<DT,DP...>::specialize
381 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
383 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
384 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
386 std::is_same<
typename ViewTraits<ST,SP...>::specialize
387 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
391 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
392 typename ViewTraits<DT,DP...>::non_const_value_type >::value
393 ,
"Deep copy destination must be non-const" );
396 ( unsigned(ViewTraits<DT,DP...>::rank) ==
397 unsigned(ViewTraits<ST,SP...>::rank) )
398 ,
"Deep copy destination and source must have same rank" );
402 typedef typename View<DT,DP...>::array_type dst_array_type;
403 typedef typename View<ST,SP...>::array_type src_array_type;
404 typename NaturalArrayType< dst_array_type >::type dst_array( dst );
405 typename NaturalArrayType< src_array_type >::type src_array( src );
408 typename PODViewDeepCopyType<
View<DT,DP...> >::type dst_array( dst );
409 typename PODViewDeepCopyType<
View<ST,SP...> >::type src_array( src );
411 Kokkos::deep_copy( ExecSpace(), dst_array , src_array );
415template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
417void deep_copy(
const View<DT,DP...> & dst ,
418 const View<ST,SP...> & src
419 ,
typename std::enable_if<(
420 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
421 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
423 std::is_same<
typename ViewTraits<DT,DP...>::specialize
424 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
426 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
427 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
429 std::is_same<
typename ViewTraits<ST,SP...>::specialize
430 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
433 using exec_space =
typename View<DT,DP...>::execution_space;
435 Kokkos::deep_copy(exec_space(), dst, src);
439template<
class T ,
class ... P >
441typename std::enable_if<
442 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
443 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
444 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
445 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
446 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
447 Kokkos::LayoutStride >::value,
448 typename Kokkos::View<T,P...>::HostMirror>::type
449create_mirror(
const Kokkos::View<T,P...> & src)
451 typedef View<
T,P...> src_type ;
452 typedef typename src_type::HostMirror dst_type ;
454 typename src_type::array_layout layout = src.layout();
455 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
457 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
460template<
class T ,
class ... P >
462typename std::enable_if<
463 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
464 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
465 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
466 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
467 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
468 Kokkos::LayoutStride >::value,
469 typename Kokkos::View<T,P...>::HostMirror>::type
470create_mirror(
const Kokkos::View<T,P...> & src)
472 typedef View<
T,P...> src_type ;
473 typedef typename src_type::array_type src_array_type ;
474 typedef typename src_type::HostMirror dst_type ;
476 Kokkos::LayoutStride layout ;
479 src_array_type src_array = src;
480 layout.dimension[0] = src_array.extent(0);
481 layout.dimension[1] = src_array.extent(1);
482 layout.dimension[2] = src_array.extent(2);
483 layout.dimension[3] = src_array.extent(3);
484 layout.dimension[4] = src_array.extent(4);
485 layout.dimension[5] = src_array.extent(5);
486 layout.dimension[6] = src_array.extent(6);
487 layout.dimension[7] = src_array.extent(7);
489 layout.stride[0] = src_array.stride_0();
490 layout.stride[1] = src_array.stride_1();
491 layout.stride[2] = src_array.stride_2();
492 layout.stride[3] = src_array.stride_3();
493 layout.stride[4] = src_array.stride_4();
494 layout.stride[5] = src_array.stride_5();
495 layout.stride[6] = src_array.stride_6();
496 layout.stride[7] = src_array.stride_7();
498 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
501template<
class Space,
class T,
class ... P,
typename Enabled>
502typename std::enable_if<
503 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
504 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
505 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
506 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value,
507 typename Impl::MirrorType<Space,
T,P ...>::view_type>::type
508create_mirror(
const Space& ,
const Kokkos::View<T,P...> & src)
510 typedef View<
T,P...> src_type ;
511 typename src_type::array_layout layout = src.layout();
512 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
513 return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),layout);
516template<
class T ,
class ... P >
518typename std::enable_if<
519 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
520 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
521 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
522 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
523 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
524 Kokkos::LayoutStride >::value,
525 typename Kokkos::View<T,P...>::HostMirror>::type
526create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
527 const Kokkos::View<T,P...> & src)
529 typedef View<
T,P...> src_type ;
530 typedef typename src_type::HostMirror dst_type ;
532 typename src_type::array_layout layout = src.layout();
533 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
536 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
539template<
class T ,
class ... P >
541typename std::enable_if<
542 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
543 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
544 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
545 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
546 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
547 Kokkos::LayoutStride >::value,
548 typename Kokkos::View<T,P...>::HostMirror>::type
549create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
550 const Kokkos::View<T,P...> & src)
552 typedef View<
T,P...> src_type ;
553 typedef typename src_type::array_type src_array_type ;
554 typedef typename src_type::HostMirror dst_type ;
556 Kokkos::LayoutStride layout ;
559 src_array_type src_array = src;
560 layout.dimension[0] = src_array.extent(0);
561 layout.dimension[1] = src_array.extent(1);
562 layout.dimension[2] = src_array.extent(2);
563 layout.dimension[3] = src_array.extent(3);
564 layout.dimension[4] = src_array.extent(4);
565 layout.dimension[5] = src_array.extent(5);
566 layout.dimension[6] = src_array.extent(6);
567 layout.dimension[7] = src_array.extent(7);
569 layout.stride[0] = src_array.stride_0();
570 layout.stride[1] = src_array.stride_1();
571 layout.stride[2] = src_array.stride_2();
572 layout.stride[3] = src_array.stride_3();
573 layout.stride[4] = src_array.stride_4();
574 layout.stride[5] = src_array.stride_5();
575 layout.stride[6] = src_array.stride_6();
576 layout.stride[7] = src_array.stride_7();
579 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
582template<
class Space,
class T,
class ... P,
typename Enable>
583typename std::enable_if<
584 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
585 Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
586 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
587 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ),
588 typename Impl::MirrorType<Space,T,P ...>::view_type>::type
589create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
590 const Space& ,
const Kokkos::View<T,P...> & src)
592 typedef View<
T,P...> src_type ;
593 typename src_type::array_layout layout = src.layout();
594 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
595 return typename Impl::MirrorType<Space,T,P ...>::view_type(
596 Kokkos::view_alloc(src.label(), wi), layout);
599template <
class Space,
class T,
class... P>
600typename Impl::MirrorViewType<Space,
T, P...>::view_type
601create_mirror_view_and_copy(
602 const Space&,
const Kokkos::View<T, P...>& src,
603 std::string
const& name,
604 typename std::enable_if<
605 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
606 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
607 std::is_same<
typename ViewTraits<T,P...>::specialize ,
608 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
609 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
613 "Kokkos::create_mirror_view_and_copy: fence before returning src view");
617template <
class Space,
class T,
class... P>
618typename Impl::MirrorViewType<Space,
T, P...>::view_type
619create_mirror_view_and_copy(
620 const Space&,
const Kokkos::View<T, P...>& src,
621 std::string
const& name,
622 typename std::enable_if<
623 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
624 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
625 std::is_same<
typename ViewTraits<T,P...>::specialize ,
626 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
627 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
629 using src_type =
View<
T,P...>;
630 using Mirror =
typename Impl::MirrorViewType<Space,
T, P...>::view_type;
631 std::string label = name.empty() ? src.label() : name;
632 typename src_type::array_layout layout = src.layout();
633 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
634 auto mirror =
typename Mirror::non_const_type{
635 view_alloc(WithoutInitializing, label), layout};
636 deep_copy(mirror, src);
642template <
unsigned N,
typename... Args>
643KOKKOS_FUNCTION std::enable_if_t<
644 N ==
View<Args...>::Rank &&
645 (std::is_same<
typename ViewTraits<Args...>::specialize,
646 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
647 std::is_same<
typename ViewTraits<Args...>::specialize,
648 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
650as_view_of_rank_n(View<Args...> v) {
656template <
unsigned N,
typename T,
typename... Args>
658 N !=
View<
T, Args...>::Rank &&
659 (std::is_same<
typename ViewTraits<
T, Args...>::specialize,
660 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
661 std::is_same<
typename ViewTraits<
T, Args...>::specialize,
662 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>::value),
663 View<
typename RankDataType<
typename View<T, Args...>::value_type,
N>::type,
665as_view_of_rank_n(View<T, Args...>) {
666 Kokkos::Impl::throw_runtime_exception(
667 "Trying to get at a View of the wrong rank");
680template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
681struct FadViewDataAnalysis
685 typedef ViewArrayAnalysis< DataType > array_analysis ;
690 typedef ViewSpecializeSacadoFad specialize ;
692 typedef typename array_analysis::dimension dimension ;
693 typedef typename array_analysis::value_type value_type ;
694 typedef typename array_analysis::const_value_type const_value_type ;
695 typedef typename array_analysis::non_const_value_type non_const_value_type ;
699 ViewDataType< value_type , dimension >::type type ;
701 ViewDataType< const_value_type , dimension >::type const_type ;
703 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
708 enum { is_const = std::is_same< value_type , const_value_type >::value };
712 std::conditional< is_const , const ScalarType , ScalarType >::type
715 typedef ScalarType non_const_scalar_type ;
716 typedef const ScalarType const_scalar_type ;
719 typedef typename array_analysis::dimension::
720 template append<( DimFad ? DimFad + 1 : 0 )>::type
727 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
730 ViewDataType< const_scalar_type , scalar_dimension >::type
731 const_scalar_array_type ;
734 ViewDataType< non_const_scalar_type , scalar_dimension >::type
735 non_const_scalar_array_type ;
740template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad,
unsigned Str
ide >
741struct FadViewDataAnalysis<DataType, LayoutContiguous<ArrayLayout,Stride>, ScalarType, DimFad>
745 typedef ViewArrayAnalysis< DataType > array_analysis ;
750 typedef ViewSpecializeSacadoFadContiguous specialize ;
752 typedef typename array_analysis::dimension dimension ;
753 typedef typename array_analysis::value_type value_type ;
754 typedef typename array_analysis::const_value_type const_value_type ;
755 typedef typename array_analysis::non_const_value_type non_const_value_type ;
759 ViewDataType< value_type , dimension >::type type ;
761 ViewDataType< const_value_type , dimension >::type const_type ;
763 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
768 enum { is_const = std::is_same< value_type , const_value_type >::value };
772 std::conditional< is_const , const ScalarType , ScalarType >::type
775 typedef ScalarType non_const_scalar_type ;
776 typedef const ScalarType const_scalar_type ;
779 typedef typename std::conditional<
780 std::is_same< ArrayLayout, Kokkos::LayoutLeft >::value,
781 typename array_analysis::dimension::
782 template prepend<0>::type,
783 typename array_analysis::dimension::
784 template append<0>::type >::type
791 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
794 ViewDataType< const_scalar_type , scalar_dimension >::type
795 const_scalar_array_type ;
798 ViewDataType< non_const_scalar_type , scalar_dimension >::type
799 non_const_scalar_array_type ;
808template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
809struct FadViewDataAnalysis<DataType, LayoutNatural<ArrayLayout>, ScalarType, DimFad>
813 typedef ViewArrayAnalysis< DataType > array_analysis ;
818 typedef void specialize ;
820 typedef typename array_analysis::dimension dimension ;
821 typedef typename array_analysis::value_type value_type ;
822 typedef typename array_analysis::const_value_type const_value_type ;
823 typedef typename array_analysis::non_const_value_type non_const_value_type ;
827 ViewDataType< value_type , dimension >::type type ;
829 ViewDataType< const_value_type , dimension >::type const_type ;
831 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
834 typedef type scalar_array_type ;
835 typedef const_type const_scalar_array_type ;
836 typedef non_const_type non_const_scalar_array_type ;
849#ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
850namespace Fad {
template<
typename >
class DFad ; }
851namespace Fad {
template<
typename ,
int >
class SFad ; }
852namespace Fad {
template<
typename ,
int >
class SLFad ; }
856namespace ELRFad {
template<
typename >
class DFad ; }
859namespace CacheFad {
template<
typename ,
int >
class SFad ; }
860namespace ELRFad {
template<
typename ,
int >
class SFad ; }
864namespace CacheFad {
template<
typename ,
int >
class SLFad ; }
865namespace ELRFad {
template<
typename ,
int >
class SLFad ; }
872#define KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( NS ) \
873template< class DataType , class ArrayLayout , typename ScalarType > \
874struct ViewDataAnalysis \
877 , Sacado:: NS ::DFad< ScalarType > \
878 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , 0 > {}; \
880template< class DataType , class ArrayLayout , typename ScalarType , int N > \
881struct ViewDataAnalysis \
884 , Sacado:: NS ::SFad< ScalarType , N > \
885 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
886 int(Sacado::StaticSize< Sacado:: NS ::SFad< ScalarType , N > >::value) \
889template< class DataType , class ArrayLayout , typename ScalarType , int N > \
890struct ViewDataAnalysis \
893 , Sacado:: NS ::SLFad< ScalarType , N > \
894 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
895 int(Sacado::StaticSize< Sacado:: NS ::SLFad< ScalarType , N > >::value) \
898template<
class DataType ,
class ArrayLayout ,
typename StorageType >
899struct ViewDataAnalysis
902 , Sacado::Fad::Exp::GeneralFad< StorageType >
903 > :
public FadViewDataAnalysis< DataType, ArrayLayout, typename StorageType::value_type , 0 > {};
905#ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
906KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( Fad )
909KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( CacheFad )
910KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRFad )
911KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRCacheFad )
913#undef KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD
923template <
class View,
class ... ViewPack>
924KOKKOS_INLINE_FUNCTION
925unsigned dimension_scalar(
const View& v,
const ViewPack&... views) {
926 const unsigned dim0 = dimension_scalar(v);
927 const unsigned dim1 = dimension_scalar(views...);
928 return dim0 >= dim1 ? dim0 : dim1 ;
937template <
typename Specialize,
typename A,
typename B >
938struct CommonViewValueType;
940template <
typename A,
typename B >
941struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFad,
A, B >
943 using value_type =
typename Sacado::Promote<A,B>::type ;
946template <
typename A,
typename B >
947struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFadContiguous,
A, B >
949 using value_type =
typename Sacado::Promote<A,B>::type ;
953template <
class Specialize,
class ValueType >
954struct CommonViewAllocProp;
956template <
class ValueType >
957struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFad, ValueType >
959 using value_type = ValueType;
964 KOKKOS_INLINE_FUNCTION
965 CommonViewAllocProp()
970 template <
class View >
971 KOKKOS_INLINE_FUNCTION
972 CommonViewAllocProp(
const View & view )
973 :
fad_dim ( dimension_scalar(view) )
975 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
979 template <
class View,
class ... Views >
980 KOKKOS_INLINE_FUNCTION
981 CommonViewAllocProp(
const View & view,
const Views & ... views )
982 :
fad_dim ( dimension_scalar(view, views... ) )
984 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
989template <
class ValueType >
990struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFadContiguous, ValueType >
992 using value_type = ValueType;
997 KOKKOS_INLINE_FUNCTION
998 CommonViewAllocProp()
1003 template <
class View >
1004 KOKKOS_INLINE_FUNCTION
1005 CommonViewAllocProp(
const View & view )
1006 :
fad_dim ( dimension_scalar(view) )
1008 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
1012 template <
class View,
class ... Views >
1013 KOKKOS_INLINE_FUNCTION
1014 CommonViewAllocProp(
const View & view,
const Views & ... views )
1015 :
fad_dim ( dimension_scalar(view, views... ) )
1017 is_view_type = (Kokkos::is_view<View>::value || Kokkos::is_view_fad<View>::value);
1022template <
typename ... P >
1023struct has_common_view_alloc_prop :
public std::false_type {};
1025template <
class Specialize,
class ValueType >
1026struct has_common_view_alloc_prop< CommonViewAllocProp<Specialize, ValueType> > :
public std::true_type {};
1030template <
typename ... >
1031struct check_has_common_view_alloc_prop;
1034struct check_has_common_view_alloc_prop<>
1036 enum { value =
false };
1039template <
typename P >
1040struct check_has_common_view_alloc_prop<P>
1042 enum { value = has_common_view_alloc_prop< P >::value };
1045template <
typename P0,
typename ... P >
1046struct check_has_common_view_alloc_prop<P0, P...>
1048 enum { value = ( (has_common_view_alloc_prop<P0>::value ==
true) ?
true : check_has_common_view_alloc_prop<P...>::value ) };
1051template <
typename ... >
1052struct compute_fad_dim_from_alloc_prop;
1055struct compute_fad_dim_from_alloc_prop<> {
1056 template <
typename CtorProp>
1057 KOKKOS_INLINE_FUNCTION
1058 static unsigned eval(
const CtorProp&) {
return 0; }
1061template <
typename P >
1062struct compute_fad_dim_from_alloc_prop<P> {
1063 template <
typename CtorProp>
1064 KOKKOS_INLINE_FUNCTION
1065 static unsigned eval(
const CtorProp&) {
return 0; }
1068template <
typename P0,
typename ... P >
1069struct compute_fad_dim_from_alloc_prop<P0,P...> {
1070 template <
typename CtorProp>
1071 KOKKOS_INLINE_FUNCTION
1072 static unsigned eval(
const CtorProp& prop) {
1073 unsigned d1 = compute_fad_dim_from_alloc_prop<P0>::eval(prop);
1074 unsigned d2 = compute_fad_dim_from_alloc_prop<P...>::eval(prop);
1075 return d1 > d2 ? d1 : d2;
1079template <
class ValueType >
1080struct compute_fad_dim_from_alloc_prop<
1081 CommonViewAllocProp<ViewSpecializeSacadoFad, ValueType>
1083 template <
typename CtorProp>
1084 KOKKOS_INLINE_FUNCTION
1085 static unsigned eval(
const CtorProp& prop) {
1086 using specialize = ViewSpecializeSacadoFad;
1087 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1088 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1089 return cast_prop.fad_dim;
1093template <
class ValueType >
1094struct compute_fad_dim_from_alloc_prop<
1095 CommonViewAllocProp<ViewSpecializeSacadoFadContiguous, ValueType>
1097 template <
typename CtorProp>
1098 KOKKOS_INLINE_FUNCTION
1099 static unsigned eval(
const CtorProp& prop) {
1100 using specialize = ViewSpecializeSacadoFadContiguous;
1101 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1102 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1103 return cast_prop.fad_dim;
1107template <
typename Traits,
typename ... P >
1108struct appendFadToLayoutViewAllocHelper
1110 using layout_type =
typename Traits::array_layout;
1111 using specialize =
typename Traits::specialize;
1112 using CtorProp = ViewCtorProp< P... >;
1114 KOKKOS_INLINE_FUNCTION
1115 static layout_type returnNewLayoutPlusFad(
const CtorProp & arg_prop,
const layout_type & arg_layout ) {
1117 layout_type appended_layout( arg_layout );
1122 compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
1123 appended_layout.dimension[ Traits::rank ] = (
fad_dim > 0) ?
fad_dim : 1;
1125 return appended_layout;
1129template <
typename Layout>
1130struct prependFadToLayout
1132 using layout_type = Layout;
1134 template <
typename FadSizeType >
1135 KOKKOS_INLINE_FUNCTION
1136 static layout_type returnNewLayoutPlusFad(
const layout_type & arg_layout,
const FadSizeType
fad_dim ) {
1138 layout_type prepended_layout(0,0,0,0,0,0,0,0);
1140 prepended_layout.dimension[0] =
fad_dim;
1142 for (
int i = 1; i < ARRAY_LAYOUT_MAX_RANK; ++i ) {
1143 prepended_layout.dimension[i] = arg_layout.dimension[i-1];
1146 return prepended_layout;
1159template<
class Traits >
1160class ViewMapping< Traits ,
1161 typename std::enable_if<
1162 ( std::is_same< typename Traits::specialize
1163 , ViewSpecializeSacadoFad >::value
1165 ( std::is_same< typename Traits::array_layout
1166 , Kokkos::LayoutLeft >::value
1168 std::is_same< typename Traits::array_layout
1169 , Kokkos::LayoutRight >::value
1171 std::is_same< typename Traits::array_layout
1172 , Kokkos::LayoutStride >::value
1175 , typename Traits::specialize
1180 template< class ,
class ... >
friend class ViewMapping ;
1181 template< class ,
class ... >
friend class Kokkos::View ;
1183 typedef typename Traits::value_type fad_type ;
1186 std::add_const< fad_value_type >::type const_fad_value_type ;
1189 typedef Sacado::integral_nonzero< unsigned , FadStaticDimension > sacado_size_type;
1192 enum { FadStaticStride =
1193 std::is_same<
typename Traits::array_layout
1194 , Kokkos::LayoutRight >::value ? 1 : 0 };
1196 typedef Sacado::integral_nonzero< unsigned , FadStaticStride > sacado_stride_type;
1198 typedef fad_value_type * handle_type ;
1200 typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1203 typedef ViewOffset<
typename Traits::dimension
1204 ,
typename Traits::array_layout
1210 <
typename array_analysis::dimension::
1211 template append<( unsigned(FadStaticDimension) > 0 ? unsigned(FadStaticDimension) + 1 : 0 )>::type
1212 ,
typename Traits::array_layout
1214 > array_offset_type ;
1216 handle_type m_impl_handle ;
1217 offset_type m_impl_offset ;
1218 array_offset_type m_array_offset ;
1219 sacado_size_type m_fad_size ;
1220 sacado_stride_type m_fad_stride ;
1227 enum { Rank = Traits::dimension::rank };
1230 template<
typename iType >
1231 KOKKOS_INLINE_FUNCTION
constexpr size_t extent(
const iType & r )
const
1232 {
return m_impl_offset.m_dim.extent(r) ; }
1234 KOKKOS_INLINE_FUNCTION
constexpr
1235 typename Traits::array_layout layout()
const
1236 {
return m_impl_offset.layout(); }
1238 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_0()
const
1239 {
return m_impl_offset.dimension_0(); }
1240 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_1()
const
1241 {
return m_impl_offset.dimension_1(); }
1242 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_2()
const
1243 {
return m_impl_offset.dimension_2(); }
1244 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_3()
const
1245 {
return m_impl_offset.dimension_3(); }
1246 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_4()
const
1247 {
return m_impl_offset.dimension_4(); }
1248 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_5()
const
1249 {
return m_impl_offset.dimension_5(); }
1250 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_6()
const
1251 {
return m_impl_offset.dimension_6(); }
1252 KOKKOS_INLINE_FUNCTION
constexpr size_t dimension_7()
const
1253 {
return m_impl_offset.dimension_7(); }
1257 using is_regular = std::false_type ;
1259 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_0()
const
1260 {
return m_impl_offset.stride_0(); }
1261 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_1()
const
1262 {
return m_impl_offset.stride_1(); }
1263 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_2()
const
1264 {
return m_impl_offset.stride_2(); }
1265 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_3()
const
1266 {
return m_impl_offset.stride_3(); }
1267 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_4()
const
1268 {
return m_impl_offset.stride_4(); }
1269 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_5()
const
1270 {
return m_impl_offset.stride_5(); }
1271 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_6()
const
1272 {
return m_impl_offset.stride_6(); }
1273 KOKKOS_INLINE_FUNCTION
constexpr size_t stride_7()
const
1274 {
return m_impl_offset.stride_7(); }
1276 template<
typename iType >
1277 KOKKOS_INLINE_FUNCTION
void stride( iType *
const s )
const
1278 { m_impl_offset.stride(s) ; }
1281 KOKKOS_FORCEINLINE_FUNCTION
constexpr unsigned dimension_scalar()
const
1282 {
return m_fad_size.value+1; }
1285 KOKKOS_FORCEINLINE_FUNCTION
constexpr unsigned stride_scalar()
const
1286 {
return m_fad_stride.value; }
1293 Sacado::ViewFadType< fad_type , FadStaticDimension , FadStaticStride >::type reference_type ;
1296 typedef fad_value_type * pointer_type ;
1299 KOKKOS_INLINE_FUNCTION
constexpr size_t span()
const
1300 {
return m_array_offset.span(); }
1303 KOKKOS_INLINE_FUNCTION
constexpr bool span_is_contiguous()
const
1304 {
return m_array_offset.span_is_contiguous() ; }
1307 KOKKOS_INLINE_FUNCTION
constexpr pointer_type data()
const
1308 {
return m_impl_handle ; }
1312 KOKKOS_FORCEINLINE_FUNCTION
1313 reference_type reference()
const
1314 {
return reference_type( m_impl_handle
1316 , m_fad_stride.value ); }
1318 template<
typename I0 >
1319 KOKKOS_FORCEINLINE_FUNCTION
1321 reference(
const I0 & i0 )
const
1322 {
return reference_type( m_impl_handle + m_array_offset(i0,0)
1324 , m_fad_stride.value ); }
1326 template<
typename I0 ,
typename I1 >
1327 KOKKOS_FORCEINLINE_FUNCTION
1328 reference_type reference(
const I0 & i0 ,
const I1 & i1 )
const
1329 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,0)
1331 , m_fad_stride.value ); }
1334 template<
typename I0 ,
typename I1 ,
typename I2 >
1335 KOKKOS_FORCEINLINE_FUNCTION
1336 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 )
const
1337 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,0)
1339 , m_fad_stride.value ); }
1341 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3 >
1342 KOKKOS_FORCEINLINE_FUNCTION
1343 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3 )
const
1344 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,0)
1346 , m_fad_stride.value ); }
1348 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1350 KOKKOS_FORCEINLINE_FUNCTION
1351 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1352 ,
const I4 & i4 )
const
1353 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,0)
1355 , m_fad_stride.value ); }
1357 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1358 ,
typename I4 ,
typename I5 >
1359 KOKKOS_FORCEINLINE_FUNCTION
1360 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1361 ,
const I4 & i4 ,
const I5 & i5 )
const
1362 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,0)
1364 , m_fad_stride.value ); }
1367 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1368 ,
typename I4 ,
typename I5 ,
typename I6 >
1369 KOKKOS_FORCEINLINE_FUNCTION
1370 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1371 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 )
const
1372 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,i6,0)
1374 , m_fad_stride.value ); }
1379 KOKKOS_INLINE_FUNCTION
1380 static size_t memory_span(
typename Traits::array_layout
const & layout )
1383 for (
int i=0; i<8; ++i)
1384 dims[i] = layout.dimension[i];
1385 if (
unsigned(FadStaticDimension) > 0)
1386 dims[unsigned(Rank)] = FadStaticDimension+1;
1388 typename Traits::array_layout alayout(
1389 dims[0], dims[1], dims[2], dims[3],
1390 dims[4], dims[5], dims[6], dims[7] );
1393 typedef std::integral_constant< unsigned , 0 > padding ;
1394 return array_offset_type( padding() , alayout ).span() *
sizeof(fad_value_type);
1399 KOKKOS_INLINE_FUNCTION ~ViewMapping() {}
1400 KOKKOS_INLINE_FUNCTION ViewMapping() : m_impl_handle(0) , m_impl_offset() , m_array_offset() , m_fad_size(0) , m_fad_stride(0) {}
1402 KOKKOS_DEFAULTED_FUNCTION ViewMapping(
const ViewMapping & ) = default ;
1403 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = (
const ViewMapping & ) = default ;
1405 KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1406 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1408 template<
class ... P >
1409 KOKKOS_INLINE_FUNCTION
1411 ( ViewCtorProp< P ... >
const & prop
1412 ,
typename Traits::array_layout
const & local_layout
1414 : m_impl_handle( ( (ViewCtorProp<void,pointer_type> const &) prop ).value )
1415 , m_impl_offset( std::integral_constant< unsigned , 0 >()
1417 , m_array_offset( std::integral_constant< unsigned , 0 >()
1421 ( Rank == 0 ? m_array_offset.dimension_0() :
1422 ( Rank == 1 ? m_array_offset.dimension_1() :
1423 ( Rank == 2 ? m_array_offset.dimension_2() :
1424 ( Rank == 3 ? m_array_offset.dimension_3() :
1425 ( Rank == 4 ? m_array_offset.dimension_4() :
1426 ( Rank == 5 ? m_array_offset.dimension_5() :
1427 ( Rank == 6 ? m_array_offset.dimension_6() :
1428 m_array_offset.dimension_7() ))))))) - 1 )
1430 ( Rank == 0 ? m_array_offset.stride_0() :
1431 ( Rank == 1 ? m_array_offset.stride_1() :
1432 ( Rank == 2 ? m_array_offset.stride_2() :
1433 ( Rank == 3 ? m_array_offset.stride_3() :
1434 ( Rank == 4 ? m_array_offset.stride_4() :
1435 ( Rank == 5 ? m_array_offset.stride_5() :
1436 ( Rank == 6 ? m_array_offset.stride_6() :
1437 m_array_offset.stride_7() ))))))))
1441 ( Rank == 0 ? m_array_offset.dimension_0() :
1442 ( Rank == 1 ? m_array_offset.dimension_1() :
1443 ( Rank == 2 ? m_array_offset.dimension_2() :
1444 ( Rank == 3 ? m_array_offset.dimension_3() :
1445 ( Rank == 4 ? m_array_offset.dimension_4() :
1446 ( Rank == 5 ? m_array_offset.dimension_5() :
1447 ( Rank == 6 ? m_array_offset.dimension_6() :
1448 m_array_offset.dimension_7() )))))));
1449 if (
unsigned(FadStaticDimension) == 0 &&
fad_dim == 0)
1450 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1458 template<
class ... P >
1459 SharedAllocationRecord<> *
1460 allocate_shared( ViewCtorProp< P... >
const & prop
1461 ,
typename Traits::array_layout
const & local_layout
1462 ,
bool execution_space_specified)
1464 typedef ViewCtorProp< P... > ctor_prop ;
1466 typedef typename ctor_prop::execution_space execution_space ;
1467 typedef typename Traits::memory_space memory_space ;
1468 typedef ViewValueFunctor< execution_space , fad_value_type > functor_type ;
1469 typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1472 typedef std::integral_constant< unsigned , 0 > padding ;
1475 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >::value };
1477 m_impl_offset = offset_type( padding(), local_layout );
1479 typename Traits::array_layout internal_layout =
1480 (test_traits_check ==
true)
1481 ? Kokkos::Impl::appendFadToLayoutViewAllocHelper< Traits, P... >::returnNewLayoutPlusFad(prop, local_layout)
1484 m_array_offset = array_offset_type( padding(), internal_layout );
1487 ( Rank == 0 ? m_array_offset.dimension_0() :
1488 ( Rank == 1 ? m_array_offset.dimension_1() :
1489 ( Rank == 2 ? m_array_offset.dimension_2() :
1490 ( Rank == 3 ? m_array_offset.dimension_3() :
1491 ( Rank == 4 ? m_array_offset.dimension_4() :
1492 ( Rank == 5 ? m_array_offset.dimension_5() :
1493 ( Rank == 6 ? m_array_offset.dimension_6() :
1494 m_array_offset.dimension_7() )))))));
1495 if (
unsigned(FadStaticDimension) == 0 &&
fad_dim == 0)
1496 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1500 ( Rank == 0 ? m_array_offset.stride_0() :
1501 ( Rank == 1 ? m_array_offset.stride_1() :
1502 ( Rank == 2 ? m_array_offset.stride_2() :
1503 ( Rank == 3 ? m_array_offset.stride_3() :
1504 ( Rank == 4 ? m_array_offset.stride_4() :
1505 ( Rank == 5 ? m_array_offset.stride_5() :
1506 ( Rank == 6 ? m_array_offset.stride_6() :
1507 m_array_offset.stride_7() )))))));
1509 const size_t alloc_size = m_array_offset.span() *
sizeof(fad_value_type);
1512 record_type *
const record =
1513 record_type::allocate( ( (ViewCtorProp<void,memory_space>
const &) prop ).value
1514 , ( (ViewCtorProp<void,std::string>
const &) prop ).value
1521 m_impl_handle = handle_type(
reinterpret_cast< pointer_type
>( record->data() ) );
1523 if ( ctor_prop::initialize ) {
1524 auto space = ((ViewCtorProp<void,execution_space>
const &) prop).value;
1527 if (execution_space_specified)
1528 record->m_destroy = functor_type( space
1529 , (fad_value_type *) m_impl_handle
1530 , m_array_offset.span()
1531 , record->get_label()
1534 record->m_destroy = functor_type((fad_value_type *) m_impl_handle
1535 , m_array_offset.span()
1536 , record->get_label()
1540 record->m_destroy.construct_shared_allocation();
1562template<
class DstTraits ,
class SrcTraits >
1563class ViewMapping< DstTraits , SrcTraits ,
1564 typename std::enable_if<(
1565 Kokkos::Impl::MemorySpaceAccess
1566 < typename DstTraits::memory_space
1567 , typename SrcTraits::memory_space >::assignable
1570 std::is_same< typename DstTraits::specialize
1571 , ViewSpecializeSacadoFad >::value
1574 std::is_same< typename SrcTraits::specialize
1575 , ViewSpecializeSacadoFad >::value
1578 , typename DstTraits::specialize
1583 enum { is_assignable =
true };
1584 enum { is_assignable_data_type =
true };
1586 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1587 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1588 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1590 template<
class DstType >
1591 KOKKOS_INLINE_FUNCTION
static
1592 void assign( DstType & dst
1593 ,
const SrcFadType & src
1594 ,
const TrackType & )
1598 std::is_same<
typename DstTraits::array_layout
1599 , Kokkos::LayoutLeft >::value ||
1600 std::is_same<
typename DstTraits::array_layout
1601 , Kokkos::LayoutRight >::value ||
1602 std::is_same<
typename DstTraits::array_layout
1603 , Kokkos::LayoutStride >::value
1607 std::is_same<
typename SrcTraits::array_layout
1608 , Kokkos::LayoutLeft >::value ||
1609 std::is_same<
typename SrcTraits::array_layout
1610 , Kokkos::LayoutRight >::value ||
1611 std::is_same<
typename SrcTraits::array_layout
1612 , Kokkos::LayoutStride >::value
1614 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1617 std::is_same<
typename DstTraits::array_layout
1618 ,
typename SrcTraits::array_layout >::value ||
1619 std::is_same<
typename DstTraits::array_layout
1620 , Kokkos::LayoutStride >::value ,
1621 "View assignment must have compatible layout" );
1624 std::is_same<
typename DstTraits::value_type
1625 ,
typename SrcTraits::value_type >::value ||
1626 std::is_same<
typename DstTraits::value_type
1627 ,
typename SrcTraits::const_value_type >::value ,
1628 "View assignment must have same value type or const = non-const" );
1631 ViewDimensionAssignable
1632 <
typename DstType::offset_type::dimension_type
1633 ,
typename SrcFadType::offset_type::dimension_type >::value ,
1634 "View assignment must have compatible dimensions" );
1637 ViewDimensionAssignable
1638 <
typename DstType::array_offset_type::dimension_type
1639 ,
typename SrcFadType::array_offset_type::dimension_type >::value ,
1640 "View assignment must have compatible dimensions" );
1642 typedef typename DstType::offset_type dst_offset_type ;
1643 typedef typename DstType::array_offset_type dst_array_offset_type ;
1645 dst.m_impl_handle = src.m_impl_handle ;
1646 dst.m_impl_offset = dst_offset_type( src.m_impl_offset );
1647 dst.m_array_offset = dst_array_offset_type( src.m_array_offset );
1648 dst.m_fad_size = src.m_fad_size.value ;
1649 dst.m_fad_stride = src.m_fad_stride.value ;
1659template<
class DstTraits ,
class SrcTraits >
1660class ViewMapping< DstTraits , SrcTraits ,
1661 typename std::enable_if<(
1662 Kokkos::Impl::MemorySpaceAccess
1663 < typename DstTraits::memory_space
1664 , typename SrcTraits::memory_space >::assignable
1667 std::is_same< typename DstTraits::specialize , void >::value
1670 std::is_same< typename SrcTraits::specialize
1671 , ViewSpecializeSacadoFad >::value
1673 , typename DstTraits::specialize
1678 enum { is_assignable =
true };
1679 enum { is_assignable_data_type =
true };
1682 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1683 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1684 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1689 template <
class DstType,
class SrcFadType,
class Truth =
void >
1690 struct AssignOffset;
1692 template <
class DstType,
class SrcFadType >
1693 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank != (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1696 KOKKOS_INLINE_FUNCTION
1697 static void assign( DstType & dst,
const SrcFadType & src )
1699 typedef typename SrcTraits::value_type TraitsValueType;
1705 typedef typename DstType::offset_type::array_layout DstLayoutType;
1707 typedef typename SrcFadType::array_offset_type::dimension_type SrcViewDimension;
1710 const size_t InnerStaticDim = Sacado::StaticSize< typename Sacado::ValueType< TraitsValueType >::type >::value;
1712 static constexpr bool is_layout_left =
1713 std::is_same< DstLayoutType, Kokkos::LayoutLeft>::value;
1715 typedef typename std::conditional< is_layout_left,
1716 typename SrcViewDimension:: template prepend< InnerStaticDim+1 >::type,
1717 typename SrcViewDimension:: template append < InnerStaticDim+1 >::type
1718 >::type SrcViewDimensionAppended;
1720 typedef std::integral_constant< unsigned , 0 > padding ;
1722 typedef ViewOffset< SrcViewDimensionAppended, DstLayoutType > TmpOffsetType;
1724 auto src_layout = src.m_array_offset.layout();
1726 if ( is_layout_left ) {
1727 auto prepend_layout = Kokkos::Impl::prependFadToLayout< DstLayoutType >::returnNewLayoutPlusFad(src_layout, InnerStaticDim+1);
1728 TmpOffsetType offset_tmp( padding(), prepend_layout );
1729 dst.m_impl_offset = offset_tmp;
1732 TmpOffsetType offset_tmp( padding(), src_layout );
1733 dst.m_impl_offset = offset_tmp;
1737 Kokkos::abort(
"Sacado error: Applying AssignOffset for case with nested Fads, but without nested Fads - something went wrong");
1742 template <
class DstType,
class SrcFadType >
1743 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank == (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
1745 KOKKOS_INLINE_FUNCTION
1746 static void assign( DstType & dst,
const SrcFadType & src )
1749 typedef typename DstType::offset_type dst_offset_type ;
1750 dst.m_impl_offset = dst_offset_type( src.m_array_offset );
1762 template <
class DstType >
1763 KOKKOS_INLINE_FUNCTION
static
1765 assign( DstType & dst
1766 ,
const SrcFadType & src
1773 std::is_same<
typename DstTraits::array_layout
1774 , Kokkos::LayoutLeft >::value ||
1775 std::is_same<
typename DstTraits::array_layout
1776 , Kokkos::LayoutRight >::value ||
1777 std::is_same<
typename DstTraits::array_layout
1778 , Kokkos::LayoutStride >::value
1782 std::is_same<
typename SrcTraits::array_layout
1783 , Kokkos::LayoutLeft >::value ||
1784 std::is_same<
typename SrcTraits::array_layout
1785 , Kokkos::LayoutRight >::value ||
1786 std::is_same<
typename SrcTraits::array_layout
1787 , Kokkos::LayoutStride >::value
1789 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1792 std::is_same<
typename DstTraits::array_layout
1793 ,
typename SrcTraits::array_layout >::value ||
1794 std::is_same<
typename DstTraits::array_layout
1795 , Kokkos::LayoutStride >::value ,
1796 "View assignment must have compatible layout" );
1799 std::is_same<
typename DstTraits::scalar_array_type
1800 ,
typename SrcTraits::scalar_array_type >::value ||
1801 std::is_same<
typename DstTraits::scalar_array_type
1802 ,
typename SrcTraits::const_scalar_array_type >::value ,
1803 "View assignment must have same value type or const = non-const" );
1806 AssignOffset< DstType, SrcFadType >::assign( dst, src );
1808 dst.m_impl_handle =
reinterpret_cast< typename DstType::handle_type
>(src.m_impl_handle) ;
1822template<
class SrcTraits ,
class ... Args >
1824 < typename std::enable_if<(
1826 std::is_same< typename SrcTraits::specialize
1827 , ViewSpecializeSacadoFad >::value
1830 std::is_same< typename SrcTraits::array_layout
1831 , Kokkos::LayoutLeft >::value ||
1832 std::is_same< typename SrcTraits::array_layout
1833 , Kokkos::LayoutRight >::value ||
1834 std::is_same< typename SrcTraits::array_layout
1835 , Kokkos::LayoutStride >::value
1844 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
1848 , R0 = bool(is_integral_extent<0,Args...>::value)
1849 , R1 = bool(is_integral_extent<1,Args...>::value)
1850 , R2 = bool(is_integral_extent<2,Args...>::value)
1851 , R3 = bool(is_integral_extent<3,Args...>::value)
1852 , R4 = bool(is_integral_extent<4,Args...>::value)
1853 , R5 = bool(is_integral_extent<5,Args...>::value)
1854 , R6 = bool(is_integral_extent<6,Args...>::value)
1858 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
1859 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
1862 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
1863 1 == SrcTraits::rank ? R0 : (
1864 2 == SrcTraits::rank ? R1 : (
1865 3 == SrcTraits::rank ? R2 : (
1866 4 == SrcTraits::rank ? R3 : (
1867 5 == SrcTraits::rank ? R4 : (
1868 6 == SrcTraits::rank ? R5 : R6 ))))))) };
1875 typedef typename std::conditional<
1879 ( std::is_same<
typename SrcTraits::array_layout
1880 , Kokkos::LayoutRight >::value
1882 ( rank == 1 ) && R0_rev
1885 ( std::is_same<
typename SrcTraits::array_layout
1886 , Kokkos::LayoutLeft >::value
1888 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
1890 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
1891 >::type array_layout ;
1893 typedef typename SrcTraits::value_type fad_type ;
1895 typedef typename std::conditional< rank == 0 , fad_type ,
1896 typename std::conditional< rank == 1 , fad_type * ,
1897 typename std::conditional< rank == 2 , fad_type ** ,
1898 typename std::conditional< rank == 3 , fad_type *** ,
1899 typename std::conditional< rank == 4 , fad_type **** ,
1900 typename std::conditional< rank == 5 , fad_type ***** ,
1901 typename std::conditional< rank == 6 , fad_type ****** ,
1903 >::type >::type >::type >::type >::type >::type >::type
1908 typedef Kokkos::ViewTraits
1911 ,
typename SrcTraits::device_type
1912 ,
typename SrcTraits::memory_traits > traits_type ;
1914 typedef Kokkos::View
1917 ,
typename SrcTraits::device_type
1918 ,
typename SrcTraits::memory_traits > type ;
1921 KOKKOS_INLINE_FUNCTION
1922 static void assign( ViewMapping< traits_type , typename traits_type::specialize > & dst
1923 , ViewMapping< SrcTraits ,typename SrcTraits::specialize >
const & src
1926 typedef ViewMapping< traits_type , typename traits_type::specialize > DstType ;
1927 typedef typename DstType::offset_type dst_offset_type ;
1928 typedef typename DstType::array_offset_type dst_array_offset_type ;
1929 typedef typename DstType::handle_type dst_handle_type ;
1931 const SubviewExtents< SrcTraits::rank , rank >
1932 extents( src.m_impl_offset.m_dim , args... );
1933 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
1934 array_extents( src.m_array_offset.m_dim , args... , Kokkos::ALL() );
1936 dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
1937 dst.m_array_offset = dst_array_offset_type( src.m_array_offset , array_extents );
1939 dst_handle_type( src.m_impl_handle +
1940 src.m_array_offset( array_extents.domain_offset(0)
1941 , array_extents.domain_offset(1)
1942 , array_extents.domain_offset(2)
1943 , array_extents.domain_offset(3)
1944 , array_extents.domain_offset(4)
1945 , array_extents.domain_offset(5)
1946 , array_extents.domain_offset(6)
1947 , array_extents.domain_offset(7) ) );
1948 dst.m_fad_size = src.m_fad_size;
1949 dst.m_fad_stride = src.m_fad_stride.value;
1960#if defined(HAVE_SACADO_KOKKOS) && \
1961 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \
1962 defined(HAVE_SACADO_VIEW_SPEC) && \
1963 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC)
1965#include "Kokkos_TeuchosCommAdapters.hpp"
1969template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
1970typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
1971 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
1974 (
const Comm<Ordinal>& comm,
1975 const EReductionType reductType ,
1977 const Kokkos::View<SD,SP...> & sendBuffer ,
1978 const Kokkos::View<RD,RP...> & recvBuffer )
1985 typedef Kokkos::View<SD,SP...> SendViewType;
1986 typedef Kokkos::View<RD,RP...> RecvViewType;
1987 typedef typename SendViewType::value_type send_value_type;
1988 typedef typename RecvViewType::value_type recv_value_type;
1990 TEUCHOS_TEST_FOR_EXCEPTION(
1991 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
1992 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
1993 "The send View's rank is " << SendViewType::rank <<
" and the receive "
1994 "View's rank is " << RecvViewType::rank <<
".");
1997 Teuchos::Array<send_value_type> localSendBuffer(count);
1998 typename SendViewType::HostMirror hostSendBuffer =
1999 Kokkos::create_mirror_view(sendBuffer);
2000 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2001 for (
Ordinal i=0; i<count; ++i)
2002 localSendBuffer[i] = hostSendBuffer(i);
2006 Teuchos::Array<recv_value_type> localRecvBuffer(count);
2007 typename RecvViewType::HostMirror hostRecvBuffer =
2008 Kokkos::create_mirror_view(recvBuffer);
2009 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2010 for (
Ordinal i=0; i<count; ++i)
2011 localRecvBuffer[i] = hostRecvBuffer(i);
2014 reduceAll(comm, reductType, count,
2015 localSendBuffer.getRawPtr(),
2016 localRecvBuffer.getRawPtr());
2019 for (
Ordinal i=0; i<count; ++i)
2020 hostRecvBuffer(i) = localRecvBuffer[i];
2021 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2025template<
typename Ordinal ,
typename Serializer ,
2026 class SD ,
class ... SP ,
class RD ,
class ... RP >
2027typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
2028 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
2031 (
const Comm<Ordinal>& comm,
2032 const Serializer& serializer,
2033 const EReductionType reductType ,
2035 const Kokkos::View<SD,SP...> & sendBuffer ,
2036 const Kokkos::View<RD,RP...> & recvBuffer )
2043 typedef Kokkos::View<SD,SP...> SendViewType;
2044 typedef Kokkos::View<RD,RP...> RecvViewType;
2045 typedef typename SendViewType::value_type send_value_type;
2046 typedef typename RecvViewType::value_type recv_value_type;
2048 TEUCHOS_TEST_FOR_EXCEPTION(
2049 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
2050 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
2051 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
2054 Teuchos::Array<send_value_type> localSendBuffer(count);
2055 typename SendViewType::HostMirror hostSendBuffer =
2056 Kokkos::create_mirror_view(sendBuffer);
2057 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2058 for (
Ordinal i=0; i<count; ++i)
2059 localSendBuffer[i] = hostSendBuffer(i);
2063 Teuchos::Array<recv_value_type> localRecvBuffer(count);
2064 typename RecvViewType::HostMirror hostRecvBuffer =
2065 Kokkos::create_mirror_view(recvBuffer);
2066 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2067 for (
Ordinal i=0; i<count; ++i)
2068 localRecvBuffer[i] = hostRecvBuffer(i);
2071 reduceAll(comm, serializer, reductType, count,
2072 localSendBuffer.getRawPtr(),
2073 localRecvBuffer.getRawPtr());
2076 for (
Ordinal i=0; i<count; ++i)
2077 hostRecvBuffer(i) = localRecvBuffer[i];
2078 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2082template<
typename Ordinal,
class D,
class ... P >
2083typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2085 (
const Comm<Ordinal>& comm,
2086 const int rootRank ,
2088 const Kokkos::View<D,P...>& buffer)
2090 typedef Kokkos::View<
D,P...> view_type;
2091 typename view_type::array_type array_buffer = buffer;
2092 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2093 broadcast( comm, rootRank, array_count, array_buffer );
2097 typename Serializer ,
2098 class D,
class ... P >
2099typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2101 (
const Comm<Ordinal>& comm,
2102 const Serializer& serializer,
2103 const int rootRank ,
2105 const Kokkos::View<D,P...>& buffer)
2107 typedef Kokkos::View<
D,P...> view_type;
2108 typename view_type::array_type array_buffer = buffer;
2109 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2110 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
2111 array_count, array_buffer );
Forward-mode AD class templated on the storage for the derivative array.
Namespace for forward-mode AD classes w/caching.
Namespace for expression-level reverse forward-mode AD classes.
Namespace for expression-level reverse forward-mode AD classes.
Namespace for forward-mode AD classes.
static const unsigned value