10 #ifndef KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
11 #define KOKKOS_EXPERIMENTAL_VIEW_SACADO_FAD_HPP
14 #if defined(HAVE_SACADO_KOKKOS)
21 #ifndef KOKKOS_IMPL_PUBLIC_INCLUDE
22 #define KOKKOS_IMPL_PUBLIC_INCLUDE
23 #define KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
25 #include "Kokkos_Layout.hpp"
26 #ifdef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
27 #undef KOKKOS_IMPL_PUBLIC_INCLUDE
28 #undef KOKKOS_IMPL_PUBLIC_INCLUDE_NOTDEFINED_CORE
36 template <
typename view_type>
37 struct is_view_fad {
static const bool value =
false; };
41 template <
typename view_type>
42 struct is_view_fad_contiguous {
static const bool value =
false; };
45 template <
typename view_type>
46 KOKKOS_INLINE_FUNCTION
48 dimension_scalar(
const view_type& ) {
53 template <
typename view_type>
54 KOKKOS_INLINE_FUNCTION
56 dimension_scalar_aligned(
const view_type& view) {
57 return dimension_scalar(view);
63 #if defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
70 struct ViewSpecializeSacadoFad {};
71 struct ViewSpecializeSacadoFadContiguous {};
73 template<
class ... Args >
74 struct is_ViewSpecializeSacadoFad {
enum {
value =
false }; };
76 template<
class D ,
class ... P ,
class ... Args >
77 struct is_ViewSpecializeSacadoFad< Kokkos::
View<D,P...> , Args... > {
79 std::is_same<
typename Kokkos::ViewTraits<
D,P...>::specialize
80 , ViewSpecializeSacadoFad >
::value
82 ( (
sizeof...(Args) == 0 ) ||
83 is_ViewSpecializeSacadoFad< Args... >
::value ) };
91 template <
typename T,
typename ... P>
92 struct is_view_fad<
View<
T,P...> > {
93 typedef View<
T,P...> view_type;
94 static const bool value =
95 std::is_same<
typename view_type::specialize,
96 Impl::ViewSpecializeSacadoFad >
::value ||
97 std::is_same<
typename view_type::specialize,
98 Impl::ViewSpecializeSacadoFadContiguous >
::value;
101 template <
typename T,
typename ... P>
102 struct is_view_fad_contiguous<
View<
T,P...> > {
103 typedef View<
T,P...> view_type;
104 static const bool value =
105 std::is_same<
typename view_type::specialize,
106 Impl::ViewSpecializeSacadoFadContiguous >
::value;
112 #include "Kokkos_Core.hpp"
121 template<
class DT,
class ... DP,
122 class ST,
class ... SP>
123 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >
::value &&
124 is_view_fad< Kokkos::View<ST,SP...> >
::value
126 view_copy(
const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
128 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
129 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
130 view_copy( dst_array_type(dst) , src_array_type(src) );
133 template<
class ExecutionSpace,
134 class DT,
class ... DP,
135 class ST,
class ... SP>
136 typename std::enable_if< is_view_fad< Kokkos::View<DT,DP...> >
::value &&
137 is_view_fad< Kokkos::View<ST,SP...> >
::value
139 view_copy(
const ExecutionSpace& space,
140 const Kokkos::View<DT,DP...>& dst,
const Kokkos::View<ST,SP...>& src)
142 typedef typename Kokkos::View<DT,DP...>::array_type dst_array_type;
143 typedef typename Kokkos::View<ST,SP...>::array_type src_array_type;
144 view_copy( space, dst_array_type(dst) , src_array_type(src) );
152 template <
typename T,
typename ... P>
153 KOKKOS_INLINE_FUNCTION
155 std::enable_if< is_view_fad<
View<
T,P...> >
::value,
unsigned >::type
156 dimension_scalar(
const View<T,P...>& view) {
157 #ifdef KOKKOS_ENABLE_DEPRECATED_CODE
158 return view.implementation_map().dimension_scalar();
160 return view.impl_map().dimension_scalar();
164 template <
typename Layout>
165 struct ApplyNatural {
166 typedef LayoutNatural<Layout> type;
169 template <
typename Layout>
170 struct ApplyNatural< LayoutNatural<Layout> > {
171 typedef LayoutNatural<Layout> type;
174 template <
typename T,
typename Enable =
void >
177 template <
typename T >
178 struct ArrayScalar<
T, typename std::enable_if< !Sacado::IsFad<T>::value >::type > {
182 template <
typename T >
183 struct ArrayScalar<
T, typename std::enable_if< Sacado::IsFad<T>::value >::type > {
184 typedef typename ArrayScalar< typename Sacado::ValueType<T>::type >::type* type;
188 template <
typename DataType,
int Rank >
189 struct AppendRankToConvertedFad {
190 static_assert( Rank > -1,
"Sacado AppendRankToConvertedFad Error: Rank < 0" );
191 typedef typename AppendRankToConvertedFad<DataType,Rank-1>::type* type;
195 template <
typename DataType >
196 struct AppendRankToConvertedFad< DataType, 0 > {
197 typedef DataType type;
201 template <
class ArrayLayout,
class Enable =
void >
202 struct ViewArrayLayoutSelector;
204 template <
class ArrayLayout >
205 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutLeft>::value >::type >
207 using type = Kokkos::LayoutLeft;
210 template <
class ArrayLayout >
211 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutRight>::value >::type >
213 using type = Kokkos::LayoutRight;
216 template <
class ArrayLayout >
217 struct ViewArrayLayoutSelector< ArrayLayout, typename std::enable_if< std::is_same<ArrayLayout, Kokkos::LayoutStride>::value >::type >
219 using type = Kokkos::LayoutStride;
222 template <
typename ViewType,
typename Enable =
void >
223 struct PODViewDeepCopyType;
225 template <
typename ViewType >
226 struct PODViewDeepCopyType< ViewType, typename std::enable_if< is_view_fad<ViewType>::value >::type >
229 typedef ViewType view_type;
230 typedef typename ArrayScalar< typename view_type::value_type >::type fad_converted_type;
231 typedef typename AppendRankToConvertedFad< fad_converted_type, view_type::rank >::type new_data_type;
233 typedef typename ViewArrayLayoutSelector<typename view_type::array_layout>::type layout;
235 typedef typename view_type::device_type device;
236 typedef typename view_type::memory_traits memory;
238 typedef Kokkos::View< new_data_type, layout, device, memory > type;
242 template <
typename ViewType >
243 struct PODViewDeepCopyType< ViewType, typename std::enable_if< !is_view_fad<ViewType>::value >::type >
245 typedef ViewType type;
249 template <
typename ViewType,
typename Enabled =
void>
250 struct NaturalArrayType {
251 typedef ViewType type;
254 template <
typename D,
typename ... P>
255 struct NaturalArrayType<
View<
D,P...>,
256 typename std::enable_if< is_view_fad< View<D,P...> >::value >::type > {
257 typedef View<
D,P...> view_type;
258 typedef typename view_type::data_type data_type;
259 typedef typename view_type::array_layout layout;
260 typedef typename view_type::device_type device;
261 typedef typename view_type::memory_traits memory;
263 typedef typename ViewArrayLayoutSelector<layout>::type natural_layout;
264 typedef View<data_type,natural_layout,device,memory> type;
269 template <
class OutputView,
typename Enabled =
void>
270 struct SacadoViewFill
272 typedef typename OutputView::const_value_type const_value_type ;
273 typedef typename OutputView::execution_space execution_space ;
275 const OutputView output ;
276 const_value_type input ;
278 KOKKOS_INLINE_FUNCTION
279 void operator()(
const size_t i0 )
const
281 const size_t n1 = output.extent(1);
282 const size_t n2 = output.extent(2);
283 const size_t n3 = output.extent(3);
284 const size_t n4 = output.extent(4);
285 const size_t n5 = output.extent(5);
286 const size_t n6 = output.extent(6);
288 for (
size_t i1 = 0 ; i1 < n1 ; ++i1 ) {
289 for (
size_t i2 = 0 ; i2 < n2 ; ++i2 ) {
290 for (
size_t i3 = 0 ; i3 < n3 ; ++i3 ) {
291 for (
size_t i4 = 0 ; i4 < n4 ; ++i4 ) {
292 for (
size_t i5 = 0 ; i5 < n5 ; ++i5 ) {
293 for (
size_t i6 = 0 ; i6 < n6 ; ++i6 ) {
294 output.access(i0,i1,i2,i3,i4,i5,i6) = input ;
298 SacadoViewFill(
const OutputView & arg_out , const_value_type & arg_in )
299 : output( arg_out ), input( arg_in )
301 const size_t n0 = output.extent(0);
302 Kokkos::RangePolicy<execution_space> policy( 0, n0 );
303 Kokkos::parallel_for( policy, *
this );
310 template<
class DT,
class ... DP >
312 const View<DT,DP...> & view ,
314 ,
typename std::enable_if<(
315 std::is_same<
typename ViewTraits<DT,DP...>::specialize
316 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
317 std::is_same<
typename ViewTraits<DT,DP...>::specialize
318 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
322 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
323 typename ViewTraits<DT,DP...>::non_const_value_type >::value
324 ,
"Can only deep copy into non-const type" );
326 Impl::SacadoViewFill<
View<DT,DP...> >( view ,
value );
331 template<
class DT,
class ... DP >
333 const View<DT,DP...> & view ,
334 const typename View<DT,DP...>::value_type & value
335 ,
typename std::enable_if<(
336 std::is_same<
typename ViewTraits<DT,DP...>::specialize
337 , Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
338 std::is_same<
typename ViewTraits<DT,DP...>::specialize
339 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value
343 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
344 typename ViewTraits<DT,DP...>::non_const_value_type >::value
345 ,
"Can only deep copy into non-const type" );
347 Impl::SacadoViewFill<
View<DT,DP...> >( view ,
value );
351 template<
class ExecSpace,
class DT ,
class ... DP ,
class ST ,
class ... SP >
353 void deep_copy(
const ExecSpace &,
354 const View<DT,DP...> & dst ,
355 const View<ST,SP...> & src
356 ,
typename std::enable_if<(
357 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
358 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
360 std::is_same<
typename ViewTraits<DT,DP...>::specialize
361 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
363 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
364 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
366 std::is_same<
typename ViewTraits<ST,SP...>::specialize
367 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
371 std::is_same<
typename ViewTraits<DT,DP...>::value_type ,
372 typename ViewTraits<DT,DP...>::non_const_value_type >::value
373 ,
"Deep copy destination must be non-const" );
376 (
unsigned(ViewTraits<DT,DP...>::rank) ==
377 unsigned(ViewTraits<ST,SP...>::rank) )
378 ,
"Deep copy destination and source must have same rank" );
382 typedef typename View<DT,DP...>::array_type dst_array_type;
383 typedef typename View<ST,SP...>::array_type src_array_type;
384 typename NaturalArrayType< dst_array_type >::type dst_array( dst );
385 typename NaturalArrayType< src_array_type >::type src_array( src );
388 typename PODViewDeepCopyType<
View<DT,DP...> >::type dst_array( dst );
389 typename PODViewDeepCopyType<
View<ST,SP...> >::type src_array( src );
391 Kokkos::deep_copy( ExecSpace(), dst_array , src_array );
395 template<
class DT ,
class ... DP ,
class ST ,
class ... SP >
397 void deep_copy(
const View<DT,DP...> & dst ,
398 const View<ST,SP...> & src
399 ,
typename std::enable_if<(
400 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize
401 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
403 std::is_same<
typename ViewTraits<DT,DP...>::specialize
404 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
406 ( std::is_same<
typename ViewTraits<ST,SP...>::specialize
407 , Kokkos::Impl::ViewSpecializeSacadoFad >::value
409 std::is_same<
typename ViewTraits<ST,SP...>::specialize
410 , Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
413 using exec_space =
typename View<DT,DP...>::execution_space;
415 Kokkos::deep_copy(exec_space(), dst, src);
419 template<
class T ,
class ... P >
421 typename std::enable_if<
422 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
423 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
424 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
425 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
426 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
427 Kokkos::LayoutStride >::value,
428 typename Kokkos::View<T,P...>::HostMirror>::type
429 create_mirror(
const Kokkos::View<T,P...> & src)
431 typedef View<
T,P...> src_type ;
432 typedef typename src_type::HostMirror dst_type ;
434 typename src_type::array_layout layout = src.layout();
435 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
437 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
440 template<
class T ,
class ... P >
442 typename std::enable_if<
443 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
444 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
445 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
446 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
447 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
448 Kokkos::LayoutStride >::value,
449 typename Kokkos::View<T,P...>::HostMirror>::type
450 create_mirror(
const Kokkos::View<T,P...> & src)
452 typedef View<
T,P...> src_type ;
453 typedef typename src_type::array_type src_array_type ;
454 typedef typename src_type::HostMirror dst_type ;
456 Kokkos::LayoutStride layout ;
459 src_array_type src_array = src;
460 layout.dimension[0] = src_array.extent(0);
461 layout.dimension[1] = src_array.extent(1);
462 layout.dimension[2] = src_array.extent(2);
463 layout.dimension[3] = src_array.extent(3);
464 layout.dimension[4] = src_array.extent(4);
465 layout.dimension[5] = src_array.extent(5);
466 layout.dimension[6] = src_array.extent(6);
467 layout.dimension[7] = src_array.extent(7);
469 layout.stride[0] = src_array.stride_0();
470 layout.stride[1] = src_array.stride_1();
471 layout.stride[2] = src_array.stride_2();
472 layout.stride[3] = src_array.stride_3();
473 layout.stride[4] = src_array.stride_4();
474 layout.stride[5] = src_array.stride_5();
475 layout.stride[6] = src_array.stride_6();
476 layout.stride[7] = src_array.stride_7();
478 return dst_type(std::string(src.label()).append(
"_mirror"), layout);
481 template<
class Space,
class T,
class ... P,
typename Enabled>
482 typename std::enable_if<
483 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
484 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
485 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
486 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value,
487 typename Impl::MirrorViewType<Space,
T,P ...>::dest_view_type>::type
488 create_mirror(
const Space& ,
const Kokkos::View<T,P...> & src)
490 typedef View<
T,P...> src_type ;
491 typename src_type::array_layout layout = src.layout();
492 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
493 return typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type(src.label(),layout);
496 template<
class T ,
class ... P >
498 typename std::enable_if<
499 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
500 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
501 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
502 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
503 !std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
504 Kokkos::LayoutStride >::value,
505 typename Kokkos::View<T,P...>::HostMirror>::type
506 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
507 const Kokkos::View<T,P...> & src)
509 typedef View<
T,P...> src_type ;
510 typedef typename src_type::HostMirror dst_type ;
512 typename src_type::array_layout layout = src.layout();
513 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
516 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
519 template<
class T ,
class ... P >
521 typename std::enable_if<
522 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
523 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
524 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
525 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ) &&
526 std::is_same<
typename Kokkos::ViewTraits<T,P...>::array_layout,
527 Kokkos::LayoutStride >::value,
528 typename Kokkos::View<T,P...>::HostMirror>::type
529 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
530 const Kokkos::View<T,P...> & src)
532 typedef View<
T,P...> src_type ;
533 typedef typename src_type::array_type src_array_type ;
534 typedef typename src_type::HostMirror dst_type ;
536 Kokkos::LayoutStride layout ;
539 src_array_type src_array = src;
540 layout.dimension[0] = src_array.extent(0);
541 layout.dimension[1] = src_array.extent(1);
542 layout.dimension[2] = src_array.extent(2);
543 layout.dimension[3] = src_array.extent(3);
544 layout.dimension[4] = src_array.extent(4);
545 layout.dimension[5] = src_array.extent(5);
546 layout.dimension[6] = src_array.extent(6);
547 layout.dimension[7] = src_array.extent(7);
549 layout.stride[0] = src_array.stride_0();
550 layout.stride[1] = src_array.stride_1();
551 layout.stride[2] = src_array.stride_2();
552 layout.stride[3] = src_array.stride_3();
553 layout.stride[4] = src_array.stride_4();
554 layout.stride[5] = src_array.stride_5();
555 layout.stride[6] = src_array.stride_6();
556 layout.stride[7] = src_array.stride_7();
559 Kokkos::view_alloc(std::string(src.label()).append(
"_mirror"), wi), layout);
562 template<
class Space,
class T,
class ... P,
typename Enable>
563 typename std::enable_if<
564 ( std::is_same<
typename ViewTraits<
T,P...>::specialize ,
565 Kokkos::Impl::ViewSpecializeSacadoFad >
::value ||
566 std::is_same<
typename ViewTraits<
T,P...>::specialize ,
567 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >
::value ),
568 typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type>::type
569 create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
570 const Space& ,
const Kokkos::View<T,P...> & src)
572 typedef View<
T,P...> src_type ;
573 typename src_type::array_layout layout = src.layout();
574 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
575 return typename Impl::MirrorViewType<Space,T,P ...>::dest_view_type(
576 Kokkos::view_alloc(src.label(), wi), layout);
579 template <
class Space,
class T,
class... P>
580 typename Impl::MirrorViewType<Space,
T, P...>::view_type
581 create_mirror_view_and_copy(
582 const Space&,
const Kokkos::View<T, P...>& src,
583 std::string
const& name,
584 typename std::enable_if<
585 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
586 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
587 std::is_same<
typename ViewTraits<T,P...>::specialize ,
588 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
589 Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
593 "Kokkos::create_mirror_view_and_copy: fence before returning src view");
597 template <
class Space,
class T,
class... P>
598 typename Impl::MirrorViewType<Space,
T, P...>::view_type
599 create_mirror_view_and_copy(
600 const Space&,
const Kokkos::View<T, P...>& src,
601 std::string
const& name,
602 typename std::enable_if<
603 ( std::is_same<
typename ViewTraits<T, P...>::specialize,
604 Kokkos::Impl::ViewSpecializeSacadoFad>::value ||
605 std::is_same<
typename ViewTraits<T,P...>::specialize ,
606 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
607 !Impl::MirrorViewType<Space, T, P...>::is_same_memspace>::type*)
609 using src_type =
View<
T,P...>;
610 using Mirror =
typename Impl::MirrorViewType<Space,
T, P...>::view_type;
611 std::string label = name.empty() ? src.label() : name;
612 typename src_type::array_layout layout = src.layout();
613 layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
614 auto mirror =
typename Mirror::non_const_type{
615 view_alloc(WithoutInitializing, label), layout};
616 deep_copy(mirror, src);
622 template <
unsigned N,
typename... Args>
623 KOKKOS_FUNCTION std::enable_if_t<
624 N ==
View<Args...>::Rank &&
625 (std::is_same<
typename ViewTraits<Args...>::specialize,
626 Kokkos::Impl::ViewSpecializeSacadoFad>
::value ||
627 std::is_same<
typename ViewTraits<Args...>::specialize,
628 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>
::value),
630 as_view_of_rank_n(View<Args...> v) {
636 template <
unsigned N,
typename T,
typename... Args>
638 N !=
View<
T, Args...>::Rank &&
639 (std::is_same<
typename ViewTraits<
T, Args...>::specialize,
640 Kokkos::Impl::ViewSpecializeSacadoFad>
::value ||
641 std::is_same<
typename ViewTraits<
T, Args...>::specialize,
642 Kokkos::Impl::ViewSpecializeSacadoFadContiguous>
::value),
643 View<
typename RankDataType<
typename View<T, Args...>::value_type,
N>::type,
645 as_view_of_rank_n(View<T, Args...>) {
646 Kokkos::Impl::throw_runtime_exception(
647 "Trying to get at a View of the wrong rank");
656 namespace Experimental {
658 template <
class DT,
class... DP>
659 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
660 const View<DT, DP...>& dst,
661 typename ViewTraits<DT, DP...>::const_value_type& value,
662 typename std::enable_if<(
663 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
664 Kokkos::Impl::ViewSpecializeSacadoFad >::value
666 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
667 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
668 && (
unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type*)
670 if (dst.data() ==
nullptr)
673 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
677 template <
class DT,
class... DP>
678 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
679 const View<DT, DP...>& dst,
680 typename ViewTraits<DT, DP...>::const_value_type& value,
681 typename std::enable_if<(
682 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
683 Kokkos::Impl::ViewSpecializeSacadoFad >::value
685 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
686 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
687 && (
unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type*)
689 if (dst.data() ==
nullptr)
692 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
693 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
697 template <
class DT,
class... DP>
698 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
699 const View<DT, DP...>& dst,
700 typename ViewTraits<DT, DP...>::const_value_type& value,
701 typename std::enable_if<(
702 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
703 Kokkos::Impl::ViewSpecializeSacadoFad >::value
705 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
706 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
707 && (
unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type*)
709 if (dst.data() ==
nullptr)
712 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
713 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
714 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
715 dst(i0,i1,i2) =
value;
718 template <
class DT,
class... DP>
719 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
720 const View<DT, DP...>& dst,
721 typename ViewTraits<DT, DP...>::const_value_type& value,
722 typename std::enable_if<(
723 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
724 Kokkos::Impl::ViewSpecializeSacadoFad >::value
726 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
727 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
728 && (
unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type*)
730 if (dst.data() ==
nullptr)
733 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
734 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
735 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
736 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
737 dst(i0,i1,i2,i3) =
value;
740 template <
class DT,
class... DP>
741 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
742 const View<DT, DP...>& dst,
743 typename ViewTraits<DT, DP...>::const_value_type& value,
744 typename std::enable_if<(
745 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
746 Kokkos::Impl::ViewSpecializeSacadoFad >::value
748 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
749 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
750 && (
unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type*)
752 if (dst.data() ==
nullptr)
755 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
756 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
757 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
758 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
759 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
760 dst(i0,i1,i2,i3,i4) =
value;
763 template <
class DT,
class... DP>
764 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
765 const View<DT, DP...>& dst,
766 typename ViewTraits<DT, DP...>::const_value_type& value,
767 typename std::enable_if<(
768 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
769 Kokkos::Impl::ViewSpecializeSacadoFad >::value
771 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
772 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
773 && (
unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type*)
775 if (dst.data() ==
nullptr)
778 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
779 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
780 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
781 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
782 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
783 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
784 dst(i0,i1,i2,i3,i4,i5) =
value;
787 template <
class DT,
class... DP>
788 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
789 const View<DT, DP...>& dst,
790 typename ViewTraits<DT, DP...>::const_value_type& value,
791 typename std::enable_if<(
792 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
793 Kokkos::Impl::ViewSpecializeSacadoFad >::value
795 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
796 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
797 && (
unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type*)
799 if (dst.data() ==
nullptr)
802 for (
size_t i0 = 0; i0 < dst.extent(0); ++i0)
803 for (
size_t i1 = 0; i1 < dst.extent(1); ++i1)
804 for (
size_t i2 = 0; i2 < dst.extent(2); ++i2)
805 for (
size_t i3 = 0; i3 < dst.extent(3); ++i3)
806 for (
size_t i4 = 0; i4 < dst.extent(4); ++i4)
807 for (
size_t i5 = 0; i5 < dst.extent(5); ++i5)
808 for (
size_t i6 = 0; i6 < dst.extent(6); ++i6)
809 dst(i0,i1,i2,i3,i4,i5,i6) =
value;
812 template <
class TeamType,
class DT,
class... DP>
813 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
814 const TeamType& team,
const View<DT, DP...>& dst,
815 typename ViewTraits<DT, DP...>::const_value_type& value,
816 typename std::enable_if<(
817 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
818 Kokkos::Impl::ViewSpecializeSacadoFad >::value
820 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
821 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
822 && (
unsigned(ViewTraits<DT, DP...>::rank) == 1))>::type*)
824 if (dst.data() ==
nullptr)
827 const size_t N = dst.extent(0);
830 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N),
831 [&](
const int&
i) { dst(i) =
value; });
835 template <
class TeamType,
class DT,
class... DP>
836 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
837 const TeamType& team,
const View<DT, DP...>& dst,
838 typename ViewTraits<DT, DP...>::const_value_type& value,
839 typename std::enable_if<(
840 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
841 Kokkos::Impl::ViewSpecializeSacadoFad >::value
843 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
844 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
845 && (
unsigned(ViewTraits<DT, DP...>::rank) == 2))>::type*)
847 if (dst.data() ==
nullptr)
850 const size_t N = dst.extent(0) * dst.extent(1);
853 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
854 int i0 = i % dst.extent(0);
855 int i1 = i / dst.extent(0);
861 template <
class TeamType,
class DT,
class... DP>
862 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
863 const TeamType& team,
const View<DT, DP...>& dst,
864 typename ViewTraits<DT, DP...>::const_value_type& value,
865 typename std::enable_if<(
866 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
867 Kokkos::Impl::ViewSpecializeSacadoFad >::value
869 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
870 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
871 && (
unsigned(ViewTraits<DT, DP...>::rank) == 3))>::type*)
873 if (dst.data() ==
nullptr)
876 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2);
879 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
880 int i0 = i % dst.extent(0);
881 int itmp = i / dst.extent(0);
882 int i1 = itmp % dst.extent(1);
883 int i2 = itmp / dst.extent(1);
884 dst(i0, i1, i2) =
value;
889 template <
class TeamType,
class DT,
class... DP>
890 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
891 const TeamType& team,
const View<DT, DP...>& dst,
892 typename ViewTraits<DT, DP...>::const_value_type& value,
893 typename std::enable_if<(
894 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
895 Kokkos::Impl::ViewSpecializeSacadoFad >::value
897 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
898 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
899 && (
unsigned(ViewTraits<DT, DP...>::rank) == 4))>::type*)
901 if (dst.data() ==
nullptr)
905 dst.extent(0) * dst.extent(1) * dst.extent(2) * dst.extent(3);
908 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
909 int i0 = i % dst.extent(0);
910 int itmp = i / dst.extent(0);
911 int i1 = itmp % dst.extent(1);
912 itmp = itmp / dst.extent(1);
913 int i2 = itmp % dst.extent(2);
914 int i3 = itmp / dst.extent(2);
915 dst(i0, i1, i2, i3) =
value;
920 template <
class TeamType,
class DT,
class... DP>
921 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
922 const TeamType& team,
const View<DT, DP...>& dst,
923 typename ViewTraits<DT, DP...>::const_value_type& value,
924 typename std::enable_if<(
925 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
926 Kokkos::Impl::ViewSpecializeSacadoFad >::value
928 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
929 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
930 && (
unsigned(ViewTraits<DT, DP...>::rank) == 5))>::type*)
932 if (dst.data() ==
nullptr)
935 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
936 dst.extent(3) * dst.extent(4);
939 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
940 int i0 = i % dst.extent(0);
941 int itmp = i / dst.extent(0);
942 int i1 = itmp % dst.extent(1);
943 itmp = itmp / dst.extent(1);
944 int i2 = itmp % dst.extent(2);
945 itmp = itmp / dst.extent(2);
946 int i3 = itmp % dst.extent(3);
947 int i4 = itmp / dst.extent(3);
948 dst(i0, i1, i2, i3, i4) =
value;
953 template <
class TeamType,
class DT,
class... DP>
954 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
955 const TeamType& team,
const View<DT, DP...>& dst,
956 typename ViewTraits<DT, DP...>::const_value_type& value,
957 typename std::enable_if<(
958 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
959 Kokkos::Impl::ViewSpecializeSacadoFad >::value
961 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
962 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
963 && (
unsigned(ViewTraits<DT, DP...>::rank) == 6))>::type*)
965 if (dst.data() ==
nullptr)
968 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
969 dst.extent(3) * dst.extent(4) * dst.extent(5);
972 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
973 int i0 = i % dst.extent(0);
974 int itmp = i / dst.extent(0);
975 int i1 = itmp % dst.extent(1);
976 itmp = itmp / dst.extent(1);
977 int i2 = itmp % dst.extent(2);
978 itmp = itmp / dst.extent(2);
979 int i3 = itmp % dst.extent(3);
980 itmp = itmp / dst.extent(3);
981 int i4 = itmp % dst.extent(4);
982 int i5 = itmp / dst.extent(4);
983 dst(i0, i1, i2, i3, i4, i5) =
value;
988 template <
class TeamType,
class DT,
class... DP>
989 void KOKKOS_INLINE_FUNCTION local_deep_copy_contiguous(
990 const TeamType& team,
const View<DT, DP...>& dst,
991 typename ViewTraits<DT, DP...>::const_value_type& value,
992 typename std::enable_if<(
993 ( std::is_same<
typename ViewTraits<DT,DP...>::specialize,
994 Kokkos::Impl::ViewSpecializeSacadoFad >::value
996 std::is_same<
typename ViewTraits<DT,DP...>::specialize,
997 Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
998 && (
unsigned(ViewTraits<DT, DP...>::rank) == 7))>::type*)
1000 if (dst.data() ==
nullptr)
1003 const size_t N = dst.extent(0) * dst.extent(1) * dst.extent(2) *
1004 dst.extent(3) * dst.extent(4) * dst.extent(5) *
1007 team.team_barrier();
1008 Kokkos::parallel_for(Kokkos::TeamThreadRange(team, N), [&](
const int& i) {
1009 int i0 = i % dst.extent(0);
1010 int itmp = i / dst.extent(0);
1011 int i1 = itmp % dst.extent(1);
1012 itmp = itmp / dst.extent(1);
1013 int i2 = itmp % dst.extent(2);
1014 itmp = itmp / dst.extent(2);
1015 int i3 = itmp % dst.extent(3);
1016 itmp = itmp / dst.extent(3);
1017 int i4 = itmp % dst.extent(4);
1018 itmp = itmp / dst.extent(4);
1019 int i5 = itmp % dst.extent(5);
1020 int i6 = itmp / dst.extent(5);
1021 dst(i0, i1, i2, i3, i4, i5, i6) =
value;
1023 team.team_barrier();
1034 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
1035 struct FadViewDataAnalysis
1039 typedef ViewArrayAnalysis< DataType > array_analysis ;
1044 typedef ViewSpecializeSacadoFad specialize ;
1046 typedef typename array_analysis::dimension dimension ;
1047 typedef typename array_analysis::value_type value_type ;
1048 typedef typename array_analysis::const_value_type const_value_type ;
1049 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1053 ViewDataType< value_type , dimension >::type type ;
1055 ViewDataType< const_value_type , dimension >::type const_type ;
1057 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1066 std::conditional< is_const , const ScalarType , ScalarType >::type
1069 typedef ScalarType non_const_scalar_type ;
1070 typedef const ScalarType const_scalar_type ;
1073 typedef typename array_analysis::dimension::
1074 template append<( DimFad ? DimFad + 1 : 0 )>::type
1081 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
1084 ViewDataType< const_scalar_type , scalar_dimension >::type
1085 const_scalar_array_type ;
1088 ViewDataType< non_const_scalar_type , scalar_dimension >::type
1089 non_const_scalar_array_type ;
1094 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad,
unsigned Str
ide >
1095 struct FadViewDataAnalysis<DataType, LayoutContiguous<ArrayLayout,Stride>, ScalarType, DimFad>
1099 typedef ViewArrayAnalysis< DataType > array_analysis ;
1104 typedef ViewSpecializeSacadoFadContiguous specialize ;
1106 typedef typename array_analysis::dimension dimension ;
1107 typedef typename array_analysis::value_type value_type ;
1108 typedef typename array_analysis::const_value_type const_value_type ;
1109 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1113 ViewDataType< value_type , dimension >::type type ;
1115 ViewDataType< const_value_type , dimension >::type const_type ;
1117 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1126 std::conditional< is_const , const ScalarType , ScalarType >::type
1129 typedef ScalarType non_const_scalar_type ;
1130 typedef const ScalarType const_scalar_type ;
1133 typedef typename std::conditional<
1135 typename array_analysis::dimension::
1136 template prepend<0>::type,
1137 typename array_analysis::dimension::
1138 template append<0>::type >::type
1145 ViewDataType< scalar_type , scalar_dimension >::type scalar_array_type ;
1148 ViewDataType< const_scalar_type , scalar_dimension >::type
1149 const_scalar_array_type ;
1152 ViewDataType< non_const_scalar_type , scalar_dimension >::type
1153 non_const_scalar_array_type ;
1162 template<
class DataType ,
class ArrayLayout ,
class ScalarType ,
unsigned DimFad >
1163 struct FadViewDataAnalysis<DataType, LayoutNatural<ArrayLayout>, ScalarType, DimFad>
1167 typedef ViewArrayAnalysis< DataType > array_analysis ;
1172 typedef void specialize ;
1174 typedef typename array_analysis::dimension dimension ;
1175 typedef typename array_analysis::value_type value_type ;
1176 typedef typename array_analysis::const_value_type const_value_type ;
1177 typedef typename array_analysis::non_const_value_type non_const_value_type ;
1181 ViewDataType< value_type , dimension >::type type ;
1183 ViewDataType< const_value_type , dimension >::type const_type ;
1185 ViewDataType< non_const_value_type , dimension >::type non_const_type ;
1188 typedef type scalar_array_type ;
1189 typedef const_type const_scalar_array_type ;
1190 typedef non_const_type non_const_scalar_array_type ;
1201 namespace Fad {
namespace Exp {
template<
typename >
class GeneralFad ; } }
1203 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1204 namespace Fad {
template<
typename >
class DFad ; }
1205 namespace Fad {
template<
typename ,
int >
class SFad ; }
1206 namespace Fad {
template<
typename ,
int >
class SLFad ; }
1209 namespace CacheFad {
template<
typename >
class DFad ; }
1210 namespace ELRFad {
template<
typename >
class DFad ; }
1211 namespace ELRCacheFad {
template<
typename >
class DFad ; }
1213 namespace CacheFad {
template<
typename ,
int >
class SFad ; }
1214 namespace ELRFad {
template<
typename ,
int >
class SFad ; }
1215 namespace ELRCacheFad {
template<
typename ,
int >
class SFad ; }
1218 namespace CacheFad {
template<
typename ,
int >
class SLFad ; }
1219 namespace ELRFad {
template<
typename ,
int >
class SLFad ; }
1220 namespace ELRCacheFad {
template<
typename ,
int >
class SLFad ; }
1226 #define KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( NS ) \
1227 template< class DataType , class ArrayLayout , typename ScalarType > \
1228 struct ViewDataAnalysis \
1231 , Sacado:: NS ::DFad< ScalarType > \
1232 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , 0 > {}; \
1234 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
1235 struct ViewDataAnalysis \
1238 , Sacado:: NS ::SFad< ScalarType , N > \
1239 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
1240 int(Sacado::StaticSize< Sacado:: NS ::SFad< ScalarType , N > >::value) \
1243 template< class DataType , class ArrayLayout , typename ScalarType , int N > \
1244 struct ViewDataAnalysis \
1247 , Sacado:: NS ::SLFad< ScalarType , N > \
1248 > : public FadViewDataAnalysis< DataType, ArrayLayout, ScalarType , \
1249 int(Sacado::StaticSize< Sacado:: NS ::SLFad< ScalarType , N > >::value) \
1252 template<
class DataType ,
class ArrayLayout ,
typename StorageType >
1253 struct ViewDataAnalysis
1256 , Sacado::Fad::Exp::GeneralFad< StorageType >
1257 > :
public FadViewDataAnalysis< DataType, ArrayLayout, typename StorageType::value_type , 0 > {};
1259 #ifndef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
1260 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( Fad )
1263 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( CacheFad )
1264 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRFad )
1265 KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD( ELRCacheFad )
1267 #undef KOKKOS_VIEW_DATA_ANALYSIS_SACADO_FAD
1277 template <
class View,
class ... ViewPack>
1278 KOKKOS_INLINE_FUNCTION
1279 unsigned dimension_scalar(
const View& v,
const ViewPack&... views) {
1280 const unsigned dim0 = dimension_scalar(v);
1281 const unsigned dim1 = dimension_scalar(views...);
1282 return dim0 >= dim1 ? dim0 : dim1 ;
1289 namespace Kokkos {
namespace Impl {
1291 template <
typename Specialize,
typename A,
typename B >
1292 struct CommonViewValueType;
1294 template <
typename A,
typename B >
1295 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFad,
A,
B >
1300 template <
typename A,
typename B >
1301 struct CommonViewValueType< Kokkos::Impl::ViewSpecializeSacadoFadContiguous,
A,
B >
1307 template <
class Specialize,
class ValueType >
1308 struct CommonViewAllocProp;
1310 template <
class ValueType >
1311 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFad, ValueType >
1313 using value_type = ValueType;
1318 KOKKOS_INLINE_FUNCTION
1319 CommonViewAllocProp()
1324 template <
class View >
1325 KOKKOS_INLINE_FUNCTION
1326 CommonViewAllocProp(
const View & view )
1327 :
fad_dim ( dimension_scalar(view) )
1333 template <
class View,
class ... Views >
1334 KOKKOS_INLINE_FUNCTION
1335 CommonViewAllocProp(
const View & view,
const Views & ... views )
1336 :
fad_dim ( dimension_scalar(view, views... ) )
1343 template <
class ValueType >
1344 struct CommonViewAllocProp< Kokkos::Impl::ViewSpecializeSacadoFadContiguous, ValueType >
1346 using value_type = ValueType;
1351 KOKKOS_INLINE_FUNCTION
1352 CommonViewAllocProp()
1357 template <
class View >
1358 KOKKOS_INLINE_FUNCTION
1359 CommonViewAllocProp(
const View & view )
1360 :
fad_dim ( dimension_scalar(view) )
1366 template <
class View,
class ... Views >
1367 KOKKOS_INLINE_FUNCTION
1368 CommonViewAllocProp(
const View & view,
const Views & ... views )
1369 :
fad_dim ( dimension_scalar(view, views... ) )
1376 template <
typename ... P >
1377 struct has_common_view_alloc_prop :
public std::false_type {};
1379 template <
class Specialize,
class ValueType >
1380 struct has_common_view_alloc_prop< CommonViewAllocProp<Specialize, ValueType> > :
public std::true_type {};
1384 template <
typename ... >
1385 struct check_has_common_view_alloc_prop;
1388 struct check_has_common_view_alloc_prop<>
1390 enum { value =
false };
1393 template <
typename P >
1394 struct check_has_common_view_alloc_prop<P>
1399 template <
typename P0,
typename ... P >
1400 struct check_has_common_view_alloc_prop<P0, P...>
1405 template <
typename ... >
1406 struct compute_fad_dim_from_alloc_prop;
1409 struct compute_fad_dim_from_alloc_prop<> {
1410 template <
typename CtorProp>
1411 KOKKOS_INLINE_FUNCTION
1412 static unsigned eval(
const CtorProp&) {
return 0; }
1415 template <
typename P >
1416 struct compute_fad_dim_from_alloc_prop<P> {
1417 template <
typename CtorProp>
1418 KOKKOS_INLINE_FUNCTION
1419 static unsigned eval(
const CtorProp&) {
return 0; }
1422 template <
typename P0,
typename ... P >
1423 struct compute_fad_dim_from_alloc_prop<P0,P...> {
1424 template <
typename CtorProp>
1425 KOKKOS_INLINE_FUNCTION
1426 static unsigned eval(
const CtorProp& prop) {
1427 unsigned d1 = compute_fad_dim_from_alloc_prop<P0>::eval(prop);
1428 unsigned d2 = compute_fad_dim_from_alloc_prop<P...>::eval(prop);
1429 return d1 > d2 ? d1 : d2;
1433 template <
class ValueType >
1434 struct compute_fad_dim_from_alloc_prop<
1435 CommonViewAllocProp<ViewSpecializeSacadoFad, ValueType>
1437 template <
typename CtorProp>
1438 KOKKOS_INLINE_FUNCTION
1439 static unsigned eval(
const CtorProp& prop) {
1440 using specialize = ViewSpecializeSacadoFad;
1441 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1442 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1443 return cast_prop.fad_dim;
1447 template <
class ValueType >
1448 struct compute_fad_dim_from_alloc_prop<
1449 CommonViewAllocProp<ViewSpecializeSacadoFadContiguous, ValueType>
1451 template <
typename CtorProp>
1452 KOKKOS_INLINE_FUNCTION
1453 static unsigned eval(
const CtorProp& prop) {
1454 using specialize = ViewSpecializeSacadoFadContiguous;
1455 using CVAP = CommonViewAllocProp< specialize, ValueType >;
1456 auto cast_prop = ((Kokkos::Impl::ViewCtorProp<void, CVAP>
const &)prop).value;
1457 return cast_prop.fad_dim;
1461 template <
typename Traits,
typename ... P >
1462 struct appendFadToLayoutViewAllocHelper
1464 using layout_type =
typename Traits::array_layout;
1465 using specialize =
typename Traits::specialize;
1466 using CtorProp = ViewCtorProp< P... >;
1468 KOKKOS_INLINE_FUNCTION
1469 static layout_type returnNewLayoutPlusFad(
const CtorProp & arg_prop,
const layout_type & arg_layout ) {
1471 layout_type appended_layout( arg_layout );
1476 compute_fad_dim_from_alloc_prop<P...>::eval(arg_prop);
1477 appended_layout.dimension[ Traits::rank ] = (fad_dim > 0) ? fad_dim : 1;
1479 return appended_layout;
1483 template <
typename Layout>
1484 struct prependFadToLayout
1486 using layout_type = Layout;
1488 template <
typename FadSizeType >
1489 KOKKOS_INLINE_FUNCTION
1490 static layout_type returnNewLayoutPlusFad(
const layout_type & arg_layout,
const FadSizeType
fad_dim ) {
1492 layout_type prepended_layout(0,0,0,0,0,0,0,0);
1494 prepended_layout.dimension[0] =
fad_dim;
1496 for (
int i = 1; i < ARRAY_LAYOUT_MAX_RANK; ++
i ) {
1497 prepended_layout.dimension[
i] = arg_layout.dimension[i-1];
1500 return prepended_layout;
1513 template<
class Traits >
1514 class ViewMapping< Traits ,
1515 typename std::enable_if<
1516 ( std::is_same< typename Traits::specialize
1517 , ViewSpecializeSacadoFad >::value
1519 ( std::is_same< typename Traits::array_layout
1520 , Kokkos::LayoutLeft >::value
1522 std::is_same< typename Traits::array_layout
1523 , Kokkos::LayoutRight >::value
1525 std::is_same< typename Traits::array_layout
1526 , Kokkos::LayoutStride >::value
1529 , typename Traits::specialize
1534 template< class ,
class ... >
friend class ViewMapping ;
1535 template< class ,
class ... >
friend class Kokkos::View ;
1537 typedef typename Traits::value_type fad_type ;
1540 std::add_const< fad_value_type >::type const_fad_value_type ;
1546 enum { FadStaticStride =
1547 std::is_same<
typename Traits::array_layout
1548 , Kokkos::LayoutRight >
::value ? 1 : 0 };
1552 typedef fad_value_type * handle_type ;
1554 typedef ViewArrayAnalysis< typename Traits::data_type > array_analysis ;
1557 typedef ViewOffset<
typename Traits::dimension
1558 ,
typename Traits::array_layout
1564 <
typename array_analysis::dimension::
1565 template append<( unsigned(FadStaticDimension) > 0 ? unsigned(FadStaticDimension) + 1 : 0 )>::type
1566 ,
typename Traits::array_layout
1568 > array_offset_type ;
1570 handle_type m_impl_handle ;
1571 offset_type m_impl_offset ;
1572 array_offset_type m_array_offset ;
1573 sacado_size_type m_fad_size ;
1574 sacado_stride_type m_fad_stride ;
1581 enum { Rank = Traits::dimension::rank };
1584 template<
typename iType >
1585 KOKKOS_INLINE_FUNCTION constexpr
size_t extent(
const iType & r )
const
1586 {
return m_impl_offset.m_dim.extent(r) ; }
1588 KOKKOS_INLINE_FUNCTION constexpr
1589 typename Traits::array_layout layout()
const
1590 {
return m_impl_offset.layout(); }
1592 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_0()
const
1593 {
return m_impl_offset.dimension_0(); }
1594 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_1()
const
1595 {
return m_impl_offset.dimension_1(); }
1596 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_2()
const
1597 {
return m_impl_offset.dimension_2(); }
1598 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_3()
const
1599 {
return m_impl_offset.dimension_3(); }
1600 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_4()
const
1601 {
return m_impl_offset.dimension_4(); }
1602 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_5()
const
1603 {
return m_impl_offset.dimension_5(); }
1604 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_6()
const
1605 {
return m_impl_offset.dimension_6(); }
1606 KOKKOS_INLINE_FUNCTION constexpr
size_t dimension_7()
const
1607 {
return m_impl_offset.dimension_7(); }
1611 using is_regular = std::false_type ;
1613 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_0()
const
1614 {
return m_impl_offset.stride_0(); }
1615 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_1()
const
1616 {
return m_impl_offset.stride_1(); }
1617 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_2()
const
1618 {
return m_impl_offset.stride_2(); }
1619 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_3()
const
1620 {
return m_impl_offset.stride_3(); }
1621 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_4()
const
1622 {
return m_impl_offset.stride_4(); }
1623 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_5()
const
1624 {
return m_impl_offset.stride_5(); }
1625 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_6()
const
1626 {
return m_impl_offset.stride_6(); }
1627 KOKKOS_INLINE_FUNCTION constexpr
size_t stride_7()
const
1628 {
return m_impl_offset.stride_7(); }
1630 template<
typename iType >
1631 KOKKOS_INLINE_FUNCTION
void stride( iType *
const s )
const
1632 { m_impl_offset.stride(s) ; }
1635 KOKKOS_FORCEINLINE_FUNCTION constexpr
unsigned dimension_scalar()
const
1636 {
return m_fad_size.
value+1; }
1639 KOKKOS_FORCEINLINE_FUNCTION constexpr
unsigned stride_scalar()
const
1640 {
return m_fad_stride.value; }
1650 typedef fad_value_type * pointer_type ;
1653 KOKKOS_INLINE_FUNCTION constexpr
size_t span()
const
1654 {
return m_array_offset.span(); }
1657 KOKKOS_INLINE_FUNCTION constexpr
bool span_is_contiguous()
const
1658 {
return m_array_offset.span_is_contiguous() ; }
1661 KOKKOS_INLINE_FUNCTION constexpr pointer_type data()
const
1662 {
return m_impl_handle ; }
1666 KOKKOS_FORCEINLINE_FUNCTION
1667 reference_type reference()
const
1668 {
return reference_type( m_impl_handle
1670 , m_fad_stride.value ); }
1672 template<
typename I0 >
1673 KOKKOS_FORCEINLINE_FUNCTION
1675 reference(
const I0 & i0 )
const
1676 {
return reference_type( m_impl_handle + m_array_offset(i0,0)
1678 , m_fad_stride.value ); }
1680 template<
typename I0 ,
typename I1 >
1681 KOKKOS_FORCEINLINE_FUNCTION
1682 reference_type reference(
const I0 & i0 ,
const I1 & i1 )
const
1683 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,0)
1685 , m_fad_stride.value ); }
1688 template<
typename I0 ,
typename I1 ,
typename I2 >
1689 KOKKOS_FORCEINLINE_FUNCTION
1690 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 )
const
1691 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,0)
1693 , m_fad_stride.value ); }
1695 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3 >
1696 KOKKOS_FORCEINLINE_FUNCTION
1697 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3 )
const
1698 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,0)
1700 , m_fad_stride.value ); }
1702 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1704 KOKKOS_FORCEINLINE_FUNCTION
1705 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1706 ,
const I4 & i4 )
const
1707 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,0)
1709 , m_fad_stride.value ); }
1711 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1712 ,
typename I4 ,
typename I5 >
1713 KOKKOS_FORCEINLINE_FUNCTION
1714 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1715 ,
const I4 & i4 ,
const I5 & i5 )
const
1716 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,0)
1718 , m_fad_stride.value ); }
1721 template<
typename I0 ,
typename I1 ,
typename I2 ,
typename I3
1722 ,
typename I4 ,
typename I5 ,
typename I6 >
1723 KOKKOS_FORCEINLINE_FUNCTION
1724 reference_type reference(
const I0 & i0 ,
const I1 & i1 ,
const I2 & i2 ,
const I3 & i3
1725 ,
const I4 & i4 ,
const I5 & i5 ,
const I6 & i6 )
const
1726 {
return reference_type( m_impl_handle + m_array_offset(i0,i1,i2,i3,i4,i5,i6,0)
1728 , m_fad_stride.value ); }
1733 KOKKOS_INLINE_FUNCTION
1734 static size_t memory_span(
typename Traits::array_layout
const & layout )
1737 for (
int i=0; i<8; ++
i)
1738 dims[i] = layout.dimension[i];
1739 if (
unsigned(FadStaticDimension) > 0)
1740 dims[unsigned(Rank)] = FadStaticDimension+1;
1742 typename Traits::array_layout alayout(
1743 dims[0], dims[1], dims[2], dims[3],
1744 dims[4], dims[5], dims[6], dims[7] );
1747 typedef std::integral_constant< unsigned , 0 > padding ;
1748 return array_offset_type( padding() , alayout ).span() *
sizeof(fad_value_type);
1753 KOKKOS_INLINE_FUNCTION ~ViewMapping() {}
1754 KOKKOS_INLINE_FUNCTION ViewMapping() : m_impl_handle(0) , m_impl_offset() , m_array_offset() , m_fad_size(0) , m_fad_stride(0) {}
1756 KOKKOS_DEFAULTED_FUNCTION ViewMapping(
const ViewMapping & ) = default ;
1757 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = (
const ViewMapping & ) = default ;
1759 KOKKOS_DEFAULTED_FUNCTION ViewMapping( ViewMapping && ) = default ;
1760 KOKKOS_DEFAULTED_FUNCTION ViewMapping & operator = ( ViewMapping && ) = default ;
1762 template<
class ... P >
1763 KOKKOS_INLINE_FUNCTION
1765 ( ViewCtorProp< P ... >
const & prop
1766 ,
typename Traits::array_layout
const & local_layout
1768 : m_impl_handle( ( (ViewCtorProp<
void,pointer_type> const &) prop ).value )
1769 , m_impl_offset( std::integral_constant< unsigned , 0 >()
1771 , m_array_offset( std::integral_constant< unsigned , 0 >()
1775 ( Rank == 0 ? m_array_offset.dimension_0() :
1776 ( Rank == 1 ? m_array_offset.dimension_1() :
1777 ( Rank == 2 ? m_array_offset.dimension_2() :
1778 ( Rank == 3 ? m_array_offset.dimension_3() :
1779 ( Rank == 4 ? m_array_offset.dimension_4() :
1780 ( Rank == 5 ? m_array_offset.dimension_5() :
1781 ( Rank == 6 ? m_array_offset.dimension_6() :
1782 m_array_offset.dimension_7() ))))))) - 1 )
1784 ( Rank == 0 ? m_array_offset.stride_0() :
1785 ( Rank == 1 ? m_array_offset.stride_1() :
1786 ( Rank == 2 ? m_array_offset.stride_2() :
1787 ( Rank == 3 ? m_array_offset.stride_3() :
1788 ( Rank == 4 ? m_array_offset.stride_4() :
1789 ( Rank == 5 ? m_array_offset.stride_5() :
1790 ( Rank == 6 ? m_array_offset.stride_6() :
1791 m_array_offset.stride_7() ))))))))
1795 ( Rank == 0 ? m_array_offset.dimension_0() :
1796 ( Rank == 1 ? m_array_offset.dimension_1() :
1797 ( Rank == 2 ? m_array_offset.dimension_2() :
1798 ( Rank == 3 ? m_array_offset.dimension_3() :
1799 ( Rank == 4 ? m_array_offset.dimension_4() :
1800 ( Rank == 5 ? m_array_offset.dimension_5() :
1801 ( Rank == 6 ? m_array_offset.dimension_6() :
1802 m_array_offset.dimension_7() )))))));
1803 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1804 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1812 template<
class ... P >
1813 SharedAllocationRecord<> *
1814 allocate_shared( ViewCtorProp< P... >
const & prop
1815 ,
typename Traits::array_layout
const & local_layout
1816 ,
bool execution_space_specified)
1818 typedef ViewCtorProp< P... > ctor_prop ;
1820 typedef typename ctor_prop::execution_space execution_space ;
1821 typedef typename Traits::memory_space memory_space ;
1822 typedef ViewValueFunctor< execution_space , fad_value_type > functor_type ;
1823 typedef SharedAllocationRecord< memory_space , functor_type > record_type ;
1826 typedef std::integral_constant< unsigned , 0 > padding ;
1829 enum { test_traits_check = Kokkos::Impl::check_has_common_view_alloc_prop< P... >
::value };
1831 m_impl_offset = offset_type( padding(), local_layout );
1833 typename Traits::array_layout internal_layout =
1834 (test_traits_check ==
true)
1835 ? Kokkos::Impl::appendFadToLayoutViewAllocHelper< Traits, P... >::returnNewLayoutPlusFad(prop, local_layout)
1838 m_array_offset = array_offset_type( padding(), internal_layout );
1840 const unsigned fad_dim =
1841 ( Rank == 0 ? m_array_offset.dimension_0() :
1842 ( Rank == 1 ? m_array_offset.dimension_1() :
1843 ( Rank == 2 ? m_array_offset.dimension_2() :
1844 ( Rank == 3 ? m_array_offset.dimension_3() :
1845 ( Rank == 4 ? m_array_offset.dimension_4() :
1846 ( Rank == 5 ? m_array_offset.dimension_5() :
1847 ( Rank == 6 ? m_array_offset.dimension_6() :
1848 m_array_offset.dimension_7() )))))));
1849 if (
unsigned(FadStaticDimension) == 0 && fad_dim == 0)
1850 Kokkos::abort(
"invalid fad dimension (0) supplied!");
1851 m_fad_size = fad_dim - 1 ;
1854 ( Rank == 0 ? m_array_offset.stride_0() :
1855 ( Rank == 1 ? m_array_offset.stride_1() :
1856 ( Rank == 2 ? m_array_offset.stride_2() :
1857 ( Rank == 3 ? m_array_offset.stride_3() :
1858 ( Rank == 4 ? m_array_offset.stride_4() :
1859 ( Rank == 5 ? m_array_offset.stride_5() :
1860 ( Rank == 6 ? m_array_offset.stride_6() :
1861 m_array_offset.stride_7() )))))));
1863 const size_t alloc_size = m_array_offset.span() *
sizeof(fad_value_type);
1866 record_type *
const record =
1867 record_type::allocate( ( (ViewCtorProp<void,memory_space>
const &) prop ).value
1868 , ( (ViewCtorProp<void,std::string>
const &) prop ).value
1875 m_impl_handle = handle_type( reinterpret_cast< pointer_type >( record->data() ) );
1877 if ( ctor_prop::initialize ) {
1878 auto space = ((ViewCtorProp<void,execution_space>
const &) prop).value;
1881 if (execution_space_specified)
1882 record->m_destroy = functor_type( space
1883 , (fad_value_type *) m_impl_handle
1884 , m_array_offset.span()
1885 , record->get_label()
1888 record->m_destroy = functor_type((fad_value_type *) m_impl_handle
1889 , m_array_offset.span()
1890 , record->get_label()
1894 record->m_destroy.construct_shared_allocation();
1916 template<
class DstTraits ,
class SrcTraits >
1917 class ViewMapping< DstTraits , SrcTraits ,
1918 typename std::enable_if<(
1919 Kokkos::Impl::MemorySpaceAccess
1920 < typename DstTraits::memory_space
1921 , typename SrcTraits::memory_space >::assignable
1924 std::is_same< typename DstTraits::specialize
1925 , ViewSpecializeSacadoFad >::value
1928 std::is_same< typename SrcTraits::specialize
1929 , ViewSpecializeSacadoFad >::value
1932 , typename DstTraits::specialize
1937 enum { is_assignable =
true };
1938 enum { is_assignable_data_type =
true };
1940 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
1941 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
1942 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
1944 template<
class DstType >
1945 KOKKOS_INLINE_FUNCTION
static
1946 void assign( DstType & dst
1947 ,
const SrcFadType & src
1948 ,
const TrackType & )
1952 std::is_same<
typename DstTraits::array_layout
1953 , Kokkos::LayoutLeft >::value ||
1954 std::is_same<
typename DstTraits::array_layout
1955 , Kokkos::LayoutRight >::value ||
1956 std::is_same<
typename DstTraits::array_layout
1957 , Kokkos::LayoutStride >::value
1961 std::is_same<
typename SrcTraits::array_layout
1962 , Kokkos::LayoutLeft >::value ||
1963 std::is_same<
typename SrcTraits::array_layout
1964 , Kokkos::LayoutRight >::value ||
1965 std::is_same<
typename SrcTraits::array_layout
1966 , Kokkos::LayoutStride >::value
1968 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
1971 std::is_same<
typename DstTraits::array_layout
1972 ,
typename SrcTraits::array_layout >::value ||
1973 std::is_same<
typename DstTraits::array_layout
1974 , Kokkos::LayoutStride >::value ,
1975 "View assignment must have compatible layout" );
1978 std::is_same<
typename DstTraits::value_type
1979 ,
typename SrcTraits::value_type >::value ||
1980 std::is_same<
typename DstTraits::value_type
1981 ,
typename SrcTraits::const_value_type >::value ,
1982 "View assignment must have same value type or const = non-const" );
1985 ViewDimensionAssignable
1986 <
typename DstType::offset_type::dimension_type
1987 ,
typename SrcFadType::offset_type::dimension_type >::value ,
1988 "View assignment must have compatible dimensions" );
1991 ViewDimensionAssignable
1992 <
typename DstType::array_offset_type::dimension_type
1993 ,
typename SrcFadType::array_offset_type::dimension_type >::value ,
1994 "View assignment must have compatible dimensions" );
1996 typedef typename DstType::offset_type dst_offset_type ;
1997 typedef typename DstType::array_offset_type dst_array_offset_type ;
1999 dst.m_impl_handle = src.m_impl_handle ;
2000 dst.m_impl_offset = dst_offset_type( src.m_impl_offset );
2001 dst.m_array_offset = dst_array_offset_type( src.m_array_offset );
2002 dst.m_fad_size = src.m_fad_size.value ;
2003 dst.m_fad_stride = src.m_fad_stride.value ;
2013 template<
class DstTraits ,
class SrcTraits >
2014 class ViewMapping< DstTraits , SrcTraits ,
2015 typename std::enable_if<(
2016 Kokkos::Impl::MemorySpaceAccess
2017 < typename DstTraits::memory_space
2018 , typename SrcTraits::memory_space >::assignable
2021 std::is_same< typename DstTraits::specialize , void >::value
2024 std::is_same< typename SrcTraits::specialize
2025 , ViewSpecializeSacadoFad >::value
2027 , typename DstTraits::specialize
2032 enum { is_assignable =
true };
2033 enum { is_assignable_data_type =
true };
2036 typedef Kokkos::Impl::SharedAllocationTracker TrackType ;
2037 typedef ViewMapping< DstTraits , typename DstTraits::specialize > DstType ;
2038 typedef ViewMapping< SrcTraits , typename SrcTraits::specialize > SrcFadType ;
2043 template <
class DstType,
class SrcFadType,
class Truth =
void >
2044 struct AssignOffset;
2046 template <
class DstType,
class SrcFadType >
2047 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank != (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
2050 KOKKOS_INLINE_FUNCTION
2051 static void assign( DstType & dst,
const SrcFadType & src )
2053 typedef typename SrcTraits::value_type TraitsValueType;
2059 typedef typename DstType::offset_type::array_layout DstLayoutType;
2061 typedef typename SrcFadType::array_offset_type::dimension_type SrcViewDimension;
2066 static constexpr
bool is_layout_left =
2069 typedef typename std::conditional< is_layout_left,
2070 typename SrcViewDimension:: template prepend< InnerStaticDim+1 >::type,
2071 typename SrcViewDimension:: template append < InnerStaticDim+1 >::type
2072 >::type SrcViewDimensionAppended;
2074 typedef std::integral_constant< unsigned , 0 > padding ;
2076 typedef ViewOffset< SrcViewDimensionAppended, DstLayoutType > TmpOffsetType;
2078 auto src_layout = src.m_array_offset.layout();
2080 if ( is_layout_left ) {
2081 auto prepend_layout = Kokkos::Impl::prependFadToLayout< DstLayoutType >::returnNewLayoutPlusFad(src_layout, InnerStaticDim+1);
2082 TmpOffsetType offset_tmp( padding(), prepend_layout );
2083 dst.m_impl_offset = offset_tmp;
2086 TmpOffsetType offset_tmp( padding(), src_layout );
2087 dst.m_impl_offset = offset_tmp;
2091 Kokkos::abort(
"Sacado error: Applying AssignOffset for case with nested Fads, but without nested Fads - something went wrong");
2096 template <
class DstType,
class SrcFadType >
2097 struct AssignOffset< DstType, SrcFadType, typename std::enable_if< ((int)DstType::offset_type::dimension_type::rank == (int)SrcFadType::array_offset_type::dimension_type::rank) >::type >
2099 KOKKOS_INLINE_FUNCTION
2100 static void assign( DstType & dst,
const SrcFadType & src )
2103 typedef typename DstType::offset_type dst_offset_type ;
2104 dst.m_impl_offset = dst_offset_type( src.m_array_offset );
2116 template <
class DstType >
2117 KOKKOS_INLINE_FUNCTION
static
2119 assign( DstType & dst
2120 ,
const SrcFadType & src
2127 std::is_same<
typename DstTraits::array_layout
2128 , Kokkos::LayoutLeft >::value ||
2129 std::is_same<
typename DstTraits::array_layout
2130 , Kokkos::LayoutRight >::value ||
2131 std::is_same<
typename DstTraits::array_layout
2132 , Kokkos::LayoutStride >::value
2136 std::is_same<
typename SrcTraits::array_layout
2137 , Kokkos::LayoutLeft >::value ||
2138 std::is_same<
typename SrcTraits::array_layout
2139 , Kokkos::LayoutRight >::value ||
2140 std::is_same<
typename SrcTraits::array_layout
2141 , Kokkos::LayoutStride >::value
2143 ,
"View of FAD requires LayoutLeft, LayoutRight, or LayoutStride" );
2146 std::is_same<
typename DstTraits::array_layout
2147 ,
typename SrcTraits::array_layout >::value ||
2148 std::is_same<
typename DstTraits::array_layout
2149 , Kokkos::LayoutStride >::value ,
2150 "View assignment must have compatible layout" );
2153 std::is_same<
typename DstTraits::scalar_array_type
2154 ,
typename SrcTraits::scalar_array_type >::value ||
2155 std::is_same<
typename DstTraits::scalar_array_type
2156 ,
typename SrcTraits::const_scalar_array_type >::value ,
2157 "View assignment must have same value type or const = non-const" );
2160 AssignOffset< DstType, SrcFadType >::assign( dst, src );
2162 dst.m_impl_handle =
reinterpret_cast< typename DstType::handle_type
>(src.m_impl_handle) ;
2176 template<
class SrcTraits ,
class ... Args >
2178 < typename std::enable_if<(
2180 std::is_same< typename SrcTraits::specialize
2181 , ViewSpecializeSacadoFad >::value
2184 std::is_same< typename SrcTraits::array_layout
2185 , Kokkos::LayoutLeft >::value ||
2186 std::is_same< typename SrcTraits::array_layout
2187 , Kokkos::LayoutRight >::value ||
2188 std::is_same< typename SrcTraits::array_layout
2189 , Kokkos::LayoutStride >::value
2198 static_assert( SrcTraits::rank ==
sizeof...(Args) ,
"" );
2212 enum { rank = unsigned(R0) + unsigned(R1) + unsigned(R2) + unsigned(R3)
2213 + unsigned(R4) + unsigned(R5) + unsigned(R6) };
2216 enum { R0_rev = ( 0 == SrcTraits::rank ? RZ : (
2217 1 == SrcTraits::rank ? R0 : (
2218 2 == SrcTraits::rank ? R1 : (
2219 3 == SrcTraits::rank ? R2 : (
2220 4 == SrcTraits::rank ? R3 : (
2221 5 == SrcTraits::rank ? R4 : (
2222 6 == SrcTraits::rank ? R5 : R6 ))))))) };
2229 typedef typename std::conditional<
2233 ( std::is_same<
typename SrcTraits::array_layout
2234 , Kokkos::LayoutRight >::value
2236 ( rank == 1 ) && R0_rev
2239 ( std::is_same<
typename SrcTraits::array_layout
2240 , Kokkos::LayoutLeft >::value
2242 ( rank == 1 ) && (SrcTraits::rank == 1) && R0
2244 ),
typename SrcTraits::array_layout , Kokkos::LayoutStride
2245 >::type array_layout ;
2247 typedef typename SrcTraits::value_type fad_type ;
2249 typedef typename std::conditional< rank == 0 , fad_type ,
2250 typename std::conditional< rank == 1 , fad_type * ,
2251 typename std::conditional< rank == 2 , fad_type ** ,
2252 typename std::conditional< rank == 3 , fad_type *** ,
2253 typename std::conditional< rank == 4 , fad_type **** ,
2254 typename std::conditional< rank == 5 , fad_type ***** ,
2255 typename std::conditional< rank == 6 , fad_type ****** ,
2257 >::type >::type >::type >::type >::type >::type >::type
2262 typedef Kokkos::ViewTraits
2265 ,
typename SrcTraits::device_type
2266 ,
typename SrcTraits::memory_traits > traits_type ;
2268 typedef Kokkos::View
2271 ,
typename SrcTraits::device_type
2272 ,
typename SrcTraits::memory_traits > type ;
2275 KOKKOS_INLINE_FUNCTION
2276 static void assign( ViewMapping< traits_type , typename traits_type::specialize > & dst
2277 , ViewMapping< SrcTraits ,typename SrcTraits::specialize >
const & src
2280 typedef ViewMapping< traits_type , typename traits_type::specialize > DstType ;
2281 typedef typename DstType::offset_type dst_offset_type ;
2282 typedef typename DstType::array_offset_type dst_array_offset_type ;
2283 typedef typename DstType::handle_type dst_handle_type ;
2285 const SubviewExtents< SrcTraits::rank , rank >
2286 extents( src.m_impl_offset.m_dim , args... );
2287 const SubviewExtents< SrcTraits::rank + 1 , rank + 1 >
2288 array_extents( src.m_array_offset.m_dim , args... , Kokkos::ALL() );
2290 dst.m_impl_offset = dst_offset_type( src.m_impl_offset , extents );
2291 dst.m_array_offset = dst_array_offset_type( src.m_array_offset , array_extents );
2293 dst_handle_type( src.m_impl_handle +
2294 src.m_array_offset( array_extents.domain_offset(0)
2295 , array_extents.domain_offset(1)
2296 , array_extents.domain_offset(2)
2297 , array_extents.domain_offset(3)
2298 , array_extents.domain_offset(4)
2299 , array_extents.domain_offset(5)
2300 , array_extents.domain_offset(6)
2301 , array_extents.domain_offset(7) ) );
2302 dst.m_fad_size = src.m_fad_size;
2303 dst.m_fad_stride = src.m_fad_stride.value;
2314 #if defined(HAVE_SACADO_KOKKOS) && \
2315 defined(HAVE_SACADO_TEUCHOSKOKKOSCOMM) && \
2316 defined(HAVE_SACADO_VIEW_SPEC) && \
2317 ! defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2319 #include "Kokkos_TeuchosCommAdapters.hpp"
2323 template<
typename Ordinal ,
class SD ,
class ... SP ,
class RD ,
class ... RP >
2324 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
2325 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
2328 (
const Comm<Ordinal>& comm,
2329 const EReductionType reductType ,
2331 const Kokkos::View<SD,SP...> & sendBuffer ,
2332 const Kokkos::View<RD,RP...> & recvBuffer )
2339 typedef Kokkos::View<SD,SP...> SendViewType;
2340 typedef Kokkos::View<RD,RP...> RecvViewType;
2341 typedef typename SendViewType::value_type send_value_type;
2342 typedef typename RecvViewType::value_type recv_value_type;
2345 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
2346 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
2347 "The send View's rank is " << SendViewType::rank <<
" and the receive "
2348 "View's rank is " << RecvViewType::rank <<
".");
2352 typename SendViewType::HostMirror hostSendBuffer =
2353 Kokkos::create_mirror_view(sendBuffer);
2354 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2356 localSendBuffer[i] = hostSendBuffer(i);
2361 typename RecvViewType::HostMirror hostRecvBuffer =
2362 Kokkos::create_mirror_view(recvBuffer);
2363 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2365 localRecvBuffer[i] = hostRecvBuffer(i);
2368 reduceAll(comm, reductType, count,
2369 localSendBuffer.getRawPtr(),
2370 localRecvBuffer.getRawPtr());
2374 hostRecvBuffer(i) = localRecvBuffer[
i];
2375 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2379 template<
typename Ordinal ,
typename Serializer ,
2380 class SD ,
class ... SP ,
class RD ,
class ... RP >
2381 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<SD,SP...> >::value &&
2382 Kokkos::is_view_fad< Kokkos::View<RD,RP...> >::value
2385 (
const Comm<Ordinal>& comm,
2386 const Serializer& serializer,
2387 const EReductionType reductType ,
2389 const Kokkos::View<SD,SP...> & sendBuffer ,
2390 const Kokkos::View<RD,RP...> & recvBuffer )
2397 typedef Kokkos::View<SD,SP...> SendViewType;
2398 typedef Kokkos::View<RD,RP...> RecvViewType;
2399 typedef typename SendViewType::value_type send_value_type;
2400 typedef typename RecvViewType::value_type recv_value_type;
2403 SendViewType::rank > 1 || RecvViewType::rank > 1, std::invalid_argument,
2404 "Teuchos::reduceAll: Both send and receive Views must have rank 1. "
2405 "The send View's rank is " << SendViewType::rank <<
" and the receive " "View's rank is " << RecvViewType::rank <<
".");
2409 typename SendViewType::HostMirror hostSendBuffer =
2410 Kokkos::create_mirror_view(sendBuffer);
2411 Kokkos::deep_copy(hostSendBuffer, sendBuffer);
2413 localSendBuffer[i] = hostSendBuffer(i);
2418 typename RecvViewType::HostMirror hostRecvBuffer =
2419 Kokkos::create_mirror_view(recvBuffer);
2420 Kokkos::deep_copy(hostRecvBuffer, recvBuffer);
2422 localRecvBuffer[i] = hostRecvBuffer(i);
2425 reduceAll(comm, serializer, reductType, count,
2426 localSendBuffer.getRawPtr(),
2427 localRecvBuffer.getRawPtr());
2431 hostRecvBuffer(i) = localRecvBuffer[
i];
2432 Kokkos::deep_copy(recvBuffer, hostRecvBuffer);
2436 template<
typename Ordinal,
class D,
class ... P >
2437 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2439 (
const Comm<Ordinal>& comm,
2440 const int rootRank ,
2442 const Kokkos::View<D,P...>& buffer)
2444 typedef Kokkos::View<
D,P...> view_type;
2445 typename view_type::array_type array_buffer = buffer;
2446 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2447 broadcast( comm, rootRank, array_count, array_buffer );
2451 typename Serializer ,
2452 class D,
class ... P >
2453 typename std::enable_if<Kokkos::is_view_fad< Kokkos::View<
D,P...> >::value>::type
2455 (
const Comm<Ordinal>& comm,
2456 const Serializer& serializer,
2457 const int rootRank ,
2459 const Kokkos::View<D,P...>& buffer)
2461 typedef Kokkos::View<
D,P...> view_type;
2462 typename view_type::array_type array_buffer = buffer;
2463 Ordinal array_count = count * Kokkos::dimension_scalar(buffer);
2464 broadcast( comm, *(serializer.getValueSerializer()), rootRank,
2465 array_count, array_buffer );
2474 #endif // defined(HAVE_SACADO_VIEW_SPEC) && !defined(SACADO_DISABLE_FAD_VIEW_SPEC)
2476 #endif // defined(HAVE_SACADO_KOKKOS)
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.