11#include <Kokkos_Core.hpp>
13#include "detail/type_seq.hpp"
22
23
24
25template <
class... QueryDDims,
class ChunkType>
26KOKKOS_FUNCTION
auto get_domain(ChunkType
const& chunk)
noexcept
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>
36 using discrete_domain_type = SupportType;
39 using allocation_mdspan_type = Kokkos::mdspan<
41 Kokkos::dextents<std::size_t, SupportType::rank()>,
44 using const_allocation_mdspan_type = Kokkos::mdspan<
46 Kokkos::dextents<std::size_t, SupportType::rank()>,
49 using discrete_element_type =
typename discrete_domain_type::discrete_element_type;
51 using discrete_vector_type =
typename discrete_domain_type::discrete_vector_type;
53 using extents_type =
typename allocation_mdspan_type::extents_type;
55 using layout_type =
typename allocation_mdspan_type::layout_type;
57 using accessor_type =
typename allocation_mdspan_type::accessor_type;
59 using mapping_type =
typename allocation_mdspan_type::mapping_type;
61 using element_type =
typename allocation_mdspan_type::element_type;
63 using value_type =
typename allocation_mdspan_type::value_type;
65 using size_type =
typename allocation_mdspan_type::size_type;
67 using data_handle_type =
typename allocation_mdspan_type::data_handle_type;
69 using reference =
typename allocation_mdspan_type::reference;
72 template <
class,
class,
class>
75 template <
class,
class,
class,
class>
78 template <
class,
class,
class>
81 static_assert(mapping_type::is_always_strided());
91 static KOKKOS_FUNCTION
constexpr int rank()
noexcept
93 return extents_type::rank();
96 static KOKKOS_FUNCTION
constexpr int rank_dynamic()
noexcept
98 return extents_type::rank_dynamic();
101 static KOKKOS_FUNCTION
constexpr size_type
static_extent(std::size_t r)
noexcept
103 return extents_type::static_extent(r);
108 return mapping_type::is_always_unique();
113 return mapping_type::is_always_exhaustive();
118 return mapping_type::is_always_strided();
122 template <
class Mapping = mapping_type>
123 static KOKKOS_FUNCTION
constexpr std::
124 enable_if_t<std::is_constructible_v<Mapping, extents_type>, allocation_mdspan_type>
125 make_allocation_mdspan(ElementType* ptr, SupportType
const& domain)
127 return allocation_mdspan_type(ptr, detail::array(domain.extents()));
131 KOKKOS_FUNCTION
constexpr accessor_type
accessor()
const
141 template <
class QueryDDim>
142 KOKKOS_FUNCTION
constexpr size_type
extent()
const noexcept
144 return m_domain.
template extent<QueryDDim>();
147 KOKKOS_FUNCTION
constexpr size_type
size()
const noexcept
152 KOKKOS_FUNCTION
constexpr mapping_type
mapping()
const noexcept
157 KOKKOS_FUNCTION
constexpr bool is_unique()
const noexcept
162 KOKKOS_FUNCTION
constexpr bool is_exhaustive()
const noexcept
167 KOKKOS_FUNCTION
constexpr bool is_strided()
const noexcept
172 template <
class QueryDDim>
173 KOKKOS_FUNCTION
constexpr size_type
stride()
const
179
180
181 KOKKOS_FUNCTION
constexpr SupportType
domain()
const noexcept
187
188
189 template <
class... QueryDDims>
197 KOKKOS_DEFAULTED_FUNCTION
constexpr ChunkCommon() =
default;
200
201
202
204 allocation_mdspan_type allocation_mdspan,
205 SupportType
const& domain)
noexcept
212
213
214
216 class Mapping = mapping_type,
217 std::enable_if_t<std::is_constructible_v<Mapping, extents_type>,
int> = 0>
218 KOKKOS_FUNCTION
constexpr ChunkCommon(ElementType* ptr, SupportType
const& domain)
223 KOKKOS_ASSERT(domain.empty() || ((ptr !=
nullptr) && !domain.empty()))
227
228
232
233
236 KOKKOS_DEFAULTED_FUNCTION ~
ChunkCommon()
noexcept =
default;
239
240
241
245
246
247
252
253
254 KOKKOS_FUNCTION
constexpr ElementType*
data_handle()
const
260
261
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
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec) const
Slice out some dimensions.
char const * label() const
Returns the label of the Chunk.
auto operator[](DiscreteDomain< QueryDDims... > const &odomain)
Slice out some dimensions.
const_allocation_mdspan_type allocation_mdspan() const
Provide a mdspan on the memory allocation.
element_type & operator()(DVects const &... dvects) noexcept
Element access using a list of DiscreteVector.
ElementType const * data_handle() const
Access to the underlying allocation pointer.
auto allocation_kokkos_view()
Provide an unmanaged Kokkos::View on the memory allocation.
auto allocation_kokkos_view() const
Provide an unmanaged Kokkos::View on the memory allocation.
Chunk(SupportType const &domain, Allocator allocator=Allocator())
Construct a Chunk on a domain with uninitialized values.
Chunk & operator=(Chunk const &other)=delete
Deleted: use deepcopy instead.
allocation_mdspan_type allocation_mdspan()
Provide a mdspan on the memory allocation.
ElementType * data_handle()
Access to the underlying allocation pointer.
element_type const & operator()(DVects const &... dvects) const noexcept
Element access using a list of DiscreteVector.
view_type span_cview() const
Chunk(Chunk const &other)=delete
Deleted: use deepcopy instead.
Chunk(std::string const &label, SupportType const &domain, Allocator allocator=Allocator())
Construct a labeled Chunk on a domain with uninitialized values.
element_type & operator()(DElems const &... delems) noexcept
Element access using a list of DiscreteElement.
Chunk()=default
Empty Chunk.
Chunk & operator=(Chunk &&other) noexcept
Move-assigns a new value to this field.
Chunk(Chunk &&other) noexcept
Constructs a new Chunk by move.
view_type span_view() const
auto operator[](DiscreteDomain< QueryDDims... > const &odomain) const
Slice out some dimensions.
element_type const & operator()(DElems const &... delems) const noexcept
Element access using a list of DiscreteElement.
auto operator[](DiscreteElement< QueryDDims... > const &slice_spec)
Slice out some dimensions.
friend class DiscreteDomain
The top-level namespace of DDC.
KOKKOS_FUNCTION auto get_domain(ChunkType const &chunk) noexcept
Access the domain (or subdomain) of a view.
constexpr bool enable_chunk< Chunk< ElementType, SupportType, Allocator > >
Chunk(SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >
Chunk(std::string const &, SupportType const &, Allocator) -> Chunk< typename Allocator::value_type, SupportType, Allocator >