Uni20
Asynchronous tensor and runtime library.
Loading...
Searching...
No Matches
mdspec.hpp
Go to the documentation of this file.
1#pragma once
2
10
11#include <concepts>
12#include <cstddef>
13#include <type_traits>
14#include <utility>
15
16namespace uni20
17{
18
29template <class ElementType, class Extents, class LayoutPolicy, AccessorPolicy Accessor, class DataDescriptor>
30 requires std::same_as<ElementType, typename Accessor::element_type>
31class mdspec {
32 public:
33 using element_type = ElementType;
34 using value_type = std::remove_cv_t<element_type>;
35 using extents_type = Extents;
36 using layout_type = LayoutPolicy;
37 using mapping_type = typename layout_type::template mapping<extents_type>;
38 using accessor_type = Accessor;
39 using data_descriptor_type = DataDescriptor;
40 using data_handle_type = typename accessor_type::data_handle_type;
41 using reference = typename accessor_type::reference;
42 using index_type = typename extents_type::index_type;
43 using size_type = typename extents_type::size_type;
44 using rank_type = typename extents_type::rank_type;
45
51 : descriptor_(std::move(descriptor)), mapping_(std::move(mapping)), accessor_(std::move(accessor))
52 {}
53
55 [[nodiscard]] static constexpr rank_type rank() noexcept { return extents_type::rank(); }
56
58 [[nodiscard]] static constexpr rank_type rank_dynamic() noexcept { return extents_type::rank_dynamic(); }
59
62 [[nodiscard]] static constexpr std::size_t static_extent(rank_type axis) noexcept
63 {
64 return extents_type::static_extent(axis);
65 }
66
68 [[nodiscard]] static constexpr bool is_always_unique() noexcept { return mapping_type::is_always_unique(); }
69
71 [[nodiscard]] static constexpr bool is_always_exhaustive() noexcept { return mapping_type::is_always_exhaustive(); }
72
74 [[nodiscard]] static constexpr bool is_always_strided() noexcept { return mapping_type::is_always_strided(); }
75
77 [[nodiscard]] constexpr auto data_descriptor() noexcept -> data_descriptor_type& { return descriptor_; }
78
80 [[nodiscard]] constexpr auto data_descriptor() const noexcept -> data_descriptor_type const& { return descriptor_; }
81
83 [[nodiscard]] constexpr auto mapping() const noexcept -> mapping_type const& { return mapping_; }
84
86 [[nodiscard]] constexpr auto accessor() const noexcept -> accessor_type const& { return accessor_; }
87
89 [[nodiscard]] constexpr auto extents() const noexcept -> extents_type const& { return mapping_.extents(); }
90
93 [[nodiscard]] constexpr index_type extent(rank_type axis) const noexcept { return this->extents().extent(axis); }
94
96 [[nodiscard]] constexpr bool is_unique() const noexcept { return mapping_.is_unique(); }
97
99 [[nodiscard]] constexpr bool is_exhaustive() const noexcept { return mapping_.is_exhaustive(); }
100
102 [[nodiscard]] constexpr bool is_strided() const noexcept { return mapping_.is_strided(); }
103
106 [[nodiscard]] constexpr index_type stride(rank_type axis) const
107 requires requires(mapping_type const& mapping) {
108 { mapping.stride(axis) } -> std::convertible_to<index_type>;
109 }
110 {
111 return mapping_.stride(axis);
112 }
113
114 private:
115 [[no_unique_address]] data_descriptor_type descriptor_;
116 [[no_unique_address]] mapping_type mapping_;
117 [[no_unique_address]] accessor_type accessor_;
118};
119
120} // namespace uni20
Store a data descriptor with the mapping and accessor for an eventual mdspan.
Definition mdspec.hpp:31
constexpr bool is_strided() const noexcept
Report whether this mapping is strided.
Definition mdspec.hpp:102
LayoutPolicy layout_type
Definition mdspec.hpp:36
constexpr index_type extent(rank_type axis) const noexcept
Return the runtime extent of one axis.
Definition mdspec.hpp:93
DataDescriptor data_descriptor_type
Definition mdspec.hpp:39
constexpr index_type stride(rank_type axis) const
Return the stride for one axis when the mapping exposes strides.
Definition mdspec.hpp:106
typename extents_type::rank_type rank_type
Definition mdspec.hpp:44
static constexpr bool is_always_exhaustive() noexcept
Report whether every mapping of this type is exhaustive.
Definition mdspec.hpp:71
Extents extents_type
Definition mdspec.hpp:35
constexpr bool is_exhaustive() const noexcept
Report whether this mapping is exhaustive.
Definition mdspec.hpp:99
typename extents_type::size_type size_type
Definition mdspec.hpp:43
static constexpr rank_type rank() noexcept
Return the static rank.
Definition mdspec.hpp:55
ElementType element_type
Definition mdspec.hpp:33
typename accessor_type::data_handle_type data_handle_type
Definition mdspec.hpp:40
typename extents_type::index_type index_type
Definition mdspec.hpp:42
constexpr auto extents() const noexcept -> extents_type const &
Return the stored extents.
Definition mdspec.hpp:89
constexpr auto data_descriptor() noexcept -> data_descriptor_type &
Return the descriptor used to acquire writable data access.
Definition mdspec.hpp:77
constexpr auto mapping() const noexcept -> mapping_type const &
Return the stored layout mapping.
Definition mdspec.hpp:83
constexpr auto data_descriptor() const noexcept -> data_descriptor_type const &
Return the descriptor used to acquire read-only data access.
Definition mdspec.hpp:80
Accessor accessor_type
Definition mdspec.hpp:38
static constexpr rank_type rank_dynamic() noexcept
Return the number of dynamic extents.
Definition mdspec.hpp:58
std::remove_cv_t< element_type > value_type
Definition mdspec.hpp:34
constexpr bool is_unique() const noexcept
Report whether this mapping is unique.
Definition mdspec.hpp:96
typename layout_type::template mapping< extents_type > mapping_type
Definition mdspec.hpp:37
typename accessor_type::reference reference
Definition mdspec.hpp:41
constexpr mdspec(data_descriptor_type descriptor, mapping_type mapping, accessor_type accessor)
Construct unresolved mdspan metadata from its three stored components.
Definition mdspec.hpp:50
constexpr auto accessor() const noexcept -> accessor_type const &
Return the stored accessor policy.
Definition mdspec.hpp:86
static constexpr std::size_t static_extent(rank_type axis) noexcept
Return the compile-time extent for one axis.
Definition mdspec.hpp:62
static constexpr bool is_always_unique() noexcept
Report whether every mapping of this type is unique.
Definition mdspec.hpp:68
static constexpr bool is_always_strided() noexcept
Report whether every mapping of this type is strided.
Definition mdspec.hpp:74
Mdspan concept and accessor extensions for Uni20.
Definition qnum.hpp:403
Definition async/async.hpp:26