MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
LocalRegion.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include <cassert>
8#include <cstddef>
9#include <cstdint>
10#include <span>
11#include <vector>
12#include <sys/uio.h>
13
15{
22 {
23 public:
30 [[nodiscard]]
31 LocalRegion sub(std::uint64_t offset, std::size_t length) const;
32
35 [[nodiscard]]
36 ::iovec toIovec() const noexcept;
37
38 public:
39 std::uint64_t addr;
40 std::size_t len;
41 void* desc;
42 };
43
44 class LocalRegionGroupSpan; // Forward declaration
45
49 {
50 public:
51 using iterator = std::vector<LocalRegion>::iterator;
52 using const_iterator = std::vector<LocalRegion>::const_iterator;
53
54 public:
55 LocalRegionGroup(std::vector<LocalRegion> inner)
56 : _inner(std::move(inner))
59 {}
60
63 [[nodiscard]]
64 ::iovec const* asIovec() const noexcept;
65
68 [[nodiscard]]
69 void* const* desc() const noexcept;
70
72 {
73 return _inner.begin();
74 }
75
77 {
78 return _inner.end();
79 }
80
81 [[nodiscard]]
83 {
84 return _inner.cbegin();
85 }
86
87 [[nodiscard]]
89 {
90 return _inner.cend();
91 }
92
94 {
95 return _inner[index];
96 }
97
98 LocalRegion const& operator[](std::size_t index) const
99 {
100 return _inner[index];
101 }
102
103 [[nodiscard]]
104 std::size_t size() const noexcept
105 {
106 return _inner.size();
107 }
108
115 [[nodiscard]]
116 LocalRegionGroupSpan span(std::size_t beginIndex, std::size_t endIndex) const;
117
118 private:
121 static std::vector<::iovec> iovFromGroup(std::vector<LocalRegion> group) noexcept;
122
125 static std::vector<void*> descFromGroup(std::vector<LocalRegion> group) noexcept;
126
127 private:
128 std::vector<LocalRegion> _inner;
129
130 std::vector<::iovec> _iovs;
131 std::vector<void*> _descs;
132 };
133
139 {
140 friend class LocalRegionGroup;
141
142 public:
143 [[nodiscard]]
144 ::iovec const* asIovec() const noexcept
145 {
146 return _iovec.data();
147 }
148
149 [[nodiscard]]
150 void* const* desc() const noexcept
151 {
152 return _descs.data();
153 }
154
155 [[nodiscard]]
156 std::size_t size() const noexcept
157 {
158 return _inner.size();
159 }
160
163 [[nodiscard]]
164 std::size_t byteSize() const noexcept;
165
166 private:
167 LocalRegionGroupSpan(std::span<LocalRegion const>, std::span<::iovec const>, std::span<void* const>);
168
169 private:
170 std::span<LocalRegion const> _inner;
171 std::span<::iovec const> _iovec;
172 std::span<void* const> _descs;
173 };
174}
Represent a span of a LocalRegionGroup.
void *const * desc() const noexcept
std::span< LocalRegion const > _inner
LocalRegionGroupSpan(std::span< LocalRegion const >, std::span<::iovec const >, std::span< void *const >)
std::size_t byteSize() const noexcept
Returns the sum of each region size in the span.
::iovec const * asIovec() const noexcept
std::vector< LocalRegion >::const_iterator const_iterator
::iovec const * asIovec() const noexcept
Return the underlying array of iovec structures representing the memory region group.
LocalRegionGroup(std::vector< LocalRegion > inner)
void *const * desc() const noexcept
Return the underlying array of descriptors representing the memory region group.
LocalRegionGroupSpan span(std::size_t beginIndex, std::size_t endIndex) const
Return a span representing a contiguous subset of the LocalRegionGroup.
std::size_t size() const noexcept
static std::vector< void * > descFromGroup(std::vector< LocalRegion > group) noexcept
Generate descriptor array from a group of LocalRegion.
LocalRegion const & operator[](std::size_t index) const
LocalRegion & operator[](std::size_t index)
static std::vector<::iovec > iovFromGroup(std::vector< LocalRegion > group) noexcept
Generate iovec array from a group of LocalRegion.
std::vector< LocalRegion >::iterator iterator
Represent a source memory region used for for data transfer.
LocalRegion sub(std::uint64_t offset, std::size_t length) const
Create a sub-region of this LocalRegion.
::iovec toIovec() const noexcept
Convert this LocalRegion to a struct iovec used by libfabric transfer functions.
uint64_t index