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

Move intelligence to Impl::create_mirror* #7

Open
wants to merge 20 commits into
base: refactor/create-mirror/constexpr
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
91d2707
Move intelligence from the create_mirror overloads to the Impl::creat…
thierryantoun Mar 21, 2024
d1bdc2e
Adding comments on create_mirror overloads
thierryantoun Mar 21, 2024
4adb813
Move intelligence from create_mirror_view overloads to Impl::create_m…
thierryantoun Mar 21, 2024
b3c30bc
Fix incorrect return for create_mirror_view
thierryantoun Mar 21, 2024
cf88dc8
Restrict MirrorViewType and MirrorType to only use a memory space
pzehner Mar 21, 2024
bb82074
Merge branch 'refactor/create-mirror/constexpr' into refactor/create-…
pzehner Mar 21, 2024
5e4f506
Check view is not specialized
pzehner Mar 22, 2024
4a9d02d
Put more explicit comments for functions
pzehner Mar 29, 2024
8613fb5
Reduce number of changes for namespaces in returns
pzehner Mar 29, 2024
cf56eef
Reduce more differences
pzehner Mar 29, 2024
353091f
Revert Space in Mirror*Type and make TestViewAPI.hpp::TestViewMirror:…
pzehner Mar 29, 2024
5d4cdc7
Fix the CTAD error
pzehner Apr 2, 2024
33a7f16
Merge branch 'refactor/create-mirror/constexpr' into refactor/create-…
pzehner Apr 4, 2024
b1e495f
Format with clang
thierryantoun Apr 4, 2024
2252860
Format Document
thierryantoun Apr 4, 2024
cd87ac0
Merge branch 'refactor/create-mirror/constexpr' into refactor/create-…
pzehner Apr 16, 2024
30b3d28
Merge branch 'refactor/create-mirror/constexpr' into refactor/create-…
pzehner Apr 17, 2024
2c9033a
Move intelligence for offset view create_mirror*
pzehner Apr 17, 2024
bbfd13f
Move intelligence for dynamic view create_mirror*
pzehner Apr 17, 2024
4e0f545
Move intelligence for dynamic rank view create_mirror*
pzehner Apr 17, 2024
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
100 changes: 22 additions & 78 deletions containers/src/Kokkos_DynRankView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T, class... P, class... ViewCtorArgs>
template <class T, class... P, class... ViewCtorArgs,
class Enable = std::enable_if_t<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
inline auto create_mirror(
const DynRankView<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
Expand Down Expand Up @@ -1984,63 +1986,39 @@ inline auto create_mirror(

// Create a mirror in host space
template <class T, class... P>
inline typename DynRankView<T, P...>::HostMirror create_mirror(
const DynRankView<T, P...>& src,
std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
void>::value>* = nullptr) {
return Impl::create_mirror(src, Kokkos::Impl::ViewCtorProp<>{});
inline auto create_mirror(
const DynRankView<T, P...>& src) {
return Impl::create_mirror(src, Kokkos::view_alloc());
}

template <class T, class... P>
inline typename DynRankView<T, P...>::HostMirror create_mirror(
Kokkos::Impl::WithoutInitializing_t wi, const DynRankView<T, P...>& src,
std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
void>::value>* = nullptr) {
inline auto create_mirror(
Kokkos::Impl::WithoutInitializing_t wi, const DynRankView<T, P...>& src) {
return Impl::create_mirror(src, Kokkos::view_alloc(wi));
}

template <class T, class... P, class... ViewCtorArgs>
inline typename DynRankView<T, P...>::HostMirror create_mirror(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
const DynRankView<T, P...>& src,
std::enable_if_t<
std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* = nullptr) {
return Impl::create_mirror(src, arg_prop);
}

// Create a mirror in a new space
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<
Kokkos::is_space<Space>::value &&
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
typename Impl::MirrorDRVType<Space, T, P...>::view_type create_mirror(
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
auto create_mirror(
const Space&, const Kokkos::DynRankView<T, P...>& src) {
return Impl::create_mirror(
src, Kokkos::view_alloc(typename Space::memory_space{}));
}

template <class Space, class T, class... P>
typename Impl::MirrorDRVType<Space, T, P...>::view_type create_mirror(
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
auto create_mirror(
Kokkos::Impl::WithoutInitializing_t wi, const Space&,
const Kokkos::DynRankView<T, P...>& src,
std::enable_if_t<std::is_same<typename ViewTraits<T, P...>::specialize,
void>::value>* = nullptr) {
const Kokkos::DynRankView<T, P...>& src) {
return Impl::create_mirror(
src, Kokkos::view_alloc(wi, typename Space::memory_space{}));
}

template <class T, class... P, class... ViewCtorArgs>
inline auto create_mirror(
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
const DynRankView<T, P...>& src,
std::enable_if_t<
std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>* = nullptr) {
using ReturnType = typename Impl::MirrorDRVType<
typename Impl::ViewCtorProp<ViewCtorArgs...>::memory_space, T,
P...>::view_type;
return ReturnType{Impl::create_mirror(src, arg_prop)};
const DynRankView<T, P...>& src) {
return Impl::create_mirror(src, arg_prop);
}

namespace Impl {
Expand Down Expand Up @@ -2081,28 +2059,8 @@ inline auto create_mirror_view(const DynRankView<T, P...>& src,

// Create a mirror view in host space
template <class T, class... P>
inline std::enable_if_t<
(std::is_same<
typename DynRankView<T, P...>::memory_space,
typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
std::is_same<typename DynRankView<T, P...>::data_type,
typename DynRankView<T, P...>::HostMirror::data_type>::value),
typename DynRankView<T, P...>::HostMirror>
create_mirror_view(const Kokkos::DynRankView<T, P...>& src) {
return src;
}

template <class T, class... P>
inline std::enable_if_t<
!(std::is_same<
typename DynRankView<T, P...>::memory_space,
typename DynRankView<T, P...>::HostMirror::memory_space>::value &&
std::is_same<
typename DynRankView<T, P...>::data_type,
typename DynRankView<T, P...>::HostMirror::data_type>::value),
typename DynRankView<T, P...>::HostMirror>
create_mirror_view(const Kokkos::DynRankView<T, P...>& src) {
return Kokkos::create_mirror(src);
inline auto create_mirror_view(const Kokkos::DynRankView<T, P...>& src) {
return Impl::create_mirror_view(src, Kokkos::view_alloc());
}

template <class T, class... P>
Expand All @@ -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 <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline typename Impl::MirrorDRViewType<Space, T, P...>::view_type
create_mirror_view(
const Space&, const Kokkos::DynRankView<T, P...>& src,
std::enable_if_t<
Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>* = nullptr) {
return src;
inline auto create_mirror_view(
const Space&, const Kokkos::DynRankView<T, P...>& src) {
return Impl::create_mirror_view(src, Kokkos::view_alloc(typename Space::memory_space()));
}

// FIXME_C++17 Improve SFINAE here.
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline typename Impl::MirrorDRViewType<Space, T, P...>::view_type
create_mirror_view(
const Space& space, const Kokkos::DynRankView<T, P...>& src,
std::enable_if_t<
!Impl::MirrorDRViewType<Space, T, P...>::is_same_memspace>* = nullptr) {
return Kokkos::create_mirror(space, src);
}

template <class Space, class T, class... P>
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline auto create_mirror_view(Kokkos::Impl::WithoutInitializing_t wi,
const Space&,
const Kokkos::DynRankView<T, P...>& src) {
Expand Down
14 changes: 8 additions & 6 deletions containers/src/Kokkos_DynamicView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class Space, class T, class... P>
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline auto create_mirror(
const Space&, const Kokkos::Experimental::DynamicView<T, P...>& src) {
return Impl::create_mirror(
src, Kokkos::view_alloc(typename Space::memory_space{}));
}

template <class Space, class T, class... P>
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
typename Kokkos::Impl::MirrorDynamicViewType<Space, T, P...>::view_type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi, const Space&,
const Kokkos::Experimental::DynamicView<T, P...>& src) {
Expand Down Expand Up @@ -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 <class Space, class T, class... P>
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline auto create_mirror_view(
const Space&, const Kokkos::Experimental::DynamicView<T, P...>& src) {
return Impl::create_mirror_view(src,
view_alloc(typename Space::memory_space{}));
}

template <class Space, class T, class... P>
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline auto create_mirror_view(
Kokkos::Impl::WithoutInitializing_t wi, const Space&,
const Kokkos::Experimental::DynamicView<T, P...>& src) {
Expand Down
6 changes: 4 additions & 2 deletions containers/src/Kokkos_OffsetView.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,8 @@ inline auto create_mirror(
src, Kokkos::view_alloc(typename Space::memory_space{}));
}

template <class Space, class T, class... P>
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
typename Kokkos::Impl::MirrorOffsetType<Space, T, P...>::view_type
create_mirror(Kokkos::Impl::WithoutInitializing_t wi, const Space&,
const Kokkos::Experimental::OffsetView<T, P...>& src) {
Expand Down Expand Up @@ -1983,7 +1984,8 @@ inline auto create_mirror_view(
src, Kokkos::view_alloc(typename Space::memory_space{}));
}

template <class Space, class T, class... P>
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
inline auto create_mirror_view(
Kokkos::Impl::WithoutInitializing_t wi, const Space&,
const Kokkos::Experimental::OffsetView<T, P...>& src) {
Expand Down
108 changes: 34 additions & 74 deletions core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <class T, class... P, class... ViewCtorArgs>
template <class T, class... P, class... ViewCtorArgs,
class = std::enable_if<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
inline auto create_mirror(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
check_view_ctor_args_create_mirror<ViewCtorArgs...>();
Expand All @@ -3494,54 +3496,39 @@ inline auto create_mirror(const Kokkos::View<T, P...>& src,
}
} // namespace Impl

// public interface
template <class T, class... P>
std::enable_if_t<std::is_void<typename ViewTraits<T, P...>::specialize>::value,
typename Kokkos::View<T, P...>::HostMirror>
create_mirror(Kokkos::View<T, P...> const& src) {
auto create_mirror(Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, Impl::ViewCtorProp<>{});
}

// public interface that accepts a without initializing flag
template <class T, class... P>
std::enable_if_t<std::is_void<typename ViewTraits<T, P...>::specialize>::value,
typename Kokkos::View<T, P...>::HostMirror>
create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
Kokkos::View<T, P...> const& src) {
auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, view_alloc(wi));
}

// public interface that accepts a space
template <class Space, class T, class... P,
typename Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
std::enable_if_t<std::is_void<typename ViewTraits<T, P...>::specialize>::value,
typename Impl::MirrorType<Space, T, P...>::view_type>
create_mirror(Space const&, Kokkos::View<T, P...> const& src) {
auto create_mirror(Space const&, Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, view_alloc(typename Space::memory_space{}));
}

template <class T, class... P, class... ViewCtorArgs,
typename Enable = std::enable_if_t<
std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
// 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) {
return Impl::create_mirror(src, arg_prop);
}

template <class T, class... P, class... ViewCtorArgs>
std::enable_if_t<
std::is_void<typename ViewTraits<T, P...>::specialize>::value &&
!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space,
typename Kokkos::View<T, P...>::HostMirror>
create_mirror(Impl::ViewCtorProp<ViewCtorArgs...> const& arg_prop,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, arg_prop);
}

// 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>>
std::enable_if_t<std::is_void<typename ViewTraits<T, P...>::specialize>::value,
typename Impl::MirrorType<Space, T, P...>::view_type>
create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> const& src) {
auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src,
view_alloc(typename Space::memory_space{}, wi));
}
Expand All @@ -3551,7 +3538,9 @@ namespace Impl {
// create a mirror view
// private interface that accepts arbitrary view constructor args passed by a
// view_alloc
template <class T, class... P, class... ViewCtorArgs>
template <class T, class... P, class... ViewCtorArgs,
class = std::enable_if<
std::is_void<typename ViewTraits<T, P...>::specialize>::value>>
inline 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 @@ -3579,67 +3568,38 @@ inline auto create_mirror_view(const Kokkos::View<T, P...>& src,
}
} // namespace Impl

// public interface
template <class T, class... P>
std::enable_if_t<
std::is_same<
typename Kokkos::View<T, P...>::memory_space,
typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
std::is_same<
typename Kokkos::View<T, P...>::data_type,
typename Kokkos::View<T, P...>::HostMirror::data_type>::value,
typename Kokkos::View<T, P...>::HostMirror>
create_mirror_view(const Kokkos::View<T, P...>& src) {
return src;
}

template <class T, class... P>
std::enable_if_t<
!(std::is_same<
typename Kokkos::View<T, P...>::memory_space,
typename Kokkos::View<T, P...>::HostMirror::memory_space>::value &&
std::is_same<
typename Kokkos::View<T, P...>::data_type,
typename Kokkos::View<T, P...>::HostMirror::data_type>::value),
typename Kokkos::View<T, P...>::HostMirror>
create_mirror_view(const Kokkos::View<T, P...>& src) {
return Kokkos::create_mirror(src);
auto create_mirror_view(const Kokkos::View<T, P...>& src) {
return Impl::create_mirror_view(src, view_alloc());
}

// public interface that accepts a without initializing flag
template <class T, class... P>
typename Kokkos::View<T, P...>::HostMirror 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));
}

// FIXME_C++17 Improve SFINAE here.
// public interface that accepts a space
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
const Space&, const Kokkos::View<T, P...>& src,
std::enable_if_t<Impl::MirrorViewType<Space, T, P...>::is_same_memspace>* =
nullptr) {
return src;
}

// FIXME_C++17 Improve SFINAE here.
template <class Space, class T, class... P,
class Enable = std::enable_if_t<Kokkos::is_space<Space>::value>>
typename Impl::MirrorViewType<Space, T, P...>::view_type create_mirror_view(
const Space& space, const Kokkos::View<T, P...>& src,
std::enable_if_t<!Impl::MirrorViewType<Space, T, P...>::is_same_memspace>* =
nullptr) {
return Kokkos::create_mirror(space, src);
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>>
typename Impl::MirrorViewType<Space, T, P...>::view_type 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
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
Loading