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
Changes from 7 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
103 changes: 29 additions & 74 deletions core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3425,7 +3425,7 @@ struct MirrorViewType {
// 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 dest_view_type = Kokkos::View<data_type, array_layout, Space>;
using dest_view_type = Kokkos::View<data_type, array_layout, memory_space>;
pzehner marked this conversation as resolved.
Show resolved Hide resolved
// If it is the same memory_space return the existsing view_type
// This will also keep the unmanaged trait if necessary
using view_type =
Expand All @@ -3449,7 +3449,7 @@ struct MirrorType {
// 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>;
using view_type = Kokkos::View<data_type, array_layout, memory_space>;
};

template <class... ViewCtorArgs>
Expand All @@ -3470,7 +3470,8 @@ void check_view_ctor_args_create_mirror() {
"not explicitly allow padding!");
}

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>>
auto create_mirror(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
check_view_ctor_args_create_mirror<ViewCtorArgs...>();
Expand All @@ -3491,60 +3492,44 @@ auto create_mirror(const Kokkos::View<T, P...>& src,
} // namespace Impl

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<>{});
}

// without_initializing
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,
auto create_mirror(Kokkos::Impl::WithoutInitializing_t wi,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror(src, view_alloc(wi));
}

// 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>>
// view_constructor_args
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);
}

// space & without_initializing
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&,
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));
}

namespace Impl {

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>>
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 @@ -3573,70 +3558,40 @@ auto create_mirror_view(const Kokkos::View<T, P...>& src,
} // namespace Impl

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 Kokkos::Impl::create_mirror_view(src, view_alloc());
}

// without_initializing
template <class T, class... P>
typename Kokkos::View<T, P...>::HostMirror create_mirror_view(
auto create_mirror_view(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be sure that auto works properly on all platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should run all the different backends with the minimum supported compilers. So far, we could build for Serial, CUDA and SYCL (latest versions of compilers, mostly).

Kokkos::Impl::WithoutInitializing_t wi, Kokkos::View<T, P...> const& src) {
return Impl::create_mirror_view(src, view_alloc(wi));
return Kokkos::Impl::create_mirror_view(src, view_alloc(wi));
}

// FIXME_C++17 Improve SFINAE here.
// space
pzehner marked this conversation as resolved.
Show resolved Hide resolved
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 Kokkos::Impl::create_mirror_view(src, view_alloc(typename Space::memory_space()));
}

//space & without_initializing
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(
auto create_mirror_view(
Kokkos::Impl::WithoutInitializing_t wi, Space const&,
Kokkos::View<T, P...> const& src) {
return Impl::create_mirror_view(
return Kokkos::Impl::create_mirror_view(
pzehner marked this conversation as resolved.
Show resolved Hide resolved
src, view_alloc(typename Space::memory_space{}, wi));
}

// view_constructor_args
template <class T, class... P, class... ViewCtorArgs>
auto create_mirror_view(const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop,
const Kokkos::View<T, P...>& src) {
return Impl::create_mirror_view(src, arg_prop);
return Kokkos::Impl::create_mirror_view(src, arg_prop);
}

namespace Impl {
Expand Down