Skip to content

Commit

Permalink
Refactor: Remove unnecessary Mirror*Types structs (kokkos#7339)
Browse files Browse the repository at this point in the history
* Remove Mirror*Types

* Always use destination view type for create_mirror for DynRankView
  • Loading branch information
pzehner authored Oct 7, 2024
1 parent d188dd5 commit fdb75eb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 68 deletions.
24 changes: 2 additions & 22 deletions containers/src/Kokkos_DynRankView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1361,26 +1361,6 @@ struct MirrorDRViewType {
std::conditional_t<is_same_memspace, src_view_type, dest_view_type>;
};

template <class Space, class T, class... P>
struct MirrorDRVType {
// The incoming view_type
using src_view_type = typename Kokkos::DynRankView<T, P...>;
// 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_v<memory_space, typename src_view_type::memory_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.
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::DynRankView<data_type, array_layout, Space>;
};

} // namespace Impl

namespace Impl {
Expand All @@ -1397,9 +1377,9 @@ inline auto create_mirror(const DynRankView<T, P...>& src,
arg_prop, std::string(src.label()).append("_mirror"));

if constexpr (Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space) {
using dst_type = typename Impl::MirrorDRVType<
using dst_type = typename Impl::MirrorDRViewType<
typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
P...>::view_type;
P...>::dest_view_type;
return dst_type(prop_copy,
Impl::reconstructLayout(src.layout(), src.rank()));
} else {
Expand Down
31 changes: 6 additions & 25 deletions containers/src/Kokkos_OffsetView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1284,27 +1284,6 @@ struct MirrorOffsetViewType {
std::conditional_t<is_same_memspace, src_view_type, dest_view_type>;
};

template <class Space, class T, class... P>
struct MirrorOffsetType {
// The incoming view_type
using src_view_type = typename Kokkos::Experimental::OffsetView<T, P...>;
// 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_v<memory_space, typename src_view_type::memory_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.)
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::Experimental::OffsetView<data_type, array_layout, Space>;
};

} // namespace Impl

namespace Impl {
Expand All @@ -1323,10 +1302,12 @@ inline auto create_mirror(const Kokkos::Experimental::OffsetView<T, P...>& src,
auto prop_copy = Impl::with_properties_if_unset(
arg_prop, std::string(src.label()).append("_mirror"));

return typename Kokkos::Impl::MirrorOffsetType<Space, T, P...>::view_type(
prop_copy, src.layout(),
{src.begin(0), src.begin(1), src.begin(2), src.begin(3), src.begin(4),
src.begin(5), src.begin(6), src.begin(7)});
return typename Kokkos::Impl::MirrorOffsetViewType<
Space, T, P...>::dest_view_type(prop_copy, src.layout(),
{src.begin(0), src.begin(1),
src.begin(2), src.begin(3),
src.begin(4), src.begin(5),
src.begin(6), src.begin(7)});
} else {
return typename Kokkos::Experimental::OffsetView<T, P...>::HostMirror(
Kokkos::create_mirror(arg_prop, src.view()), src.begins());
Expand Down
22 changes: 1 addition & 21 deletions core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3441,26 +3441,6 @@ struct MirrorViewType {
std::conditional_t<is_same_memspace, src_view_type, dest_view_type>;
};

template <class Space, class T, class... P>
struct MirrorType {
// The incoming view_type
using src_view_type = typename Kokkos::View<T, P...>;
// 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_v<memory_space, typename src_view_type::memory_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.
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<data_type, array_layout, Space>;
};

// collection of static asserts for create_mirror and create_mirror_view
template <class... ViewCtorArgs>
void check_view_ctor_args_create_mirror() {
Expand Down Expand Up @@ -3494,7 +3474,7 @@ inline auto create_mirror(const Kokkos::View<T, P...>& src,
if constexpr (Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space) {
using memory_space = typename decltype(prop_copy)::memory_space;
using dst_type =
typename Impl::MirrorType<memory_space, T, P...>::view_type;
typename Impl::MirrorViewType<memory_space, T, P...>::dest_view_type;
return dst_type(prop_copy, src.layout());
} else {
using dst_type = typename View<T, P...>::HostMirror;
Expand Down

0 comments on commit fdb75eb

Please sign in to comment.