Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove MirrorType structure #8

Open
wants to merge 5 commits into
base: refactor/create-mirror/move_intelligence
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 31 additions & 42 deletions core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3432,26 +3432,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<memory_space, typename src_view_type::memory_space>::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<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 All @@ -3471,9 +3451,11 @@ void check_view_ctor_args_create_mirror() {
"not explicitly allow padding!");
}

// private interface that accepts arbitrary view constructor args passed by a view_alloc
// private interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class T, class... P, class... ViewCtorArgs,
class = std::enable_if<std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
class = std::enable_if<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
auto create_mirror(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
check_view_ctor_args_create_mirror<ViewCtorArgs...>();
Expand All @@ -3484,7 +3466,7 @@ 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 All @@ -3502,7 +3484,7 @@ auto create_mirror(Kokkos::View<T, P...> const& src) {
// public interface that accepts a without initializing flag
template <class T, class... P>
auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
Kokkos::View<T, P...> const& src) {
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, view_alloc(wi));
}

Expand All @@ -3513,7 +3495,8 @@ auto create_mirror(Space const&, Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, view_alloc(typename Space::memory_space{}));
}

// public interface that accepts arbitrary view constructor args passed by a view_alloc
// public interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class T, class... P, class... ViewCtorArgs>
auto create_mirror(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
Kokkos::View<T, P...> const& src) {
Expand All @@ -3524,16 +3507,18 @@ auto create_mirror(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> const& src) {
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src,
view_alloc(typename Space::memory_space{}, wi));
}

namespace Impl {

// private interface that accepts arbitrary view constructor args passed by a view_alloc
// private interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class T, class... P, class... ViewCtorArgs,
class = std::enable_if<std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
class = std::enable_if<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
auto create_mirror_view(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
if constexpr (!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space) {
Expand Down Expand Up @@ -3569,30 +3554,30 @@ auto create_mirror_view(const Kokkos::View<T, P...>& src) {

// public interface that accepts a without initializing flag
template <class T, class... P>
auto create_mirror_view(
Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View<T, P...> const& src) {
auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror_view(src, view_alloc(wi));
}

// public interface that accepts a space
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
auto create_mirror_view(
const Space& space, const Kokkos::View<T, P...>& src) {
return Impl::create_mirror_view(src, view_alloc(typename Space::memory_space()));
auto create_mirror_view(const Space& space, const Kokkos::View<T, P...>& 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 <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
auto create_mirror_view(
Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> const& src) {
auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> 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
// public interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class T, class... P, class... ViewCtorArgs>
auto create_mirror_view(const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
const Kokkos::View<T, P...>& src) {
Expand Down Expand Up @@ -3620,23 +3605,27 @@ void check_view_ctor_args_create_mirror_view_and_copy() {
"not explicitly allow padding!");
}

} // namespace Impl
} // namespace Impl

// public interface that accepts arbitrary view constructor args passed by a view_alloc
// public interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class... ViewCtorArgs, class T, class... P,
class = std::enable_if<std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
class = std::enable_if<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
auto create_mirror_view_and_copy(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
const Kokkos::View<T, P...>& src) {
using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;

Impl::check_view_ctor_args_create_mirror_view_and_copy<ViewCtorArgs...>();

if constexpr (Impl::MirrorViewType<typename alloc_prop_input::memory_space, T, P...>::is_same_memspace) {
if constexpr (Impl::MirrorViewType<typename alloc_prop_input::memory_space, T,
P...>::is_same_memspace) {
// same behavior as deep_copy(src, src)
if constexpr (!alloc_prop_input::has_execution_space)
fence(
"Kokkos::create_mirror_view_and_copy: fence before returning src view");
"Kokkos::create_mirror_view_and_copy: fence before returning src "
"view");
return src;
} else {
using Space = typename alloc_prop_input::memory_space;
Expand Down