Skip to content

Commit

Permalink
sacado,stokhos: update create_mirror overloads
Browse files Browse the repository at this point in the history
* Move sfinae logic from final function argument to return type
* Add overloads taking WithoutInitialization argument, by @etphipp
  • Loading branch information
ndellingwood committed Feb 4, 2022
1 parent a94ef56 commit 05d2d86
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 154 deletions.
141 changes: 109 additions & 32 deletions packages/sacado/src/KokkosExp_View_Fad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,18 +416,15 @@ void deep_copy( const View<DT,DP...> & dst ,

template< class T , class ... P >
inline
typename Kokkos::View<T,P...>::HostMirror
create_mirror( const Kokkos::View<T,P...> & src
, typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
&&
! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
, Kokkos::LayoutStride >::value
>::type *
)
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
!std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typedef typename src_type::HostMirror dst_type ;
Expand All @@ -440,18 +437,15 @@ create_mirror( const Kokkos::View<T,P...> & src

template< class T , class ... P >
inline
typename Kokkos::View<T,P...>::HostMirror
create_mirror( const Kokkos::View<T,P...> & src
, typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
&&
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
, Kokkos::LayoutStride >::value
>::type *
)
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typedef typename src_type::array_type src_array_type ;
Expand Down Expand Up @@ -483,20 +477,103 @@ create_mirror( const Kokkos::View<T,P...> & src
}

template<class Space, class T, class ... P>
typename Impl::MirrorType<Space,T,P ...>::view_type
create_mirror(const Space& , const Kokkos::View<T,P...> & src
, typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value )
>::type *) {
typename std::enable_if<
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value,
typename Impl::MirrorType<Space,T,P ...>::view_type>::type
create_mirror(const Space& , const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typename src_type::array_layout layout = src.layout();
layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
return typename Impl::MirrorType<Space,T,P ...>::view_type(src.label(),layout);
}

template< class T , class ... P >
inline
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
!std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typedef typename src_type::HostMirror dst_type ;

typename src_type::array_layout layout = src.layout();
layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);

return dst_type(
Kokkos::view_alloc(std::string(src.label()).append("_mirror"), wi), layout);
}

template< class T , class ... P >
inline
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typedef typename src_type::array_type src_array_type ;
typedef typename src_type::HostMirror dst_type ;

Kokkos::LayoutStride layout ;

// Use dimensions/strides from array_type to get hidden dim/stride
src_array_type src_array = src;
layout.dimension[0] = src_array.extent(0);
layout.dimension[1] = src_array.extent(1);
layout.dimension[2] = src_array.extent(2);
layout.dimension[3] = src_array.extent(3);
layout.dimension[4] = src_array.extent(4);
layout.dimension[5] = src_array.extent(5);
layout.dimension[6] = src_array.extent(6);
layout.dimension[7] = src_array.extent(7);

layout.stride[0] = src_array.stride_0();
layout.stride[1] = src_array.stride_1();
layout.stride[2] = src_array.stride_2();
layout.stride[3] = src_array.stride_3();
layout.stride[4] = src_array.stride_4();
layout.stride[5] = src_array.stride_5();
layout.stride[6] = src_array.stride_6();
layout.stride[7] = src_array.stride_7();

return dst_type(
Kokkos::view_alloc(std::string(src.label()).append("_mirror"), wi), layout);
}

template<class Space, class T, class ... P, typename Enable>
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ),
typename Impl::MirrorType<Space,T,P ...>::view_type>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Space& , const Kokkos::View<T,P...> & src)
{
typedef View<T,P...> src_type ;
typename src_type::array_layout layout = src.layout();
layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src);
return typename Impl::MirrorType<Space,T,P ...>::view_type(
Kokkos::view_alloc(src.label(), wi), layout);
}

} // namespace Kokkos

//----------------------------------------------------------------------------
Expand Down
84 changes: 58 additions & 26 deletions packages/sacado/src/Kokkos_View_Fad_Fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,41 +80,73 @@ struct MirrorType;

template< class T , class ... P >
inline
typename Kokkos::View<T,P...>::HostMirror
create_mirror(
const Kokkos::View<T,P...> & src,
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
!std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value >::type * = 0);

Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(const Kokkos::View<T,P...> & src);

template< class T , class ... P >
inline
typename Kokkos::View<T,P...>::HostMirror
create_mirror(
const Kokkos::View<T,P...> & src,
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value >::type * = 0);
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(const Kokkos::View<T,P...> & src);

template<class Space, class T, class ... P>
typename Impl::MirrorType<Space,T,P ...>::view_type
create_mirror(
const Space&,
const Kokkos::View<T,P...> & src,
typename std::enable_if<
std::is_same< typename ViewTraits<T,P...>::specialize ,
typename std::enable_if<
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value,
typename Impl::MirrorType<Space,T,P ...>::view_type>::type
create_mirror(const Space&, const Kokkos::View<T,P...> & src);

template< class T , class ... P >
inline
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value >::type * = 0);
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
!std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Kokkos::View<T,P...> & src);

template< class T , class ... P >
inline
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ) &&
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value,
typename Kokkos::View<T,P...>::HostMirror>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Kokkos::View<T,P...> & src);

template<class Space, class T, class ... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
typename std::enable_if<
( std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFad >::value ||
std::is_same< typename ViewTraits<T,P...>::specialize ,
Kokkos::Impl::ViewSpecializeSacadoFadContiguous >::value ),
typename Impl::MirrorType<Space,T,P ...>::view_type>::type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
const Space&, const Kokkos::View<T,P...> & src);

} // namespace Kokkos

Expand Down
Loading

0 comments on commit 05d2d86

Please sign in to comment.