diff --git a/include/ddc/chunk.hpp b/include/ddc/chunk.hpp index 80e44f7a1..332fbbbd0 100644 --- a/include/ddc/chunk.hpp +++ b/include/ddc/chunk.hpp @@ -259,7 +259,7 @@ class Chunk, Allocator> s.mapping(), std::make_index_sequence {}); return Kokkos::View< - detail::mdspan_to_kokkos_element_type_t, + detail::mdspan_to_kokkos_element_t, decltype(kokkos_layout), typename Allocator::memory_space>(s.data(), kokkos_layout); } @@ -275,7 +275,7 @@ class Chunk, Allocator> s.mapping(), std::make_index_sequence {}); return Kokkos::View< - detail::mdspan_to_kokkos_element_type_t, + detail::mdspan_to_kokkos_element_t, decltype(kokkos_layout), typename Allocator::memory_space>(s.data(), kokkos_layout); } diff --git a/include/ddc/chunk_span.hpp b/include/ddc/chunk_span.hpp index 71b8f3def..f15a3d0cc 100644 --- a/include/ddc/chunk_span.hpp +++ b/include/ddc/chunk_span.hpp @@ -304,7 +304,7 @@ class ChunkSpan, LayoutStridedPolicy, Memo s.mapping(), std::make_index_sequence {}); return Kokkos::View< - detail::mdspan_to_kokkos_element_type_t, + detail::mdspan_to_kokkos_element_t, decltype(kokkos_layout), MemorySpace>(s.data(), kokkos_layout); } @@ -325,9 +325,9 @@ template < class... DDims, class = std::enable_if_t::value>> ChunkSpan(KokkosView const& view, DiscreteDomain domain) -> ChunkSpan< - detail::kokkos_to_mdspan_element_type_t, + detail::kokkos_to_mdspan_element_t, DiscreteDomain, - detail::mdspan_layout_t, + detail::kokkos_to_mdspan_layout_t, typename KokkosView::memory_space>; template < diff --git a/include/ddc/detail/kokkos.hpp b/include/ddc/detail/kokkos.hpp index 2880edf33..39ae21f81 100644 --- a/include/ddc/detail/kokkos.hpp +++ b/include/ddc/detail/kokkos.hpp @@ -8,55 +8,101 @@ namespace detail { -template -struct mdspan_layout; +template +struct type_holder +{ + using type = T; +}; template -using mdspan_layout_t = typename mdspan_layout::type; +struct kokkos_to_mdspan_layout +{ + static_assert( + std::is_same_v, + "Usage of non-specialized kokkos_to_mdspan_layout struct is not allowed"); +}; template <> -struct mdspan_layout +struct kokkos_to_mdspan_layout { using type = std::experimental::layout_left; }; template <> -struct mdspan_layout +struct kokkos_to_mdspan_layout { using type = std::experimental::layout_right; }; template <> -struct mdspan_layout +struct kokkos_to_mdspan_layout { using type = std::experimental::layout_stride; }; +/// Alias template to transform a mdspan layout type to a Kokkos layout type +template +using kokkos_to_mdspan_layout_t = typename kokkos_to_mdspan_layout::type; -template -struct kokkos_layout; template -using kokkos_layout_t = typename kokkos_layout::type; +struct mdspan_to_kokkos_layout +{ + static_assert( + std::is_same_v, + "Usage of non-specialized mdspan_to_kokkos_layout struct is not allowed"); +}; template <> -struct kokkos_layout +struct mdspan_to_kokkos_layout { using type = Kokkos::LayoutLeft; }; template <> -struct kokkos_layout +struct mdspan_to_kokkos_layout { using type = Kokkos::LayoutRight; }; template <> -struct kokkos_layout +struct mdspan_to_kokkos_layout { using type = Kokkos::LayoutStride; }; +/// Alias template to transform a Kokkos layout type to a mdspan layout type +template +using mdspan_to_kokkos_layout_t = typename mdspan_to_kokkos_layout::type; + +template +struct mdspan_to_kokkos_element + : std::conditional_t< + N == 0, + type_holder, + mdspan_to_kokkos_element, N - 1>> +{ +}; + +/// Alias template to transform a mdspan element type to a Kokkos element type +/// Only dynamic dimensions is supported for now i.e. `double[4]*` is not yet covered. +template +using mdspan_to_kokkos_element_t = typename mdspan_to_kokkos_element::type; + +template +struct kokkos_to_mdspan_element + : std::conditional_t< + std::is_pointer_v>, + kokkos_to_mdspan_element>>, + type_holder> +{ +}; + +/// Alias template to transform a Kokkos element type to a mdspan element type +/// Only dynamic dimensions is supported for now i.e. `double[4]*` is not yet covered. +template +using kokkos_to_mdspan_element_t = typename kokkos_to_mdspan_element::type; + template Kokkos::LayoutStride make_layout_stride( @@ -67,13 +113,13 @@ Kokkos::LayoutStride make_layout_stride( } template -kokkos_layout_t build_kokkos_layout( +mdspan_to_kokkos_layout_t build_kokkos_layout( EP const& ep, MP const& mapping, std::index_sequence) { DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function) - using kokkos_layout_type = kokkos_layout_t; + using kokkos_layout_type = mdspan_to_kokkos_layout_t; if constexpr (std::is_same_v) { std::array storage; std::experimental::mdspan< @@ -91,53 +137,14 @@ kokkos_layout_t build_kokkos_layout( DDC_IF_NVCC_THEN_POP } -/// Recursively add a pointer -template -struct mdspan_to_kokkos_element_type : mdspan_to_kokkos_element_type, N - 1> -{ -}; - -template -struct mdspan_to_kokkos_element_type -{ - using type = ET; -}; - -template -using mdspan_to_kokkos_element_type_t = typename mdspan_to_kokkos_element_type::type; - -template -struct final_type -{ - using type = T; - static constexpr std::size_t rank = N; -}; - -/// Recursively remove a pointer -template -struct kokkos_to_mdspan_element_type - : std::conditional_t< - std::is_pointer_v>, - kokkos_to_mdspan_element_type>, N + 1>, - final_type> -{ -}; - -template -using kokkos_to_mdspan_element_type_t = typename kokkos_to_mdspan_element_type::type; - -template -constexpr inline std::size_t kokkos_to_mdspan_element_type_rank - = kokkos_to_mdspan_element_type::rank; - template auto build_mdspan(Kokkos::View const view, std::index_sequence) { DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function) - using element_type = kokkos_to_mdspan_element_type_t; + using element_type = kokkos_to_mdspan_element_t; using extents_type = std::experimental::dextents::rank>; - using layout_type - = mdspan_layout_t::array_layout>; + using layout_type = kokkos_to_mdspan_layout_t< + typename Kokkos::View::array_layout>; using mapping_type = typename layout_type::template mapping; extents_type exts(view.extent(Is)...); if constexpr (std::is_same_v) { diff --git a/include/ddc/transform_reduce.hpp b/include/ddc/transform_reduce.hpp index 94f7fe4bc..33cac5469 100644 --- a/include/ddc/transform_reduce.hpp +++ b/include/ddc/transform_reduce.hpp @@ -15,71 +15,72 @@ namespace detail { template -struct KokkosReducer; - -template -using KokkosReducer_t = typename KokkosReducer::type; +struct ddc_to_kokkos_reducer; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::Sum; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::Prod; }; template <> -struct KokkosReducer +struct ddc_to_kokkos_reducer { using type = Kokkos::LAnd; }; template <> -struct KokkosReducer +struct ddc_to_kokkos_reducer { using type = Kokkos::LOr; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::BAnd; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::BOr; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { static_assert(std::is_same_v, "This reducer is not yet implemented"); }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::Min; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::Max; }; template -struct KokkosReducer> +struct ddc_to_kokkos_reducer> { using type = Kokkos::MinMax; }; +/// Alias template to transform a DDC reducer type to a Kokkos reducer type +template +using ddc_to_kokkos_reducer_t = typename ddc_to_kokkos_reducer::type; + /** A serial reduction over a nD domain * @param[in] domain the range over which to apply the algorithm * @param[in] neutral the neutral element of the reduction operation @@ -165,7 +166,7 @@ inline T transform_reduce_kokkos( BinaryReductionOp, UnaryTransformOp, DDim0>(reduce, transform), - KokkosReducer_t(result)); + ddc_to_kokkos_reducer_t(result)); return result; } @@ -208,7 +209,7 @@ inline T transform_reduce_kokkos( DDim0, DDim1, DDims...>(reduce, transform), - KokkosReducer_t(result)); + ddc_to_kokkos_reducer_t(result)); return result; }