From 892cd84c93ef9b8b279492cad1408e59c6190375 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 11:29:58 +0100 Subject: [PATCH 01/26] MirrorViewType takes account of data type --- core/src/Kokkos_CopyViews.hpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 08f6ba8d696..0921e86dad1 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3414,11 +3414,6 @@ struct MirrorViewType { using src_view_type = typename Kokkos::View; // The memory space for the mirror view using memory_space = typename Space::memory_space; - // Check whether it is the same memory space - enum { - is_same_memspace = - std::is_same::value - }; // The array_layout using array_layout = typename src_view_type::array_layout; // The data type (we probably want it non-const since otherwise we can't even @@ -3426,10 +3421,23 @@ struct MirrorViewType { using data_type = typename src_view_type::non_const_data_type; // The destination view type if it is not the same memory space using dest_view_type = Kokkos::View; - // If it is the same memory_space return the existsing view_type + + // Check whether it is the same memory space + enum { + is_same_memspace = + std::is_same::value + }; + + // Check whether it is the same data type + enum { + is_same_data_type = + std::is_same::value + }; + + // If it is the same memory_space and data_type return the existsing view_type // This will also keep the unmanaged trait if necessary using view_type = - std::conditional_t; + std::conditional_t; }; template From 374534e915d29b2f481d6f9a04bc4ae94955a7a7 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 12:08:12 +0100 Subject: [PATCH 02/26] Shorthand for same memspace and same data type --- core/src/Kokkos_CopyViews.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 0921e86dad1..7d6806f5844 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3434,10 +3434,15 @@ struct MirrorViewType { std::is_same::value }; + // Shorthand for both memory space and data type check + enum { + is_same = is_same_memspace && is_same_data_type + }; + // If it is the same memory_space and data_type return the existsing view_type // This will also keep the unmanaged trait if necessary using view_type = - std::conditional_t; + std::conditional_t; }; template From bb3b164e28df0ad234beece681f3cdd3fd2a2744 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Thu, 7 Mar 2024 15:00:15 +0100 Subject: [PATCH 03/26] cm modif --- core/src/Kokkos_CopyViews.hpp | 70 ++++++++++++++--------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 7d6806f5844..de6b4c6ca6d 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3445,6 +3445,7 @@ struct MirrorViewType { std::conditional_t; }; +// TODO: Delete this struct ? template struct MirrorType { // The incoming view_type @@ -3484,12 +3485,14 @@ void check_view_ctor_args_create_mirror() { } template -inline std::enable_if_t::has_memory_space, - typename Kokkos::View::HostMirror> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - using src_type = View; - using dst_type = typename src_type::HostMirror; + inline std::enable_if_t < + !Impl::ViewCtorProp::has_memory_space && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::dest_view_type> + create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { + + using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; check_view_ctor_args_create_mirror(); @@ -3499,69 +3502,50 @@ create_mirror(const Kokkos::View& src, return dst_type(prop_copy, src.layout()); } -// Create a mirror in a new space (specialization for different space) -template ::has_memory_space>> -auto create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { +template < + class T, class... P, class... ViewCtorArgs, + typename Enable = std::enable_if_t< + std::is_void::specialize>::value && + Impl::ViewCtorProp::has_memory_space>, + typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> + create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { + + using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); auto prop_copy = Impl::with_properties_if_unset( arg_prop, std::string(src.label()).append("_mirror")); - using alloc_prop = decltype(prop_copy); - return typename Impl::MirrorType::view_type(prop_copy, src.layout()); + return dst_type(prop_copy, src.layout()); } } // namespace Impl template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::View const& v) { +auto create_mirror(Kokkos::View const& v) { return Impl::create_mirror(v, Impl::ViewCtorProp<>{}); } template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(wi)); } -template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> +template +std::enable_if_t::value>, auto> create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } -template ::specialize>::value && - Impl::ViewCtorProp::has_memory_space>> +template auto create_mirror(Impl::ViewCtorProp const& arg_prop, Kokkos::View const& v) { return Impl::create_mirror(v, 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& v) { - return Impl::create_mirror(v, arg_prop); -} - -template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> +template +std::enable_if_t::value>, auto> create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); From 3687fce4998533c3d2f534fd8a49f56f41d3c8bb Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 15:00:09 +0100 Subject: [PATCH 04/26] Refactor create_mirror_view --- core/src/Kokkos_CopyViews.hpp | 120 +++++++++++----------------------- 1 file changed, 39 insertions(+), 81 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index de6b4c6ca6d..7e6d587b61d 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3553,47 +3553,37 @@ create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, namespace Impl { +// TODO use if constexpr for is_same +// same memory space and data type on host template inline std::enable_if_t< !Impl::ViewCtorProp::has_memory_space && - (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> + Impl::MirrorViewType::is_same, + typename Impl::MirrorViewType::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); return src; } +// different memory space or data type on host template inline std::enable_if_t< !Impl::ViewCtorProp::has_memory_space && - !(std::is_same::memory_space, - typename Kokkos::View< - T, P...>::HostMirror::memory_space>::value && - std::is_same< - typename Kokkos::View::data_type, - typename Kokkos::View::HostMirror::data_type>::value), - typename Kokkos::View::HostMirror> + !Impl::MirrorViewType::is_same, + typename Impl::MirrorViewType::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); } // Create a mirror view in a new space (specialization for same space) -template ::has_memory_space>> -std::enable_if_t::memory_space, - T, P...>::is_same_memspace, - typename Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, - T, P...>::view_type> +// same memory space and data type on another space +template +inline std::enable_if_t< + Impl::ViewCtorProp::has_memory_space>> && + Impl::MirrorViewType::memory_space, T, P...>::is_same, + Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); @@ -3601,82 +3591,50 @@ create_mirror_view(const Kokkos::View& src, } // Create a mirror view in a new space (specialization for different space) -template ::has_memory_space>> -std::enable_if_t::memory_space, - T, P...>::is_same_memspace, - typename Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, - T, P...>::view_type> +// different memory space or data type on another space +template +inline std::enable_if_t< + Impl::ViewCtorProp::has_memory_space>> && + !Impl::MirrorViewType::memory_space, T, P...>::is_same, + Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); } } // namespace Impl +// view 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; +auto create_mirror_view(const Kokkos::View& src) { + return Impl::create_mirror_view(src, Impl::ViewCtorProp<>{}); } +// view and without initializing 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); -} - -template -typename Kokkos::View::HostMirror create_mirror_view( - Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { - return Impl::create_mirror_view(v, view_alloc(wi)); -} - -// FIXME_C++17 Improve SFINAE here. -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; +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. -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); +// viel and space +template +std::enable_if_t::value>, auto> +create_mirror_view( + const Space&, const Kokkos::View& src) { + return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } -template ::value>> -typename Impl::MirrorViewType::view_type create_mirror_view( +// view, space and without initializing +template +std::enable_if_t::value>, auto> +create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, Space const&, - Kokkos::View const& v) { + Kokkos::View const& src) { return Impl::create_mirror_view( - v, view_alloc(typename Space::memory_space{}, wi)); + src, view_alloc(typename Space::memory_space{}, wi)); } +// view and view constructor properties template auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, const Kokkos::View& v) { From 08361bb43c465d37d20360b975fdab4139866ca1 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Thu, 7 Mar 2024 16:21:33 +0100 Subject: [PATCH 05/26] bzr --- core/src/Kokkos_CopyViews.hpp | 57 ++++++++++++++++------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 7e6d587b61d..3803978d119 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3485,11 +3485,11 @@ void check_view_ctor_args_create_mirror() { } template - inline std::enable_if_t < - !Impl::ViewCtorProp::has_memory_space && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::dest_view_type> - create_mirror(const Kokkos::View& src, +inline std::enable_if_t < + std::is_void::memory_space>::value && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::dest_view_type> +create_mirror(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; @@ -3502,16 +3502,15 @@ template return dst_type(prop_copy, src.layout()); } -template < - class T, class... P, class... ViewCtorArgs, - typename Enable = std::enable_if_t< - std::is_void::specialize>::value && - Impl::ViewCtorProp::has_memory_space>, - typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> - create_mirror(const Kokkos::View& src, +template +inline std::enable_if_t< + !std::is_void::memory_space>::value && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> +create_mirror(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { - using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; + using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); auto prop_copy = Impl::with_properties_if_unset( @@ -3532,9 +3531,8 @@ auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, return Impl::create_mirror(v, view_alloc(wi)); } -template -std::enable_if_t::value>, auto> -create_mirror(Space const&, Kokkos::View const& v) { +template ::value>> +auto create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } @@ -3544,9 +3542,8 @@ auto create_mirror(Impl::ViewCtorProp const& arg_prop, return Impl::create_mirror(v, arg_prop); } -template -std::enable_if_t::value>, auto> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, +template ::value>> +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); } @@ -3581,9 +3578,9 @@ create_mirror_view(const Kokkos::View& src, // same memory space and data type on another space template inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space>> && - Impl::MirrorViewType::memory_space, T, P...>::is_same, - Impl::MirrorViewType::memory_space, T, P...>::view_type> + Impl::ViewCtorProp::has_memory_space && + Impl::MirrorViewType::memory_space, T, P...>::is_same, + typename Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); @@ -3594,9 +3591,9 @@ create_mirror_view(const Kokkos::View& src, // different memory space or data type on another space template inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space>> && - !Impl::MirrorViewType::memory_space, T, P...>::is_same, - Impl::MirrorViewType::memory_space, T, P...>::view_type> + Impl::ViewCtorProp::has_memory_space && + !Impl::MirrorViewType::memory_space, T, P...>::is_same, + typename Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); @@ -3617,17 +3614,15 @@ auto create_mirror_view( } // viel and space -template -std::enable_if_t::value>, auto> -create_mirror_view( +template ::value>> +auto create_mirror_view( const Space&, const Kokkos::View& src) { return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } // view, space and without initializing -template -std::enable_if_t::value>, auto> -create_mirror_view( +template ::value>> +auto create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& src) { return Impl::create_mirror_view( From 1380a2f1bcfccffe4e0603e98387a0409d08948d Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 17:52:56 +0100 Subject: [PATCH 06/26] Allow empty MirrorViewType --- core/src/Kokkos_CopyViews.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 3803978d119..8d7b00771e1 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3407,6 +3407,24 @@ inline void realloc( namespace Kokkos { namespace Impl { +// Deduce Mirror Types +template +struct MirrorViewType; + +// Dummy mirror view type that contains nothing +template +struct MirrorViewType { + using src_view_type = void; + using memory_space = void; + using array_layout = void; + using data_type = void; + using dest_view_type = void; + using view_type = void; + static constexpr bool is_same_namespace = false; + static constexpr bool is_same_data_type = false; + static constexpr bool is_same = false; +}; + // Deduce Mirror Types template struct MirrorViewType { From 0621533105a02af1364f8a9bd183df1ba12a3839 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 18:31:45 +0100 Subject: [PATCH 07/26] Compact create_mirror_* functions --- core/src/Kokkos_CopyViews.hpp | 113 ++++++++++++---------------------- 1 file changed, 38 insertions(+), 75 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 8d7b00771e1..702bb94c986 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3425,7 +3425,7 @@ struct MirrorViewType { static constexpr bool is_same = false; }; -// Deduce Mirror Types +// Actual mirror view type template struct MirrorViewType { // The incoming view_type @@ -3502,119 +3502,82 @@ void check_view_ctor_args_create_mirror() { "not explicitly allow padding!"); } -template -inline std::enable_if_t < - std::is_void::memory_space>::value && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::dest_view_type> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - - using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; +template ::specialize>::value>> +inline auto create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { - check_view_ctor_args_create_mirror(); + // get desired space + using space_type = std::conditional_t::has_memory_space, + typename Impl::ViewCtorProp::memory_space, + DefaultHostExecutionSpace>; - auto prop_copy = Impl::with_properties_if_unset( - arg_prop, std::string(src.label()).append("_mirror")); - - return dst_type(prop_copy, src.layout()); -} - -template -inline std::enable_if_t< - !std::is_void::memory_space>::value && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { + using mirror_view_type = typename Impl::MirrorViewType; - using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); + // append label name with "_mirror" auto prop_copy = Impl::with_properties_if_unset( arg_prop, std::string(src.label()).append("_mirror")); - return dst_type(prop_copy, src.layout()); + return typename mirror_view_type::dest_view_type(prop_copy, src.layout()); } } // namespace Impl +// view template auto create_mirror(Kokkos::View const& v) { return Impl::create_mirror(v, Impl::ViewCtorProp<>{}); } +// view and without initializing template auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(wi)); } +// view and space template ::value>> auto create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } -template -auto create_mirror(Impl::ViewCtorProp const& arg_prop, - Kokkos::View const& v) { - return Impl::create_mirror(v, arg_prop); -} - +// view, space and without initializing template ::value>> auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); } -namespace Impl { - -// TODO use if constexpr for is_same -// same memory space and data type on host +// view and view constructor properties template -inline std::enable_if_t< - !Impl::ViewCtorProp::has_memory_space && - Impl::MirrorViewType::is_same, - typename Impl::MirrorViewType::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp&) { - check_view_ctor_args_create_mirror(); - return src; +auto create_mirror(Impl::ViewCtorProp const& arg_prop, + Kokkos::View const& v) { + return Impl::create_mirror(v, arg_prop); } -// different memory space or data type on host -template -inline std::enable_if_t< - !Impl::ViewCtorProp::has_memory_space && - !Impl::MirrorViewType::is_same, - typename Impl::MirrorViewType::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - return Kokkos::Impl::create_mirror(src, arg_prop); -} +namespace Impl { -// Create a mirror view in a new space (specialization for same space) -// same memory space and data type on another space template -inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space && - Impl::MirrorViewType::memory_space, T, P...>::is_same, - typename Impl::MirrorViewType::memory_space, T, P...>::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp&) { - check_view_ctor_args_create_mirror(); - return src; -} +inline auto create_mirror_view(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { -// Create a mirror view in a new space (specialization for different space) -// different memory space or data type on another space -template -inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space && - !Impl::MirrorViewType::memory_space, T, P...>::is_same, - typename Impl::MirrorViewType::memory_space, T, P...>::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - return Kokkos::Impl::create_mirror(src, arg_prop); + // get desired space + using space_type = std::conditional_t::has_memory_space, + typename Impl::ViewCtorProp::memory_space, + DefaultHostExecutionSpace>; + + using mirror_view_type = typename Impl::MirrorViewType; + + if constexpr (mirror_view_type::is_same) { + // shallow copy if src and dest both spaces and data types are the same + check_view_ctor_args_create_mirror(); + return src; + } else { + // create mirror if src and dest spaces are different + return Kokkos::Impl::create_mirror(src, arg_prop); + } } } // namespace Impl From 181328a2889679d86b8fcfbbf56a15ab2ae5ce6a Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 10:24:26 +0100 Subject: [PATCH 08/26] No more MirrorType --- core/src/Kokkos_CopyViews.hpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 702bb94c986..895603546d2 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3463,27 +3463,6 @@ struct MirrorViewType { std::conditional_t; }; -// TODO: Delete this struct ? -template -struct MirrorType { - // The incoming view_type - using src_view_type = typename Kokkos::View; - // The memory space for the mirror view - using memory_space = typename Space::memory_space; - // Check whether it is the same memory space - enum { - is_same_memspace = - std::is_same::value - }; - // The array_layout - using array_layout = typename src_view_type::array_layout; - // The data type (we probably want it non-const since otherwise we can't even - // deep_copy to it. - using data_type = typename src_view_type::non_const_data_type; - // The destination view type if it is not the same memory space - using view_type = Kokkos::View; -}; - template void check_view_ctor_args_create_mirror() { using alloc_prop_input = Impl::ViewCtorProp; From 3e9c00a0f4daa1e683684e51d2660cd90c2a18d7 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 14:24:07 +0100 Subject: [PATCH 09/26] mirror and copy --- core/src/Kokkos_CopyViews.hpp | 106 ++++++++++++++-------------------- 1 file changed, 44 insertions(+), 62 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 895603546d2..cae3191754f 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3596,88 +3596,70 @@ auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, return Impl::create_mirror_view(v, arg_prop); } -template -auto create_mirror_view_and_copy( - const Impl::ViewCtorProp&, - const Kokkos::View& src, - std::enable_if_t< - std::is_void::specialize>::value && - Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, T, - P...>::is_same_memspace>* = nullptr) { +template +void check_view_ctor_args_create_mirror_and_copy() { using alloc_prop_input = Impl::ViewCtorProp; + static_assert( - alloc_prop_input::has_memory_space, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must include a memory space!"); + !alloc_prop_input::has_label, + "The view constructor arguments passed to Kokkos::create_mirror[_view] " + "must not include a label!"); static_assert(!alloc_prop_input::has_pointer, "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " + "Kokkos::create_mirror[_view] must " "not include a pointer!"); static_assert(!alloc_prop_input::allow_padding, "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " + "Kokkos::create_mirror[_view] must " "not explicitly allow padding!"); - - // same behavior as deep_copy(src, src) - if (!alloc_prop_input::has_execution_space) - fence( - "Kokkos::create_mirror_view_and_copy: fence before returning src view"); - return src; } -template +template ::specialize>::value>> auto create_mirror_view_and_copy( const Impl::ViewCtorProp& arg_prop, - const Kokkos::View& src, - std::enable_if_t< - std::is_void::specialize>::value && - !Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, T, - P...>::is_same_memspace>* = nullptr) { - using alloc_prop_input = Impl::ViewCtorProp; - static_assert( - alloc_prop_input::has_memory_space, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must include a memory space!"); - static_assert(!alloc_prop_input::has_pointer, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " - "not include a pointer!"); - static_assert(!alloc_prop_input::allow_padding, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " - "not explicitly allow padding!"); - using Space = typename alloc_prop_input::memory_space; - using Mirror = typename Impl::MirrorViewType::view_type; - - auto arg_prop_copy = Impl::with_properties_if_unset( - arg_prop, std::string{}, WithoutInitializing, - typename Space::execution_space{}); - - std::string& label = Impl::get_property(arg_prop_copy); - if (label.empty()) label = src.label(); - auto mirror = typename Mirror::non_const_type{arg_prop_copy, src.layout()}; - if constexpr (alloc_prop_input::has_execution_space) { - deep_copy(Impl::get_property(arg_prop_copy), - mirror, src); - } else - deep_copy(mirror, src); - return mirror; -} + const Kokkos::View& src) { + + using alloc_prop_input = Impl::ViewCtorProp; + check_view_ctor_args_create_mirror_and_copy(); + + // get desired space + using space_type = std::conditional_t; + + using mirror_view_type = typename Impl::MirrorViewType; + using nonconst_mirror = typename mirror_view_type::view_type::non_const_type; + + if constexpr(mirror_view_type::is_same){ + // same behavior as deep_copy(src, src) + fence( + "Kokkos::create_mirror_view_and_copy: fence before returning src view"); + return src; + } else { + auto arg_prop_copy = Impl::with_properties_if_unset( + arg_prop, std::string{}, WithoutInitializing, + typename space_type::execution_space{}); + + std::string& label = Impl::get_property(arg_prop_copy); + if (label.empty()) label = src.label(); + + auto mirror = nonconst_mirror{arg_prop_copy, src.layout()};; + deep_copy(mirror, src); + return mirror; + } + } // Previously when using auto here, the intel compiler 19.3 would // sometimes not create a symbol, guessing that it somehow is a combination // of auto and just forwarding arguments (see issue #5196) template ::value>> + typename Enable = std::enable_if_t::value>, + class = std::enable_if_t::specialize>::value>> typename Impl::MirrorViewType::view_type create_mirror_view_and_copy( const Space&, const Kokkos::View& src, - std::string const& name = "", - std::enable_if_t< - std::is_void::specialize>::value>* = - nullptr) { + std::string const& name = "") { return create_mirror_view_and_copy( Kokkos::view_alloc(typename Space::memory_space{}, name), src); } From c228dc201252b6cc11f9654a77665de754c180d7 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 15:02:36 +0100 Subject: [PATCH 10/26] correction --- core/src/Kokkos_CopyViews.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index cae3191754f..d9dfc486332 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3601,16 +3601,16 @@ void check_view_ctor_args_create_mirror_and_copy() { using alloc_prop_input = Impl::ViewCtorProp; static_assert( - !alloc_prop_input::has_label, - "The view constructor arguments passed to Kokkos::create_mirror[_view] " - "must not include a label!"); + alloc_prop_input::has_memory_space, + "The view constructor arguments passed to " + "Kokkos::create_mirror_view_and_copy must include a memory space!"); static_assert(!alloc_prop_input::has_pointer, "The view constructor arguments passed to " - "Kokkos::create_mirror[_view] must " + "Kokkos::create_mirror_view_and_copy must " "not include a pointer!"); static_assert(!alloc_prop_input::allow_padding, "The view constructor arguments passed to " - "Kokkos::create_mirror[_view] must " + "Kokkos::create_mirror_view_and_copy must " "not explicitly allow padding!"); } @@ -3621,7 +3621,7 @@ auto create_mirror_view_and_copy( const Kokkos::View& src) { using alloc_prop_input = Impl::ViewCtorProp; - check_view_ctor_args_create_mirror_and_copy(); + check_view_ctor_args_create_mirror_and_copy(); // get desired space using space_type = std::conditional_t; using mirror_view_type = typename Impl::MirrorViewType; - using nonconst_mirror = typename mirror_view_type::view_type::non_const_type; if constexpr(mirror_view_type::is_same){ // same behavior as deep_copy(src, src) @@ -3637,6 +3636,8 @@ auto create_mirror_view_and_copy( "Kokkos::create_mirror_view_and_copy: fence before returning src view"); return src; } else { + + using nonconst_mirror = typename mirror_view_type::dest_view_type; auto arg_prop_copy = Impl::with_properties_if_unset( arg_prop, std::string{}, WithoutInitializing, typename space_type::execution_space{}); @@ -3644,8 +3645,8 @@ auto create_mirror_view_and_copy( std::string& label = Impl::get_property(arg_prop_copy); if (label.empty()) label = src.label(); - auto mirror = nonconst_mirror{arg_prop_copy, src.layout()};; - deep_copy(mirror, src); + auto mirror = nonconst_mirror{arg_prop_copy, src.layout()}; + deep_copy(Impl::get_property(arg_prop_copy), mirror, src); return mirror; } } From 8b868a4ec6285001ceb7970a3aeabdb1104254cc Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Tue, 12 Mar 2024 16:22:59 +0100 Subject: [PATCH 11/26] check on execspace? --- core/src/Kokkos_CopyViews.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index d9dfc486332..15b77f34e63 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3632,8 +3632,9 @@ auto create_mirror_view_and_copy( if constexpr(mirror_view_type::is_same){ // same behavior as deep_copy(src, src) - fence( - "Kokkos::create_mirror_view_and_copy: fence before returning src view"); + if constexpr (!alloc_prop_input::has_execution_space) + fence( + "Kokkos::create_mirror_view_and_copy: fence before returning src view"); return src; } else { From f4adf5a7b53cf38d573765fb16d57c7ab225c3d5 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 11:29:58 +0100 Subject: [PATCH 12/26] MirrorViewType takes account of data type --- core/src/Kokkos_CopyViews.hpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 08f6ba8d696..0921e86dad1 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3414,11 +3414,6 @@ struct MirrorViewType { using src_view_type = typename Kokkos::View; // The memory space for the mirror view using memory_space = typename Space::memory_space; - // Check whether it is the same memory space - enum { - is_same_memspace = - std::is_same::value - }; // The array_layout using array_layout = typename src_view_type::array_layout; // The data type (we probably want it non-const since otherwise we can't even @@ -3426,10 +3421,23 @@ struct MirrorViewType { using data_type = typename src_view_type::non_const_data_type; // The destination view type if it is not the same memory space using dest_view_type = Kokkos::View; - // If it is the same memory_space return the existsing view_type + + // Check whether it is the same memory space + enum { + is_same_memspace = + std::is_same::value + }; + + // Check whether it is the same data type + enum { + is_same_data_type = + std::is_same::value + }; + + // If it is the same memory_space and data_type return the existsing view_type // This will also keep the unmanaged trait if necessary using view_type = - std::conditional_t; + std::conditional_t; }; template From 02118ea14d1b8dd97d843df2b6e79958d7c65187 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 12:08:12 +0100 Subject: [PATCH 13/26] Shorthand for same memspace and same data type --- core/src/Kokkos_CopyViews.hpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 0921e86dad1..7d6806f5844 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3434,10 +3434,15 @@ struct MirrorViewType { std::is_same::value }; + // Shorthand for both memory space and data type check + enum { + is_same = is_same_memspace && is_same_data_type + }; + // If it is the same memory_space and data_type return the existsing view_type // This will also keep the unmanaged trait if necessary using view_type = - std::conditional_t; + std::conditional_t; }; template From 939b24547285e9734a3bc1a8bee207588fdf462f Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Thu, 7 Mar 2024 15:00:15 +0100 Subject: [PATCH 14/26] cm modif --- core/src/Kokkos_CopyViews.hpp | 70 ++++++++++++++--------------------- 1 file changed, 27 insertions(+), 43 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 7d6806f5844..de6b4c6ca6d 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3445,6 +3445,7 @@ struct MirrorViewType { std::conditional_t; }; +// TODO: Delete this struct ? template struct MirrorType { // The incoming view_type @@ -3484,12 +3485,14 @@ void check_view_ctor_args_create_mirror() { } template -inline std::enable_if_t::has_memory_space, - typename Kokkos::View::HostMirror> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - using src_type = View; - using dst_type = typename src_type::HostMirror; + inline std::enable_if_t < + !Impl::ViewCtorProp::has_memory_space && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::dest_view_type> + create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { + + using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; check_view_ctor_args_create_mirror(); @@ -3499,69 +3502,50 @@ create_mirror(const Kokkos::View& src, return dst_type(prop_copy, src.layout()); } -// Create a mirror in a new space (specialization for different space) -template ::has_memory_space>> -auto create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { +template < + class T, class... P, class... ViewCtorArgs, + typename Enable = std::enable_if_t< + std::is_void::specialize>::value && + Impl::ViewCtorProp::has_memory_space>, + typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> + create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { + + using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); auto prop_copy = Impl::with_properties_if_unset( arg_prop, std::string(src.label()).append("_mirror")); - using alloc_prop = decltype(prop_copy); - return typename Impl::MirrorType::view_type(prop_copy, src.layout()); + return dst_type(prop_copy, src.layout()); } } // namespace Impl template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::View const& v) { +auto create_mirror(Kokkos::View const& v) { return Impl::create_mirror(v, Impl::ViewCtorProp<>{}); } template -std::enable_if_t::specialize>::value, - typename Kokkos::View::HostMirror> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(wi)); } -template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> +template +std::enable_if_t::value>, auto> create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } -template ::specialize>::value && - Impl::ViewCtorProp::has_memory_space>> +template auto create_mirror(Impl::ViewCtorProp const& arg_prop, Kokkos::View const& v) { return Impl::create_mirror(v, 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& v) { - return Impl::create_mirror(v, arg_prop); -} - -template ::value>> -std::enable_if_t::specialize>::value, - typename Impl::MirrorType::view_type> +template +std::enable_if_t::value>, auto> create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); From f88cc9f210906382674b2b02e990f7e6857da88c Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 15:00:09 +0100 Subject: [PATCH 15/26] Refactor create_mirror_view --- core/src/Kokkos_CopyViews.hpp | 120 +++++++++++----------------------- 1 file changed, 39 insertions(+), 81 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index de6b4c6ca6d..7e6d587b61d 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3553,47 +3553,37 @@ create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, namespace Impl { +// TODO use if constexpr for is_same +// same memory space and data type on host template inline std::enable_if_t< !Impl::ViewCtorProp::has_memory_space && - (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> + Impl::MirrorViewType::is_same, + typename Impl::MirrorViewType::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); return src; } +// different memory space or data type on host template inline std::enable_if_t< !Impl::ViewCtorProp::has_memory_space && - !(std::is_same::memory_space, - typename Kokkos::View< - T, P...>::HostMirror::memory_space>::value && - std::is_same< - typename Kokkos::View::data_type, - typename Kokkos::View::HostMirror::data_type>::value), - typename Kokkos::View::HostMirror> + !Impl::MirrorViewType::is_same, + typename Impl::MirrorViewType::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); } // Create a mirror view in a new space (specialization for same space) -template ::has_memory_space>> -std::enable_if_t::memory_space, - T, P...>::is_same_memspace, - typename Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, - T, P...>::view_type> +// same memory space and data type on another space +template +inline std::enable_if_t< + Impl::ViewCtorProp::has_memory_space>> && + Impl::MirrorViewType::memory_space, T, P...>::is_same, + Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); @@ -3601,82 +3591,50 @@ create_mirror_view(const Kokkos::View& src, } // Create a mirror view in a new space (specialization for different space) -template ::has_memory_space>> -std::enable_if_t::memory_space, - T, P...>::is_same_memspace, - typename Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, - T, P...>::view_type> +// different memory space or data type on another space +template +inline std::enable_if_t< + Impl::ViewCtorProp::has_memory_space>> && + !Impl::MirrorViewType::memory_space, T, P...>::is_same, + Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); } } // namespace Impl +// view 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; +auto create_mirror_view(const Kokkos::View& src) { + return Impl::create_mirror_view(src, Impl::ViewCtorProp<>{}); } +// view and without initializing 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); -} - -template -typename Kokkos::View::HostMirror create_mirror_view( - Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { - return Impl::create_mirror_view(v, view_alloc(wi)); -} - -// FIXME_C++17 Improve SFINAE here. -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; +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. -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); +// viel and space +template +std::enable_if_t::value>, auto> +create_mirror_view( + const Space&, const Kokkos::View& src) { + return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } -template ::value>> -typename Impl::MirrorViewType::view_type create_mirror_view( +// view, space and without initializing +template +std::enable_if_t::value>, auto> +create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, Space const&, - Kokkos::View const& v) { + Kokkos::View const& src) { return Impl::create_mirror_view( - v, view_alloc(typename Space::memory_space{}, wi)); + src, view_alloc(typename Space::memory_space{}, wi)); } +// view and view constructor properties template auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, const Kokkos::View& v) { From 22d9e360b6321e609a6670a82951625d2a35fb92 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Thu, 7 Mar 2024 16:21:33 +0100 Subject: [PATCH 16/26] bzr --- core/src/Kokkos_CopyViews.hpp | 57 ++++++++++++++++------------------- 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 7e6d587b61d..3803978d119 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3485,11 +3485,11 @@ void check_view_ctor_args_create_mirror() { } template - inline std::enable_if_t < - !Impl::ViewCtorProp::has_memory_space && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::dest_view_type> - create_mirror(const Kokkos::View& src, +inline std::enable_if_t < + std::is_void::memory_space>::value && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::dest_view_type> +create_mirror(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; @@ -3502,16 +3502,15 @@ template return dst_type(prop_copy, src.layout()); } -template < - class T, class... P, class... ViewCtorArgs, - typename Enable = std::enable_if_t< - std::is_void::specialize>::value && - Impl::ViewCtorProp::has_memory_space>, - typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> - create_mirror(const Kokkos::View& src, +template +inline std::enable_if_t< + !std::is_void::memory_space>::value && + std::is_void::specialize>::value, + typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> +create_mirror(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { - using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; + using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); auto prop_copy = Impl::with_properties_if_unset( @@ -3532,9 +3531,8 @@ auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, return Impl::create_mirror(v, view_alloc(wi)); } -template -std::enable_if_t::value>, auto> -create_mirror(Space const&, Kokkos::View const& v) { +template ::value>> +auto create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } @@ -3544,9 +3542,8 @@ auto create_mirror(Impl::ViewCtorProp const& arg_prop, return Impl::create_mirror(v, arg_prop); } -template -std::enable_if_t::value>, auto> -create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, +template ::value>> +auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); } @@ -3581,9 +3578,9 @@ create_mirror_view(const Kokkos::View& src, // same memory space and data type on another space template inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space>> && - Impl::MirrorViewType::memory_space, T, P...>::is_same, - Impl::MirrorViewType::memory_space, T, P...>::view_type> + Impl::ViewCtorProp::has_memory_space && + Impl::MirrorViewType::memory_space, T, P...>::is_same, + typename Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp&) { check_view_ctor_args_create_mirror(); @@ -3594,9 +3591,9 @@ create_mirror_view(const Kokkos::View& src, // different memory space or data type on another space template inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space>> && - !Impl::MirrorViewType::memory_space, T, P...>::is_same, - Impl::MirrorViewType::memory_space, T, P...>::view_type> + Impl::ViewCtorProp::has_memory_space && + !Impl::MirrorViewType::memory_space, T, P...>::is_same, + typename Impl::MirrorViewType::memory_space, T, P...>::view_type> create_mirror_view(const Kokkos::View& src, const Impl::ViewCtorProp& arg_prop) { return Kokkos::Impl::create_mirror(src, arg_prop); @@ -3617,17 +3614,15 @@ auto create_mirror_view( } // viel and space -template -std::enable_if_t::value>, auto> -create_mirror_view( +template ::value>> +auto create_mirror_view( const Space&, const Kokkos::View& src) { return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } // view, space and without initializing -template -std::enable_if_t::value>, auto> -create_mirror_view( +template ::value>> +auto create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& src) { return Impl::create_mirror_view( From c246d67d153de93f7b041052d5d0eafe81574a35 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 17:52:56 +0100 Subject: [PATCH 17/26] Allow empty MirrorViewType --- core/src/Kokkos_CopyViews.hpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 3803978d119..8d7b00771e1 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3407,6 +3407,24 @@ inline void realloc( namespace Kokkos { namespace Impl { +// Deduce Mirror Types +template +struct MirrorViewType; + +// Dummy mirror view type that contains nothing +template +struct MirrorViewType { + using src_view_type = void; + using memory_space = void; + using array_layout = void; + using data_type = void; + using dest_view_type = void; + using view_type = void; + static constexpr bool is_same_namespace = false; + static constexpr bool is_same_data_type = false; + static constexpr bool is_same = false; +}; + // Deduce Mirror Types template struct MirrorViewType { From e05244afb4a021800368e4b634c6d385f3002533 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 7 Mar 2024 18:31:45 +0100 Subject: [PATCH 18/26] Compact create_mirror_* functions --- core/src/Kokkos_CopyViews.hpp | 113 ++++++++++++---------------------- 1 file changed, 38 insertions(+), 75 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 8d7b00771e1..702bb94c986 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3425,7 +3425,7 @@ struct MirrorViewType { static constexpr bool is_same = false; }; -// Deduce Mirror Types +// Actual mirror view type template struct MirrorViewType { // The incoming view_type @@ -3502,119 +3502,82 @@ void check_view_ctor_args_create_mirror() { "not explicitly allow padding!"); } -template -inline std::enable_if_t < - std::is_void::memory_space>::value && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::dest_view_type> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - - using dst_type = typename Kokkos::Impl::MirrorViewType::dest_view_type; +template ::specialize>::value>> +inline auto create_mirror(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { - check_view_ctor_args_create_mirror(); + // get desired space + using space_type = std::conditional_t::has_memory_space, + typename Impl::ViewCtorProp::memory_space, + DefaultHostExecutionSpace>; - auto prop_copy = Impl::with_properties_if_unset( - arg_prop, std::string(src.label()).append("_mirror")); - - return dst_type(prop_copy, src.layout()); -} - -template -inline std::enable_if_t< - !std::is_void::memory_space>::value && - std::is_void::specialize>::value, - typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type> -create_mirror(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { + using mirror_view_type = typename Impl::MirrorViewType; - using dst_type = typename Kokkos::Impl::MirrorViewType::memory_space, T, P...>::dest_view_type; check_view_ctor_args_create_mirror(); + // append label name with "_mirror" auto prop_copy = Impl::with_properties_if_unset( arg_prop, std::string(src.label()).append("_mirror")); - return dst_type(prop_copy, src.layout()); + return typename mirror_view_type::dest_view_type(prop_copy, src.layout()); } } // namespace Impl +// view template auto create_mirror(Kokkos::View const& v) { return Impl::create_mirror(v, Impl::ViewCtorProp<>{}); } +// view and without initializing template auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(wi)); } +// view and space template ::value>> auto create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } -template -auto create_mirror(Impl::ViewCtorProp const& arg_prop, - Kokkos::View const& v) { - return Impl::create_mirror(v, arg_prop); -} - +// view, space and without initializing template ::value>> auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); } -namespace Impl { - -// TODO use if constexpr for is_same -// same memory space and data type on host +// view and view constructor properties template -inline std::enable_if_t< - !Impl::ViewCtorProp::has_memory_space && - Impl::MirrorViewType::is_same, - typename Impl::MirrorViewType::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp&) { - check_view_ctor_args_create_mirror(); - return src; +auto create_mirror(Impl::ViewCtorProp const& arg_prop, + Kokkos::View const& v) { + return Impl::create_mirror(v, arg_prop); } -// different memory space or data type on host -template -inline std::enable_if_t< - !Impl::ViewCtorProp::has_memory_space && - !Impl::MirrorViewType::is_same, - typename Impl::MirrorViewType::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - return Kokkos::Impl::create_mirror(src, arg_prop); -} +namespace Impl { -// Create a mirror view in a new space (specialization for same space) -// same memory space and data type on another space template -inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space && - Impl::MirrorViewType::memory_space, T, P...>::is_same, - typename Impl::MirrorViewType::memory_space, T, P...>::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp&) { - check_view_ctor_args_create_mirror(); - return src; -} +inline auto create_mirror_view(const Kokkos::View& src, + const Impl::ViewCtorProp& arg_prop) { -// Create a mirror view in a new space (specialization for different space) -// different memory space or data type on another space -template -inline std::enable_if_t< - Impl::ViewCtorProp::has_memory_space && - !Impl::MirrorViewType::memory_space, T, P...>::is_same, - typename Impl::MirrorViewType::memory_space, T, P...>::view_type> -create_mirror_view(const Kokkos::View& src, - const Impl::ViewCtorProp& arg_prop) { - return Kokkos::Impl::create_mirror(src, arg_prop); + // get desired space + using space_type = std::conditional_t::has_memory_space, + typename Impl::ViewCtorProp::memory_space, + DefaultHostExecutionSpace>; + + using mirror_view_type = typename Impl::MirrorViewType; + + if constexpr (mirror_view_type::is_same) { + // shallow copy if src and dest both spaces and data types are the same + check_view_ctor_args_create_mirror(); + return src; + } else { + // create mirror if src and dest spaces are different + return Kokkos::Impl::create_mirror(src, arg_prop); + } } } // namespace Impl From afc6c9b34a7a40bb5e72d50e11c9d9144df1f61e Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 10:24:26 +0100 Subject: [PATCH 19/26] No more MirrorType --- core/src/Kokkos_CopyViews.hpp | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 702bb94c986..895603546d2 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3463,27 +3463,6 @@ struct MirrorViewType { std::conditional_t; }; -// TODO: Delete this struct ? -template -struct MirrorType { - // The incoming view_type - using src_view_type = typename Kokkos::View; - // The memory space for the mirror view - using memory_space = typename Space::memory_space; - // Check whether it is the same memory space - enum { - is_same_memspace = - std::is_same::value - }; - // The array_layout - using array_layout = typename src_view_type::array_layout; - // The data type (we probably want it non-const since otherwise we can't even - // deep_copy to it. - using data_type = typename src_view_type::non_const_data_type; - // The destination view type if it is not the same memory space - using view_type = Kokkos::View; -}; - template void check_view_ctor_args_create_mirror() { using alloc_prop_input = Impl::ViewCtorProp; From a5db78fa60f01d431474c7e4edf1a357c85595f1 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 14:24:07 +0100 Subject: [PATCH 20/26] mirror and copy --- core/src/Kokkos_CopyViews.hpp | 106 ++++++++++++++-------------------- 1 file changed, 44 insertions(+), 62 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 895603546d2..cae3191754f 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3596,88 +3596,70 @@ auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, return Impl::create_mirror_view(v, arg_prop); } -template -auto create_mirror_view_and_copy( - const Impl::ViewCtorProp&, - const Kokkos::View& src, - std::enable_if_t< - std::is_void::specialize>::value && - Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, T, - P...>::is_same_memspace>* = nullptr) { +template +void check_view_ctor_args_create_mirror_and_copy() { using alloc_prop_input = Impl::ViewCtorProp; + static_assert( - alloc_prop_input::has_memory_space, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must include a memory space!"); + !alloc_prop_input::has_label, + "The view constructor arguments passed to Kokkos::create_mirror[_view] " + "must not include a label!"); static_assert(!alloc_prop_input::has_pointer, "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " + "Kokkos::create_mirror[_view] must " "not include a pointer!"); static_assert(!alloc_prop_input::allow_padding, "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " + "Kokkos::create_mirror[_view] must " "not explicitly allow padding!"); - - // same behavior as deep_copy(src, src) - if (!alloc_prop_input::has_execution_space) - fence( - "Kokkos::create_mirror_view_and_copy: fence before returning src view"); - return src; } -template +template ::specialize>::value>> auto create_mirror_view_and_copy( const Impl::ViewCtorProp& arg_prop, - const Kokkos::View& src, - std::enable_if_t< - std::is_void::specialize>::value && - !Impl::MirrorViewType< - typename Impl::ViewCtorProp::memory_space, T, - P...>::is_same_memspace>* = nullptr) { - using alloc_prop_input = Impl::ViewCtorProp; - static_assert( - alloc_prop_input::has_memory_space, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must include a memory space!"); - static_assert(!alloc_prop_input::has_pointer, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " - "not include a pointer!"); - static_assert(!alloc_prop_input::allow_padding, - "The view constructor arguments passed to " - "Kokkos::create_mirror_view_and_copy must " - "not explicitly allow padding!"); - using Space = typename alloc_prop_input::memory_space; - using Mirror = typename Impl::MirrorViewType::view_type; - - auto arg_prop_copy = Impl::with_properties_if_unset( - arg_prop, std::string{}, WithoutInitializing, - typename Space::execution_space{}); - - std::string& label = Impl::get_property(arg_prop_copy); - if (label.empty()) label = src.label(); - auto mirror = typename Mirror::non_const_type{arg_prop_copy, src.layout()}; - if constexpr (alloc_prop_input::has_execution_space) { - deep_copy(Impl::get_property(arg_prop_copy), - mirror, src); - } else - deep_copy(mirror, src); - return mirror; -} + const Kokkos::View& src) { + + using alloc_prop_input = Impl::ViewCtorProp; + check_view_ctor_args_create_mirror_and_copy(); + + // get desired space + using space_type = std::conditional_t; + + using mirror_view_type = typename Impl::MirrorViewType; + using nonconst_mirror = typename mirror_view_type::view_type::non_const_type; + + if constexpr(mirror_view_type::is_same){ + // same behavior as deep_copy(src, src) + fence( + "Kokkos::create_mirror_view_and_copy: fence before returning src view"); + return src; + } else { + auto arg_prop_copy = Impl::with_properties_if_unset( + arg_prop, std::string{}, WithoutInitializing, + typename space_type::execution_space{}); + + std::string& label = Impl::get_property(arg_prop_copy); + if (label.empty()) label = src.label(); + + auto mirror = nonconst_mirror{arg_prop_copy, src.layout()};; + deep_copy(mirror, src); + return mirror; + } + } // Previously when using auto here, the intel compiler 19.3 would // sometimes not create a symbol, guessing that it somehow is a combination // of auto and just forwarding arguments (see issue #5196) template ::value>> + typename Enable = std::enable_if_t::value>, + class = std::enable_if_t::specialize>::value>> typename Impl::MirrorViewType::view_type create_mirror_view_and_copy( const Space&, const Kokkos::View& src, - std::string const& name = "", - std::enable_if_t< - std::is_void::specialize>::value>* = - nullptr) { + std::string const& name = "") { return create_mirror_view_and_copy( Kokkos::view_alloc(typename Space::memory_space{}, name), src); } From 571f340cb4c7569134a40d27ee6d368b9d8406b9 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Fri, 8 Mar 2024 15:02:36 +0100 Subject: [PATCH 21/26] correction --- core/src/Kokkos_CopyViews.hpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index cae3191754f..d9dfc486332 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3601,16 +3601,16 @@ void check_view_ctor_args_create_mirror_and_copy() { using alloc_prop_input = Impl::ViewCtorProp; static_assert( - !alloc_prop_input::has_label, - "The view constructor arguments passed to Kokkos::create_mirror[_view] " - "must not include a label!"); + alloc_prop_input::has_memory_space, + "The view constructor arguments passed to " + "Kokkos::create_mirror_view_and_copy must include a memory space!"); static_assert(!alloc_prop_input::has_pointer, "The view constructor arguments passed to " - "Kokkos::create_mirror[_view] must " + "Kokkos::create_mirror_view_and_copy must " "not include a pointer!"); static_assert(!alloc_prop_input::allow_padding, "The view constructor arguments passed to " - "Kokkos::create_mirror[_view] must " + "Kokkos::create_mirror_view_and_copy must " "not explicitly allow padding!"); } @@ -3621,7 +3621,7 @@ auto create_mirror_view_and_copy( const Kokkos::View& src) { using alloc_prop_input = Impl::ViewCtorProp; - check_view_ctor_args_create_mirror_and_copy(); + check_view_ctor_args_create_mirror_and_copy(); // get desired space using space_type = std::conditional_t; using mirror_view_type = typename Impl::MirrorViewType; - using nonconst_mirror = typename mirror_view_type::view_type::non_const_type; if constexpr(mirror_view_type::is_same){ // same behavior as deep_copy(src, src) @@ -3637,6 +3636,8 @@ auto create_mirror_view_and_copy( "Kokkos::create_mirror_view_and_copy: fence before returning src view"); return src; } else { + + using nonconst_mirror = typename mirror_view_type::dest_view_type; auto arg_prop_copy = Impl::with_properties_if_unset( arg_prop, std::string{}, WithoutInitializing, typename space_type::execution_space{}); @@ -3644,8 +3645,8 @@ auto create_mirror_view_and_copy( std::string& label = Impl::get_property(arg_prop_copy); if (label.empty()) label = src.label(); - auto mirror = nonconst_mirror{arg_prop_copy, src.layout()};; - deep_copy(mirror, src); + auto mirror = nonconst_mirror{arg_prop_copy, src.layout()}; + deep_copy(Impl::get_property(arg_prop_copy), mirror, src); return mirror; } } From 978d9d548a30c7c96d2bcb8c4ca82d3aacaae7af Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Tue, 12 Mar 2024 17:11:45 +0100 Subject: [PATCH 22/26] Fix fence being called unexpectedly --- core/src/Kokkos_CopyViews.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index d9dfc486332..0b8710f363d 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3632,8 +3632,10 @@ auto create_mirror_view_and_copy( if constexpr(mirror_view_type::is_same){ // same behavior as deep_copy(src, src) - fence( - "Kokkos::create_mirror_view_and_copy: fence before returning src view"); + if constexpr (!alloc_prop_input::has_execution_space) + fence( + "Kokkos::create_mirror_view_and_copy: fence before returning src view"); + return src; } else { From 7cc7de377c1845c52291e6533cba4b329388c48d Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Tue, 12 Mar 2024 17:12:14 +0100 Subject: [PATCH 23/26] Rationalize which space to pass to MirrorViewType --- core/src/Kokkos_CopyViews.hpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 0b8710f363d..daefe1d3ce0 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3489,7 +3489,7 @@ inline auto create_mirror(const Kokkos::View& src, // get desired space using space_type = std::conditional_t::has_memory_space, typename Impl::ViewCtorProp::memory_space, - DefaultHostExecutionSpace>; + DefaultHostExecutionSpace::memory_space>; using mirror_view_type = typename Impl::MirrorViewType; @@ -3545,7 +3545,7 @@ inline auto create_mirror_view(const Kokkos::View& src, // get desired space using space_type = std::conditional_t::has_memory_space, typename Impl::ViewCtorProp::memory_space, - DefaultHostExecutionSpace>; + DefaultHostExecutionSpace::memory_space>; using mirror_view_type = typename Impl::MirrorViewType; @@ -3626,7 +3626,7 @@ auto create_mirror_view_and_copy( // get desired space using space_type = std::conditional_t; + DefaultHostExecutionSpace::memory_space>; using mirror_view_type = typename Impl::MirrorViewType; @@ -3638,7 +3638,6 @@ auto create_mirror_view_and_copy( return src; } else { - using nonconst_mirror = typename mirror_view_type::dest_view_type; auto arg_prop_copy = Impl::with_properties_if_unset( arg_prop, std::string{}, WithoutInitializing, From f6e9e1a52b6bbbae26de487051eb75c5232138a1 Mon Sep 17 00:00:00 2001 From: thierry antoun Date: Wed, 13 Mar 2024 14:06:11 +0100 Subject: [PATCH 24/26] correction push force --- core/src/Kokkos_CopyViews.hpp | 96 ++--------------------------------- 1 file changed, 4 insertions(+), 92 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index c9f51d38c70..c7263c38764 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3407,24 +3407,6 @@ inline void realloc( namespace Kokkos { namespace Impl { -// Deduce Mirror Types -template -struct MirrorViewType; - -// Dummy mirror view type that contains nothing -template -struct MirrorViewType { - using src_view_type = void; - using memory_space = void; - using array_layout = void; - using data_type = void; - using dest_view_type = void; - using view_type = void; - static constexpr bool is_same_namespace = false; - static constexpr bool is_same_data_type = false; - static constexpr bool is_same = false; -}; - // Actual mirror view type template struct MirrorViewType; @@ -3476,22 +3458,6 @@ struct MirrorViewType { is_same = is_same_memspace && is_same_data_type }; - // If it is the same memory_space and data_type return the existsing view_type - // This will also keep the unmanaged trait if necessary - using view_type = - std::conditional_t; - - // Check whether it is the same data type - enum { - is_same_data_type = - std::is_same::value - }; - - // Shorthand for both memory space and data type check - enum { - is_same = is_same_memspace && is_same_data_type - }; - // If it is the same memory_space and data_type return the existsing view_type // This will also keep the unmanaged trait if necessary using view_type = @@ -3530,47 +3496,33 @@ inline auto create_mirror(const Kokkos::View& src, check_view_ctor_args_create_mirror(); - // append label name with "_mirror" // append label name with "_mirror" auto prop_copy = Impl::with_properties_if_unset( arg_prop, std::string(src.label()).append("_mirror")); return typename mirror_view_type::dest_view_type(prop_copy, src.layout()); - return typename mirror_view_type::dest_view_type(prop_copy, src.layout()); -} + } } // namespace Impl -// view // view template -auto create_mirror(Kokkos::View const& v) { auto create_mirror(Kokkos::View const& v) { return Impl::create_mirror(v, Impl::ViewCtorProp<>{}); } -// view and without initializing // view and without initializing template -auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(wi)); } -// view and space -template ::value>> -auto create_mirror(Space const&, Kokkos::View const& v) { // view and space template ::value>> auto create_mirror(Space const&, Kokkos::View const& v) { return Impl::create_mirror(v, view_alloc(typename Space::memory_space{})); } -// view, space and without initializing -template ::value>> -auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, - Kokkos::View const& v) { - return Impl::create_mirror(v, view_alloc(typename Space::memory_space{}, wi)); // view, space and without initializing template ::value>> auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, @@ -3579,10 +3531,8 @@ auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&, } // view and view constructor properties -// view and view constructor properties -template -auto create_mirror(Impl::ViewCtorProp const& arg_prop, - Kokkos::View const& v) { +template ::specialize>::value>> auto create_mirror(Impl::ViewCtorProp const& arg_prop, Kokkos::View const& v) { return Impl::create_mirror(v, arg_prop); @@ -3612,39 +3562,20 @@ inline auto create_mirror_view(const Kokkos::View& src, } } // namespace Impl -// view // view template auto create_mirror_view(const Kokkos::View& src) { return Impl::create_mirror_view(src, Impl::ViewCtorProp<>{}); } -// view and without initializing -auto create_mirror_view(const Kokkos::View& src) { - return Impl::create_mirror_view(src, Impl::ViewCtorProp<>{}); -} - // view and without initializing template auto create_mirror_view( Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& src) { return Impl::create_mirror_view(src, view_alloc(wi)); -auto create_mirror_view( - Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View const& src) { - return Impl::create_mirror_view(src, view_alloc(wi)); -} - -// viel and space -template ::value>> -auto create_mirror_view( - const Space&, const Kokkos::View& src) { - return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space{})); } -// view, space and without initializing -template ::value>> -auto create_mirror_view( -// viel and space +// view and space template ::value>> auto create_mirror_view( const Space&, const Kokkos::View& src) { @@ -3656,13 +3587,10 @@ template const& src) { - Kokkos::View const& src) { return Impl::create_mirror_view( src, view_alloc(typename Space::memory_space{}, wi)); - src, view_alloc(typename Space::memory_space{}, wi)); } -// view and view constructor properties // view and view constructor properties template auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, @@ -3670,13 +3598,10 @@ auto create_mirror_view(const Impl::ViewCtorProp& arg_prop, return Impl::create_mirror_view(v, arg_prop); } -template -void check_view_ctor_args_create_mirror_and_copy() { template void check_view_ctor_args_create_mirror_and_copy() { using alloc_prop_input = Impl::ViewCtorProp; - static_assert( alloc_prop_input::has_memory_space, "The view constructor arguments passed to " @@ -3691,8 +3616,6 @@ void check_view_ctor_args_create_mirror_and_copy() { "not explicitly allow padding!"); } -template ::specialize>::value>> template ::specialize>::value>> auto create_mirror_view_and_copy( @@ -3730,14 +3653,6 @@ auto create_mirror_view_and_copy( return mirror; } } - std::string& label = Impl::get_property(arg_prop_copy); - if (label.empty()) label = src.label(); - - auto mirror = nonconst_mirror{arg_prop_copy, src.layout()}; - deep_copy(Impl::get_property(arg_prop_copy), mirror, src); - return mirror; - } - } // Previously when using auto here, the intel compiler 19.3 would // sometimes not create a symbol, guessing that it somehow is a combination @@ -3745,13 +3660,10 @@ auto create_mirror_view_and_copy( template ::value>, class = std::enable_if_t::specialize>::value>> - typename Enable = std::enable_if_t::value>, - class = std::enable_if_t::specialize>::value>> typename Impl::MirrorViewType::view_type create_mirror_view_and_copy( const Space&, const Kokkos::View& src, std::string const& name = "") { - std::string const& name = "") { return create_mirror_view_and_copy( Kokkos::view_alloc(typename Space::memory_space{}, name), src); } From 0de31db8bf00e44d1ff2bde6d028d0cfcf4c068e Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 14 Mar 2024 16:21:32 +0100 Subject: [PATCH 25/26] Make MirrorViewType similar to View::HostMirror --- core/src/Kokkos_CopyViews.hpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index c7263c38764..6f9b69d4b8f 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3430,15 +3430,29 @@ template struct MirrorViewType { // The incoming view_type using src_view_type = typename Kokkos::View; + // The memory space for the mirror view using memory_space = typename Space::memory_space; + + // The execution space for the mirror view + using execution_space = typename Space::execution_space; + // The array_layout using array_layout = typename src_view_type::array_layout; + // The data type (we probably want it non-const since otherwise we can't even - // deep_copy to it. + // deep_copy to it) using data_type = typename src_view_type::non_const_data_type; + + // The hooks policy + using hooks_policy = typename src_view_type::traits::hooks_policy; + // The destination view type if it is not the same memory space - using dest_view_type = Kokkos::View; + // If the memory space is the host space, use View::HostMirror + using dest_view_type = std::conditional_t< + std::is_same_v, + typename Kokkos::View::HostMirror, + typename Kokkos::View, hooks_policy>>; // Check whether it is the same memory space From 3f04e05ee056ba49c98e5479130b410d64ec7f38 Mon Sep 17 00:00:00 2001 From: Paul Zehner Date: Thu, 14 Mar 2024 20:25:13 +0100 Subject: [PATCH 26/26] Compare memory_space instead of execution_space --- core/src/Kokkos_CopyViews.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/Kokkos_CopyViews.hpp b/core/src/Kokkos_CopyViews.hpp index 6f9b69d4b8f..236d3ed7a51 100644 --- a/core/src/Kokkos_CopyViews.hpp +++ b/core/src/Kokkos_CopyViews.hpp @@ -3448,9 +3448,9 @@ struct MirrorViewType { using hooks_policy = typename src_view_type::traits::hooks_policy; // The destination view type if it is not the same memory space - // If the memory space is the host space, use View::HostMirror + // If the memory space is the host memory space, use View::HostMirror using dest_view_type = std::conditional_t< - std::is_same_v, + std::is_same_v, typename Kokkos::View::HostMirror, typename Kokkos::View, hooks_policy>>;