diff --git a/containers/src/Kokkos_DynRankView.hpp b/containers/src/Kokkos_DynRankView.hpp index 9eb6ea4018d..14894040e10 100644 --- a/containers/src/Kokkos_DynRankView.hpp +++ b/containers/src/Kokkos_DynRankView.hpp @@ -1956,7 +1956,9 @@ void check_view_ctor_args_create_mirror_drv() { // create a mirror // private interface that accepts arbitrary view constructor args passed by a // view_alloc -template +template ::specialize>::value>> inline auto create_mirror( const DynRankView& src, const Impl::ViewCtorProp& arg_prop) { @@ -1984,48 +1986,30 @@ inline auto create_mirror( // Create a mirror in host space template -inline typename DynRankView::HostMirror create_mirror( - const DynRankView& src, - std::enable_if_t::specialize, - void>::value>* = nullptr) { - return Impl::create_mirror(src, Kokkos::Impl::ViewCtorProp<>{}); +inline auto create_mirror( + const DynRankView& src) { + return Impl::create_mirror(src, Kokkos::view_alloc()); } template -inline typename DynRankView::HostMirror create_mirror( - Kokkos::Impl::WithoutInitializing_t wi, const DynRankView& src, - std::enable_if_t::specialize, - void>::value>* = nullptr) { +inline auto create_mirror( + Kokkos::Impl::WithoutInitializing_t wi, const DynRankView& src) { return Impl::create_mirror(src, Kokkos::view_alloc(wi)); } -template -inline typename DynRankView::HostMirror create_mirror( - const Impl::ViewCtorProp& arg_prop, - const DynRankView& src, - std::enable_if_t< - std::is_void::specialize>::value && - !Impl::ViewCtorProp::has_memory_space>* = nullptr) { - return Impl::create_mirror(src, arg_prop); -} - -// Create a mirror in a new space template ::value && - std::is_void::specialize>::value>> -typename Impl::MirrorDRVType::view_type create_mirror( + class Enable = std::enable_if_t::value>> +auto create_mirror( const Space&, const Kokkos::DynRankView& src) { return Impl::create_mirror( src, Kokkos::view_alloc(typename Space::memory_space{})); } -template -typename Impl::MirrorDRVType::view_type create_mirror( +template ::value>> +auto create_mirror( Kokkos::Impl::WithoutInitializing_t wi, const Space&, - const Kokkos::DynRankView& src, - std::enable_if_t::specialize, - void>::value>* = nullptr) { + const Kokkos::DynRankView& src) { return Impl::create_mirror( src, Kokkos::view_alloc(wi, typename Space::memory_space{})); } @@ -2033,14 +2017,8 @@ typename Impl::MirrorDRVType::view_type create_mirror( template inline auto create_mirror( const Impl::ViewCtorProp& arg_prop, - const DynRankView& src, - std::enable_if_t< - std::is_void::specialize>::value && - Impl::ViewCtorProp::has_memory_space>* = nullptr) { - using ReturnType = typename Impl::MirrorDRVType< - typename Impl::ViewCtorProp::memory_space, T, - P...>::view_type; - return ReturnType{Impl::create_mirror(src, arg_prop)}; + const DynRankView& src) { + return Impl::create_mirror(src, arg_prop); } namespace Impl { @@ -2081,28 +2059,8 @@ inline auto create_mirror_view(const DynRankView& src, // Create a mirror view in host space template -inline std::enable_if_t< - (std::is_same< - typename DynRankView::memory_space, - typename DynRankView::HostMirror::memory_space>::value && - std::is_same::data_type, - typename DynRankView::HostMirror::data_type>::value), - typename DynRankView::HostMirror> -create_mirror_view(const Kokkos::DynRankView& src) { - return src; -} - -template -inline std::enable_if_t< - !(std::is_same< - typename DynRankView::memory_space, - typename DynRankView::HostMirror::memory_space>::value && - std::is_same< - typename DynRankView::data_type, - typename DynRankView::HostMirror::data_type>::value), - typename DynRankView::HostMirror> -create_mirror_view(const Kokkos::DynRankView& src) { - return Kokkos::create_mirror(src); +inline auto create_mirror_view(const Kokkos::DynRankView& src) { + return Impl::create_mirror_view(src, Kokkos::view_alloc()); } template @@ -2112,29 +2070,15 @@ inline auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi, } // Create a mirror view in a new space -// FIXME_C++17 Improve SFINAE here. template ::value>> -inline typename Impl::MirrorDRViewType::view_type -create_mirror_view( - const Space&, const Kokkos::DynRankView& src, - std::enable_if_t< - Impl::MirrorDRViewType::is_same_memspace>* = nullptr) { - return src; +inline auto create_mirror_view( + const Space&, const Kokkos::DynRankView& src) { + return Impl::create_mirror_view(src, Kokkos::view_alloc(typename Space::memory_space())); } -// FIXME_C++17 Improve SFINAE here. template ::value>> -inline typename Impl::MirrorDRViewType::view_type -create_mirror_view( - const Space& space, const Kokkos::DynRankView& src, - std::enable_if_t< - !Impl::MirrorDRViewType::is_same_memspace>* = nullptr) { - return Kokkos::create_mirror(space, src); -} - -template + typename Enable = std::enable_if_t::value>> inline auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi, const Space&, const Kokkos::DynRankView& src) { diff --git a/containers/src/Kokkos_DynamicView.hpp b/containers/src/Kokkos_DynamicView.hpp index dce716f74ef..d6a876e8808 100644 --- a/containers/src/Kokkos_DynamicView.hpp +++ b/containers/src/Kokkos_DynamicView.hpp @@ -660,15 +660,16 @@ inline auto create_mirror( return Impl::create_mirror(src, Kokkos::view_alloc(wi)); } -// Create a mirror in a new space -template +template ::value>> inline auto create_mirror( const Space&, const Kokkos::Experimental::DynamicView& src) { return Impl::create_mirror( src, Kokkos::view_alloc(typename Space::memory_space{})); } -template +template ::value>> typename Kokkos::Impl::MirrorDynamicViewType::view_type create_mirror(Kokkos::Impl::WithoutInitializing_t wi, const Space&, const Kokkos::Experimental::DynamicView& src) { @@ -733,15 +734,16 @@ inline auto create_mirror_view( return Impl::create_mirror_view(src, Kokkos::view_alloc(wi)); } -// Create a mirror in a new space -template +template ::value>> inline auto create_mirror_view( const Space&, const Kokkos::Experimental::DynamicView& src) { return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } -template +template ::value>> inline auto create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, const Space&, const Kokkos::Experimental::DynamicView& src) { diff --git a/containers/src/Kokkos_OffsetView.hpp b/containers/src/Kokkos_OffsetView.hpp index 936262c0a32..159d5708c8d 100644 --- a/containers/src/Kokkos_OffsetView.hpp +++ b/containers/src/Kokkos_OffsetView.hpp @@ -1910,7 +1910,8 @@ inline auto create_mirror( src, Kokkos::view_alloc(typename Space::memory_space{})); } -template +template ::value>> typename Kokkos::Impl::MirrorOffsetType::view_type create_mirror(Kokkos::Impl::WithoutInitializing_t wi, const Space&, const Kokkos::Experimental::OffsetView& src) { @@ -1983,7 +1984,8 @@ inline auto create_mirror_view( src, Kokkos::view_alloc(typename Space::memory_space{})); } -template +template ::value>> inline auto create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, const Space&, const Kokkos::Experimental::OffsetView& src) { diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 2d9ca6d1bba..2952f97c5ef 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3474,7 +3474,9 @@ void check_view_ctor_args_create_mirror() { // create a mirror // private interface that accepts arbitrary view constructor args passed by a // view_alloc -template +template ::specialize>::value>> inline auto create_mirror(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { check_view_ctor_args_create_mirror(); @@ -3494,54 +3496,39 @@ inline auto create_mirror(const Kokkos::View& src, } } // namespace Impl +// public interface template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::View const& src) { +auto create_mirror(Kokkos::View const& src) { return Impl::create_mirror(src, Impl::ViewCtorProp<>{}); } +// public interface that accepts a without initializing flag template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, - Kokkos::View const& src) { +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, + Kokkos::View const& src) { return Impl::create_mirror(src, view_alloc(wi)); } +// public interface that accepts a space template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> -create_mirror(Space const&, Kokkos::View const& src) { +auto create_mirror(Space const&, Kokkos::View const& src) { return Impl::create_mirror(src, view_alloc(typename Space::memory_space{})); } -template ::specialize>::value && - Impl::ViewCtorProp::has_memory_space>> +// public interface that accepts arbitrary view constructor args passed by a +// view_alloc +template auto create_mirror(Impl::ViewCtorProp const& arg_prop, Kokkos::View const& src) { return Impl::create_mirror(src, arg_prop); } -template -std::enable_if_t< - std::is_void::specialize>::value && - !Impl::ViewCtorProp::has_memory_space, - typename Kokkos::View::HostMirror> -create_mirror(Impl::ViewCtorProp const& arg_prop, - Kokkos::View const& src) { - return Impl::create_mirror(src, arg_prop); -} - +// public interface that accepts a space and a without initializing flag template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, - Kokkos::View const& src) { +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, + Kokkos::View const& src) { return Impl::create_mirror(src, view_alloc(typename Space::memory_space{}, wi)); } @@ -3551,7 +3538,9 @@ namespace Impl { // create a mirror view // private interface that accepts arbitrary view constructor args passed by a // view_alloc -template +template ::specialize>::value>> inline auto create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { if constexpr (!Impl::ViewCtorProp::has_memory_space) { @@ -3579,67 +3568,38 @@ inline auto create_mirror_view(const Kokkos::View& src, } } // namespace Impl +// public interface template -std::enable_if_t< - std::is_same< - typename Kokkos::View::memory_space, - typename Kokkos::View::HostMirror::memory_space>::value && - std::is_same< - typename Kokkos::View::data_type, - typename Kokkos::View::HostMirror::data_type>::value, - typename Kokkos::View::HostMirror> -create_mirror_view(const Kokkos::View& src) { - return src; -} - -template -std::enable_if_t< - !(std::is_same< - typename Kokkos::View::memory_space, - typename Kokkos::View::HostMirror::memory_space>::value && - std::is_same< - typename Kokkos::View::data_type, - typename Kokkos::View::HostMirror::data_type>::value), - typename Kokkos::View::HostMirror> -create_mirror_view(const Kokkos::View& src) { - return Kokkos::create_mirror(src); +auto create_mirror_view(const Kokkos::View& src) { + return Impl::create_mirror_view(src, view_alloc()); } +// public interface that accepts a without initializing flag template -typename Kokkos::View::HostMirror create_mirror_view( - Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& src) { +auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi, + Kokkos::View const& src) { return Impl::create_mirror_view(src, view_alloc(wi)); } -// FIXME_C++17 Improve SFINAE here. +// public interface that accepts a space template ::value>> -typename Impl::MirrorViewType::view_type create_mirror_view( - const Space&, const Kokkos::View& src, - std::enable_if_t::is_same_memspace>* = - nullptr) { - return src; -} - -// FIXME_C++17 Improve SFINAE here. -template ::value>> -typename Impl::MirrorViewType::view_type create_mirror_view( - const Space& space, const Kokkos::View& src, - std::enable_if_t::is_same_memspace>* = - nullptr) { - return Kokkos::create_mirror(space, src); +auto create_mirror_view(const Space& space, const Kokkos::View& src) { + return Impl::create_mirror_view(src, + view_alloc(typename Space::memory_space())); } +// public interface that accepts a space and a without initializing flag template ::value>> -typename Impl::MirrorViewType::view_type create_mirror_view( - Kokkos::Impl::WithoutInitializing_t wi, Space const&, - Kokkos::View const& src) { +auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi, Space const&, + Kokkos::View const& src) { return Impl::create_mirror_view( src, view_alloc(typename Space::memory_space{}, wi)); } +// public interface that accepts arbitrary view constructor args passed by a +// view_alloc template auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, const Kokkos::View& src) { diff --git a/core/unit_test/TestViewAPI.hpp b/core/unit_test/TestViewAPI.hpp index ca098dbc247..3fd2b02296f 100644 --- a/core/unit_test/TestViewAPI.hpp +++ b/core/unit_test/TestViewAPI.hpp @@ -47,7 +47,7 @@ struct TestViewOperator { enum { N = 1000 }; enum { D = 3 }; - using view_type = Kokkos::View; + using view_type = Kokkos::View; const view_type v1; const view_type v2; @@ -837,18 +837,15 @@ struct TestViewMirror { view_const_cast(v)); } - template + template struct CopyUnInit { - using mirror_view_type = typename Kokkos::Impl::MirrorViewType< - Space, double *, Layout, Kokkos::HostSpace, MemoryTraits>::view_type; - - mirror_view_type a_d; + View a_d; KOKKOS_INLINE_FUNCTION - CopyUnInit(mirror_view_type &a_d_) : a_d(a_d_) {} + explicit CopyUnInit(View &a_d_) : a_d(a_d_) {} KOKKOS_INLINE_FUNCTION - void operator()(const typename Space::size_type i) const { + void operator()(const typename View::size_type i) const { a_d(i) = (double)(10 - i); } }; @@ -875,7 +872,7 @@ struct TestViewMirror { Kokkos::parallel_for( Kokkos::RangePolicy(0, int(10)), - CopyUnInit(a_d)); + CopyUnInit(a_d)); Kokkos::deep_copy(a_h, a_d); @@ -909,10 +906,10 @@ class TestViewAPI { using dView0 = Kokkos::View; using dView1 = Kokkos::View; - using dView2 = Kokkos::View; - using dView3 = Kokkos::View; - using dView4 = Kokkos::View; - using const_dView4 = Kokkos::View; + using dView2 = Kokkos::View; + using dView3 = Kokkos::View; + using dView4 = Kokkos::View; + using const_dView4 = Kokkos::View; using dView4_unmanaged = Kokkos::View; using host = typename dView0::host_mirror_space; @@ -1022,8 +1019,8 @@ class TestViewAPI { static void run_test_contruction_from_layout_2() { using dView3_0 = Kokkos::View; - using dView3_1 = Kokkos::View; - using dView3_2 = Kokkos::View; + using dView3_1 = Kokkos::View; + using dView3_2 = Kokkos::View; using dView3_3 = Kokkos::View; dView3_0 v_0("v_0", N0, N1, N2); @@ -1359,8 +1356,8 @@ class TestViewAPI { // Check Deep Copy of two empty 2D views { - Kokkos::View d; - Kokkos::View h; + Kokkos::View d; + Kokkos::View h; Kokkos::deep_copy(d, h); Kokkos::deep_copy(h, d); }