12#include <experimental/mdspan>
14#include <Kokkos_Core.hpp>
16#include "ddc/chunk_traits.hpp"
17#include "ddc/detail/macros.hpp"
18#include "ddc/discrete_domain.hpp"
33template <
class ElementType,
class SupportType,
class LayoutStr
idedPolicy>
43 std::experimental::dextents<std::size_t,
sizeof...(DDims)>,
44 std::experimental::layout_stride>;
52 std::experimental::dextents<std::size_t,
sizeof...(DDims)>,
57 std::experimental::dextents<std::size_t,
sizeof...(DDims)>,
62 using extents_type =
typename allocation_mdspan_type::extents_type;
64 using layout_type =
typename allocation_mdspan_type::layout_type;
68 using mapping_type =
typename allocation_mdspan_type::mapping_type;
70 using element_type =
typename allocation_mdspan_type::element_type;
72 using value_type =
typename allocation_mdspan_type::value_type;
74 using size_type =
typename allocation_mdspan_type::size_type;
78 using reference =
typename allocation_mdspan_type::reference;
81 template <
class,
class,
class>
84 template <
class,
class,
class,
class>
87 template <
class,
class,
class>
90 static_assert(mapping_type::is_always_strided());
102 return extents_type::rank();
107 return extents_type::rank_dynamic();
112 return extents_type::static_extent(
r);
117 return mapping_type::is_always_unique();
122 return mapping_type::is_always_exhaustive();
127 return mapping_type::is_always_strided();
131 template <
class Mapping = mapping_type>
133 enable_if_t<std::is_constructible_v<Mapping, extents_type>, internal_mdspan_type>
134 make_internal_mdspan(
ElementType* ptr, mdomain_type
const& domain)
136 if (domain.empty()) {
137 return internal_mdspan_type(
139 std::experimental::layout_stride::mapping<extents_type>());
145 std::array<std::size_t,
sizeof...(DDims)>
strides_s {
154 return m_internal_mdspan.accessor();
162 template <
class QueryDDim>
170 return allocation_mdspan().size();
175 return allocation_mdspan().mapping();
180 return allocation_mdspan().is_unique();
185 return allocation_mdspan().is_exhaustive();
190 return allocation_mdspan().is_strided();
193 template <
class QueryDDim>
227 : m_internal_mdspan(std::move(internal_mdspan))
238 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
240 : m_internal_mdspan(make_internal_mdspan(ptr, domain))
276 ElementType* ptr = m_internal_mdspan.data_handle();
277 if (!m_domain.
empty()) {
278 ptr += m_internal_mdspan.mapping()(
front<DDims>(m_domain).uid()...);
288 return m_internal_mdspan;
298 if constexpr (std::is_same_v<LayoutStridedPolicy, std::experimental::layout_stride>) {
static KOKKOS_FUNCTION constexpr int rank() noexcept
Definition chunk_common.hpp:100
std::experimental::mdspan< const ElementType, std::experimental::dextents< std::size_t, sizeof...(DDims)>, LayoutStridedPolicy > const_allocation_mdspan_type
Definition chunk_common.hpp:55
internal_mdspan_type m_internal_mdspan
The raw view of the data.
Definition chunk_common.hpp:94
mdomain_type m_domain
The mesh on which this chunk is defined.
Definition chunk_common.hpp:97
static KOKKOS_FUNCTION constexpr bool is_always_strided() noexcept
Definition chunk_common.hpp:125
KOKKOS_FUNCTION constexpr bool is_unique() const noexcept
Definition chunk_common.hpp:178
static KOKKOS_FUNCTION constexpr int rank_dynamic() noexcept
Definition chunk_common.hpp:105
KOKKOS_FUNCTION constexpr mdomain_type domain() const noexcept
Provide access to the domain on which this chunk is defined.
Definition chunk_common.hpp:202
std::experimental::mdspan< ElementType, std::experimental::dextents< std::size_t, sizeof...(DDims)>, std::experimental::layout_stride > internal_mdspan_type
the raw mdspan underlying this, with the same indexing (0 might no be dereferenceable)
Definition chunk_common.hpp:41
KOKKOS_FUNCTION constexpr bool is_exhaustive() const noexcept
Definition chunk_common.hpp:183
KOKKOS_FUNCTION constexpr size_type extent() const noexcept
Definition chunk_common.hpp:163
KOKKOS_FUNCTION constexpr mapping_type mapping() const noexcept
Definition chunk_common.hpp:173
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon const &other)=default
Copy-assigns a new value to this ChunkCommon, yields a new view to the same data.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon const &other)=default
Constructs a new ChunkCommon by copy, yields a new view to the same data.
KOKKOS_FUNCTION constexpr DiscreteVector< DDims... > extents() const noexcept
Definition chunk_common.hpp:157
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon()=default
Empty ChunkCommon.
typename allocation_mdspan_type::mapping_type mapping_type
Definition chunk_common.hpp:68
KOKKOS_FUNCTION constexpr ElementType * data_handle() const
Access to the underlying allocation pointer.
Definition chunk_common.hpp:274
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
Provide a modifiable view of the data.
Definition chunk_common.hpp:294
std::experimental::mdspan< ElementType, std::experimental::dextents< std::size_t, sizeof...(DDims)>, LayoutStridedPolicy > allocation_mdspan_type
The dereferenceable part of the co-domain but with a different domain, starting at 0.
Definition chunk_common.hpp:50
KOKKOS_FUNCTION constexpr ChunkCommon(internal_mdspan_type internal_mdspan, mdomain_type const &domain) noexcept
Constructs a new ChunkCommon from scratch.
Definition chunk_common.hpp:224
KOKKOS_FUNCTION constexpr ChunkCommon(ElementType *ptr, mdomain_type const &domain)
Constructs a new ChunkCommon from scratch.
Definition chunk_common.hpp:239
typename allocation_mdspan_type::size_type size_type
Definition chunk_common.hpp:74
typename allocation_mdspan_type::data_handle_type data_handle_type
Definition chunk_common.hpp:76
typename allocation_mdspan_type::layout_type layout_type
Definition chunk_common.hpp:64
static KOKKOS_FUNCTION constexpr bool is_always_unique() noexcept
Definition chunk_common.hpp:115
typename allocation_mdspan_type::accessor_type accessor_type
Definition chunk_common.hpp:66
KOKKOS_FUNCTION constexpr internal_mdspan_type internal_mdspan() const
Provide a modifiable view of the data.
Definition chunk_common.hpp:286
KOKKOS_FUNCTION constexpr size_type stride() const
Definition chunk_common.hpp:194
static KOKKOS_FUNCTION constexpr size_type static_extent(std::size_t r) noexcept
Definition chunk_common.hpp:110
KOKKOS_DEFAULTED_FUNCTION ~ChunkCommon()=default
typename mdomain_type::discrete_element_type discrete_element_type
Definition chunk_common.hpp:60
typename allocation_mdspan_type::reference reference
Definition chunk_common.hpp:78
KOKKOS_FUNCTION constexpr accessor_type accessor() const
Definition chunk_common.hpp:152
typename allocation_mdspan_type::element_type element_type
Definition chunk_common.hpp:70
static KOKKOS_FUNCTION constexpr bool is_always_exhaustive() noexcept
Definition chunk_common.hpp:120
KOKKOS_FUNCTION constexpr size_type size() const noexcept
Definition chunk_common.hpp:168
typename allocation_mdspan_type::extents_type extents_type
Definition chunk_common.hpp:62
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon &&other)=default
Move-assigns a new value to this ChunkCommon.
KOKKOS_FUNCTION constexpr bool is_strided() const noexcept
Definition chunk_common.hpp:188
typename allocation_mdspan_type::value_type value_type
Definition chunk_common.hpp:72
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > domain() const noexcept
Provide access to the domain on which this chunk is defined.
Definition chunk_common.hpp:211
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon &&other)=default
Constructs a new ChunkCommon by move.
Definition discrete_domain.hpp:51
KOKKOS_FUNCTION constexpr bool empty() const noexcept
Definition discrete_domain.hpp:202
KOKKOS_FUNCTION constexpr mlength_type extents() const noexcept
Definition discrete_domain.hpp:142
A DiscreteVector is a vector in the discrete dimension.
Definition discrete_vector.hpp:254
The top-level namespace of DDC.
Definition aligned_allocator.hpp:11
KOKKOS_FUNCTION auto get_domain(ChunkType const &chunk) noexcept
Access the domain (or subdomain) of a view.
Definition chunk_common.hpp:27
constexpr bool enable_chunk
Definition chunk_traits.hpp:16
KOKKOS_FUNCTION constexpr DiscreteElementType const & uid(DiscreteElement< Tag > const &tuple) noexcept
Definition discrete_element.hpp:51
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > select(DiscreteDomain< DDims... > const &domain)
Definition discrete_domain.hpp:385
Definition chunk_common.hpp:34
Definition chunk_span.hpp:30