10 #ifndef KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
11 #define KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
15 #include "Kokkos_Core_fwd.hpp"
17 #if (KOKKOS_VERSION > 40700) && !defined(KOKKOS_ENABLE_IMPL_VIEW_LEGACY) \
18 && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
19 #define SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
22 #ifdef SACADO_HAS_NEW_KOKKOS_VIEW_IMPL
25 #if defined(HAVE_SACADO_KOKKOS)
32 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
33 #define KOKKOS_IMPL_PUBLIC_INCLUDE
34 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
36 #include "Kokkos_Layout.hpp"
37 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
38 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
39 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
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>
57 KOKKOS_INLINE_FUNCTION
59 dimension_scalar(
const view_type& ) {
64 template <
typename view_type>
65 KOKKOS_INLINE_FUNCTION
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::traits::specialize,
107 Impl::ViewSpecializeSacadoFad >
::value ||
108 std::is_same<
typename view_type::traits::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::traits::specialize,
117 Impl::ViewSpecializeSacadoFadContiguous >
::value;
123 #include "Kokkos_Core.hpp"
132 template<
class DT,
class ... DP,
133 class ST,
class ... SP>
134 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >
::value &&
135 is_view_fad< Kokkos::View<ST,SP...> >
::value
137 view_copy(
const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
139 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
140 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
141 view_copy( dst_array_type(dst) , src_array_type(src) );
144 template<
class ExecutionSpace,
145 class DT,
class ... DP,
146 class ST,
class ... SP>
147 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >
::value &&
148 is_view_fad< Kokkos::View<ST,SP...> >
::value
150 view_copy(
const ExecutionSpace& space,
151 const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
153 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
154 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
155 view_copy( space, dst_array_type(dst) , src_array_type(src) );
163 template <
typename T,
typename ... P>
164 KOKKOS_INLINE_FUNCTION
166 std::enable_if< is_view_fad<
View<
T,P...> >
::value,
unsigned >::type
167 dimension_scalar(
const View<T,P...>& view) {
168 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
169 return view.implementation_map().dimension_scalar();
171 return view.impl_map().dimension_scalar();
175 template <
typename Layout>
176 struct ApplyNatural {
177 typedef LayoutNatural<Layout> type;
180 template <
typename Layout>
181 struct ApplyNatural< LayoutNatural<Layout> > {
182 typedef LayoutNatural<Layout> type;
185 template <
typename T,
typename Enable =
void >
188 template <
typename T >
189 struct ArrayScalar<
T, typename std::enable_if< !Sacado::IsFad<T>::value >::type > {
193 template <
typename T >
194 struct ArrayScalar<
T, typename std::enable_if< Sacado::IsFad<T>::value >::type > {
195 typedef typename ArrayScalar< typename Sacado::ValueType<T>::type >::type* type;
199 template <
typename DataType,
int Rank >
200 struct AppendRankToConvertedFad {
201 static_assert( Rank > -1,
"Sacado AppendRankToConvertedFad Error: Rank < 0" );
202 typedef typename AppendRankToConvertedFad<DataType,Rank-1>::type* type;
206 template <
typename DataType >
207 struct AppendRankToConvertedFad< DataType, 0 > {
208 typedef DataType type;
212 template <
class ArrayLayout,
class Enable =
void >
213 struct ViewArrayLayoutSelector;
215 template <
class ArrayLayout >
216 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutLeft>::value >::type >
218 using type = Kokkos::LayoutLeft;
221 template <
class ArrayLayout >
222 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutRight>::value >::type >
224 using type = Kokkos::LayoutRight;
227 template <
class ArrayLayout >
228 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutStride>::value >::type >
230 using type = Kokkos::LayoutStride;
233 template <
typename ViewType,
typename Enable =
void >
234 struct PODViewDeepCopyType;
236 template <
typename ViewType >
237 struct PODViewDeepCopyType< ViewType, typename std::enable_if< is_view_fad<ViewType>::value >::type >
240 typedef ViewType view_type;
241 typedef typename ArrayScalar< typename view_type::value_type >::type fad_converted_type;
242 typedef typename AppendRankToConvertedFad< fad_converted_type, view_type::rank >::type new_data_type;
244 typedef typename ViewArrayLayoutSelector<typename view_type::array_layout>::type layout;
246 typedef typename view_type::device_type device;
247 typedef typename view_type::memory_traits memory;
249 typedef Kokkos::View< new_data_type, layout, device, memory > type;
253 template <
typename ViewType >
254 struct PODViewDeepCopyType< ViewType, typename std::enable_if< !is_view_fad<ViewType>::value >::type >
256 typedef ViewType type;
260 template <
typename ViewType,
typename Enabled =
void>
261 struct NaturalArrayType {
262 typedef ViewType type;
265 template <
typename D,
typename ... P>
266 struct NaturalArrayType<
View<
D,P...>,
267 typename std::enable_if< is_view_fad< View<D,P...> >::value >::type > {
268 typedef View<
D,P...> view_type;
269 typedef typename view_type::data_type data_type;
270 typedef typename view_type::array_layout layout;
271 typedef typename view_type::device_type device;
272 typedef typename view_type::memory_traits memory;
274 typedef typename ViewArrayLayoutSelector<layout>::type natural_layout;
275 typedef View<data_type,natural_layout,device,memory> type;
280 template <
class OutputView,
typename Enabled =
void>
281 struct SacadoViewFill
283 typedef typename OutputView::const_value_type const_value_type ;
284 typedef typename OutputView::execution_space execution_space ;
286 const OutputView output ;
287 const_value_type input ;
289 KOKKOS_INLINE_FUNCTION
290 void operator()(
const size_t i0 )
const
292 const size_t n1 = output.extent(1);
293 const size_t n2 = output.extent(2);
294 const size_t n3 = output.extent(3);
295 const size_t n4 = output.extent(4);
296 const size_t n5 = output.extent(5);
297 const size_t n6 = output.extent(6);
299 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
300 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
301 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
302 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
303 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
304 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
305 output.access(i0,i1,i2,i3,i4,i5,i6) = input ;
309 SacadoViewFill(
const OutputView & arg_out , const_value_type & arg_in )
310 : output( arg_out ), input( arg_in )
312 const size_t n0 = output.extent(0);
313 Kokkos::RangePolicy<execution_space> policy( 0, n0 );
314 Kokkos::parallel_for( policy, *
this );
321 template<
class DT,
class ... DP >
323 const View<DT,DP...> & view ,
325 ,
typename std::enable_if<(
326 std::is_same<
typename ViewTraits<DT,DP...>::specialize
327 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
328 std::is_same<
typename ViewTraits<DT,DP...>::specialize
329 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
333 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
334 typename ViewTraits<DT,DP...>::non_const_value_type >::value
335 ,
"Can only deep copy into non-const type" );
337 Impl::SacadoViewFill<
View<DT,DP...> >( view ,
value );
342 template<
class DT,
class ... DP >
344 const View<DT,DP...> & view ,
345 const typename View<DT,DP...>::value_type & value
346 ,
typename std::enable_if<(
347 std::is_same<
typename ViewTraits<DT,DP...>::specialize
348 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
349 std::is_same<
typename ViewTraits<DT,DP...>::specialize
350 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
354 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
355 typename ViewTraits<DT,DP...>::non_const_value_type >::value
356 ,
"Can only deep copy into non-const type" );
358 Impl::SacadoViewFill<
View<DT,DP...> >( view ,
value );
362 template<
class ExecSpace,
class DT ,
class ... DP ,
class ST ,
class ... SP >
364 void deep_copy(
const ExecSpace &,
365 const View<DT,DP...> & dst ,
366 const View<ST,SP...> & src
367 ,
typename std::enable_if<(
368 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
369 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
371 std::is_same<
typename ViewTraits<DT,DP...>::specialize
372 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
374 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
375 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
377 std::is_same<
typename ViewTraits<ST,SP...>::specialize
378 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
382 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
383 typename ViewTraits<DT,DP...>::non_const_value_type >::value
384 ,
"Deep copy destination must be non-const" );
387 (
unsigned(ViewTraits<DT,DP...>::rank) ==
388 unsigned(ViewTraits<ST,SP...>::rank) )
389 ,
"Deep copy destination and source must have same rank" );
393 typedef typename View<DT,DP...>::array_type dst_array_type;
394 typedef typename View<ST,SP...>::array_type src_array_type;
395 typename NaturalArrayType< dst_array_type >::type dst_array( dst );
396 typename NaturalArrayType< src_array_type >::type src_array( src );
399 typename PODViewDeepCopyType<
View<DT,DP...> >::type dst_array( dst );
400 typename PODViewDeepCopyType<
View<ST,SP...> >::type src_array( src );
402 Kokkos::deep_copy( ExecSpace(), dst_array , src_array );
406 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
408 void deep_copy(
const View<DT,DP...> & dst ,
409 const View<ST,SP...> & src
410 ,
typename std::enable_if<(
411 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
412 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
414 std::is_same<
typename ViewTraits<DT,DP...>::specialize
415 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
417 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
418 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
420 std::is_same<
typename ViewTraits<ST,SP...>::specialize
421 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
424 using exec_space =
typename View<DT,DP...>::execution_space;
426 Kokkos::deep_copy(exec_space(), dst, src);
430 template<
class T ,
class ... P >
432 typename std::enable_if<
433 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
434 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
435 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
436 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
437 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
438 Kokkos::LayoutStride >::value,
439 typename Kokkos::View<T,P...>::host_mirror_type>::type
440 create_mirror(
const Kokkos::View<T,P...> & src)
442 typedef View<
T,P...> src_type ;
443 typedef typename src_type::host_mirror_type dst_type ;
445 typename src_type::array_layout layout = src.layout();
446 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
448 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
451 template<
class T ,
class ... P >
453 typename std::enable_if<
454 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
455 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
456 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
457 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
458 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
459 Kokkos::LayoutStride >::value,
460 typename Kokkos::View<T,P...>::host_mirror_type>::type
461 create_mirror(
const Kokkos::View<T,P...> & src)
463 typedef View<
T,P...> src_type ;
464 typedef typename src_type::array_type src_array_type ;
465 typedef typename src_type::host_mirror_type dst_type ;
467 Kokkos::LayoutStride layout ;
470 src_array_type src_array = src;
471 layout.dimension[0] = src_array.extent(0);
472 layout.dimension[1] = src_array.extent(1);
473 layout.dimension[2] = src_array.extent(2);
474 layout.dimension[3] = src_array.extent(3);
475 layout.dimension[4] = src_array.extent(4);
476 layout.dimension[5] = src_array.extent(5);
477 layout.dimension[6] = src_array.extent(6);
478 layout.dimension[7] = src_array.extent(7);
480 layout.stride[0] = src_array.stride_0();
481 layout.stride[1] = src_array.stride_1();
482 layout.stride[2] = src_array.stride_2();
483 layout.stride[3] = src_array.stride_3();
484 layout.stride[4] = src_array.stride_4();
485 layout.stride[5] = src_array.stride_5();
486 layout.stride[6] = src_array.stride_6();
487 layout.stride[7] = src_array.stride_7();
489 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
492 template<
class Space,
class T,
class ... P,
typename Enabled>
493 typename std::enable_if<
494 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
495 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
496 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
497 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value,
498 typename Impl::MirrorViewType<Space,
T,P ...>::dest_view_type>::type
499 create_mirror(
const Space& ,
const Kokkos::View<T,P...> & src)
501 typedef View<
T,P...> src_type ;
502 typename src_type::array_layout layout = src.layout();
503 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
504 return typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type(src.label(),layout);
507 template<
class T ,
class ... P >
509 typename std::enable_if<
510 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
511 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
512 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
513 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
514 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
515 Kokkos::LayoutStride >::value,
516 typename Kokkos::View<T,P...>::host_mirror_type>::type
517 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
518 const Kokkos::View<T,P...> & src)
520 typedef View<
T,P...> src_type ;
521 typedef typename src_type::host_mirror_type dst_type ;
523 typename src_type::array_layout layout = src.layout();
524 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
527 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
530 template<
class T ,
class ... P >
532 typename std::enable_if<
533 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
534 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
535 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
536 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
537 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
538 Kokkos::LayoutStride >::value,
539 typename Kokkos::View<T,P...>::host_mirror_type>::type
540 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
541 const Kokkos::View<T,P...> & src)
543 typedef View<
T,P...> src_type ;
544 typedef typename src_type::array_type src_array_type ;
545 typedef typename src_type::host_mirror_type dst_type ;
547 Kokkos::LayoutStride layout ;
550 src_array_type src_array = src;
551 layout.dimension[0] = src_array.extent(0);
552 layout.dimension[1] = src_array.extent(1);
553 layout.dimension[2] = src_array.extent(2);
554 layout.dimension[3] = src_array.extent(3);
555 layout.dimension[4] = src_array.extent(4);
556 layout.dimension[5] = src_array.extent(5);
557 layout.dimension[6] = src_array.extent(6);
558 layout.dimension[7] = src_array.extent(7);
560 layout.stride[0] = src_array.stride_0();
561 layout.stride[1] = src_array.stride_1();
562 layout.stride[2] = src_array.stride_2();
563 layout.stride[3] = src_array.stride_3();
564 layout.stride[4] = src_array.stride_4();
565 layout.stride[5] = src_array.stride_5();
566 layout.stride[6] = src_array.stride_6();
567 layout.stride[7] = src_array.stride_7();
570 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
573 template<
class Space,
class T,
class ... P,
typename Enable>
574 typename std::enable_if<
575 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
576 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
577 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
578 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ),
579 typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type>::type
580 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
581 const Space& ,
const Kokkos::View<T,P...> & src)
583 typedef View<
T,P...> src_type ;
584 typename src_type::array_layout layout = src.layout();
585 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
586 return typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type(
587 Kokkos::view_alloc(src.label(), wi), layout);
590 template <
class Space,
class T,
class... P>
591 typename Impl::MirrorViewType<Space,
T, P...>::view_type
592 create_mirror_view_and_copy(
593 const Space&,
const Kokkos::View<T, P...>& src,
594 std::string
const& name,
595 typename std::enable_if<
596 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
597 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
598 std::is_same<
typename ViewTraits<T,P...>::specialize ,
599 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
600 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
604 "Kokkos::create_mirror_view_and_copy: fence before returning src view");
608 template <
class Space,
class T,
class... P>
609 typename Impl::MirrorViewType<Space,
T, P...>::view_type
610 create_mirror_view_and_copy(
611 const Space&,
const Kokkos::View<T, P...>& src,
612 std::string
const& name,
613 typename std::enable_if<
614 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
615 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
616 std::is_same<
typename ViewTraits<T,P...>::specialize ,
617 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
618 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
620 using src_type =
View<
T,P...>;
621 using Mirror =
typename Impl::MirrorViewType<Space,
T, P...>::view_type;
622 std::string label = name.empty() ? src.label() : name;
623 typename src_type::array_layout layout = src.layout();
624 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
625 auto mirror =
typename Mirror::non_const_type{
626 view_alloc(WithoutInitializing, label), layout};
627 deep_copy(mirror, src);
633 template <
unsigned N,
typename... Args>
634 KOKKOS_FUNCTION std::enable_if_t<
635 N ==
View<Args...>::Rank &&
636 (std::is_same<
typename ViewTraits<Args...>::specialize,
637 Kokkos::Impl::ViewSpecializeSacadoFad>
::value ||
638 std::is_same<
typename ViewTraits<Args...>::specialize,
639 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>
::value),
641 as_view_of_rank_n(View<Args...> v) {
647 template <
unsigned N,
typename T,
typename... Args>
649 N !=
View<
T, Args...>::Rank &&
650 (std::is_same<
typename ViewTraits<
T, Args...>::specialize,
651 Kokkos::Impl::ViewSpecializeSacadoFad>
::value ||
652 std::is_same<
typename ViewTraits<
T, Args...>::specialize,
653 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>
::value),
654 View<
typename RankDataType<
typename View<T, Args...>::value_type,
N>::type,
656 as_view_of_rank_n(View<T, Args...>) {
657 Kokkos::Impl::throw_runtime_exception(
658 "Trying to get at a View of the wrong rank");
667 namespace Experimental {
669 template <
class DT,
class... DP>
670 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
671 const View<DT, DP...>& dst,
672 typename ViewTraits<DT, DP...>::const_value_type& value,
673 typename std::enable_if<(
674 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
675 Kokkos::Impl::ViewSpecializeSacadoFad >::value
677 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
678 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
679 && (
unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type*)
681 if (dst.data() ==
nullptr)
684 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
688 template <
class DT,
class... DP>
689 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
690 const View<DT, DP...>& dst,
691 typename ViewTraits<DT, DP...>::const_value_type& value,
692 typename std::enable_if<(
693 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
694 Kokkos::Impl::ViewSpecializeSacadoFad >::value
696 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
697 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
698 && (
unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type*)
700 if (dst.data() ==
nullptr)
703 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
704 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
708 template <
class DT,
class... DP>
709 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
710 const View<DT, DP...>& dst,
711 typename ViewTraits<DT, DP...>::const_value_type& value,
712 typename std::enable_if<(
713 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
714 Kokkos::Impl::ViewSpecializeSacadoFad >::value
716 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
717 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
718 && (
unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type*)
720 if (dst.data() ==
nullptr)
723 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
724 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
725 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
726 dst(i0,i1,i2) =
value;
729 template <
class DT,
class... DP>
730 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
731 const View<DT, DP...>& dst,
732 typename ViewTraits<DT, DP...>::const_value_type& value,
733 typename std::enable_if<(
734 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
735 Kokkos::Impl::ViewSpecializeSacadoFad >::value
737 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
738 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
739 && (
unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type*)
741 if (dst.data() ==
nullptr)
744 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
745 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
746 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
747 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
748 dst(i0,i1,i2,i3) =
value;
751 template <
class DT,
class... DP>
752 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
753 const View<DT, DP...>& dst,
754 typename ViewTraits<DT, DP...>::const_value_type& value,
755 typename std::enable_if<(
756 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
757 Kokkos::Impl::ViewSpecializeSacadoFad >::value
759 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
760 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
761 && (
unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type*)
763 if (dst.data() ==
nullptr)
766 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
767 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
768 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
769 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
770 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
771 dst(i0,i1,i2,i3,i4) =
value;
774 template <
class DT,
class... DP>
775 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
776 const View<DT, DP...>& dst,
777 typename ViewTraits<DT, DP...>::const_value_type& value,
778 typename std::enable_if<(
779 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
780 Kokkos::Impl::ViewSpecializeSacadoFad >::value
782 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
783 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
784 && (
unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type*)
786 if (dst.data() ==
nullptr)
789 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
790 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
791 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
792 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
793 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
794 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
795 dst(i0,i1,i2,i3,i4,i5) =
value;
798 template <
class DT,
class... DP>
799 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
800 const View<DT, DP...>& dst,
801 typename ViewTraits<DT, DP...>::const_value_type& value,
802 typename std::enable_if<(
803 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
804 Kokkos::Impl::ViewSpecializeSacadoFad >::value
806 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
807 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
808 && (
unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type*)
810 if (dst.data() ==
nullptr)
813 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
814 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
815 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
816 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
817 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
818 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
819 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
820 dst(i0,i1,i2,i3,i4,i5,i6) =
value;
823 template <
class TeamType,
class DT,
class... DP>
824 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
825 const TeamType& team,
const View<DT, DP...>& dst,
826 typename ViewTraits<DT, DP...>::const_value_type& value,
827 typename std::enable_if<(
828 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
829 Kokkos::Impl::ViewSpecializeSacadoFad >::value
831 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
832 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
833 && (
unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type*)
835 if (dst.data() ==
nullptr)
838 const size_t N = dst.extent(0);
841 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N),
842 [&](
const int&
i) { dst(i) =
value; });
846 template <
class TeamType,
class DT,
class... DP>
847 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
848 const TeamType& team,
const View<DT, DP...>& dst,
849 typename ViewTraits<DT, DP...>::const_value_type& value,
850 typename std::enable_if<(
851 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
852 Kokkos::Impl::ViewSpecializeSacadoFad >::value
854 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
855 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
856 && (
unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type*)
858 if (dst.data() ==
nullptr)
861 const size_t N = dst.extent(0) * dst.extent(1);
864 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
865 int i0 = i % dst.extent(0);
866 int i1 = i / dst.extent(0);
872 template <
class TeamType,
class DT,
class... DP>
873 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
874 const TeamType& team,
const View<DT, DP...>& dst,
875 typename ViewTraits<DT, DP...>::const_value_type& value,
876 typename std::enable_if<(
877 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
878 Kokkos::Impl::ViewSpecializeSacadoFad >::value
880 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
881 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
882 && (
unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type*)
884 if (dst.data() ==
nullptr)
887 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
890 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
891 int i0 = i % dst.extent(0);
892 int itmp = i / dst.extent(0);
893 int i1 = itmp % dst.extent(1);
894 int i2 = itmp / dst.extent(1);
895 dst(i0, i1, i2) =
value;
900 template <
class TeamType,
class DT,
class... DP>
901 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
902 const TeamType& team,
const View<DT, DP...>& dst,
903 typename ViewTraits<DT, DP...>::const_value_type& value,
904 typename std::enable_if<(
905 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
906 Kokkos::Impl::ViewSpecializeSacadoFad >::value
908 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
909 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
910 && (
unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type*)
912 if (dst.data() ==
nullptr)
916 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
919 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
920 int i0 = i % dst.extent(0);
921 int itmp = i / dst.extent(0);
922 int i1 = itmp % dst.extent(1);
923 itmp = itmp / dst.extent(1);
924 int i2 = itmp % dst.extent(2);
925 int i3 = itmp / dst.extent(2);
926 dst(i0, i1, i2, i3) =
value;
931 template <
class TeamType,
class DT,
class... DP>
932 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
933 const TeamType& team,
const View<DT, DP...>& dst,
934 typename ViewTraits<DT, DP...>::const_value_type& value,
935 typename std::enable_if<(
936 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
937 Kokkos::Impl::ViewSpecializeSacadoFad >::value
939 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
940 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
941 && (
unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type*)
943 if (dst.data() ==
nullptr)
946 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
947 dst.extent(3) * dst.extent(4);
950 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
951 int i0 = i % dst.extent(0);
952 int itmp = i / dst.extent(0);
953 int i1 = itmp % dst.extent(1);
954 itmp = itmp / dst.extent(1);
955 int i2 = itmp % dst.extent(2);
956 itmp = itmp / dst.extent(2);
957 int i3 = itmp % dst.extent(3);
958 int i4 = itmp / dst.extent(3);
959 dst(i0, i1, i2, i3, i4) =
value;
964 template <
class TeamType,
class DT,
class... DP>
965 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
966 const TeamType& team,
const View<DT, DP...>& dst,
967 typename ViewTraits<DT, DP...>::const_value_type& value,
968 typename std::enable_if<(
969 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
970 Kokkos::Impl::ViewSpecializeSacadoFad >::value
972 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
973 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
974 && (
unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type*)
976 if (dst.data() ==
nullptr)
979 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
980 dst.extent(3) * dst.extent(4) * dst.extent(5);
983 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
984 int i0 = i % dst.extent(0);
985 int itmp = i / dst.extent(0);
986 int i1 = itmp % dst.extent(1);
987 itmp = itmp / dst.extent(1);
988 int i2 = itmp % dst.extent(2);
989 itmp = itmp / dst.extent(2);
990 int i3 = itmp % dst.extent(3);
991 itmp = itmp / dst.extent(3);
992 int i4 = itmp % dst.extent(4);
993 int i5 = itmp / dst.extent(4);
994 dst(i0, i1, i2, i3, i4, i5) =
value;
999 template <
class TeamType,
class DT,
class... DP>
1000 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
1001 const TeamType& team,
const View<DT, DP...>& dst,
1002 typename ViewTraits<DT, DP...>::const_value_type& value,
1003 typename std::enable_if<(
1004 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
1005 Kokkos::Impl::ViewSpecializeSacadoFad >::value
1007 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
1008 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
1009 && (
unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type*)
1011 if (dst.data() ==
nullptr)
1014 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
1015 dst.extent(3) * dst.extent(4) * dst.extent(5) *
1018 team.team_barrier();
1019 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
1020 int i0 = i % dst.extent(0);
1021 int itmp = i / dst.extent(0);
1022 int i1 = itmp % dst.extent(1);
1023 itmp = itmp / dst.extent(1);
1024 int i2 = itmp % dst.extent(2);
1025 itmp = itmp / dst.extent(2);
1026 int i3 = itmp % dst.extent(3);
1027 itmp = itmp / dst.extent(3);
1028 int i4 = itmp % dst.extent(4);
1029 itmp = itmp / dst.extent(4);
1030 int i5 = itmp % dst.extent(5);
1031 int i6 = itmp / dst.extent(5);
1032 dst(i0, i1, i2, i3, i4, i5, i6) =
value;
1034 team.team_barrier();
1045 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
1046 struct FadViewDataAnalysis
1050 typedef ViewArrayAnalysis< DataType > array_analysis ;
1055 typedef ViewSpecializeSacadoFad specialize ;
1057 typedef typename array_analysis::dimension dimension ;
1058 typedef typename array_analysis::value_type value_type ;
1059 typedef typename array_analysis::const_value_type const_value_type ;
1060 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1064 ViewDataType< value_type , dimension >::type type ;
1066 ViewDataType< const_value_type , dimension >::type const_type ;
1068 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1077 std::conditional< is_const , const ScalarType , ScalarType >::type
1080 typedef ScalarType non_const_scalar_type ;
1081 typedef const ScalarType const_scalar_type ;
1084 typedef typename array_analysis::dimension::
1085 template append<( DimFad ? DimFad + 1 : 0 )>::type
1092 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
1095 ViewDataType< const_scalar_type , scalar_dimension >::type
1096 const_scalar_array_type ;
1099 ViewDataType< non_const_scalar_type , scalar_dimension >::type
1100 non_const_scalar_array_type ;
1105 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad,
unsigned Str
ide >
1106 struct FadViewDataAnalysis<DataType, LayoutContiguous<ArrayLayout,Stride>, ScalarType, DimFad>
1110 typedef ViewArrayAnalysis< DataType > array_analysis ;
1115 typedef ViewSpecializeSacadoFadContiguous specialize ;
1117 typedef typename array_analysis::dimension dimension ;
1118 typedef typename array_analysis::value_type value_type ;
1119 typedef typename array_analysis::const_value_type const_value_type ;
1120 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1124 ViewDataType< value_type , dimension >::type type ;
1126 ViewDataType< const_value_type , dimension >::type const_type ;
1128 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1137 std::conditional< is_const , const ScalarType , ScalarType >::type
1140 typedef ScalarType non_const_scalar_type ;
1141 typedef const ScalarType const_scalar_type ;
1144 typedef typename std::conditional<
1146 typename array_analysis::dimension::
1147 template prepend<0>::type,
1148 typename array_analysis::dimension::
1149 template append<0>::type >::type
1156 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
1159 ViewDataType< const_scalar_type , scalar_dimension >::type
1160 const_scalar_array_type ;
1163 ViewDataType< non_const_scalar_type , scalar_dimension >::type
1164 non_const_scalar_array_type ;
1173 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
1174 struct FadViewDataAnalysis<DataType, LayoutNatural<ArrayLayout>, ScalarType, DimFad>
1178 typedef ViewArrayAnalysis< DataType > array_analysis ;
1183 typedef void specialize ;
1185 typedef typename array_analysis::dimension dimension ;
1186 typedef typename array_analysis::value_type value_type ;
1187 typedef typename array_analysis::const_value_type const_value_type ;
1188 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1192 ViewDataType< value_type , dimension >::type type ;
1194 ViewDataType< const_value_type , dimension >::type const_type ;
1196 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1199 typedef type scalar_array_type ;
1200 typedef const_type const_scalar_array_type ;
1201 typedef non_const_type non_const_scalar_array_type ;
1212 namespace Fad {
namespace Exp {
template<
typename >
class GeneralFad ; } }
1214 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1215 namespace Fad {
template<
typename >
class DFad ; }
1216 namespace Fad {
template<
typename ,
int >
class SFad ; }
1217 namespace Fad {
template<
typename ,
int >
class SLFad ; }
1220 namespace CacheFad {
template<
typename >
class DFad ; }
1221 namespace ELRFad {
template<
typename >
class DFad ; }
1222 namespace ELRCacheFad {
template<
typename >
class DFad ; }
1224 namespace CacheFad {
template<
typename ,
int >
class SFad ; }
1225 namespace ELRFad {
template<
typename ,
int >
class SFad ; }
1226 namespace ELRCacheFad {
template<
typename ,
int >
class SFad ; }
1229 namespace CacheFad {
template<
typename ,
int >
class SLFad ; }
1230 namespace ELRFad {
template<
typename ,
int >
class SLFad ; }
1231 namespace ELRCacheFad {
template<
typename ,
int >
class SLFad ; }
1237 #define KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( NS ) \
1238 template< class DataType , class ArrayLayout , typename ScalarType > \
1239 struct ViewDataAnalysis \
1242 , Sacado:: NS ::DFad< ScalarType > \
1243 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , 0 > {}; \
1245 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
1246 struct ViewDataAnalysis \
1249 , Sacado:: NS ::SFad< ScalarType , N > \
1250 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
1251 int(Sacado::StaticSize< Sacado:: NS ::SFad< ScalarType , N > >::value) \
1254 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
1255 struct ViewDataAnalysis \
1258 , Sacado:: NS ::SLFad< ScalarType , N > \
1259 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
1260 int(Sacado::StaticSize< Sacado:: NS ::SLFad< ScalarType , N > >::value) \
1263 template<
class DataType ,
class ArrayLayout ,
typename StorageType >
1264 struct ViewDataAnalysis
1267 , Sacado::Fad::Exp::GeneralFad< StorageType >
1268 > :
public FadViewDataAnalysis< DataType, ArrayLayout, typename StorageType::value_type , 0 > {};
1270 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1271 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( Fad )
1274 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( CacheFad )
1275 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRFad )
1276 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRCacheFad )
1278 #undef KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD
1288 template <
class View,
class ... ViewPack>
1289 KOKKOS_INLINE_FUNCTION
1290 unsigned dimension_scalar(
const View& v,
const ViewPack&... views) {
1291 const unsigned dim0 = dimension_scalar(v);
1292 const unsigned dim1 = dimension_scalar(views...);
1293 return dim0 >= dim1 ? dim0 : dim1 ;
1300 namespace Kokkos {
namespace Impl {
1302 template <
typename Specialize,
typename A,
typename B >
1303 struct CommonViewValueType;
1305 template <
typename A,
typename B >
1306 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFad,
A,
B >
1311 template <
typename A,
typename B >
1312 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFadContiguous,
A,
B >
1318 template <
class Specialize,
class ValueType >
1319 struct CommonViewAllocProp;
1321 template <
class ValueType >
1322 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFad, ValueType >
1324 using value_type = ValueType;
1329 KOKKOS_INLINE_FUNCTION
1330 CommonViewAllocProp()
1335 template <
class View >
1336 KOKKOS_INLINE_FUNCTION
1337 CommonViewAllocProp(
const View & view )
1338 :
fad_dim ( dimension_scalar(view) )
1344 template <
class View,
class ... Views >
1345 KOKKOS_INLINE_FUNCTION
1346 CommonViewAllocProp(
const View & view,
const Views & ... views )
1347 :
fad_dim ( dimension_scalar(view, views... ) )
1354 template <
class ValueType >
1355 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFadContiguous, ValueType >
1357 using value_type = ValueType;
1362 KOKKOS_INLINE_FUNCTION
1363 CommonViewAllocProp()
1368 template <
class View >
1369 KOKKOS_INLINE_FUNCTION
1370 CommonViewAllocProp(
const View & view )
1371 :
fad_dim ( dimension_scalar(view) )
1377 template <
class View,
class ... Views >
1378 KOKKOS_INLINE_FUNCTION
1379 CommonViewAllocProp(
const View & view,
const Views & ... views )
1380 :
fad_dim ( dimension_scalar(view, views... ) )
1387 template <
typename ... P >
1388 struct has_common_view_alloc_prop :
public std::false_type {};
1390 template <
class Specialize,
class ValueType >
1391 struct has_common_view_alloc_prop< CommonViewAllocProp<Specialize, ValueType> > :
public std::true_type {};
1395 template <
typename ... >
1396 struct check_has_common_view_alloc_prop;
1399 struct check_has_common_view_alloc_prop<>
1401 enum { value =
false };
1404 template <
typename P >
1405 struct check_has_common_view_alloc_prop<P>
1410 template <
typename P0,
typename ... P >
1411 struct check_has_common_view_alloc_prop<P0, P...>
1416 template <
typename ... >
1417 struct compute_fad_dim_from_alloc_prop;
1420 struct compute_fad_dim_from_alloc_prop<> {
1421 template <
typename CtorProp>
1422 KOKKOS_INLINE_FUNCTION
1423 static unsigned eval(
const CtorProp&) {
return 0; }
1426 template <
typename P >
1427 struct compute_fad_dim_from_alloc_prop<P> {
1428 template <
typename CtorProp>
1429 KOKKOS_INLINE_FUNCTION
1430 static unsigned eval(
const CtorProp&) {
return 0; }
1433 template <
typename P0,
typename ... P >
1434 struct compute_fad_dim_from_alloc_prop<P0,P...> {
1435 template <
typename CtorProp>
1436 KOKKOS_INLINE_FUNCTION
1437 static unsigned eval(
const CtorProp& prop) {
1438 unsigned d1 = compute_fad_dim_from_alloc_prop<P0>::eval(prop);
1439 unsigned d2 = compute_fad_dim_from_alloc_prop<P...>::eval(prop);
1440 return d1 > d2 ? d1 : d2;
1444 template <
class ValueType >
1445 struct compute_fad_dim_from_alloc_prop<
1446 CommonViewAllocProp<ViewSpecializeSacadoFad, ValueType>
1448 template <
typename CtorProp>
1449 KOKKOS_INLINE_FUNCTION
1450 static unsigned eval(
const CtorProp& prop) {
1451 using specialize = ViewSpecializeSacadoFad;
1452 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1453 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1454 return cast_prop.fad_dim;
1458 template <
class ValueType >
1459 struct compute_fad_dim_from_alloc_prop<
1460 CommonViewAllocProp<ViewSpecializeSacadoFadContiguous, ValueType>
1462 template <
typename CtorProp>
1463 KOKKOS_INLINE_FUNCTION
1464 static unsigned eval(
const CtorProp& prop) {
1465 using specialize = ViewSpecializeSacadoFadContiguous;
1466 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1467 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1468 return cast_prop.fad_dim;
1472 template <
typename Traits,
typename ... P >
1473 struct appendFadToLayoutViewAllocHelper
1475 using layout_type =
typename Traits::array_layout;
1476 using specialize =
typename Traits::specialize;
1477 using CtorProp = ViewCtorProp< P... >;
1479 KOKKOS_INLINE_FUNCTION
1480 static layout_type returnNewLayoutPlusFad(
const CtorProp & arg_prop,
const layout_type & arg_layout ) {
1482 layout_type appended_layout( arg_layout );
1487 compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
1488 appended_layout.dimension[ Traits::rank ] = (fad_dim > 0) ? fad_dim : 1;
1490 return appended_layout;
1494 template <
typename Layout>
1495 struct prependFadToLayout
1497 using layout_type = Layout;
1499 template <
typename FadSizeType >
1500 KOKKOS_INLINE_FUNCTION
1501 static layout_type returnNewLayoutPlusFad(
const layout_type & arg_layout,
const FadSizeType
fad_dim ) {
1503 layout_type prepended_layout(0,0,0,0,0,0,0,0);
1505 prepended_layout.dimension[0] =
fad_dim;
1507 for (
int i = 1; i < ARRAY_LAYOUT_MAX_RANK; ++
i ) {
1508 prepended_layout.dimension[
i] = arg_layout.dimension[i-1];
1511 return prepended_layout;
1524 template<
class Traits >
1525 class ViewMapping< Traits ,
1526 typename std::enable_if<
1527 ( std::is_same< typename Traits::specialize
1528 , ViewSpecializeSacadoFad >::value
1530 ( std::is_same< typename Traits::array_layout
1531 , Kokkos::LayoutLeft >::value
1533 std::is_same< typename Traits::array_layout
1534 , Kokkos::LayoutRight >::value
1536 std::is_same< typename Traits::array_layout
1537 , Kokkos::LayoutStride >::value
1540 , typename Traits::specialize
1545 template< class ,
class ... >
friend class ViewMapping ;
1546 template< class ,
class ... >
friend class Kokkos::View ;
1548 typedef typename Traits::value_type fad_type ;
1551 std::add_const< fad_value_type >::type const_fad_value_type ;
1557 enum { FadStaticStride =
1558 std::is_same<
typename Traits::array_layout
1559 , Kokkos::LayoutRight >
::value ? 1 : 0 };
1563 typedef fad_value_type * handle_type ;
1565 typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1568 typedef ViewOffset<
typename Traits::dimension
1569 ,
typename Traits::array_layout
1575 <
typename array_analysis::dimension::
1576 template append<( unsigned(FadStaticDimension) > 0 ? unsigned(FadStaticDimension) + 1 : 0 )>::type
1577 ,
typename Traits::array_layout
1579 > array_offset_type ;
1581 handle_type m_impl_handle ;
1582 offset_type m_impl_offset ;
1583 array_offset_type m_array_offset ;
1584 sacado_size_type m_fad_size ;
1585 sacado_stride_type m_fad_stride ;
1592 enum { Rank = Traits::dimension::rank };
1595 template<
typename iType >
1596 KOKKOS_INLINE_FUNCTION constexpr
size_t extent(
const iType & r )
const
1597 {
return m_impl_offset.m_dim.extent(r) ; }
1599 KOKKOS_INLINE_FUNCTION constexpr
1600 typename Traits::array_layout layout()
const
1601 {
return m_impl_offset.layout(); }
1603 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_0()
const
1604 {
return m_impl_offset.dimension_0(); }
1605 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_1()
const
1606 {
return m_impl_offset.dimension_1(); }
1607 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_2()
const
1608 {
return m_impl_offset.dimension_2(); }
1609 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_3()
const
1610 {
return m_impl_offset.dimension_3(); }
1611 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_4()
const
1612 {
return m_impl_offset.dimension_4(); }
1613 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_5()
const
1614 {
return m_impl_offset.dimension_5(); }
1615 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_6()
const
1616 {
return m_impl_offset.dimension_6(); }
1617 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_7()
const
1618 {
return m_impl_offset.dimension_7(); }
1622 using is_regular = std::false_type ;
1624 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_0()
const
1625 {
return m_impl_offset.stride_0(); }
1626 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_1()
const
1627 {
return m_impl_offset.stride_1(); }
1628 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_2()
const
1629 {
return m_impl_offset.stride_2(); }
1630 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_3()
const
1631 {
return m_impl_offset.stride_3(); }
1632 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_4()
const
1633 {
return m_impl_offset.stride_4(); }
1634 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_5()
const
1635 {
return m_impl_offset.stride_5(); }
1636 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_6()
const
1637 {
return m_impl_offset.stride_6(); }
1638 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_7()
const
1639 {
return m_impl_offset.stride_7(); }
1641 template<
typename iType >
1642 KOKKOS_INLINE_FUNCTION
void stride( iType *
const s )
const
1643 { m_impl_offset.stride(s) ; }
1646 KOKKOS_FORCEINLINE_FUNCTION constexpr
unsigned dimension_scalar()
const
1647 {
return m_fad_size.
value+1; }
1650 KOKKOS_FORCEINLINE_FUNCTION constexpr
unsigned stride_scalar()
const
1651 {
return m_fad_stride.value; }
1661 typedef fad_value_type * pointer_type ;
1664 KOKKOS_INLINE_FUNCTION constexpr
size_t span()
const
1665 {
return m_array_offset.span(); }
1668 KOKKOS_INLINE_FUNCTION constexpr
bool span_is_contiguous()
const
1669 {
return m_array_offset.span_is_contiguous() ; }
1672 KOKKOS_INLINE_FUNCTION constexpr pointer_type data()
const
1673 {
return m_impl_handle ; }
1677 KOKKOS_FORCEINLINE_FUNCTION
1678 reference_type reference()
const
1679 {
return reference_type( m_impl_handle
1681 , m_fad_stride.value ); }
1683 template<
typename I0 >
1684 KOKKOS_FORCEINLINE_FUNCTION
1686 reference(
const I0 & i0 )
const
1687 {
return reference_type( m_impl_handle + m_array_offset(i0,0)
1689 , m_fad_stride.value ); }
1691 template<
typename I0 ,
typename I1 >
1692 KOKKOS_FORCEINLINE_FUNCTION
1693 reference_type reference(
const I0 & i0 ,
const I1 & i1 )
const
1694 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,0)
1696 , m_fad_stride.value ); }
1699 template<
typename I0 ,
typename I1 ,
typename I2 >
1700 KOKKOS_FORCEINLINE_FUNCTION
1701 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 )
const
1702 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,0)
1704 , m_fad_stride.value ); }
1706 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3 >
1707 KOKKOS_FORCEINLINE_FUNCTION
1708 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3 )
const
1709 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,0)
1711 , m_fad_stride.value ); }
1713 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1715 KOKKOS_FORCEINLINE_FUNCTION
1716 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1717 ,
const I4 & i4 )
const
1718 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,0)
1720 , m_fad_stride.value ); }
1722 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1723 ,
typename I4 ,
typename I5 >
1724 KOKKOS_FORCEINLINE_FUNCTION
1725 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1726 ,
const I4 & i4 ,
const I5 & i5 )
const
1727 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,0)
1729 , m_fad_stride.value ); }
1732 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1733 ,
typename I4 ,
typename I5 ,
typename I6 >
1734 KOKKOS_FORCEINLINE_FUNCTION
1735 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1736 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 )
const
1737 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,i6,0)
1739 , m_fad_stride.value ); }
1744 KOKKOS_INLINE_FUNCTION
1745 static size_t memory_span(
typename Traits::array_layout
const & layout )
1748 for (
int i=0; i<8; ++
i)
1749 dims[i] = layout.dimension[i];
1750 if (
unsigned(FadStaticDimension) > 0)
1751 dims[unsigned(Rank)] = FadStaticDimension+1;
1753 typename Traits::array_layout alayout(
1754 dims[0], dims[1], dims[2], dims[3],
1755 dims[4], dims[5], dims[6], dims[7] );
1758 typedef std::integral_constant< unsigned , 0 > padding ;
1759 return array_offset_type( padding() , alayout ).span() *
sizeof(fad_value_type);
1764 KOKKOS_INLINE_FUNCTION ~ViewMapping() {}
1765 KOKKOS_INLINE_FUNCTION ViewMapping() : m_impl_handle(0) , m_impl_offset() , m_array_offset() , m_fad_size(0) , m_fad_stride(0) {}
1767 KOKKOS_DEFAULTED_FUNCTION ViewMapping(
const ViewMapping & ) = default ;
1768 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = (
const ViewMapping & ) = default ;
1770 KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1771 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1773 template<
class ... P >
1774 KOKKOS_INLINE_FUNCTION
1776 ( ViewCtorProp< P ... >
const & prop
1777 ,
typename Traits::array_layout
const & local_layout
1779 : m_impl_handle( ( (ViewCtorProp<
void,pointer_type> const &) prop ).value )
1780 , m_impl_offset( std::integral_constant< unsigned , 0 >()
1782 , m_array_offset( std::integral_constant< unsigned , 0 >()
1786 ( Rank == 0 ? m_array_offset.dimension_0() :
1787 ( Rank == 1 ? m_array_offset.dimension_1() :
1788 ( Rank == 2 ? m_array_offset.dimension_2() :
1789 ( Rank == 3 ? m_array_offset.dimension_3() :
1790 ( Rank == 4 ? m_array_offset.dimension_4() :
1791 ( Rank == 5 ? m_array_offset.dimension_5() :
1792 ( Rank == 6 ? m_array_offset.dimension_6() :
1793 m_array_offset.dimension_7() ))))))) - 1 )
1795 ( Rank == 0 ? m_array_offset.stride_0() :
1796 ( Rank == 1 ? m_array_offset.stride_1() :
1797 ( Rank == 2 ? m_array_offset.stride_2() :
1798 ( Rank == 3 ? m_array_offset.stride_3() :
1799 ( Rank == 4 ? m_array_offset.stride_4() :
1800 ( Rank == 5 ? m_array_offset.stride_5() :
1801 ( Rank == 6 ? m_array_offset.stride_6() :
1802 m_array_offset.stride_7() ))))))))
1806 ( Rank == 0 ? m_array_offset.dimension_0() :
1807 ( Rank == 1 ? m_array_offset.dimension_1() :
1808 ( Rank == 2 ? m_array_offset.dimension_2() :
1809 ( Rank == 3 ? m_array_offset.dimension_3() :
1810 ( Rank == 4 ? m_array_offset.dimension_4() :
1811 ( Rank == 5 ? m_array_offset.dimension_5() :
1812 ( Rank == 6 ? m_array_offset.dimension_6() :
1813 m_array_offset.dimension_7() )))))));
1814 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1815 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1823 template<
class ... P >
1824 SharedAllocationRecord<> *
1825 allocate_shared( ViewCtorProp< P... >
const & prop
1826 ,
typename Traits::array_layout
const & local_layout
1827 ,
bool execution_space_specified)
1829 typedef ViewCtorProp< P... > ctor_prop ;
1831 typedef typename ctor_prop::execution_space execution_space ;
1832 typedef typename Traits::memory_space memory_space ;
1833 typedef ViewValueFunctor< execution_space , fad_value_type > functor_type ;
1834 typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1837 typedef std::integral_constant< unsigned , 0 > padding ;
1840 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >
::value };
1842 m_impl_offset = offset_type( padding(), local_layout );
1844 typename Traits::array_layout internal_layout =
1845 (test_traits_check ==
true)
1846 ? Kokkos::Impl::appendFadToLayoutViewAllocHelper< Traits, P... >::returnNewLayoutPlusFad(prop, local_layout)
1849 m_array_offset = array_offset_type( padding(), internal_layout );
1851 const unsigned fad_dim =
1852 ( Rank == 0 ? m_array_offset.dimension_0() :
1853 ( Rank == 1 ? m_array_offset.dimension_1() :
1854 ( Rank == 2 ? m_array_offset.dimension_2() :
1855 ( Rank == 3 ? m_array_offset.dimension_3() :
1856 ( Rank == 4 ? m_array_offset.dimension_4() :
1857 ( Rank == 5 ? m_array_offset.dimension_5() :
1858 ( Rank == 6 ? m_array_offset.dimension_6() :
1859 m_array_offset.dimension_7() )))))));
1860 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1861 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1862 m_fad_size = fad_dim - 1 ;
1865 ( Rank == 0 ? m_array_offset.stride_0() :
1866 ( Rank == 1 ? m_array_offset.stride_1() :
1867 ( Rank == 2 ? m_array_offset.stride_2() :
1868 ( Rank == 3 ? m_array_offset.stride_3() :
1869 ( Rank == 4 ? m_array_offset.stride_4() :
1870 ( Rank == 5 ? m_array_offset.stride_5() :
1871 ( Rank == 6 ? m_array_offset.stride_6() :
1872 m_array_offset.stride_7() )))))));
1874 const size_t alloc_size = m_array_offset.span() *
sizeof(fad_value_type);
1877 record_type *
const record =
1878 record_type::allocate( ( (ViewCtorProp<void,memory_space>
const &) prop ).value
1879 , ( (ViewCtorProp<void,std::string>
const &) prop ).value
1886 m_impl_handle = handle_type( reinterpret_cast< pointer_type >( record->data() ) );
1888 if ( ctor_prop::initialize ) {
1889 auto space = ((ViewCtorProp<void,execution_space>
const &) prop).value;
1892 if (execution_space_specified)
1893 record->m_destroy = functor_type( space
1894 , (fad_value_type *) m_impl_handle
1895 , m_array_offset.span()
1896 , record->get_label()
1899 record->m_destroy = functor_type((fad_value_type *) m_impl_handle
1900 , m_array_offset.span()
1901 , record->get_label()
1905 record->m_destroy.construct_shared_allocation();
1927 template<
class DstTraits ,
class SrcTraits >
1928 class ViewMapping< DstTraits , SrcTraits ,
1929 typename std::enable_if<(
1930 Kokkos::Impl::MemorySpaceAccess
1931 < typename DstTraits::memory_space
1932 , typename SrcTraits::memory_space >::assignable
1935 std::is_same< typename DstTraits::specialize
1936 , ViewSpecializeSacadoFad >::value
1939 std::is_same< typename SrcTraits::specialize
1940 , ViewSpecializeSacadoFad >::value
1943 , typename DstTraits::specialize
1948 enum { is_assignable =
true };
1949 enum { is_assignable_data_type =
true };
1951 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1952 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1953 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1955 template<
class DstType >
1956 KOKKOS_INLINE_FUNCTION
static
1957 void assign( DstType & dst
1958 ,
const SrcFadType & src
1959 ,
const TrackType & )
1963 std::is_same<
typename DstTraits::array_layout
1964 , Kokkos::LayoutLeft >::value ||
1965 std::is_same<
typename DstTraits::array_layout
1966 , Kokkos::LayoutRight >::value ||
1967 std::is_same<
typename DstTraits::array_layout
1968 , Kokkos::LayoutStride >::value
1972 std::is_same<
typename SrcTraits::array_layout
1973 , Kokkos::LayoutLeft >::value ||
1974 std::is_same<
typename SrcTraits::array_layout
1975 , Kokkos::LayoutRight >::value ||
1976 std::is_same<
typename SrcTraits::array_layout
1977 , Kokkos::LayoutStride >::value
1979 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1982 std::is_same<
typename DstTraits::array_layout
1983 ,
typename SrcTraits::array_layout >::value ||
1984 std::is_same<
typename DstTraits::array_layout
1985 , Kokkos::LayoutStride >::value ,
1986 "View assignment must have compatible layout" );
1989 std::is_same<
typename DstTraits::value_type
1990 ,
typename SrcTraits::value_type >::value ||
1991 std::is_same<
typename DstTraits::value_type
1992 ,
typename SrcTraits::const_value_type >::value ,
1993 "View assignment must have same value type or const = non-const" );
1996 ViewDimensionAssignable
1997 <
typename DstType::offset_type::dimension_type
1998 ,
typename SrcFadType::offset_type::dimension_type >::value ,
1999 "View assignment must have compatible dimensions" );
2002 ViewDimensionAssignable
2003 <
typename DstType::array_offset_type::dimension_type
2004 ,
typename SrcFadType::array_offset_type::dimension_type >::value ,
2005 "View assignment must have compatible dimensions" );
2007 typedef typename DstType::offset_type dst_offset_type ;
2008 typedef typename DstType::array_offset_type dst_array_offset_type ;
2010 dst.m_impl_handle = src.m_impl_handle ;
2011 dst.m_impl_offset = dst_offset_type( src.m_impl_offset );
2012 dst.m_array_offset = dst_array_offset_type( src.m_array_offset );
2013 dst.m_fad_size = src.m_fad_size.value ;
2014 dst.m_fad_stride = src.m_fad_stride.value ;
2024 template<
class DstTraits ,
class SrcTraits >
2025 class ViewMapping< DstTraits , SrcTraits ,
2026 typename std::enable_if<(
2027 Kokkos::Impl::MemorySpaceAccess
2028 < typename DstTraits::memory_space
2029 , typename SrcTraits::memory_space >::assignable
2032 std::is_same< typename DstTraits::specialize , void >::value
2035 std::is_same< typename SrcTraits::specialize
2036 , ViewSpecializeSacadoFad >::value
2038 , typename DstTraits::specialize
2043 enum { is_assignable =
true };
2044 enum { is_assignable_data_type =
true };
2047 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
2048 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
2049 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
2054 template <
class DstType,
class SrcFadType,
class Truth =
void >
2055 struct AssignOffset;
2057 template <
class DstType,
class SrcFadType >
2058 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank != (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
2061 KOKKOS_INLINE_FUNCTION
2062 static void assign( DstType & dst,
const SrcFadType & src )
2064 typedef typename SrcTraits::value_type TraitsValueType;
2070 typedef typename DstType::offset_type::array_layout DstLayoutType;
2072 typedef typename SrcFadType::array_offset_type::dimension_type SrcViewDimension;
2077 static constexpr
bool is_layout_left =
2080 typedef typename std::conditional< is_layout_left,
2081 typename SrcViewDimension:: template prepend< InnerStaticDim+1 >::type,
2082 typename SrcViewDimension:: template append < InnerStaticDim+1 >::type
2083 >::type SrcViewDimensionAppended;
2085 typedef std::integral_constant< unsigned , 0 > padding ;
2087 typedef ViewOffset< SrcViewDimensionAppended, DstLayoutType > TmpOffsetType;
2089 auto src_layout = src.m_array_offset.layout();
2091 if ( is_layout_left ) {
2092 auto prepend_layout = Kokkos::Impl::prependFadToLayout< DstLayoutType >::returnNewLayoutPlusFad(src_layout, InnerStaticDim+1);
2093 TmpOffsetType offset_tmp( padding(), prepend_layout );
2094 dst.m_impl_offset = offset_tmp;
2097 TmpOffsetType offset_tmp( padding(), src_layout );
2098 dst.m_impl_offset = offset_tmp;
2102 Kokkos::abort(
"Sacado error: Applying AssignOffset for case with nested Fads, but without nested Fads - something went wrong");
2107 template <
class DstType,
class SrcFadType >
2108 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank == (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
2110 KOKKOS_INLINE_FUNCTION
2111 static void assign( DstType & dst,
const SrcFadType & src )
2114 typedef typename DstType::offset_type dst_offset_type ;
2115 dst.m_impl_offset = dst_offset_type( src.m_array_offset );
2127 template <
class DstType >
2128 KOKKOS_INLINE_FUNCTION
static
2130 assign( DstType & dst
2131 ,
const SrcFadType & src
2138 std::is_same<
typename DstTraits::array_layout
2139 , Kokkos::LayoutLeft >::value ||
2140 std::is_same<
typename DstTraits::array_layout
2141 , Kokkos::LayoutRight >::value ||
2142 std::is_same<
typename DstTraits::array_layout
2143 , Kokkos::LayoutStride >::value
2147 std::is_same<
typename SrcTraits::array_layout
2148 , Kokkos::LayoutLeft >::value ||
2149 std::is_same<
typename SrcTraits::array_layout
2150 , Kokkos::LayoutRight >::value ||
2151 std::is_same<
typename SrcTraits::array_layout
2152 , Kokkos::LayoutStride >::value
2154 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
2157 std::is_same<
typename DstTraits::array_layout
2158 ,
typename SrcTraits::array_layout >::value ||
2159 std::is_same<
typename DstTraits::array_layout
2160 , Kokkos::LayoutStride >::value ,
2161 "View assignment must have compatible layout" );
2164 std::is_same<
typename DstTraits::scalar_array_type
2165 ,
typename SrcTraits::scalar_array_type >::value ||
2166 std::is_same<
typename DstTraits::scalar_array_type
2167 ,
typename SrcTraits::const_scalar_array_type >::value ,
2168 "View assignment must have same value type or const = non-const" );
2171 AssignOffset< DstType, SrcFadType >::assign( dst, src );
2173 dst.m_impl_handle =
reinterpret_cast< typename DstType::handle_type
>(src.m_impl_handle) ;
2187 template<
class SrcTraits ,
class ... Args >
2189 < typename std::enable_if<(
2191 std::is_same< typename SrcTraits::specialize
2192 , ViewSpecializeSacadoFad >::value
2195 std::is_same< typename SrcTraits::array_layout
2196 , Kokkos::LayoutLeft >::value ||
2197 std::is_same< typename SrcTraits::array_layout
2198 , Kokkos::LayoutRight >::value ||
2199 std::is_same< typename SrcTraits::array_layout
2200 , Kokkos::LayoutStride >::value
2209 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
2223 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
2224 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
2227 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
2228 1 == SrcTraits::rank ? R0 : (
2229 2 == SrcTraits::rank ? R1 : (
2230 3 == SrcTraits::rank ? R2 : (
2231 4 == SrcTraits::rank ? R3 : (
2232 5 == SrcTraits::rank ? R4 : (
2233 6 == SrcTraits::rank ? R5 : R6 ))))))) };
2240 typedef typename std::conditional<
2244 ( std::is_same<
typename SrcTraits::array_layout
2245 , Kokkos::LayoutRight >::value
2247 ( rank == 1 ) && R0_rev
2250 ( std::is_same<
typename SrcTraits::array_layout
2251 , Kokkos::LayoutLeft >::value
2253 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
2255 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
2256 >::type array_layout ;
2258 typedef typename SrcTraits::value_type fad_type ;
2260 typedef typename std::conditional< rank == 0 , fad_type ,
2261 typename std::conditional< rank == 1 , fad_type * ,
2262 typename std::conditional< rank == 2 , fad_type ** ,
2263 typename std::conditional< rank == 3 , fad_type *** ,
2264 typename std::conditional< rank == 4 , fad_type **** ,
2265 typename std::conditional< rank == 5 , fad_type ***** ,
2266 typename std::conditional< rank == 6 , fad_type ****** ,
2268 >::type >::type >::type >::type >::type >::type >::type
2273 typedef Kokkos::ViewTraits
2276 ,
typename SrcTraits::device_type
2277 ,
typename SrcTraits::memory_traits > traits_type ;
2279 typedef Kokkos::View
2282 ,
typename SrcTraits::device_type
2283 ,
typename SrcTraits::memory_traits > type ;
2286 KOKKOS_INLINE_FUNCTION
2287 static void assign( ViewMapping< traits_type , typename traits_type::specialize > & dst
2288 , ViewMapping< SrcTraits ,typename SrcTraits::specialize >
const & src
2291 typedef ViewMapping< traits_type , typename traits_type::specialize > DstType ;
2292 typedef typename DstType::offset_type dst_offset_type ;
2293 typedef typename DstType::array_offset_type dst_array_offset_type ;
2294 typedef typename DstType::handle_type dst_handle_type ;
2296 const SubviewExtents< SrcTraits::rank , rank >
2297 extents( src.m_impl_offset.m_dim , args... );
2298 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
2299 array_extents( src.m_array_offset.m_dim , args... , Kokkos::ALL() );
2301 dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
2302 dst.m_array_offset = dst_array_offset_type( src.m_array_offset , array_extents );
2304 dst_handle_type( src.m_impl_handle +
2305 src.m_array_offset( array_extents.domain_offset(0)
2306 , array_extents.domain_offset(1)
2307 , array_extents.domain_offset(2)
2308 , array_extents.domain_offset(3)
2309 , array_extents.domain_offset(4)
2310 , array_extents.domain_offset(5)
2311 , array_extents.domain_offset(6)
2312 , array_extents.domain_offset(7) ) );
2313 dst.m_fad_size = src.m_fad_size;
2314 dst.m_fad_stride = src.m_fad_stride.value;
2325 #if defined(HAVE_SACADO_KOKKOS) && \
2326 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \
2327 defined(HAVE_SACADO_VIEW_SPEC) && \
2328 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2330 #include "Kokkos_TeuchosCommAdapters.hpp"
2334 template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
2335 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
2336 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
2339 (
const Comm<Ordinal>& comm,
2340 const EReductionType reductType ,
2342 const Kokkos::View<SD,SP...> & sendBuffer ,
2343 const Kokkos::View<RD,RP...> & recvBuffer )
2350 typedef Kokkos::View<SD,SP...> SendViewType;
2351 typedef Kokkos::View<RD,RP...> RecvViewType;
2352 typedef typename SendViewType::value_type send_value_type;
2353 typedef typename RecvViewType::value_type recv_value_type;
2356 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
2357 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
2358 "The send View's rank is " << SendViewType::rank <<
" and the receive "
2359 "View's rank is " << RecvViewType::rank <<
".");
2363 typename SendViewType::host_mirror_type hostSendBuffer =
2364 Kokkos::create_mirror_view(sendBuffer);
2365 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2367 localSendBuffer[i] = hostSendBuffer(i);
2372 typename RecvViewType::host_mirror_type hostRecvBuffer =
2373 Kokkos::create_mirror_view(recvBuffer);
2374 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2376 localRecvBuffer[i] = hostRecvBuffer(i);
2379 reduceAll(comm, reductType, count,
2380 localSendBuffer.getRawPtr(),
2381 localRecvBuffer.getRawPtr());
2385 hostRecvBuffer(i) = localRecvBuffer[
i];
2386 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2390 template<
typename Ordinal ,
typename Serializer ,
2391 class SD ,
class ... SP ,
class RD ,
class ... RP >
2392 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
2393 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
2396 (
const Comm<Ordinal>& comm,
2397 const Serializer& serializer,
2398 const EReductionType reductType ,
2400 const Kokkos::View<SD,SP...> & sendBuffer ,
2401 const Kokkos::View<RD,RP...> & recvBuffer )
2408 typedef Kokkos::View<SD,SP...> SendViewType;
2409 typedef Kokkos::View<RD,RP...> RecvViewType;
2410 typedef typename SendViewType::value_type send_value_type;
2411 typedef typename RecvViewType::value_type recv_value_type;
2414 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
2415 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
2416 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
2420 typename SendViewType::host_mirror_type hostSendBuffer =
2421 Kokkos::create_mirror_view(sendBuffer);
2422 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2424 localSendBuffer[i] = hostSendBuffer(i);
2429 typename RecvViewType::host_mirror_type hostRecvBuffer =
2430 Kokkos::create_mirror_view(recvBuffer);
2431 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2433 localRecvBuffer[i] = hostRecvBuffer(i);
2436 reduceAll(comm, serializer, reductType, count,
2437 localSendBuffer.getRawPtr(),
2438 localRecvBuffer.getRawPtr());
2442 hostRecvBuffer(i) = localRecvBuffer[
i];
2443 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2447 template<
typename Ordinal,
class D,
class ... P >
2448 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2450 (
const Comm<Ordinal>& comm,
2451 const int rootRank ,
2453 const Kokkos::View<D,P...>& buffer)
2455 typedef Kokkos::View<
D,P...> view_type;
2456 typename view_type::array_type array_buffer = buffer;
2457 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2458 broadcast( comm, rootRank, array_count, array_buffer );
2462 typename Serializer ,
2463 class D,
class ... P >
2464 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2466 (
const Comm<Ordinal>& comm,
2467 const Serializer& serializer,
2468 const int rootRank ,
2470 const Kokkos::View<D,P...>& buffer)
2472 typedef Kokkos::View<
D,P...> view_type;
2473 typename view_type::array_type array_buffer = buffer;
2474 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2475 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
2476 array_count, array_buffer );
2485 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2487 #endif // defined(HAVE_SACADO_KOKKOS)
2491 #endif // defined(SACADO_HAS_NEW_KOKKOS_VIEW_IMPL)
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.
GeneralFad< DynamicStorage< T > > DFad
GeneralFad< StaticFixedStorage< T, Num > > SFad
Base template specification for testing whether type is statically sized.
Get view type for any Fad type.