diff --git a/packages/stokhos/src/sacado/kokkos/vector/KokkosExp_View_MP_Vector_Contiguous.hpp b/packages/stokhos/src/sacado/kokkos/vector/KokkosExp_View_MP_Vector_Contiguous.hpp index 6e949e3808fa..552c84ec1649 100644 --- a/packages/stokhos/src/sacado/kokkos/vector/KokkosExp_View_MP_Vector_Contiguous.hpp +++ b/packages/stokhos/src/sacado/kokkos/vector/KokkosExp_View_MP_Vector_Contiguous.hpp @@ -92,150 +92,106 @@ struct FlatArrayType< View, typedef View type; }; -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - !std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(const Kokkos::View & src) +template +inline auto create_mirror( + const Impl::ViewCtorProp& arg_prop, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) { - typedef View src_type ; - typedef typename src_type::HostMirror dst_type ; + static_assert(std::is_same_v::array_layout, LayoutLeft> || + std::is_same_v::array_layout, LayoutRight> || + std::is_same_v::array_layout, LayoutStride>); - typename src_type::array_layout layout = src.layout(); - layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src); + using src_type = View; - return dst_type(std::string(src.label()).append("_mirror"), layout); -} + auto layout = [&] () { + if constexpr ( ! std::is_same_v::array_layout, LayoutStride>) { + return src.layout(); + } else { + LayoutStride layout; -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(const Kokkos::View & src) -{ - typedef View src_type ; - typedef typename src_type::HostMirror dst_type ; - - Kokkos::LayoutStride layout ; - - layout.dimension[0] = src.extent(0); - layout.dimension[1] = src.extent(1); - layout.dimension[2] = src.extent(2); - layout.dimension[3] = src.extent(3); - layout.dimension[4] = src.extent(4); - layout.dimension[5] = src.extent(5); - layout.dimension[6] = src.extent(6); - layout.dimension[7] = src.extent(7); - - layout.stride[0] = src.stride_0(); - layout.stride[1] = src.stride_1(); - layout.stride[2] = src.stride_2(); - layout.stride[3] = src.stride_3(); - layout.stride[4] = src.stride_4(); - layout.stride[5] = src.stride_5(); - layout.stride[6] = src.stride_6(); - layout.stride[7] = src.stride_7(); + for (int idx = 0; idx <= 7; ++idx) { + layout.dimension[idx] = src.extent(idx); + layout.stride [idx] = src.stride(idx); + } - layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src); + return layout; + } + }(); + + layout.dimension[src_type::rank] = dimension_scalar(src); + + const auto prop_copy = Impl::with_properties_if_unset( + arg_prop, std::string(src.label()).append("_mirror")); - return dst_type(std::string(src.label()).append("_mirror"), layout); + if constexpr (Impl::ViewCtorProp::has_memory_space){ + return typename Impl::MirrorType::memory_space, T, P ...>::view_type(prop_copy, layout); + } else { + return typename View::HostMirror(prop_copy, layout); + } } -template -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value, - typename Impl::MirrorType::view_type>::type -create_mirror(const Space& , const Kokkos::View & src) +template +inline auto create_mirror( + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) { - typedef View src_type ; - typename src_type::array_layout layout = src.layout(); - layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src); - return typename Impl::MirrorType::view_type(src.label(),layout); + return create_mirror(view_alloc(), src); } -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - !std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - const Kokkos::View & src) +template +inline auto create_mirror( + const Space& space, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) { - typedef View 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); + return create_mirror(view_alloc(space), src); } -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - const Kokkos::View & src) +template +inline auto create_mirror( + Impl::WithoutInitializing_t wi, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) { - typedef View src_type ; - typedef typename src_type::HostMirror dst_type ; - - Kokkos::LayoutStride layout ; - - layout.dimension[0] = src.extent(0); - layout.dimension[1] = src.extent(1); - layout.dimension[2] = src.extent(2); - layout.dimension[3] = src.extent(3); - layout.dimension[4] = src.extent(4); - layout.dimension[5] = src.extent(5); - layout.dimension[6] = src.extent(6); - layout.dimension[7] = src.extent(7); - - layout.stride[0] = src.stride_0(); - layout.stride[1] = src.stride_1(); - layout.stride[2] = src.stride_2(); - layout.stride[3] = src.stride_3(); - layout.stride[4] = src.stride_4(); - layout.stride[5] = src.stride_5(); - layout.stride[6] = src.stride_6(); - layout.stride[7] = src.stride_7(); - - layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src); + return create_mirror(view_alloc(wi), src); +} - return dst_type( - Kokkos::view_alloc(std::string(src.label()).append("_mirror"), wi), layout); +template +inline auto create_mirror( + Impl::WithoutInitializing_t wi, + const Space& space, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) +{ + return create_mirror(view_alloc(wi, space), src); } -template -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value, - typename Impl::MirrorType::view_type>::type -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - const Space&, const Kokkos::View & src) +template +inline auto create_mirror_view( + const Impl::ViewCtorProp& arg_prop, + const Kokkos::View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* +) { - typedef View src_type ; - typename src_type::array_layout layout = src.layout(); - layout.dimension[src_type::rank] = Kokkos::dimension_scalar(src); - return typename Impl::MirrorType::view_type( - Kokkos::view_alloc(src.label(), wi), layout); + return Impl::create_mirror_view(src, arg_prop); } template diff --git a/packages/stokhos/src/sacado/kokkos/vector/Kokkos_View_MP_Vector_Fwd.hpp b/packages/stokhos/src/sacado/kokkos/vector/Kokkos_View_MP_Vector_Fwd.hpp index 2071f7ef9a8e..f6a465e2b42d 100644 --- a/packages/stokhos/src/sacado/kokkos/vector/Kokkos_View_MP_Vector_Fwd.hpp +++ b/packages/stokhos/src/sacado/kokkos/vector/Kokkos_View_MP_Vector_Fwd.hpp @@ -60,67 +60,59 @@ namespace Kokkos { // Declare overloads of create_mirror() so they are in scope // Kokkos_Core.hpp is included below -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - !std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(const Kokkos::View & src); - -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(const Kokkos::View & src); - -template::value>> -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value, - typename Impl::MirrorType::view_type>::type -create_mirror(const Space&, - const Kokkos::View & src); - -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - !std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - const Kokkos::View & src); - -template< class T , class ... P > -inline -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value && - std::is_same< typename Kokkos::ViewTraits::array_layout, - Kokkos::LayoutStride >::value, - typename Kokkos::View::HostMirror>::type -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - const Kokkos::View & src); - -template::value>> -typename std::enable_if< - std::is_same< typename ViewTraits::specialize , - Kokkos::Experimental::Impl::ViewMPVectorContiguous >::value, - typename Impl::MirrorType::view_type>::type - create_mirror( - Kokkos::Impl::WithoutInitializing_t wi, - const Space&, - const Kokkos::View & src); +template +inline auto create_mirror( + const Impl::ViewCtorProp& arg_prop, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); + +template +inline auto create_mirror( + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); + +template ::value>> +inline auto create_mirror( + const Space& space, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); + +template +inline auto create_mirror( + Impl::WithoutInitializing_t wi, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); + +template ::value>> +inline auto create_mirror( + Impl::WithoutInitializing_t wi, + const Space& space, + const View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); + +template +inline auto create_mirror_view( + const Impl::ViewCtorProp& arg_prop, + const Kokkos::View& src, + typename std::enable_if_t< + std::is_same_v::specialize, + Experimental::Impl::ViewMPVectorContiguous>>* = nullptr +); template typename Impl::MirrorViewType::view_type