MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
RDMTarget.cpp
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#include "RDMTarget.hpp"
6#include <cstdint>
7#include <memory>
9#include <rdma/fabric.h>
10#include <rdma/fi_eq.h>
11#include "AddressVector.hpp"
12#include "EventQueue.hpp"
13#include "Exception.hpp"
14#include "FabricAddress.hpp"
15#include "FabricInfo.hpp"
16#include "FabricInfoHelpers.hpp"
17#include "Format.hpp" // IWYU pragma: keep; Includes template specializations of fmt::formatter for our types
18#include "Protocol.hpp"
19#include "Provider.hpp"
20#include "Region.hpp"
21
23{
24 std::pair<std::unique_ptr<RDMTarget>, std::unique_ptr<TargetInfo>> RDMTarget::setup(mxlFabricsTargetConfig const& config, FabricInfoView info,
25 TargetSetupOptions const& options)
26 {
27 requireCapability(info, FI_REMOTE_WRITE, "Interface is missing required remote write capability");
28 auto const provider = providerFromString(info->fabric_attr->prov_name);
29 if (!provider)
30 {
31 throw Exception::invalidArgument("invalid provider: {}", info->fabric_attr->prov_name);
32 }
33
34 MXL_INFO("Setting up RDM target with source address: {}", FabricAddress::fromSource(info).toString());
35
36 auto fabric = Fabric::open(info);
37 auto domain = Domain::open(fabric);
38
39 auto endpoint = Endpoint::create(domain);
40
42 if (options.cqDepth)
43 {
44 cqAttr.size = *options.cqDepth;
45 }
46 if (provider == Provider::EFA)
47 {
49 {
51 {
52 throw Exception::make(MXL_ERR_NO_FABRIC, "Blocking API support requested, but not available for this fabric/version");
53 }
54
55 cqAttr.waitObject = FI_WAIT_NONE;
56 }
57 }
58
59 auto cq = CompletionQueue::open(domain, cqAttr);
60 endpoint.bind(cq, FI_RECV | FI_TRANSMIT);
61
62 // Connectionless endpoints must be bound to an address vector. Even if it is not using the address vector.
63 auto av = AddressVector::open(domain);
64 endpoint.bind(av);
65
66 endpoint.bind(EventQueue::open(fabric));
67
68 // Connectionless endpoints must be explictely enabled when they are ready to be used.
69 endpoint.enable();
70
71 auto mxlRegions = MxlRegions::forWriter(config.writer);
72 auto protocol = selectIngressProtocol(mxlRegions.dataLayout(), mxlRegions.regions(), mxlRegions.maxSyncBatchSize());
73 auto targetInfo = std::make_unique<TargetInfo>(
74 endpoint.id(), endpoint.localAddress(), *provider, protocol->registerMemory(domain), protocol->bounceBufferInfo());
75
76 struct MakeUniqueEnabler : RDMTarget
77 {
78 MakeUniqueEnabler(Endpoint ep, std::unique_ptr<IngressProtocol> proto)
79 : RDMTarget(std::move(ep), std::move(proto))
80 {}
81 };
82
83 return {std::make_unique<MakeUniqueEnabler>(std::move(endpoint), std::move(protocol)), std::move(targetInfo)};
84 }
85
86 RDMTarget::RDMTarget(Endpoint ep, std::unique_ptr<IngressProtocol> proto)
87 : _ep(std::move(ep))
88 , _protocol(std::move(proto))
89 {}
90
91 std::optional<Target::ReadResult> RDMTarget::read()
92 {
94 }
95
96 std::optional<Target::ReadResult> RDMTarget::readBlocking(std::chrono::steady_clock::duration timeout)
97 {
99 }
100
102 {
103 // no connection, no shutdown...
104 }
105
106 template<QueueReadMode queueReadMode>
107 std::optional<Target::ReadResult> RDMTarget::readNext(std::chrono::steady_clock::duration timeout)
108 {
109 drainEventQueue(*_ep.eventQueue());
110 try
111 {
112 auto completion = readCompletionQueue<queueReadMode>(*_ep.completionQueue(), timeout);
113 if (completion)
114 {
115 return _protocol->read(_ep, *completion);
116 }
117 }
118 catch (FabricException const& ex)
119 {
120 if (ex.isInterrupted())
121 {
122 return std::make_optional<Target::Interrupted>();
123 }
124
125 throw;
126 }
127
128 return {};
129 }
130
131}
#define MXL_INFO(...)
Definition Logging.hpp:45
static std::shared_ptr< AddressVector > open(std::shared_ptr< Domain > domain, Attributes attr=Attributes::defaults())
Create an AddressVector.
static std::shared_ptr< CompletionQueue > open(std::shared_ptr< Domain > domain, Attributes const &attr=Attributes::defaults())
Create a new completion queue in the specified domain.
static bool isWaitObjectSupportedForEFA() noexcept
Check if wait any wait object type supported by the EFA provider for this libfabric version.
static std::shared_ptr< Domain > open(std::shared_ptr< Fabric > fabric)
Open a new domain associated with the specified fabric.
Definition Domain.cpp:30
RAII Wrapper around a libfabric endpoint (fi_ep).
Definition Endpoint.hpp:29
static Endpoint create(std::shared_ptr< Domain > domain, FabricInfoView info)
Allocates (active) new endpoint.
Definition Endpoint.cpp:56
static std::shared_ptr< EventQueue > open(std::shared_ptr< Fabric >, Attributes const &attr=Attributes::defaults())
Create a new event queue associated with the specified fabric.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
static Exception make(mxlStatus status, fmt::format_string< T... > fmt, T &&... args)
Make any type of exception.
Definition Exception.hpp:35
static FabricAddress fromSource(FabricInfoView info) noexcept
Build a FabricAddress from the source address of info.
An internal exception type that extends.
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
static std::shared_ptr< Fabric > open(FabricInfoView info)
Open a fabric object based on the provided FabricInfoView.
Definition Fabric.cpp:15
static MxlRegions forWriter(mxlFlowWriter)
Definition Region.cpp:110
static std::pair< std::unique_ptr< RDMTarget >, std::unique_ptr< TargetInfo > > setup(mxlFabricsTargetConfig const &config, FabricInfoView info, TargetSetupOptions const &options)
Set up a fresh RDMTarget and its associated TargetInfo based on the given configuration.
Definition RDMTarget.cpp:24
std::optional< Target::ReadResult > readNext(std::chrono::steady_clock::duration timeout)
Internal method to drive progress based on the current state.
virtual std::optional< Target::ReadResult > read() final
Determine if new data can be consumed.
Definition RDMTarget.cpp:91
std::unique_ptr< IngressProtocol > _protocol
Definition RDMTarget.hpp:61
virtual std::optional< Target::ReadResult > readBlocking(std::chrono::steady_clock::duration timeout) final
Definition RDMTarget.cpp:96
RDMTarget(Endpoint ep, std::unique_ptr< IngressProtocol > protocol)
Construct an RDMTarget with the given endpoint and immediate data location.
Definition RDMTarget.cpp:86
virtual void shutdown() final
Shut down the target gracefully. Initiates a graceful shutdown of the target and blocks until the shu...
struct mxlFabricsTargetConfig_t mxlFabricsTargetConfig
@ MXL_FABRICS_IFACE_CAP_BLOCKING_OPERATIONS
Definition fabrics.h:78
@ MXL_ERR_NO_FABRIC
Definition mxl.h:46
void drainEventQueue(EventQueue &eq)
Read all entries from a connectionless endpoint's event queue and log the errors among them.
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
Definition Provider.cpp:49
std::unique_ptr< IngressProtocol > selectIngressProtocol(DataLayout const &layout, std::vector< Region > regions, std::uint32_t maxSyncBatchSize)
Select an appropriate ingress protocol based on the data layout.
Definition Protocol.cpp:13
std::optional< Completion > readCompletionQueue(CompletionQueue &eq, std::chrono::steady_clock::duration timeout)
Helper to read a completion queue with blocking or non-blocking behaviour.
void requireCapability(FabricInfoView info, std::uint64_t cap, std::string_view message)
mxlFabricsInterfaceCaps caps
Definition fabrics.h:101
mxlFlowWriter writer
Definition fabrics.h:131
mxlFabricsInterfaceConfig interface
Definition fabrics.h:130
static Attributes defaults()
Returns the a CompletionQueueAttr with all of its attributes set to reasonable defaults.
Provider-independent tuning options for target setup.
Definition Target.hpp:23
std::optional< std::size_t > cqDepth
Desired completion-queue depth.
Definition Target.hpp:29