MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::RMASampleIngressProtocol Class Referencefinal

Ingress protocol for RMA writer endpoint for audio samples. More...

#include <ProtocolIngressRMA.hpp>

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

Public Member Functions

virtual std::optional< TargetInfoBounceBufferInfo > bounceBufferInfo () const override
virtual bool canReadGrains () const noexcept override
 This protocol cannot read grains, since it is designed for remote writes of audio samples.
virtual bool canReadSamples () const noexcept override
 This protocol can read samples, since it is designed for remote writes of audio samples.
virtual std::optional< Target::ReadResult > read (Endpoint const &endpoint, Completion const &completion) override
virtual std::vector< RemoteRegion > registerMemory (std::shared_ptr< Domain > domain) override
 Register local memory regions used in this protocol.
virtual void reset () override
 RMASampleIngressProtocol (Region region, DataLayout::Continuous const &dataLayout, std::uint32_t maxSyncBatchSize)
virtual void start (Endpoint const &endpoint) override
 Start receiving.
Public Member Functions inherited from mxl::lib::fabrics::ofi::IngressProtocol
virtual ~IngressProtocol ()=default

Private Member Functions

LocalRegion immDataRegion ()
AudioBounceBuffer makeAudioBounceBuffer (DataLayout::Continuous const &layout, std::uint32_t maxSyncBatchSize)
 Helper function to create an AudioBounceBuffer based on the given audio data layout and maximum synchronous batch size. Entries are as big as the maximum number of samples that can be transferred in a single batch, which is determined by maxSyncBatchSize. The number of entries is determined by how many batches are needed to cover the entire history buffer.

Private Attributes

AudioBounceBuffer _bounceBuffer
std::optional< Target::ImmediateDataLocation > _immDataBuffer {}
bool _isMemoryRegistered = false
Region _region

Detailed Description

Ingress protocol for RMA writer endpoint for audio samples.

Definition at line 67 of file ProtocolIngressRMA.hpp.

Constructor & Destructor Documentation

◆ RMASampleIngressProtocol()

mxl::lib::fabrics::ofi::RMASampleIngressProtocol::RMASampleIngressProtocol ( Region region,
DataLayout::Continuous const & dataLayout,
std::uint32_t maxSyncBatchSize )

Construct an RMASampleIngressProtocol with the given region and data layout.

Parameters
regionThe memory region containing audio. The audio samples will be first received in one of the bounce buffer entry and will then be copied to this region.

Definition at line 103 of file ProtocolIngressRMA.cpp.

104 : _bounceBuffer{makeAudioBounceBuffer(layout, maxSyncBatchSize)}
105 , _region{region}
106 {}
AudioBounceBuffer makeAudioBounceBuffer(DataLayout::Continuous const &layout, std::uint32_t maxSyncBatchSize)
Helper function to create an AudioBounceBuffer based on the given audio data layout and maximum synch...

Member Function Documentation

◆ bounceBufferInfo()

std::optional< TargetInfoBounceBufferInfo > mxl::lib::fabrics::ofi::RMASampleIngressProtocol::bounceBufferInfo ( ) const
nodiscardoverridevirtual

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 121 of file ProtocolIngressRMA.cpp.

122 {
123 auto const entrySize = _bounceBuffer.entrySize(); // All entries have the same size, we can just take the size of the first one
124 auto const entryCount = _bounceBuffer.entryCount();
125
126 return TargetInfoBounceBufferInfo{.entryCount = entryCount, .entrySize = entrySize};
127 }

◆ canReadGrains()

bool mxl::lib::fabrics::ofi::RMASampleIngressProtocol::canReadGrains ( ) const
nodiscardoverridevirtualnoexcept

This protocol cannot read grains, since it is designed for remote writes of audio samples.

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 164 of file ProtocolIngressRMA.cpp.

165 {
166 return false;
167 }

◆ canReadSamples()

bool mxl::lib::fabrics::ofi::RMASampleIngressProtocol::canReadSamples ( ) const
nodiscardoverridevirtualnoexcept

This protocol can read samples, since it is designed for remote writes of audio samples.

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 169 of file ProtocolIngressRMA.cpp.

170 {
171 return true;
172 }

◆ immDataRegion()

LocalRegion mxl::lib::fabrics::ofi::RMASampleIngressProtocol::immDataRegion ( )
private

Definition at line 177 of file ProtocolIngressRMA.cpp.

178 {
179 if (!_immDataBuffer)
180 {
181 _immDataBuffer.emplace();
182 }
183
184 return _immDataBuffer->toLocalRegion();
185 }
std::optional< Target::ImmediateDataLocation > _immDataBuffer

◆ makeAudioBounceBuffer()

AudioBounceBuffer mxl::lib::fabrics::ofi::RMASampleIngressProtocol::makeAudioBounceBuffer ( DataLayout::Continuous const & layout,
std::uint32_t maxSyncBatchSize )
private

Helper function to create an AudioBounceBuffer based on the given audio data layout and maximum synchronous batch size. Entries are as big as the maximum number of samples that can be transferred in a single batch, which is determined by maxSyncBatchSize. The number of entries is determined by how many batches are needed to cover the entire history buffer.

Definition at line 187 of file ProtocolIngressRMA.cpp.

188 {
189 auto const oneSampleSize = layout.sampleSize * layout.channelCount;
190 auto const entrySize = oneSampleSize * maxSyncBatchSize;
191 auto const historySize = layout.bufferLength * oneSampleSize;
192
193 auto const entryCount = (historySize + entrySize - 1U) / entrySize; // ceil(historySize / entrySize)
194
195 MXL_INFO("Creating audio bounce buffer with entry size {} bytes and entry count {}, maxSyncBatchSize {} historySize {} bufferLength {}",
196 entrySize,
197 entryCount,
198 maxSyncBatchSize,
199 historySize,
200 layout.bufferLength);
201 return {entryCount, entrySize, layout};
202 }
#define MXL_INFO(...)
Definition Logging.hpp:45

◆ read()

std::optional< Target::ReadResult > mxl::lib::fabrics::ofi::RMASampleIngressProtocol::read ( Endpoint const & endpoint,
Completion const & completion )
nodiscardoverridevirtual

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 137 of file ProtocolIngressRMA.cpp.

138 {
139 auto completionData = completion.tryData();
140 if (!completionData)
141 {
142 return {};
143 }
144
145 if (_immDataBuffer)
146 {
147 endpoint.recv(immDataRegion());
148 }
149
150 auto const immData = completionData->data();
151 if (!immData)
152 {
153 throw Exception::invalidState("Received a completion without immediate data.");
154 }
155
156 auto const header = _bounceBuffer.unpack(*immData, _region);
157 if (header.count == 0)
158 {
159 return {};
160 }
161 return std::make_optional<Target::SampleReadResult>(header.headIndex, header.count);
162 }
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59

◆ registerMemory()

std::vector< RemoteRegion > mxl::lib::fabrics::ofi::RMASampleIngressProtocol::registerMemory ( std::shared_ptr< Domain > domain)
nodiscardoverridevirtual

Register local memory regions used in this protocol.

Parameters
domainThe domain to register memory with.
Returns
A vector of RemoteRegion representing the registered memory regions for remote access.
Note
This actually registers the memory of the internal bounce buffer, not the region passed in the constructor.

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 108 of file ProtocolIngressRMA.cpp.

109 {
111 {
112 throw Exception::invalidState("Memory is already registered.");
113 }
114
115 domain->registerRegions(_bounceBuffer.getRegions(), FI_REMOTE_WRITE);
116 _isMemoryRegistered = true;
117
118 return domain->remoteRegions();
119 }

◆ reset()

void mxl::lib::fabrics::ofi::RMASampleIngressProtocol::reset ( )
overridevirtual

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 174 of file ProtocolIngressRMA.cpp.

175 {}

◆ start()

void mxl::lib::fabrics::ofi::RMASampleIngressProtocol::start ( Endpoint const & endpoint)
overridevirtual

Start receiving.

Implements mxl::lib::fabrics::ofi::IngressProtocol.

Definition at line 129 of file ProtocolIngressRMA.cpp.

130 {
131 if (endpoint.domain()->usingRecvBufForCqData())
132 {
133 endpoint.recv(immDataRegion());
134 }
135 }

Member Data Documentation

◆ _bounceBuffer

AudioBounceBuffer mxl::lib::fabrics::ofi::RMASampleIngressProtocol::_bounceBuffer
private

Definition at line 118 of file ProtocolIngressRMA.hpp.

◆ _immDataBuffer

std::optional<Target::ImmediateDataLocation> mxl::lib::fabrics::ofi::RMASampleIngressProtocol::_immDataBuffer {}
private

Definition at line 121 of file ProtocolIngressRMA.hpp.

121{};

◆ _isMemoryRegistered

bool mxl::lib::fabrics::ofi::RMASampleIngressProtocol::_isMemoryRegistered = false
private

Definition at line 120 of file ProtocolIngressRMA.hpp.

◆ _region

Region mxl::lib::fabrics::ofi::RMASampleIngressProtocol::_region
private

Definition at line 119 of file ProtocolIngressRMA.hpp.


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