Skip to content

Commit

Permalink
kokkos#6805: move MDSpan impl from Kokkos::Experimental::Impl->Kokkos…
Browse files Browse the repository at this point in the history
…::Impl
  • Loading branch information
nmm0 committed May 15, 2024
1 parent 9ac9c63 commit dafaf2d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
28 changes: 14 additions & 14 deletions core/src/Kokkos_View.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ struct ViewTraits {
};

#ifdef KOKKOS_ENABLE_IMPL_MDSPAN
namespace Experimental::Impl {
namespace Impl {
struct UnsupportedKokkosArrayLayout;

template <class Traits, class Enabled = void>
Expand All @@ -385,17 +385,17 @@ struct MDSpanViewTraits {
// "Natural" mdspan for a view if the View's ArrayLayout is supported.
template <class Traits>
struct MDSpanViewTraits<
Traits, std::void_t<typename Experimental::Impl::LayoutFromArrayLayout<
Traits, std::void_t<typename Impl::LayoutFromArrayLayout<
typename Traits::array_layout>::type>> {
using index_type = std::size_t;
using extents_type = typename Experimental::Impl::ExtentsFromDataType<
using extents_type = typename Impl::ExtentsFromDataType<
index_type, typename Traits::data_type>::type;
using mdspan_layout_type = typename Experimental::Impl::LayoutFromArrayLayout<
using mdspan_layout_type = typename Impl::LayoutFromArrayLayout<
typename Traits::array_layout>::type;
using mdspan_type =
mdspan<typename Traits::value_type, extents_type, mdspan_layout_type>;
};
} // namespace Experimental::Impl
} // namespace Impl
#endif // KOKKOS_ENABLE_IMPL_MDSPAN

/** \class View
Expand Down Expand Up @@ -1752,17 +1752,17 @@ class View : public ViewTraits<DataType, Properties...> {
//----------------------------------------
// MDSpan converting constructors
#ifdef KOKKOS_ENABLE_IMPL_MDSPAN
template <typename U = typename Experimental::Impl::MDSpanViewTraits<
template <typename U = typename Impl::MDSpanViewTraits<
traits>::mdspan_type>
KOKKOS_INLINE_FUNCTION MDSPAN_CONDITIONAL_EXPLICIT(traits::is_managed) View(
const typename Experimental::Impl::MDSpanViewTraits<traits>::mdspan_type&
const typename Impl::MDSpanViewTraits<traits>::mdspan_type&
mds,
std::enable_if_t<!std::is_same_v<
Experimental::Impl::UnsupportedKokkosArrayLayout, U>>* = nullptr)
Impl::UnsupportedKokkosArrayLayout, U>>* = nullptr)
: View(mds.data_handle(),
Experimental::Impl::array_layout_from_mapping<
Impl::array_layout_from_mapping<
typename traits::array_layout,
typename Experimental::Impl::MDSpanViewTraits<
typename Impl::MDSpanViewTraits<
traits>::mdspan_type>(mds.mapping())) {}

//----------------------------------------
Expand All @@ -1772,10 +1772,10 @@ class View : public ViewTraits<DataType, Properties...> {
KOKKOS_INLINE_FUNCTION constexpr operator mdspan<
OtherElementType, OtherExtents, OtherLayoutPolicy, OtherAccessor>() {
using mdspan_type =
typename Experimental::Impl::MDSpanViewTraits<traits>::mdspan_type;
typename Impl::MDSpanViewTraits<traits>::mdspan_type;
return mdspan_type{
data(),
Experimental::Impl::mapping_from_view_mapping<mdspan_type>(m_map)};
Impl::mapping_from_view_mapping<mdspan_type>(m_map)};
}

template <class OtherAccessorType,
Expand All @@ -1785,14 +1785,14 @@ class View : public ViewTraits<DataType, Properties...> {
KOKKOS_INLINE_FUNCTION constexpr auto to_mdspan(
const OtherAccessorType& other_accessor) {
using mdspan_type =
typename Experimental::Impl::MDSpanViewTraits<traits>::mdspan_type;
typename Impl::MDSpanViewTraits<traits>::mdspan_type;
using ret_mdspan_type =
mdspan<typename mdspan_type::element_type,
typename mdspan_type::extents_type,
typename mdspan_type::layout_type, OtherAccessorType>;
return ret_mdspan_type{
data(),
Experimental::Impl::mapping_from_view_mapping<mdspan_type>(m_map),
Impl::mapping_from_view_mapping<mdspan_type>(m_map),
other_accessor};
}
#endif // KOKKOS_ENABLE_IMPL_MDSPAN
Expand Down
5 changes: 1 addition & 4 deletions core/src/View/MDSpan/Kokkos_MDSpan_Extents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ struct ViewDimension;

template <class T, class Dim>
struct ViewDataType;
} // namespace Kokkos::Impl

namespace Kokkos::Experimental::Impl {

// A few things to note --
// - mdspan allows for 0-rank extents similarly to View, so we don't need
Expand Down Expand Up @@ -128,6 +125,6 @@ constexpr KOKKOS_INLINE_FUNCTION auto extents_from_view_mapping(
return extents_from_view_mapping_impl<Extents>(
view_mapping, std::make_index_sequence<Extents::rank()>{});
}
} // namespace Kokkos::Experimental::Impl
} // namespace Kokkos::Impl

#endif // KOKKOS_EXPERIMENTAL_MDSPAN_EXTENTS_HPP
4 changes: 2 additions & 2 deletions core/src/View/MDSpan/Kokkos_MDSpan_Layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static_assert(false,
#include <Kokkos_Core_fwd.hpp>
#include <impl/Kokkos_ViewDataAnalysis.hpp>

namespace Kokkos::Experimental::Impl {
namespace Kokkos::Impl {
template <class Layout>
struct ArrayLayoutFromLayout;

Expand Down Expand Up @@ -151,6 +151,6 @@ KOKKOS_INLINE_FUNCTION auto view_offset_from_mdspan(
static constexpr auto padding = ArrayLayoutFromLayout<LayoutPolicy>::padding;
return offset_type(padding, array_layout_from_mdspan(mds));
};
} // namespace Kokkos::Experimental::Impl
} // namespace Kokkos::Impl

#endif // KOKKOS_EXPERIMENTAL_MDSPAN_LAYOUT_HPP
11 changes: 5 additions & 6 deletions core/unit_test/view/TestExtentsDatatypeConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ namespace {

// Helper to make static tests more succinct
template <typename DataType, typename Extent>
constexpr bool datatype_matches_extent =
std::is_same_v<typename Kokkos::Experimental::Impl::ExtentsFromDataType<
std::size_t, DataType>::type,
Extent>;
constexpr bool datatype_matches_extent = std::is_same_v<
typename Kokkos::Impl::ExtentsFromDataType<std::size_t, DataType>::type,
Extent>;

template <typename DataType, typename BaseType, typename Extents>
constexpr bool extent_matches_datatype =
std::is_same_v<DataType, typename Kokkos::Experimental::Impl::
DataTypeFromExtents<BaseType, Extents>::type>;
std::is_same_v<DataType, typename Kokkos::Impl::DataTypeFromExtents<
BaseType, Extents>::type>;

// Conversion from DataType to extents
// 0-rank view
Expand Down
10 changes: 4 additions & 6 deletions core/unit_test/view/TestMDSpanConversion.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ struct TestViewMDSpanConversion {
const MDSpanLayoutMapping &mapping) {
using view_type = Kokkos::View<DataType, KokkosLayout, ExecutionSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>;
using natural_mdspan_type =
typename Kokkos::Experimental::Impl::MDSpanViewTraits<
typename view_type::traits>::mdspan_type;
using natural_mdspan_type = typename Kokkos::Impl::MDSpanViewTraits<
typename view_type::traits>::mdspan_type;
using mapping_type = MDSpanLayoutMapping;
using mdspan_layout_type = typename MDSpanLayoutMapping::layout_type;
using extents_type = typename mapping_type::extents_type;
Expand Down Expand Up @@ -85,9 +84,8 @@ struct TestViewMDSpanConversion {
static void test_conversion_to_mdspan(
const MDSpanLayoutMapping &ref_layout_mapping, ViewType v) {
using view_type = ViewType;
using natural_mdspan_type =
typename Kokkos::Experimental::Impl::MDSpanViewTraits<
typename view_type::traits>::mdspan_type;
using natural_mdspan_type = typename Kokkos::Impl::MDSpanViewTraits<
typename view_type::traits>::mdspan_type;

natural_mdspan_type cvt = v;
ASSERT_EQ(cvt.data_handle(), v.data());
Expand Down

0 comments on commit dafaf2d

Please sign in to comment.