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

RAII Wrapper around a libfabric endpoint (fi_ep). More...

#include <Endpoint.hpp>

Public Types

using Id = std::uintptr_t
 An id type that can be used to reference this endpoint from completions and events.

Public Member Functions

void accept ()
 Accept an incoming connection.
std::shared_ptr< AddressVector > addressVector () const
 Get the associated addres vector.
void bind (std::shared_ptr< AddressVector > av)
 Bind the endpoint to an address vector.
void bind (std::shared_ptr< CompletionQueue > cq, std::uint64_t flags)
 Bind the endpoint to a completion queue.
void bind (std::shared_ptr< EventQueue > eq)
 Bind the endpoint to an event queue.
std::shared_ptr< CompletionQueue > completionQueue () const
 Get the associated completion queue.
void connect (RawFabricAddress const &addr)
 Initiate a connection to a remote (passive) endpoint.
std::shared_ptr< Domain > domain () const
 Get the domain that the endpoint has beed created on.
void enable ()
 This call transitions the endpoint into an enabled state.
 Endpoint (Endpoint &&) noexcept
 Endpoint (Endpoint const &)=delete
std::shared_ptr< EventQueue > eventQueue () const
 Get the assiociated event queue.
Id id () const noexcept
 Get the id of this endpoint.
FabricInfoView info () const noexcept
 Get the fabric information passed to Endpoint::create() initially.
RawFabricAddress localAddress () const
Endpoint & operator= (Endpoint &&)
void operator= (Endpoint const &)=delete
::fid_ep const * raw () const noexcept
 Get the raw libfabric handle to this endpoint.
::fid_ep * raw () noexcept
 Get the raw libfabric handle to this endpoint.
std::pair< std::optional< Completion >, std::optional< Event > > readQueues ()
 Do a non-blocking read of both the event and completion queue associated with this endpoint.
std::pair< std::optional< Completion >, std::optional< Event > > readQueuesBlocking (std::chrono::steady_clock::duration timeout)
 Do a combined blocking read of both the event and completion queue associated with this endpoint.
void recv (LocalRegion region) const
 Push a recv work request to the endpoint work queue.
void shutdown ()
 Initiate a graceful shutdown on a connection-oriented endpoint.
std::size_t write (Completion::Token token, LocalRegion const &local, RemoteRegion const &remote, ::fi_addr_t destAddr=FI_ADDR_UNSPEC, std::optional< std::uint32_t > immData=std::nullopt) const
 Push a remote write work request of a single contiguous buffer to the endpoint work queue.
std::size_t write (Completion::Token token, LocalRegionGroup const &localGroup, RemoteRegion const &remote, ::fi_addr_t destAddr=FI_ADDR_UNSPEC, std::optional< std::uint32_t > immData=std::nullopt) const
 Push a remote write work request of a scatter-gather list to the endpoint work queue.
 ~Endpoint ()
 Destructor releases all resources.

Static Public Member Functions

static constexpr Id contextValueToId (void *contextValue) noexcept
 Convert between Ids and context values that can be written to and read from raw libfabric queue entries and fid_t.
static Endpoint create (std::shared_ptr< Domain > domain)
 Creates a new (active) endpoint.
static Endpoint create (std::shared_ptr< Domain > domain, FabricInfoView info)
 Allocates (active) new endpoint.
static Endpoint create (std::shared_ptr< Domain > domain, Id id)
 Create an (active) endpoint.
static Endpoint create (std::shared_ptr< Domain > domain, Id id, FabricInfoView)
 Create an (active) endpoint.
static Id idFromFID (::fid_ep *) noexcept
 Read the endpoint id from a libfabric object reference.
static Id idFromFID (::fid_t) noexcept
 Read the endpoint id from a libfabric object reference.
static constexpr Id idFromToken (Completion::Token token) noexcept
 Convert a completion token value to an endpoint id value. Convert a completion token to an endpoint id value. This does not perform any lookups, it just converts the types. This is a pure function and will always return the same endpoint id for the same completion token. This function enables using the endpoint id as a completion token.
static constexpr void * idToContextValue (Id id) noexcept
 Convert between Ids and context values that can be written to and read from raw libfabric queue entries and fid_t.
static Id randomId () noexcept
 Generate a new random endpoint id.
static constexpr Completion::Token tokenFromId (Id id) noexcept
 Convert an endpoint id value to a completion token value. Convert an endpoint id to a completion token value. This does not perform any lookups, it just converts the types. This is a pure function and will always return the same token value for the same endpoint id. This function enables using the endpoint id as a completion token.

Static Public Attributes

static constexpr auto const EQReadInterval = std::chrono::milliseconds(100)
 The minimum interval at which the event queue will be polled when doing a blocking read of both (event and completion) queues.

Private Member Functions

void close ()
 Close the endpoint and release all resources. Called from the destructor and the move assignment operator.
 Endpoint (::fid_ep *raw, FabricInfoView info, std::shared_ptr< Domain > domain, std::optional< std::shared_ptr< CompletionQueue > > cq=std::nullopt, std::optional< std::shared_ptr< EventQueue > > eq=std::nullopt, std::optional< std::shared_ptr< AddressVector > > av=std::nullopt)
 Construct the endpoint.
void writeImpl (Completion::Token token, ::iovec const *msgIov, std::size_t iovCount, void **desc, ::fi_rma_iov const *rmaIov, ::fi_addr_t destAddr, std::optional< std::uint32_t > immData) const
 Internal implementation of the remote write request.

Private Attributes

std::optional< std::shared_ptr< AddressVector > > _av
std::optional< std::shared_ptr< CompletionQueue > > _cq
std::shared_ptr< Domain > _domain
std::optional< std::shared_ptr< EventQueue > > _eq
FabricInfo _info
::fid_ep * _raw

Detailed Description

RAII Wrapper around a libfabric endpoint (fi_ep).

Definition at line 28 of file Endpoint.hpp.

Member Typedef Documentation

◆ Id

using mxl::lib::fabrics::ofi::Endpoint::Id = std::uintptr_t

An id type that can be used to reference this endpoint from completions and events.

Definition at line 38 of file Endpoint.hpp.

Constructor & Destructor Documentation

◆ ~Endpoint()

mxl::lib::fabrics::ofi::Endpoint::~Endpoint ( )

Destructor releases all resources.

If the event or completion queue have events pending that reference this endpoint, they still will be delivered, but the reference to the endpoint inside these events can no longer be used.

Definition at line 88 of file Endpoint.cpp.

89 {
90 catchAndLogFabricError([this]() { close(); }, "Failed to close endpoint");
91 }
void close()
Close the endpoint and release all resources. Called from the destructor and the move assignment oper...
Definition Endpoint.cpp:105
void catchAndLogFabricError(F &&fun, std::string_view msg)

◆ Endpoint() [1/3]

mxl::lib::fabrics::ofi::Endpoint::Endpoint ( Endpoint const & )
delete

◆ Endpoint() [2/3]

mxl::lib::fabrics::ofi::Endpoint::Endpoint ( Endpoint && other)
noexcept

Definition at line 121 of file Endpoint.cpp.

122 : _raw(other._raw)
123 , _info(std::move(other._info))
124 , _domain(std::move(other._domain))
125 , _cq(std::move(other._cq))
126 , _eq(std::move(other._eq))
127 , _av(std::move(other._av))
128 {
129 other._raw = nullptr;
130 }
std::optional< std::shared_ptr< AddressVector > > _av
Definition Endpoint.hpp:327
std::shared_ptr< Domain > _domain
Definition Endpoint.hpp:323
std::optional< std::shared_ptr< EventQueue > > _eq
Definition Endpoint.hpp:326
std::optional< std::shared_ptr< CompletionQueue > > _cq
Definition Endpoint.hpp:325

◆ Endpoint() [3/3]

mxl::lib::fabrics::ofi::Endpoint::Endpoint ( ::fid_ep * raw,
FabricInfoView info,
std::shared_ptr< Domain > domain,
std::optional< std::shared_ptr< CompletionQueue > > cq = std::nullopt,
std::optional< std::shared_ptr< EventQueue > > eq = std::nullopt,
std::optional< std::shared_ptr< AddressVector > > av = std::nullopt )
private

Construct the endpoint.

Definition at line 93 of file Endpoint.cpp.

95 : _raw(raw)
96 , _info(info.owned())
97 , _domain(std::move(domain))
98 , _cq(std::move(cq))
99 , _eq(std::move(eq))
100 , _av(std::move(av))
101 {
102 MXL_DEBUG("Endpoint {} created", Endpoint::idFromFID(raw));
103 }
#define MXL_DEBUG(...)
Definition Logging.hpp:34
::fid_ep * raw() noexcept
Get the raw libfabric handle to this endpoint.
Definition Endpoint.cpp:312
static Id idFromFID(::fid_t) noexcept
Read the endpoint id from a libfabric object reference.
Definition Endpoint.cpp:41
std::shared_ptr< Domain > domain() const
Get the domain that the endpoint has beed created on.
Definition Endpoint.cpp:302
FabricInfoView info() const noexcept
Get the fabric information passed to Endpoint::create() initially.
Definition Endpoint.cpp:307

Member Function Documentation

◆ accept()

void mxl::lib::fabrics::ofi::Endpoint::accept ( )

Accept an incoming connection.

Information about the incoming connection must previously have been passed to Endpoint::create(). A successfully accepted connection request will result in the active (connecting) endpoint seeing an Event::Connected event on its associated event queue. A rejected or failed connection request will generate an error event. The error entry will provide additional details describing the reason for the failed attempt. An Event::Connected event will also be generated on the passive side for the accepting endpoint once the connection has been properly established. The fid of the FI_CONNECTED event will be that of the endpoint passed to fi_accept as opposed to the listening passive endpoint. Outbound data transfers cannot be initiated on a connection-oriented endpoint until an FI_CONNECTED event has been generated. However, receive buffers may be associated with an endpoint anytime.

Definition at line 174 of file Endpoint.cpp.

175 {
176 auto dummy = std::uint8_t{};
177 fiCall(::fi_accept, "Failed to accept connection", _raw, &dummy, sizeof(dummy));
178 }
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.

◆ addressVector()

std::shared_ptr< AddressVector > mxl::lib::fabrics::ofi::Endpoint::addressVector ( ) const
nodiscard

Get the associated addres vector.

If an address vector is associated with this endpoint. Get the AV. Throws an exception if no address vector is associated with this endpoint.

Definition at line 215 of file Endpoint.cpp.

216 {
217 if (!_av)
218 {
219 throw Exception::internal("No address vector bound to the endpoint!");
220 }
221 return *_av;
222 }
static Exception internal(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INTERNAL exception.
Definition Exception.hpp:51

◆ bind() [1/3]

void mxl::lib::fabrics::ofi::Endpoint::bind ( std::shared_ptr< AddressVector > av)

Bind the endpoint to an address vector.

The endpoint can be bound to an address vector only once. The Endpoint object will take ownership of an instance of the shared pointer, so the address vector can not be destroyed before the endpoint.

Definition at line 162 of file Endpoint.cpp.

163 {
164 fiCall(::fi_ep_bind, "Failed to bind address vector to endpoint", _raw, &av->raw()->fid, 0);
165
166 _av = av;
167 }

◆ bind() [2/3]

void mxl::lib::fabrics::ofi::Endpoint::bind ( std::shared_ptr< CompletionQueue > cq,
std::uint64_t flags )

Bind the endpoint to a completion queue.

The endpoint can be bound to a completion queue only once. The Endpoint object will take ownership of an instance of the shared pointer, so the queue can not be destroyed before the endpoint.

Definition at line 155 of file Endpoint.cpp.

156 {
157 fiCall(::fi_ep_bind, "Failed to bind completion queue to endpoint", _raw, &cq->raw()->fid, flags);
158
159 _cq = cq;
160 }
gInfo flags
Mark the grain as invalid.

◆ bind() [3/3]

void mxl::lib::fabrics::ofi::Endpoint::bind ( std::shared_ptr< EventQueue > eq)

Bind the endpoint to an event queue.

The endpoint can be bound to an event queue only once. The Endpoint object will take ownership of an instance of the shared pointer, so the queue can not be destroyed before the endpoint.

Definition at line 148 of file Endpoint.cpp.

149 {
150 fiCall(::fi_ep_bind, "Failed to bind event queue to endpoint", _raw, &eq->raw()->fid, 0);
151
152 _eq = eq;
153 }

◆ close()

void mxl::lib::fabrics::ofi::Endpoint::close ( )
private

Close the endpoint and release all resources. Called from the destructor and the move assignment operator.

Definition at line 105 of file Endpoint.cpp.

106 {
107 if (_raw)
108 {
109#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_DEBUG
110 auto id = this->id();
111#endif
112
113 fiCall(::fi_close, "Failed to close endpoint", &_raw->fid);
114
115 MXL_DEBUG("Endoint {} closed", id);
116
117 _raw = nullptr;
118 }
119 }
Id id() const noexcept
Get the id of this endpoint.
Definition Endpoint.cpp:83

◆ completionQueue()

std::shared_ptr< CompletionQueue > mxl::lib::fabrics::ofi::Endpoint::completionQueue ( ) const
nodiscard

Get the associated completion queue.

If a completion queue is associated with this endpoint. Get the queue. Throws an exception if no completion queue is associated with this endpoint.

Definition at line 195 of file Endpoint.cpp.

196 {
197 if (!_cq)
198 {
199 throw Exception::internal("no Completion queue is bound to the endpoint"); // Is this the right throw??
200 }
201
202 return *_cq;
203 }

◆ connect()

void mxl::lib::fabrics::ofi::Endpoint::connect ( RawFabricAddress const & addr)

Initiate a connection to a remote (passive) endpoint.

This function can only be called once in the lifetime of an Endpoint. After a connection was established, A Event::Connected event will be posted to the event queue associated with this endpoint.

Definition at line 180 of file Endpoint.cpp.

181 {
182 fiCall(::fi_connect, "Failed to connect endpoint", _raw, addr.raw(), nullptr, 0);
183 }

◆ contextValueToId()

constexpr Id mxl::lib::fabrics::ofi::Endpoint::contextValueToId ( void * contextValue)
inlinestaticnodiscardconstexprnoexcept

Convert between Ids and context values that can be written to and read from raw libfabric queue entries and fid_t.

Definition at line 57 of file Endpoint.hpp.

58 {
59 return std::bit_cast<Endpoint::Id>(contextValue);
60 }

◆ create() [1/4]

Endpoint mxl::lib::fabrics::ofi::Endpoint::create ( std::shared_ptr< Domain > domain)
static

Creates a new (active) endpoint.

A new random id will be chosen to identify the endpoint in completions and events.

Definition at line 51 of file Endpoint.cpp.

52 {
53 return Endpoint::create(std::move(domain), randomId());
54 }
static Id randomId() noexcept
Generate a new random endpoint id.
Definition Endpoint.cpp:32
static Endpoint create(std::shared_ptr< Domain > domain, FabricInfoView info)
Allocates (active) new endpoint.
Definition Endpoint.cpp:56

◆ create() [2/4]

Endpoint mxl::lib::fabrics::ofi::Endpoint::create ( std::shared_ptr< Domain > domain,
FabricInfoView info )
static

Allocates (active) new endpoint.

If the endpoint is allocated in order to accept a connection request. The fabric information obtained when accepting the connection must be passed via the info parameter. A random id will be chosen to identify the endpoint in events.

Definition at line 56 of file Endpoint.cpp.

57 {
58 return Endpoint::create(std::move(domain), randomId(), info);
59 }

◆ create() [3/4]

Endpoint mxl::lib::fabrics::ofi::Endpoint::create ( std::shared_ptr< Domain > domain,
Id id )
static

Create an (active) endpoint.

Definition at line 78 of file Endpoint.cpp.

79 {
80 return Endpoint::create(domain, epid, domain->fabric()->info());
81 }

◆ create() [4/4]

Endpoint mxl::lib::fabrics::ofi::Endpoint::create ( std::shared_ptr< Domain > domain,
Id id,
FabricInfoView info )
static

Create an (active) endpoint.

If the endpoint is allocated in order to accept a connection request. The fabric information obtained when accepting the connection must be passed via the info parameter.

Definition at line 61 of file Endpoint.cpp.

62 {
63 ::fid_ep* raw;
64
65 fiCall(::fi_endpoint, "Failed to create endpoint", domain->raw(), info.raw(), &raw, idToContextValue(epid));
66
67 // expose the private constructor to std::make_shared inside this function
68 struct MakeSharedEnabler : public Endpoint
69 {
70 MakeSharedEnabler(::fid_ep* raw, FabricInfoView info, std::shared_ptr<Domain> domain)
71 : Endpoint(raw, info, domain)
72 {}
73 };
74
75 return {raw, info, std::move(domain)};
76 }
Endpoint(Endpoint const &)=delete
static constexpr void * idToContextValue(Id id) noexcept
Convert between Ids and context values that can be written to and read from raw libfabric queue entri...
Definition Endpoint.hpp:49
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.

◆ domain()

std::shared_ptr< Domain > mxl::lib::fabrics::ofi::Endpoint::domain ( ) const
nodiscard

Get the domain that the endpoint has beed created on.

Definition at line 302 of file Endpoint.cpp.

303 {
304 return _domain;
305 }

◆ enable()

void mxl::lib::fabrics::ofi::Endpoint::enable ( )

This call transitions the endpoint into an enabled state.

An endpoint must be enabled before it may be used to perform data transfers. Enabling an endpoint typically results in hardware resources being assigned to it. Endpoints making use of completion queues, event queues, and/or address vectors must be bound to them before being enabled.

Definition at line 169 of file Endpoint.cpp.

170 {
171 fiCall(::fi_enable, "Failed to enable endpoint", _raw);
172 }

◆ eventQueue()

std::shared_ptr< EventQueue > mxl::lib::fabrics::ofi::Endpoint::eventQueue ( ) const
nodiscard

Get the assiociated event queue.

If an event queue is associated with this endpoint. Get the queue. Throws an exception if no event queue is associated with this endpoint.

Definition at line 205 of file Endpoint.cpp.

206 {
207 if (!_eq)
208 {
209 throw Exception::internal("No event queue bound to the endpoint"); // Is this the right throw??
210 }
211
212 return *_eq;
213 }

◆ id()

Endpoint::Id mxl::lib::fabrics::ofi::Endpoint::id ( ) const
nodiscardnoexcept

Get the id of this endpoint.

The id can be used to reference the endpoint from completion and regular events.

Definition at line 83 of file Endpoint.cpp.

84 {
85 return contextValueToId(_raw->fid.context);
86 }
static constexpr Id contextValueToId(void *contextValue) noexcept
Convert between Ids and context values that can be written to and read from raw libfabric queue entri...
Definition Endpoint.hpp:57

◆ idFromFID() [1/2]

Endpoint::Id mxl::lib::fabrics::ofi::Endpoint::idFromFID ( ::fid_ep * fid)
staticnoexcept

Read the endpoint id from a libfabric object reference.

The result is only guaranteed to be valid if the fid refers to a libfabric endpoint that was created with Endpoint::create()

Definition at line 46 of file Endpoint.cpp.

47 {
48 return idFromFID(&fid->fid);
49 }

◆ idFromFID() [2/2]

Endpoint::Id mxl::lib::fabrics::ofi::Endpoint::idFromFID ( ::fid_t fid)
staticnoexcept

Read the endpoint id from a libfabric object reference.

The result is only guaranteed to be valid if the fid refers to a libfabric endpoint that was created with Endpoint::create()

Definition at line 41 of file Endpoint.cpp.

42 {
43 return contextValueToId(fid->context);
44 }

◆ idFromToken()

constexpr Id mxl::lib::fabrics::ofi::Endpoint::idFromToken ( Completion::Token token)
inlinestaticnodiscardconstexprnoexcept

Convert a completion token value to an endpoint id value. Convert a completion token to an endpoint id value. This does not perform any lookups, it just converts the types. This is a pure function and will always return the same endpoint id for the same completion token. This function enables using the endpoint id as a completion token.

Definition at line 82 of file Endpoint.hpp.

83 {
84 static_assert(std::is_same_v<Completion::Token, Id>, "Completion token and endpoint id should be the same underlying type.");
85 return token;
86 }

◆ idToContextValue()

constexpr void * mxl::lib::fabrics::ofi::Endpoint::idToContextValue ( Id id)
inlinestaticnodiscardconstexprnoexcept

Convert between Ids and context values that can be written to and read from raw libfabric queue entries and fid_t.

Definition at line 49 of file Endpoint.hpp.

50 {
51 return std::bit_cast<void*>(id);
52 }

◆ info()

FabricInfoView mxl::lib::fabrics::ofi::Endpoint::info ( ) const
nodiscardnoexcept

Get the fabric information passed to Endpoint::create() initially.

Definition at line 307 of file Endpoint.cpp.

308 {
309 return _info.view();
310 }

◆ localAddress()

RawFabricAddress mxl::lib::fabrics::ofi::Endpoint::localAddress ( ) const
nodiscard

Obtain the local fabric address for this endpoint.

Definition at line 190 of file Endpoint.cpp.

191 {
192 return RawFabricAddress::fromFid(&_raw->fid, _info.view());
193 }
static RawFabricAddress fromFid(::fid_t fid, FabricInfoView info)
Retrieve the fabric address of an endpoint by passing its fid.
Definition Address.cpp:27

◆ operator=() [1/2]

Endpoint & mxl::lib::fabrics::ofi::Endpoint::operator= ( Endpoint && other)

Definition at line 132 of file Endpoint.cpp.

133 {
134 close();
135
136 _raw = other._raw;
137 other._raw = nullptr;
138
139 _info = std::move(other._info);
140 _domain = std::move(other._domain);
141 _eq = std::move(other._eq);
142 _cq = std::move(other._cq);
143 _av = std::move(other._av);
144
145 return *this;
146 }

◆ operator=() [2/2]

void mxl::lib::fabrics::ofi::Endpoint::operator= ( Endpoint const & )
delete

◆ randomId()

Endpoint::Id mxl::lib::fabrics::ofi::Endpoint::randomId ( )
staticnodiscardnoexcept

Generate a new random endpoint id.

Definition at line 32 of file Endpoint.cpp.

33 {
34 // Use a global static random engine to prevent endpoint id collisions.
35 static auto mu = std::mutex{};
36 static auto engine = std::mt19937_64{std::random_device{}()};
37 auto const lock = std::scoped_lock{mu};
38 return std::uniform_int_distribution<Endpoint::Id>{}(engine);
39 }

◆ raw() [1/2]

fid_ep const * mxl::lib::fabrics::ofi::Endpoint::raw ( ) const
nodiscardnoexcept

Get the raw libfabric handle to this endpoint.

Definition at line 317 of file Endpoint.cpp.

318 {
319 return _raw;
320 }

◆ raw() [2/2]

fid_ep * mxl::lib::fabrics::ofi::Endpoint::raw ( )
noexcept

Get the raw libfabric handle to this endpoint.

Definition at line 312 of file Endpoint.cpp.

313 {
314 return _raw;
315 }

◆ readQueues()

std::pair< std::optional< Completion >, std::optional< Event > > mxl::lib::fabrics::ofi::Endpoint::readQueues ( )

Do a non-blocking read of both the event and completion queue associated with this endpoint.

Definition at line 224 of file Endpoint.cpp.

225 {
226 std::optional<Completion> completion{std::nullopt};
227 std::optional<Event> event{std::nullopt};
228
229 if (_cq)
230 {
231 completion = (*_cq)->read();
232 }
233
234 if (_eq)
235 {
236 event = (*_eq)->read();
237 }
238
239 return {completion, event};
240 }

◆ readQueuesBlocking()

std::pair< std::optional< Completion >, std::optional< Event > > mxl::lib::fabrics::ofi::Endpoint::readQueuesBlocking ( std::chrono::steady_clock::duration timeout)

Do a combined blocking read of both the event and completion queue associated with this endpoint.

This function will do a non-blocking read of the event queue in an interval of 100ms and block on the completion queue the rest of the time.

Definition at line 242 of file Endpoint.cpp.

243 {
244 std::optional<Completion> completion{std::nullopt};
245 std::optional<Event> event{std::nullopt};
246
247 // No queues, no blocking;
248 if (!_eq && !_cq)
249 {
250 throw Exception::invalidState("No queues bound to endpoint");
251 }
252
253 // There is no event queue, so we just block on the completion queue.
254 if (!_eq)
255 {
256 return {(*_cq)->readBlocking(timeout), event};
257 }
258
259 auto timeoutMs = std::chrono::duration_cast<std::remove_const_t<decltype(EQReadInterval)>>(timeout);
260
261 // This is the simple case: The user-supplied timeout is less than the minimum EventQueue read interval. So we just read the EventQueue once
262 // and then block on the CompletionQueue until the specified timeout.
263 if (timeoutMs < EQReadInterval)
264 {
265 auto event = (*_eq)->read();
266 auto completion = (*_cq)->readBlocking(timeout);
267
268 return {completion, event};
269 }
270
271 // The time point at which we must return control to the user.
272 auto deadline = std::chrono::steady_clock::now() + timeout;
273
274 for (;;)
275 {
276 // The maximum duration we can block for until we must return control to the caller.
277 auto timeUntilDeadline = std::chrono::duration_cast<std::chrono::milliseconds>(deadline - std::chrono::steady_clock::now());
278
279 // If the time is up, we return control.
280 if (timeUntilDeadline <= std::chrono::milliseconds(0))
281 {
282 return {completion, event};
283 }
284
285 // Do a non-blocking read of the event queue first.
286 event = (*_eq)->read();
287 if (event)
288 {
289 return {completion, event};
290 }
291
292 // And then block on the completion queue until either the minimum duration between event queue reads has elapsed, or the latest point in
293 // time at which we need to return control to the caller has been reached.
294 completion = (*_cq)->readBlocking(std::min(EQReadInterval, timeUntilDeadline));
295 if (completion)
296 {
297 return {completion, event};
298 }
299 }
300 }
static constexpr auto const EQReadInterval
The minimum interval at which the event queue will be polled when doing a blocking read of both (even...
Definition Endpoint.hpp:34
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59

◆ recv()

void mxl::lib::fabrics::ofi::Endpoint::recv ( LocalRegion region) const

Push a recv work request to the endpoint work queue.

If this is used to receive media data, a bounce buffer shall be used to receive the data into, following by a post completion operation to copy the data back to the media buffers. This is required, because we only know the identification of the receive media data once it is received. In the MXL context, this function can also be used to receive immediate data if domain function usingRecvBufForCqData returns true.

Parameters
regionSource memory region to receive data into

Definition at line 398 of file Endpoint.cpp.

399 {
400 auto iovec = region.toIovec();
401 fiCall(::fi_recv, "Failed to push recv to work queue", _raw, iovec.iov_base, iovec.iov_len, nullptr, FI_ADDR_UNSPEC, nullptr);
402 }

◆ shutdown()

void mxl::lib::fabrics::ofi::Endpoint::shutdown ( )

Initiate a graceful shutdown on a connection-oriented endpoint.

When the shutdown is complete, a Event::Shutdown event will be posted to the event queue associated with this endpoint.

Definition at line 185 of file Endpoint.cpp.

186 {
187 fiCall(::fi_shutdown, "Failed to shutdown endpoint", _raw, 0);
188 }

◆ tokenFromId()

constexpr Completion::Token mxl::lib::fabrics::ofi::Endpoint::tokenFromId ( Id id)
inlinestaticnodiscardconstexprnoexcept

Convert an endpoint id value to a completion token value. Convert an endpoint id to a completion token value. This does not perform any lookups, it just converts the types. This is a pure function and will always return the same token value for the same endpoint id. This function enables using the endpoint id as a completion token.

Definition at line 69 of file Endpoint.hpp.

70 {
71 static_assert(std::is_same_v<Completion::Token, Id>, "Completion token and endpoint id should be the same underlying type.");
72 return id;
73 }

◆ write() [1/2]

std::size_t mxl::lib::fabrics::ofi::Endpoint::write ( Completion::Token token,
LocalRegion const & local,
RemoteRegion const & remote,
::fi_addr_t destAddr = FI_ADDR_UNSPEC,
std::optional< std::uint32_t > immData = std::nullopt ) const
nodiscard

Push a remote write work request of a single contiguous buffer to the endpoint work queue.

When the write is complete, a Completion::Data will be pushed to the completion queue associated with the endpoint. Before a write request can be made, the endpoint must have been enabled.

Parameters
tokenCompletion token to associate with the write operation
localSource memory region to write from
remoteGroupDestination memory regions to write to
destAddrThe destination address of the target endpoint. This is unused when using connected endpoints.
immData64 bits of user data that will be available in the completion entry associated with this transfer.
Returns
The number of requests posted to the endpoint work queue

Definition at line 343 of file Endpoint.cpp.

345 {
346 std::vector<void*> descs{local.desc};
347
348 auto msgIov = local.toIovec();
349 auto rmaIov = remote.toRmaIov();
350
351 writeImpl(token, &msgIov, 1, descs.data(), &rmaIov, destAddr, immData);
352
353 return 1;
354 }
void writeImpl(Completion::Token token, ::iovec const *msgIov, std::size_t iovCount, void **desc, ::fi_rma_iov const *rmaIov, ::fi_addr_t destAddr, std::optional< std::uint32_t > immData) const
Internal implementation of the remote write request.
Definition Endpoint.cpp:322

◆ write() [2/2]

std::size_t mxl::lib::fabrics::ofi::Endpoint::write ( Completion::Token token,
LocalRegionGroup const & localGroup,
RemoteRegion const & remote,
::fi_addr_t destAddr = FI_ADDR_UNSPEC,
std::optional< std::uint32_t > immData = std::nullopt ) const
nodiscard

Push a remote write work request of a scatter-gather list to the endpoint work queue.

When the write is complete, a Completion::Data will be pushed to the completion queue associated with the endpoint. Before a write request can be made, the endpoint must have been enabled.

Parameters
tokenCompletion token to associate with the write operation
localGroupSource memory regions to write from (scatter-gather version)
remoteGroupDestination memory regions to write to
destAddrThe destination address of the target endpoint. This is unused when using connected endpoints.
64bits of user data that will be available in the completion entry associated with this transfer.
Returns
The number of requests posted to the endpoint work queue
Note
In this function, there will potentially be more than a single write transfer. This occurs if the IOV limit supported by the endpoint is smaller than the number of local regions in the local region group. In that case, multiple writes are performed. This behavior is handled completely by the function and will return the number of writes performed accordingly. Note that, only the last transfer is posted with immediate data to signal completion to the target.

Definition at line 356 of file Endpoint.cpp.

358 {
359 auto remoteRmaIov = remote.toRmaIov();
360 auto remoteOffset = std::size_t{0};
361
362 auto const iovLimit = info().txIovLimit();
363 auto const nbWrites = (localGroup.size() + iovLimit - 1) / iovLimit; // ceil(group.size() / iovLimit)
364
365 for (auto i = std::size_t{0}; i < nbWrites; i++)
366 {
367 auto const begin = i * iovLimit;
368 auto const end = begin + std::min(iovLimit, localGroup.size() - begin);
369
370 auto const localGroupSpan = localGroup.span(begin, end);
371
372 // Validate that we don't bust the remote region
373 if ((remoteOffset + localGroupSpan.byteSize()) > remote.len)
374 {
375 throw Exception::invalidArgument("Local region group is too large for the remote region.");
376 }
377
378 remoteRmaIov.addr = remote.addr + remoteOffset;
379 remoteRmaIov.len = localGroupSpan.byteSize();
380
381 auto const isLastWrite = (i == nbWrites - 1);
382 auto const immDataForWrite = isLastWrite ? immData : std::nullopt;
383
384 writeImpl(token,
385 localGroupSpan.asIovec(),
386 localGroupSpan.size(),
387 const_cast<void**>(localGroupSpan.desc()),
388 &remoteRmaIov,
389 destAddr,
390 immDataForWrite);
391
392 remoteOffset += localGroupSpan.byteSize();
393 }
394
395 return nbWrites;
396 }
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
std::size_t txIovLimit() const noexcept
Return the IOV limit for this fabric info, which is the maximum number of iovecs that can be posted i...

◆ writeImpl()

void mxl::lib::fabrics::ofi::Endpoint::writeImpl ( Completion::Token token,
::iovec const * msgIov,
std::size_t iovCount,
void ** desc,
::fi_rma_iov const * rmaIov,
::fi_addr_t destAddr,
std::optional< std::uint32_t > immData ) const
private

Internal implementation of the remote write request.

Definition at line 322 of file Endpoint.cpp.

324 {
325 std::uint64_t data = immData.value_or(0);
326 std::uint64_t flags = FI_DELIVERY_COMPLETE;
327 flags |= immData.has_value() ? FI_REMOTE_CQ_DATA : 0;
328
329 ::fi_msg_rma msg = {
330 .msg_iov = msgIov,
331 .desc = desc,
332 .iov_count = iovCount,
333 .addr = destAddr,
334 .rma_iov = rmaIov,
335 .rma_iov_count = 1,
336 .context = Completion::tokenToContextValue(token),
337 .data = data,
338 };
339
340 fiCall(::fi_writemsg, "Failed to push rma write to work queue.", _raw, &msg, flags);
341 }
static constexpr void * tokenToContextValue(Token token) noexcept
Convert between completion tokens and context values that can be written to and read from raw libfabr...

Member Data Documentation

◆ _av

std::optional<std::shared_ptr<AddressVector> > mxl::lib::fabrics::ofi::Endpoint::_av
private

Address vector lives here after Endpoint::bind()

Definition at line 327 of file Endpoint.hpp.

◆ _cq

std::optional<std::shared_ptr<CompletionQueue> > mxl::lib::fabrics::ofi::Endpoint::_cq
private

Completion queue lives here after Endpoint::bind()

Definition at line 325 of file Endpoint.hpp.

◆ _domain

std::shared_ptr<Domain> mxl::lib::fabrics::ofi::Endpoint::_domain
private

Domain in which the endpoint was created

Definition at line 323 of file Endpoint.hpp.

◆ _eq

std::optional<std::shared_ptr<EventQueue> > mxl::lib::fabrics::ofi::Endpoint::_eq
private

Event queue lives here after Endpoint::bind()

Definition at line 326 of file Endpoint.hpp.

◆ _info

FabricInfo mxl::lib::fabrics::ofi::Endpoint::_info
private

Info passed via Endpoint::create()

Definition at line 322 of file Endpoint.hpp.

◆ _raw

::fid_ep* mxl::lib::fabrics::ofi::Endpoint::_raw
private

Raw resource reference

Definition at line 321 of file Endpoint.hpp.

◆ EQReadInterval

auto const mxl::lib::fabrics::ofi::Endpoint::EQReadInterval = std::chrono::milliseconds(100)
staticconstexpr

The minimum interval at which the event queue will be polled when doing a blocking read of both (event and completion) queues.

Definition at line 34 of file Endpoint.hpp.


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