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 discrete_vector_type =
typename discrete_domain_type::discrete_vector_type;
63 using extents_type =
typename allocation_mdspan_type::extents_type;
65 using layout_type =
typename allocation_mdspan_type::layout_type;
67 using accessor_type =
typename allocation_mdspan_type::accessor_type;
69 using mapping_type =
typename allocation_mdspan_type::mapping_type;
71 using element_type =
typename allocation_mdspan_type::element_type;
73 using value_type =
typename allocation_mdspan_type::value_type;
75 using size_type =
typename allocation_mdspan_type::size_type;
77 using data_handle_type =
typename allocation_mdspan_type::data_handle_type;
79 using reference =
typename allocation_mdspan_type::reference;
82 template <
class,
class,
class>
85 template <
class,
class,
class,
class>
88 template <
class,
class,
class>
91 static_assert(mapping_type::is_always_strided());
103 return extents_type::rank();
108 return extents_type::rank_dynamic();
113 return extents_type::static_extent(r);
118 return mapping_type::is_always_unique();
123 return mapping_type::is_always_exhaustive();
128 return mapping_type::is_always_strided();
132 template <
class Mapping = mapping_type>
133 static KOKKOS_FUNCTION
constexpr std::
134 enable_if_t<std::is_constructible_v<Mapping, extents_type>, internal_mdspan_type>
135 make_internal_mdspan(ElementType* ptr, discrete_domain_type
const& domain)
137 if (domain.empty()) {
138 return internal_mdspan_type(ptr, Kokkos::layout_stride::mapping<extents_type>());
140 extents_type
const extents_r(::
ddc::extents<DDims>(domain).value()...);
141 mapping_type
const mapping_r(extents_r);
143 extents_type
const extents_s((front<DDims>(domain) +
ddc::extents<DDims>(domain)).uid()...);
144 std::array<std::size_t,
sizeof...(DDims)>
const strides_s {
145 mapping_r.stride(type_seq_rank_v<DDims, detail::TypeSeq<DDims...>>)...};
146 Kokkos::layout_stride::mapping<extents_type>
const mapping_s(extents_s, strides_s);
147 return internal_mdspan_type(ptr - mapping_s(front<DDims>(domain).uid()...), mapping_s);
161 template <
class QueryDDim>
164 return m_domain.
template extent<QueryDDim>();
192 template <
class QueryDDim>
195 return m_internal_mdspan.stride(type_seq_rank_v<QueryDDim, detail::TypeSeq<DDims...>>);
199
200
207
208
209 template <
class... QueryDDims>
220
221
222
224 internal_mdspan_type internal_mdspan,
225 discrete_domain_type
const& domain)
noexcept
232
233
234
236 class Mapping = mapping_type,
237 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
243 assert(domain.empty() || ((ptr !=
nullptr) && !domain.empty()));
247
248
252
253
259
260
261
265
266
267
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);
309template <
class ElementType,
class SupportType,
class LayoutStridedPolicy>
313 using discrete_domain_type = SupportType;
316 using allocation_mdspan_type = Kokkos::mdspan<
318 Kokkos::dextents<std::size_t, SupportType::rank()>,
319 LayoutStridedPolicy>;
321 using const_allocation_mdspan_type = Kokkos::mdspan<
323 Kokkos::dextents<std::size_t, SupportType::rank()>,
324 LayoutStridedPolicy>;
326 using discrete_element_type =
typename discrete_domain_type::discrete_element_type;
328 using discrete_vector_type =
typename discrete_domain_type::discrete_vector_type;
330 using extents_type =
typename allocation_mdspan_type::extents_type;
332 using layout_type =
typename allocation_mdspan_type::layout_type;
334 using accessor_type =
typename allocation_mdspan_type::accessor_type;
336 using mapping_type =
typename allocation_mdspan_type::mapping_type;
338 using element_type =
typename allocation_mdspan_type::element_type;
340 using value_type =
typename allocation_mdspan_type::value_type;
342 using size_type =
typename allocation_mdspan_type::size_type;
344 using data_handle_type =
typename allocation_mdspan_type::data_handle_type;
346 using reference =
typename allocation_mdspan_type::reference;
349 template <
class,
class,
class>
352 template <
class,
class,
class,
class>
355 template <
class,
class,
class>
358 static_assert(mapping_type::is_always_strided());
370 return extents_type::rank();
375 return extents_type::rank_dynamic();
380 return extents_type::static_extent(r);
385 return mapping_type::is_always_unique();
390 return mapping_type::is_always_exhaustive();
395 return mapping_type::is_always_strided();
399 template <
class Mapping = mapping_type>
400 static KOKKOS_FUNCTION
constexpr std::
401 enable_if_t<std::is_constructible_v<Mapping, extents_type>, allocation_mdspan_type>
402 make_allocation_mdspan(ElementType* ptr, SupportType
const& domain)
404 return allocation_mdspan_type(ptr, detail::array(domain.extents()));
418 template <
class QueryDDim>
421 return m_domain.
template extent<QueryDDim>();
449 template <
class QueryDDim>
456
457
464
465
466 template <
class... QueryDDims>
477
478
479
481 allocation_mdspan_type allocation_mdspan,
482 SupportType
const& domain)
noexcept
489
490
491
493 class Mapping = mapping_type,
494 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
500 assert(domain.empty() || ((ptr !=
nullptr) && !domain.empty()));
504
505
509
510
516
517
518
522
523
524
529
530
537
538
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.
KOKKOS_FUNCTION constexpr bool is_strided() const noexcept
KOKKOS_DEFAULTED_FUNCTION ~ChunkCommon() noexcept=default
KOKKOS_FUNCTION constexpr ElementType * data_handle() const
Access to the underlying allocation pointer.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon()=default
Empty ChunkCommon.
allocation_mdspan_type m_allocation_mdspan
The raw view of the data.
KOKKOS_FUNCTION constexpr SupportType domain() const noexcept
Provide access to the domain on which this chunk is defined.
static KOKKOS_FUNCTION constexpr bool is_always_strided() noexcept
KOKKOS_FUNCTION constexpr allocation_mdspan_type allocation_mdspan() const
Provide a modifiable view of the data.
KOKKOS_FUNCTION constexpr ChunkCommon(allocation_mdspan_type allocation_mdspan, SupportType const &domain) noexcept
Constructs a new ChunkCommon from scratch.
KOKKOS_FUNCTION constexpr ChunkCommon(ElementType *ptr, SupportType const &domain)
Constructs a new ChunkCommon from scratch.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon(ChunkCommon const &other)=default
Constructs a new ChunkCommon by copy, yields a new view to the same data.
static KOKKOS_FUNCTION constexpr bool is_always_unique() 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 & 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 &&other) noexcept=default
Constructs a new ChunkCommon by move.
KOKKOS_DEFAULTED_FUNCTION constexpr ChunkCommon & operator=(ChunkCommon &&other) noexcept=default
Move-assigns a new value to this ChunkCommon.
KOKKOS_FUNCTION constexpr size_type extent() const noexcept
KOKKOS_FUNCTION constexpr size_type stride() const
KOKKOS_FUNCTION constexpr bool is_exhaustive() const noexcept
KOKKOS_FUNCTION constexpr mapping_type mapping() const noexcept
static KOKKOS_FUNCTION constexpr int rank() noexcept
KOKKOS_FUNCTION constexpr bool is_unique() const noexcept
KOKKOS_FUNCTION constexpr accessor_type accessor() const
KOKKOS_FUNCTION constexpr SupportType::discrete_vector_type extents() const noexcept
KOKKOS_FUNCTION constexpr size_type size() const noexcept
SupportType m_domain
The mesh on which this chunk is defined.
static KOKKOS_FUNCTION constexpr int rank_dynamic() noexcept
static KOKKOS_FUNCTION constexpr size_type static_extent(std::size_t r) noexcept
static KOKKOS_FUNCTION constexpr bool is_always_exhaustive() noexcept
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.