Skip to content

Commit

Permalink
Enforce create_mirror restrictions w.r.t. ViewCtorArgs on all variants
Browse files Browse the repository at this point in the history
  • Loading branch information
masterleinad committed Jul 25, 2023
1 parent 4d1c6c3 commit 3a255d1
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions core/src/Kokkos_CopyViews.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3437,27 +3437,33 @@ struct MirrorType {
using view_type = Kokkos::View<data_type, array_layout, Space>;
};

template <class... ViewCtorArgs>
void check_view_ctor_args_create_mirror() {
using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;

static_assert(
!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] must "
"not include a pointer!");
static_assert(!alloc_prop_input::allow_padding,
"The view constructor arguments passed to "
"Kokkos::create_mirror[_view] must "
"not explicitly allow padding!");
}

template <class T, class... P, class... ViewCtorArgs>
inline std::enable_if_t<!Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space,
typename Kokkos::View<T, P...>::HostMirror>
create_mirror(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
using src_type = View<T, P...>;
using dst_type = typename src_type::HostMirror;
using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;
using src_type = View<T, P...>;
using dst_type = typename src_type::HostMirror;

static_assert(
!alloc_prop_input::has_label,
"The view constructor arguments passed to Kokkos::create_mirror "
"must not include a label!");
static_assert(
!alloc_prop_input::has_pointer,
"The view constructor arguments passed to Kokkos::create_mirror must "
"not include a pointer!");
static_assert(
!alloc_prop_input::allow_padding,
"The view constructor arguments passed to Kokkos::create_mirror must "
"not explicitly allow padding!");
check_view_ctor_args_create_mirror<ViewCtorArgs...>();

auto prop_copy = Impl::with_properties_if_unset(
arg_prop, std::string(src.label()).append("_mirror"));
Expand All @@ -3471,20 +3477,7 @@ template <class T, class... P, class... ViewCtorArgs,
Impl::ViewCtorProp<ViewCtorArgs...>::has_memory_space>>
auto create_mirror(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>& arg_prop) {
using alloc_prop_input = Impl::ViewCtorProp<ViewCtorArgs...>;

static_assert(
!alloc_prop_input::has_label,
"The view constructor arguments passed to Kokkos::create_mirror "
"must not include a label!");
static_assert(
!alloc_prop_input::has_pointer,
"The view constructor arguments passed to Kokkos::create_mirror must "
"not include a pointer!");
static_assert(
!alloc_prop_input::allow_padding,
"The view constructor arguments passed to Kokkos::create_mirror must "
"not explicitly allow padding!");
check_view_ctor_args_create_mirror<ViewCtorArgs...>();

auto prop_copy = Impl::with_properties_if_unset(
arg_prop, std::string(src.label()).append("_mirror"));
Expand Down Expand Up @@ -3560,6 +3553,7 @@ inline std::enable_if_t<
typename Kokkos::View<T, P...>::HostMirror>
create_mirror_view(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>&) {
check_view_ctor_args_create_mirror<ViewCtorArgs...>();
return src;
}

Expand Down Expand Up @@ -3590,6 +3584,7 @@ std::enable_if_t<Impl::MirrorViewType<
T, P...>::view_type>
create_mirror_view(const Kokkos::View<T, P...>& src,
const Impl::ViewCtorProp<ViewCtorArgs...>&) {
check_view_ctor_args_create_mirror<ViewCtorArgs...>();
return src;
}

Expand Down

0 comments on commit 3a255d1

Please sign in to comment.