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>;
48 using mdomain_type [[deprecated(
"Use `discrete_domain_type` instead")]]
52 using allocation_mdspan_type = Kokkos::mdspan<
54 Kokkos::dextents<std::size_t,
sizeof...(DDims)>,
57 using const_allocation_mdspan_type = Kokkos::mdspan<
59 Kokkos::dextents<std::size_t,
sizeof...(DDims)>,
62 using discrete_element_type =
typename discrete_domain_type::discrete_element_type;
64 using extents_type =
typename allocation_mdspan_type::extents_type;
66 using layout_type =
typename allocation_mdspan_type::layout_type;
68 using accessor_type =
typename allocation_mdspan_type::accessor_type;
70 using mapping_type =
typename allocation_mdspan_type::mapping_type;
72 using element_type =
typename allocation_mdspan_type::element_type;
74 using value_type =
typename allocation_mdspan_type::value_type;
76 using size_type =
typename allocation_mdspan_type::size_type;
78 using data_handle_type =
typename allocation_mdspan_type::data_handle_type;
80 using reference =
typename allocation_mdspan_type::reference;
83 template <
class,
class,
class>
86 template <
class,
class,
class,
class>
89 template <
class,
class,
class>
92 static_assert(mapping_type::is_always_strided());
104 return extents_type::rank();
109 return extents_type::rank_dynamic();
114 return extents_type::static_extent(r);
119 return mapping_type::is_always_unique();
124 return mapping_type::is_always_exhaustive();
129 return mapping_type::is_always_strided();
133 template <
class Mapping = mapping_type>
134 static KOKKOS_FUNCTION
constexpr std::
135 enable_if_t<std::is_constructible_v<Mapping, extents_type>, internal_mdspan_type>
136 make_internal_mdspan(ElementType* ptr, discrete_domain_type
const& domain)
138 if (domain.empty()) {
139 return internal_mdspan_type(ptr, Kokkos::layout_stride::mapping<extents_type>());
141 extents_type
const extents_r(::
ddc::extents<DDims>(domain).value()...);
142 mapping_type
const mapping_r(extents_r);
144 extents_type
const extents_s((front<DDims>(domain) +
ddc::extents<DDims>(domain)).uid()...);
145 std::array<std::size_t,
sizeof...(DDims)>
const strides_s {
146 mapping_r.stride(type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
147 Kokkos::layout_stride::mapping<extents_type>
const mapping_s(extents_s, strides_s);
148 return internal_mdspan_type(ptr - mapping_s(front<DDims>(domain).uid()...), mapping_s);
162 template <
class QueryDDim>
165 return m_domain.
template extent<QueryDDim>();
193 template <
class QueryDDim>
196 return m_internal_mdspan.stride(type_seq_rank_v<QueryDDim, detail::TypeSeq<DDims...>>);
200
201
208
209
210 template <
class... QueryDDims>
213 return select<QueryDDims...>(domain());
221
222
223
225 internal_mdspan_type internal_mdspan,
226 discrete_domain_type
const& domain)
noexcept
233
234
235
237 class Mapping = mapping_type,
238 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
244 assert(domain.empty() || ((ptr !=
nullptr) && !domain.empty()));
248
249
253
254
260
261
262
266
267
268
272
273
284
285
292
293
296 DDC_IF_NVCC_THEN_PUSH_AND_SUPPRESS(implicit_return_from_non_void_function)
297 extents_type
const extents_s(::
ddc::extents<DDims>(
m_domain).value()...);
298 if constexpr (std::is_same_v<LayoutStridedPolicy, Kokkos::layout_stride>) {
302 mapping_type
const map(extents_s);
static KOKKOS_FUNCTION constexpr int rank() noexcept
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 ~ChunkCommon()=default
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)=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.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon &&other)=default
Constructs a new ChunkCommon by move.
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.