13#include <Kokkos_Core.hpp>
15#include "ddc/chunk_traits.hpp"
16#include "ddc/detail/macros.hpp"
17#include "ddc/discrete_domain.hpp"
22
23
24
25template <
class... QueryDDims,
class ChunkType>
28 static_assert(is_chunk_v<ChunkType>,
"Not a chunk span type");
29 return chunk.
template domain<QueryDDims...>();
32template <
class ElementType,
class SupportType,
class LayoutStridedPolicy>
35template <
class ElementType,
class... DDims,
class LayoutStridedPolicy>
40 using internal_mdspan_type = Kokkos::mdspan<
42 Kokkos::dextents<std::size_t,
sizeof...(DDims)>,
43 Kokkos::layout_stride>;
49 using allocation_mdspan_type = Kokkos::mdspan<
51 Kokkos::dextents<std::size_t,
sizeof...(DDims)>,
54 using const_allocation_mdspan_type = Kokkos::mdspan<
56 Kokkos::dextents<std::size_t,
sizeof...(DDims)>,
59 using discrete_element_type =
typename discrete_domain_type::discrete_element_type;
61 using extents_type =
typename allocation_mdspan_type::extents_type;
63 using layout_type =
typename allocation_mdspan_type::layout_type;
65 using accessor_type =
typename allocation_mdspan_type::accessor_type;
67 using mapping_type =
typename allocation_mdspan_type::mapping_type;
69 using element_type =
typename allocation_mdspan_type::element_type;
71 using value_type =
typename allocation_mdspan_type::value_type;
73 using size_type =
typename allocation_mdspan_type::size_type;
75 using data_handle_type =
typename allocation_mdspan_type::data_handle_type;
77 using reference =
typename allocation_mdspan_type::reference;
80 template <
class,
class,
class>
83 template <
class,
class,
class,
class>
86 template <
class,
class,
class>
89 static_assert(mapping_type::is_always_strided());
101 return extents_type::rank();
106 return extents_type::rank_dynamic();
111 return extents_type::static_extent(r);
116 return mapping_type::is_always_unique();
121 return mapping_type::is_always_exhaustive();
126 return mapping_type::is_always_strided();
130 template <
class Mapping = mapping_type>
131 static KOKKOS_FUNCTION
constexpr std::
132 enable_if_t<std::is_constructible_v<Mapping, extents_type>, internal_mdspan_type>
133 make_internal_mdspan(ElementType* ptr, discrete_domain_type
const& domain)
135 if (domain.empty()) {
136 return internal_mdspan_type(ptr, Kokkos::layout_stride::mapping<extents_type>());
138 extents_type
const extents_r(::
ddc::extents<DDims>(domain).value()...);
139 mapping_type
const mapping_r(extents_r);
141 extents_type
const extents_s((front<DDims>(domain) +
ddc::extents<DDims>(domain)).uid()...);
142 std::array<std::size_t,
sizeof...(DDims)>
const strides_s {
143 mapping_r.stride(type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
144 Kokkos::layout_stride::mapping<extents_type>
const mapping_s(extents_s, strides_s);
145 return internal_mdspan_type(ptr - mapping_s(front<DDims>(domain).uid()...), mapping_s);
159 template <
class QueryDDim>
162 return m_domain.
template extent<QueryDDim>();
190 template <
class QueryDDim>
193 return m_internal_mdspan.stride(type_seq_rank_v<QueryDDim, detail::TypeSeq<DDims...>>);
197
198
205
206
207 template <
class... QueryDDims>
218
219
220
222 internal_mdspan_type internal_mdspan,
223 discrete_domain_type
const& domain)
noexcept
230
231
232
234 class Mapping = mapping_type,
235 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
241 assert(domain.empty() || ((ptr !=
nullptr) && !domain.empty()));
245
246
250
251
257
258
259
263
264
265
270
271
282
283
290
291
294 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
295 extents_type
const extents_s(::
ddc::extents<DDims>(
m_domain).value()...);
296 if constexpr (std::is_same_v<LayoutStridedPolicy, Kokkos::layout_stride>) {
300 mapping_type
const map(extents_s);
static KOKKOS_FUNCTION constexpr int rank() noexcept
KOKKOS_DEFAULTED_FUNCTION ~ChunkCommon() noexcept=default
internal_mdspan_type m_internal_mdspan
The raw view of the data.
static KOKKOS_FUNCTION constexpr bool is_always_strided() noexcept
KOKKOS_FUNCTION constexpr bool is_unique() const noexcept
static KOKKOS_FUNCTION constexpr int rank_dynamic() noexcept
KOKKOS_FUNCTION constexpr bool is_exhaustive() const noexcept
KOKKOS_FUNCTION constexpr size_type extent() const noexcept
KOKKOS_FUNCTION constexpr mapping_type mapping() const noexcept
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_FUNCTION constexpr discrete_domain_type domain() const noexcept
Provide access to the domain on which this chunk is defined.
discrete_domain_type m_domain
The mesh on which this chunk is defined.
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
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon()=default
Empty ChunkCommon.
KOKKOS_FUNCTION constexpr ElementType * data_handle() const
Access to the underlying allocation pointer.
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
Provide a modifiable view of the data.
KOKKOS_FUNCTION constexpr ChunkCommon(internal_mdspan_type internal_mdspan, discrete_domain_type const &domain) noexcept
Constructs a new ChunkCommon from scratch.
static KOKKOS_FUNCTION constexpr bool is_always_unique() noexcept
KOKKOS_FUNCTION constexpr internal_mdspan_type internal_mdspan() const
Provide a modifiable view of the data.
KOKKOS_FUNCTION constexpr size_type stride() const
static KOKKOS_FUNCTION constexpr size_type static_extent(std::size_t r) noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon &&other) noexcept=default
Constructs a new ChunkCommon by move.
KOKKOS_FUNCTION constexpr accessor_type accessor() const
KOKKOS_FUNCTION constexpr ChunkCommon(ElementType *ptr, discrete_domain_type const &domain)
Constructs a new ChunkCommon from scratch.
static KOKKOS_FUNCTION constexpr bool is_always_exhaustive() noexcept
KOKKOS_FUNCTION constexpr size_type size() const noexcept
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon &&other) noexcept=default
Move-assigns a new value to this ChunkCommon.
KOKKOS_FUNCTION constexpr bool is_strided() const noexcept
KOKKOS_FUNCTION constexpr DiscreteDomain< QueryDDims... > domain() const noexcept
Provide access to the domain on which this chunk is defined.
friend class DiscreteDomain
KOKKOS_FUNCTION constexpr bool operator!=(DiscreteVector< OTags... > const &rhs) const noexcept
The top-level namespace of DDC.
KOKKOS_FUNCTION auto get_domain(ChunkType const &chunk) noexcept
Access the domain (or subdomain) of a view.