Skip to content

Commit

Permalink
New View: fix up more ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
crtrott committed Jul 11, 2024
1 parent d0fb3ba commit 3462bd7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
23 changes: 12 additions & 11 deletions core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,21 +510,12 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
template<class ... Args>
View(pointer_type ptr, Args ... args)
: base_t(Kokkos::view_wrap(ptr), typename mdspan_type::mapping_type(typename mdspan_type::extents_type{args...})) {}
#if 0
// Wrap memory according to properties and array layout
template <class... P>
explicit KOKKOS_INLINE_FUNCTION View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer,
typename traits::array_layout> const& arg_layout)
: base_t(arg_prop, arg_layout) {}

// Simple dimension-only layout
// Constructor which allows always 8 sizes should be deprecated
template <class... P>
explicit inline View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<!Impl::ViewCtorProp<P...>::has_pointer, size_t> const
arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N0 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N1 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N2 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
const size_t arg_N3 = KOKKOS_IMPL_CTOR_DEFAULT_ARG,
Expand All @@ -540,6 +531,16 @@ class View : public Impl::BasicViewFromTraits<DataType, Properties...>::type {
"overload taking a layout object instead.");
}

#if 0
// Wrap memory according to properties and array layout
template <class... P>
explicit KOKKOS_INLINE_FUNCTION View(
const Impl::ViewCtorProp<P...>& arg_prop,
std::enable_if_t<Impl::ViewCtorProp<P...>::has_pointer,
typename traits::array_layout> const& arg_layout)
: base_t(arg_prop, arg_layout) {}


template <class... P>
explicit KOKKOS_INLINE_FUNCTION View(
const Impl::ViewCtorProp<P...>& arg_prop,
Expand Down
16 changes: 16 additions & 0 deletions core/src/View/MDSpan/Kokkos_MDSpan_Accessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ class ReferenceCountedAccessor {
OtherElementType (*)[], element_type (*)[]>>>
constexpr ReferenceCountedAccessor(
const ReferenceCountedAccessor<OtherElementType, MemorySpace>&) {}

template <class OtherElementType,
class = std::enable_if_t<std::is_convertible_v<
OtherElementType (*)[], element_type (*)[]>>>
constexpr ReferenceCountedAccessor(
const default_accessor<OtherElementType>&) {}

operator default_accessor<element_type>() const { return {}; }

constexpr reference access(data_handle_type p, size_t i) const {
return p.get()[i];
Expand Down Expand Up @@ -371,6 +379,14 @@ class ReferenceCountedAccessor<ElementType, AnonymousSpace> {
constexpr ReferenceCountedAccessor(
const ReferenceCountedAccessor<OtherElementType, OtherSpace>&) {}

template <class OtherElementType,
class = std::enable_if_t<std::is_convertible_v<
OtherElementType (*)[], element_type (*)[]>>>
constexpr ReferenceCountedAccessor(
const default_accessor<OtherElementType>&) {}

operator default_accessor<element_type>() const { return {}; }

constexpr reference access(data_handle_type p, size_t i) const {
return p.get()[i];
}
Expand Down
2 changes: 2 additions & 0 deletions core/unit_test/default/TestDefaultDeviceDevelop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ TEST(defaultdevicetype, development_test) {
auto prop = Kokkos::view_alloc("C");
Kokkos::View<float*, Kokkos::LayoutRight> c(prop, Kokkos::LayoutRight(5));
Kokkos::View<int*> b_um(b.data(), 5);
Kokkos::View<int*, Kokkos::MemoryTraits<Kokkos::Atomic>> b_atomic(b);
Kokkos::View<int*, Kokkos::MemoryTraits<Kokkos::Unmanaged>> b_unmanaged(b);
Kokkos::mdspan<int, Kokkos::dextents<int, 1>> mds(b.data(), 5);
auto sub_a = Kokkos::submdspan(mds, std::pair{1,3});
auto sub_b = Kokkos::submdspan(mds, std::array{1,3});
Expand Down

0 comments on commit 3462bd7

Please sign in to comment.