MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::RMASampleEgressProtocol Class Reference

#include <ProtocolEgressRMA.hpp>

Inheritance diagram for mxl::lib::fabrics::ofi::RMASampleEgressProtocol:
Collaboration diagram for mxl::lib::fabrics::ofi::RMASampleEgressProtocol:

Public Member Functions

virtual bool hasPendingWork () const final
 Check if there is uncompleted requests.
virtual void processCompletion (Completion const &) final
 Process a completion event. Any post-processing after a transfer should be done here.
virtual void registerMemory (std::shared_ptr< Domain > domain) final
 Register local memory regions used in this protocol.
virtual std::size_t reset () final
 Destroy the protocol object.
virtual void transferGrain (Endpoint const &ep, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint32_t payloadOffset, SliceRange const &sliceRange, ::fi_addr_t destAddr=FI_ADDR_UNSPEC) final
 Transfer a grain to a remote target.
virtual void transferSamples (Endpoint const &ep, std::uint64_t headIndex, std::size_t count, ::fi_addr_t destAddr=FI_ADDR_UNSPEC) final
 Transfer samples to a remote target.
Public Member Functions inherited from mxl::lib::fabrics::ofi::EgressProtocol
virtual ~EgressProtocol ()=default

Private Member Functions

 RMASampleEgressProtocol (Completion::Token token, TargetInfo info, DataLayout::Continuous dataLayout, LocalRegion _localRegion, std::size_t bounceBufferEntryCount)

Static Private Member Functions

static std::vector< LocalRegion > makeScatterGatherList (DataLayout::Continuous const &layout, std::uint64_t headIndex, std::size_t count, LocalRegion const &region)
 Create the scatter-gather list for a given audio region and data layout. This will be used for the remote write transfer. The list will be created based on the head index and count of samples to transfer.

Private Attributes

std::size_t _bounceBufferEntryCount
std::uint32_t _bounceBufferEntryIndex {0}
std::vector< LocalRegion > _entryHeaderRegions
std::vector< AudioEntryHeader > _entryHeaders
DataLayout::Continuous _layout
LocalRegion _localRegion
std::size_t _pending = 0
TargetInfo _remoteInfo
Completion::Token _token

Friends

class RMASampleEgressProtocolTemplate

Detailed Description

Definition at line 79 of file ProtocolEgressRMA.hpp.

Constructor & Destructor Documentation

◆ RMASampleEgressProtocol()

mxl::lib::fabrics::ofi::RMASampleEgressProtocol::RMASampleEgressProtocol ( Completion::Token token,
TargetInfo info,
DataLayout::Continuous dataLayout,
LocalRegion _localRegion,
std::size_t bounceBufferEntryCount )
private

Definition at line 136 of file ProtocolEgressRMA.cpp.

138 : _token{token}
139 , _remoteInfo{std::move(info)}
140 , _layout{layout}
141 , _localRegion{localRegion}
142 , _entryHeaders{bounceBufferEntryCount}
143 , _bounceBufferEntryCount{bounceBufferEntryCount}
144 {}

Member Function Documentation

◆ hasPendingWork()

bool mxl::lib::fabrics::ofi::RMASampleEgressProtocol::hasPendingWork ( ) const
nodiscardfinalvirtual

Check if there is uncompleted requests.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 221 of file ProtocolEgressRMA.cpp.

222 {
223 return _pending > 0;
224 }

◆ makeScatterGatherList()

std::vector< LocalRegion > mxl::lib::fabrics::ofi::RMASampleEgressProtocol::makeScatterGatherList ( DataLayout::Continuous const & layout,
std::uint64_t headIndex,
std::size_t count,
LocalRegion const & region )
staticprivate

Create the scatter-gather list for a given audio region and data layout. This will be used for the remote write transfer. The list will be created based on the head index and count of samples to transfer.

Parameters
layoutThe audio data layout.
headIndexThe head index of the audio samples to transfer.
countThe number of samples per channel to transfer.
regionThe local region corresponding to the user provided audio region. This is used to calculate the addresses for the scatter-gather list entries.
Returns
A vector of local regions representing the scatter-gather list for the transfer.

Definition at line 231 of file ProtocolEgressRMA.cpp.

233 {
236 count,
237 layout.bufferLength,
238 layout.sampleSize,
239 layout.channelCount,
240 reinterpret_cast<std::uint8_t*>(region.addr), // NOLINT
241 slice);
242
243 // Double the scatter-gather list length if the second fragment is present.
244 auto const sgListLen = (slice.base.fragments[1].size > 0) ? 2 * slice.count : slice.count;
245
246 // Create the scatter-gather list using the slices. We create at least one scatter-gather entry per channel. We potentially create an
247 // additional one per channel if 2 fragments are present (wrap-around). When a fragment is not present its size will be 0.
248 auto sgList = std::vector<LocalRegion>{};
249 sgList.reserve(sgListLen);
250 // Write all fragments for one channel before moving to the next channel.
251 // Doing otherwise (fragment first) only works when source and target wrapped slices split at the same fragment sizes.
252 // If source and target have different ring positions, the target consumes the bytes with different fragment sizes and "stitches" the channel
253 // data back together incorrectly.
254 for (auto chan = std::size_t{0}; chan < slice.count; chan++)
255 {
256 for (auto const& fragment : slice.base.fragments)
257 {
258 // check if the fragment present
259 if (fragment.size > 0)
260 {
261 auto const srcAddr = reinterpret_cast<std::uintptr_t>(fragment.pointer) + (slice.stride * chan);
262
263 sgList.emplace_back(LocalRegion{.addr = srcAddr, .len = fragment.size, .desc = region.desc});
264 }
265 }
266 }
267
268 return sgList;
269 }
static void getMutableMultiBufferSlices(std::uint64_t index, std::size_t count, std::size_t bufferLength, std::size_t sampleWordSize, std::size_t channelCount, std::uint8_t *baseBufferPtr, mxlMutableWrappedMultiBufferSlice &slice) noexcept
struct mxlMutableWrappedMultiBufferSlice_t mxlMutableWrappedMultiBufferSlice
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.

◆ processCompletion()

void mxl::lib::fabrics::ofi::RMASampleEgressProtocol::processCompletion ( Completion const & )
finalvirtual

Process a completion event. Any post-processing after a transfer should be done here.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 213 of file ProtocolEgressRMA.cpp.

214 {
215 if (_pending > 0)
216 {
217 --_pending;
218 }
219 }

◆ registerMemory()

void mxl::lib::fabrics::ofi::RMASampleEgressProtocol::registerMemory ( std::shared_ptr< Domain > domain)
finalvirtual

Register local memory regions used in this protocol.

Parameters
domainThe domain to register memory with.
Note
This is used to register additional local memory regions. One example of this, is in the case where there is a metadata header that needs to be transferred along with the actual data, and the header is stored in a different memory region from the data. And such memory region can only be created after the protocol template creates the protocol instance since the header content is only known after the instance is created.
With this protocol, the audio entry headers will get registered.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 146 of file ProtocolEgressRMA.cpp.

147 {
148 if (_entryHeaders.empty())
149 {
150 throw Exception::invalidState("Entry headers buffer are not initialized.");
151 }
152
153 auto entryHeaderRegions = std::vector<Region>{};
154 entryHeaderRegions.reserve(_entryHeaders.size());
155 for (auto& header : _entryHeaders)
156 {
157 entryHeaderRegions.emplace_back(reinterpret_cast<std::uintptr_t>(&header),
158 sizeof(AudioEntryHeader),
159 nullptr,
160 nullptr,
161 Region::Location::host()); // Host, because the bounce buffer will always be stored on host memory.
162 }
163
164 // The domain is shared with all endpoints, if there's more than 1 target, we can't assume that the first audio header entry for this target
165 // will be at index 1 (right after the audio samples buffer). Read the number of regions already registered to the domain, then
166 // register the entry header regions, and finally get the local regions again to retrieve the actual regions corresponding to the entry
167 // headers we just registered. Use the offset to correctly get the entry header regions in the list of local regions.
168 auto const offset = domain->localRegions().size();
169 domain->registerRegions(entryHeaderRegions, FI_WRITE);
170 auto const localRegions = domain->localRegions();
171
172 _entryHeaderRegions = std::vector(localRegions.cbegin() + static_cast<std::ptrdiff_t>(offset), localRegions.cend());
173 }
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59
static Location host() noexcept
specify a host memory location.
Definition Region.cpp:23

◆ reset()

std::size_t mxl::lib::fabrics::ofi::RMASampleEgressProtocol::reset ( )
finalvirtual

Destroy the protocol object.

Returns
The number of pending transfers.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 226 of file ProtocolEgressRMA.cpp.

227 {
228 return std::exchange(_pending, 0);
229 }

◆ transferGrain()

void mxl::lib::fabrics::ofi::RMASampleEgressProtocol::transferGrain ( Endpoint const & ep,
std::uint64_t localIndex,
std::uint64_t remoteIndex,
std::uint32_t payloadOffset,
SliceRange const & sliceRange,
::fi_addr_t destAddr = FI_ADDR_UNSPEC )
finalvirtual

Transfer a grain to a remote target.

Parameters
localRegionThe local region to transfer from.
remoteIndexThe index of the remote grain to transfer to.
payloadOffsetThe payload offset within the grain.
sliceRangeThe range of slices to transfer.
destAddrThe destination address. This is ignored for connection-oriented endpoints.
Note
This is unsupported in this protocol since it is designed for audio data. Calling this function will result in an Exception::invalidState being thrown.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 175 of file ProtocolEgressRMA.cpp.

176 {
177 throw Exception::invalidState("transferGrain is not supported in RMASampleEgressProtocol.");
178 }

◆ transferSamples()

void mxl::lib::fabrics::ofi::RMASampleEgressProtocol::transferSamples ( Endpoint const & ep,
std::uint64_t headIndex,
std::size_t count,
::fi_addr_t destAddr = FI_ADDR_UNSPEC )
finalvirtual

Transfer samples to a remote target.

Parameters
headIndexThe head index of the samples to transfer.
countThe number of samples per channel to transfer.
destAddrThe destination address. This is ignored for connection-oriented endpoints.

Implements mxl::lib::fabrics::ofi::EgressProtocol.

Definition at line 180 of file ProtocolEgressRMA.cpp.

181 {
182 if (count == 0)
183 {
184 throw Exception::invalidArgument("Count must be greater than 0.");
185 }
186
187 auto const entrySizeRequired = (_layout.sampleSize * _layout.channelCount * count) + sizeof(AudioEntryHeader);
188 if (entrySizeRequired > _remoteInfo.bounceBufferInfo->entrySize)
189 {
190 throw Exception::invalidArgument("Count is too large for the bounce buffer entry size. Count {}, entry size {}, required entry size {}.",
191 count,
192 _remoteInfo.bounceBufferInfo->entrySize,
193 entrySizeRequired);
194 }
195
196 // 1- Create the scatter-gather list for the transfer and prepend the audio header.
197 auto sgl = makeScatterGatherList(_layout, headIndex, count, _localRegion);
198 // set the header and prepend it to the scatter-gather list.
199 _entryHeaders[_bounceBufferEntryIndex].headIndex = headIndex;
201 sgl.insert(sgl.begin(), _entryHeaderRegions[_bounceBufferEntryIndex]);
202
203 // 2- Get the remote region
204 auto const remoteRegion = _remoteInfo.remoteRegions[_bounceBufferEntryIndex % _remoteInfo.remoteRegions.size()];
205
206 // 3- Send the remote write
207 _pending += ep.write(_token, sgl, remoteRegion, destAddr, _bounceBufferEntryIndex);
208
209 // 4- update bounce buffer entry index for the next transfer
211 }
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
static std::vector< LocalRegion > makeScatterGatherList(DataLayout::Continuous const &layout, std::uint64_t headIndex, std::size_t count, LocalRegion const &region)
Create the scatter-gather list for a given audio region and data layout. This will be used for the re...

◆ RMASampleEgressProtocolTemplate

friend class RMASampleEgressProtocolTemplate
friend

Definition at line 112 of file ProtocolEgressRMA.hpp.

Member Data Documentation

◆ _bounceBufferEntryCount

std::size_t mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_bounceBufferEntryCount
private

The total number of bounce buffer entries. Used to wrap around the bounce buffer entry index.

Definition at line 141 of file ProtocolEgressRMA.hpp.

◆ _bounceBufferEntryIndex

std::uint32_t mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_bounceBufferEntryIndex {0}
private

The index of the bounce buffer entry to use for the next transfer.

Definition at line 140 of file ProtocolEgressRMA.hpp.

140{0};

◆ _entryHeaderRegions

std::vector<LocalRegion> mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_entryHeaderRegions
private

A vector of local regions corresponding to the entry headers. These regions are registered and used for remote writes to the bounce buffer.

Definition at line 137 of file ProtocolEgressRMA.hpp.

◆ _entryHeaders

std::vector<AudioEntryHeader> mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_entryHeaders
private

A vector of audio entry headers used for the bounce buffer. This is needed to keep track of the metadata of each bounce buffer entry.

Definition at line 135 of file ProtocolEgressRMA.hpp.

◆ _layout

DataLayout::Continuous mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_layout
private

Definition at line 133 of file ProtocolEgressRMA.hpp.

◆ _localRegion

LocalRegion mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_localRegion
private

Registered local region corresponding to the user provided audio region.

Definition at line 134 of file ProtocolEgressRMA.hpp.

◆ _pending

std::size_t mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_pending = 0
private

Definition at line 139 of file ProtocolEgressRMA.hpp.

◆ _remoteInfo

TargetInfo mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_remoteInfo
private

Definition at line 132 of file ProtocolEgressRMA.hpp.

◆ _token

Completion::Token mxl::lib::fabrics::ofi::RMASampleEgressProtocol::_token
private

Definition at line 131 of file ProtocolEgressRMA.hpp.


The documentation for this class was generated from the following files: