38 [](
Host const&) -> std::uint64_t {
return 0; },
39 [](
Cuda const&
cuda) -> std::uint64_t
41 return static_cast<std::uint64_t
>(
cuda._deviceId);
52 [](
Host const&) -> ::fi_hmem_iface {
return FI_HMEM_SYSTEM; },
53 [](
Cuda const&) -> ::fi_hmem_iface
63 return std::holds_alternative<Host>(
_inner);
72 [&](
Location::Cuda const&) -> std::string {
return fmt::format(
"cuda, id={}",
id()); },
90 return ::iovec{.iov_base =
reinterpret_cast<void*
>(
base), .iov_len =
size};
100 std::vector<::iovec> iovecs;
101 std::ranges::transform(group, std::back_inserter(iovecs), [](
Region const& reg) {
return reg.
toIovec(); });
138 if (mxlRegions._regions.size() != discreteFlow.grainCount())
143 for (std::size_t i = 0; i < discreteFlow.grainCount(); ++i)
145 mxlRegions._regions[i].grainIndexPtr = &discreteFlow.grainAt(i)->header.info.index;
146 mxlRegions._regions[i].validSlicesPtr = &discreteFlow.grainAt(i)->header.info.validSlices;
156 "GrainHeader type size changed! The Fabrics API makes assumptions on the memory layout of a flow, please review the code below if the "
157 "change is intended!");
162 "GPU memory is not currently supported in the Flow API of MXL. Edit the code below when it is supported");
168 auto regions = std::vector<Region>{};
169 regions.reserve(discreteFlow.grainCount());
170 for (
auto i = std::size_t{0}; i < discreteFlow.grainCount(); ++i)
172 auto grain = discreteFlow.grainAt(i);
174 auto grainInfoBaseAddr =
reinterpret_cast<std::uintptr_t
>(discreteFlow.grainAt(i));
176 auto grainPayloadSize = grain->header.info.grainSize;
178 regions.emplace_back(grainInfoBaseAddr, grainInfoSize + grainPayloadSize,
nullptr,
nullptr,
Region::Location::host());
182 return {std::move(regions),
184 discreteFlow.flowInfo()->config.common.maxSyncBatchSizeHint};
189 auto regions = std::vector<Region>{};
192 regions.emplace_back(
reinterpret_cast<std::uintptr_t
>(continuousFlow.channelData()),
193 continuousFlow.channelDataSize(),
198 return {std::move(regions),
199 DataLayout::fromContinuous(continuousFlow.sampleWordSize(), continuousFlow.channelCount(), continuousFlow.channelBufferLength()),
200 continuousFlow.flowInfo()->config.common.maxSyncBatchSizeHint};
210 if (slot >= regions.size())
215 return *regions[slot].grainIndexPtr;
220 if (slot >= regions.size())
225 *regions[slot].validSlicesPtr = validSlices;
Internal shared-memory headers for discrete grains and event slots.
Grain * grainAt(std::size_t i) noexcept
constexpr mxlFlowInfo * flowInfo() noexcept
Describes the layout of data within memory regions.
static DataLayout fromContinuous(std::size_t sampleSize, std::size_t channelCount, std::size_t bufferLength) noexcept
Create a DataLayout representing audio data.
static DataLayout fromDiscrete(std::array< std::uint32_t, MXL_MAX_PLANES_PER_GRAIN > const &sliceSizes, std::uint16_t totalSlices) noexcept
Create a DataLayout representing video data.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
static Exception make(mxlStatus status, fmt::format_string< T... > fmt, T &&... args)
Make any type of exception.
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Represent a collection of memory regions.
MxlRegions(std::vector< Region > regions, DataLayout dataLayout, std::uint32_t maxSyncBatchSize=0)
DataLayout const & dataLayout() const noexcept
std::vector< Region > const & regions() const noexcept
View accessor for the underlying regions.
std::vector< Region > _regions
std::uint32_t _maxSyncBatchSize
static MxlRegions forReader(mxlFlowReader)
static MxlRegions forWriter(mxlFlowWriter)
std::uint32_t maxSyncBatchSize() const noexcept
static std::vector<::iovec > iovecsFromGroup(std::vector< Region > const &group) noexcept
std::vector<::iovec > _iovecs
::iovec const * asIovec() const noexcept
Represent a CUDA device memory location variant.
Represent a host memory location variant.
Represent the location of a memory region.
std::string toString() const noexcept
Generate a string representation of the memory location.
std::uint64_t id() const noexcept
Return the device id. For host location 0 is returned.
static Location host() noexcept
specify a host memory location.
static Location cuda(int deviceId) noexcept
specify a CUDA device memory location.
bool isHost() const noexcept
Return true if the memory location is on host.
::fi_hmem_iface iface() const noexcept
Convert the current location to libfabric "iface" representation.
Represent a memory region (unregistered).
::iovec toIovec() const noexcept
Convert the Region to an iovec structure.
::iovec iovecFromRegion(std::uintptr_t, std::size_t) noexcept
::iovec const * asIovec() const noexcept
Return the underlying iovec structure representing the memory region.
Public flow reader, writer, payload and synchronization APIs.
struct mxlFlowReader_t * mxlFlowReader
struct mxlFlowWriter_t * mxlFlowWriter
@ MXL_PAYLOAD_LOCATION_HOST_MEMORY
std::uint64_t getGrainIndexInRingSlot(std::vector< Region > const ®ions, std::uint16_t slot)
MxlRegions mxlFabricsRegionsFromMutableFlow(FlowData &flow)
Convert a FlowData's memory regions to MxlRegions. FlowData are obtained from an MXL FlowWriter or Fl...
MxlRegions mxlFabricsRegionsFromFlow(FlowData const &flow)
Convert a FlowData's memory regions to MxlRegions. FlowData are obtained from an MXL FlowWriter or Fl...
void setValidSlicesForGrain(std::vector< Region > const ®ions, std::uint16_t slot, std::uint16_t validSlices)
FlowWriter * to_FlowWriter(mxlFlowWriter writer) noexcept
Utility function to convert from a C mxlFlowWriter handle to a C++ FlowWriter instance.
FlowReader * to_FlowReader(mxlFlowReader reader) noexcept
Utility function to convert from a C mxlFlowReader handle to a C++ FlowReader instance.
mxlCommonFlowConfigInfo common