Skip to content

Commit

Permalink
Sacado/Stokhos: Update create_mirror() overloads for specialized types
Browse files Browse the repository at this point in the history
I don't think these changes are strictly necessary with the updates in
Kokkos, but they keep the function prototypes in-sync with Kokkos.
  • Loading branch information
etphipp committed Jan 22, 2022
1 parent f916330 commit ca382db
Show file tree
Hide file tree
Showing 3 changed files with 469 additions and 160 deletions.
225 changes: 165 additions & 60 deletions packages/sacado/src/KokkosExp_View_Fad.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,41 +147,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 ) &&
!std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout,
Kokkos::LayoutStride >::value >::type * = 0);
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);


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 * = 0);
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);

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(const Space&, 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<
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 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 >::type * = 0);
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 Expand Up @@ -483,18 +515,14 @@ 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 @@ -507,18 +535,14 @@ 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 @@ -549,21 +573,102 @@ create_mirror( const Kokkos::View<T,P...> & src
return dst_type(std::string(src.label()).append("_mirror"), layout);
}

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 *) {
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(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
Loading

0 comments on commit ca382db

Please sign in to comment.