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

A single endpoint within an RDMInitiator. More...

#include <RDMInitiator.hpp>

Collaboration diagram for mxl::lib::fabrics::ofi::RDMInitiatorTarget:

Classes

struct  Activated
 The endpoint activated state. More...
struct  Done
 The endpoint is done and can be evicted from the initiator. More...
struct  Idle
 The idle state. More...
struct  Removing
 The removing state. More...

Public Member Functions

void activate (Endpoint &ep)
 Try to activate the endpoint.
bool canEvict () const noexcept
 Returns true if the target was shut down and can be evicted from the initiator.
void finishRemoval (Endpoint &ep)
 Complete the removal once all outstanding writes have completed or RemoveTimeout has elapsed.
void handleCompletion (Endpoint &ep, Completion completion)
 Handle a completion event for this endpoint.
bool hasPendingWork () const noexcept
 Returns true if there's pending work for this target.
bool isIdle () const noexcept
 Returns true if the endpoint is idle and could be actived.
 RDMInitiatorTarget (std::unique_ptr< EgressProtocol > proto, TargetInfo remoteInfo)
 Construct a new RDMInitiatorEndpoint object.
void shutdown (Endpoint &ep)
 Stop transfers to this target.
void transferGrain (Endpoint const &ep, std::uint64_t localIndex, std::uint64_t remoteIndex, std::uint64_t remotePayloadOffset, SliceRange const &sliceRange)
 Post a grain data transfer request to this endpoint.
void transferSamples (Endpoint const &ep, std::uint64_t headIndex, std::size_t count)
 Post a sample data transfer request to this endpoint.

Static Public Attributes

static constexpr auto RemoveTimeout = std::chrono::seconds(2)
 Upper bound for the removing state. A target that disappears may never complete the outstanding writes.

Private Types

using State = std::variant<Idle, Activated, Removing, Done>
 The various states that the endpoint can be in are stored inside a variant that we move from and then back into when processing events.

Private Attributes

std::unique_ptr< EgressProtocol > _proto
TargetInfo _remoteInfo
State _state

Detailed Description

A single endpoint within an RDMInitiator.

Definition at line 23 of file RDMInitiator.hpp.

Member Typedef Documentation

◆ State

The various states that the endpoint can be in are stored inside a variant that we move from and then back into when processing events.

Definition at line 123 of file RDMInitiator.hpp.

Constructor & Destructor Documentation

◆ RDMInitiatorTarget()

mxl::lib::fabrics::ofi::RDMInitiatorTarget::RDMInitiatorTarget ( std::unique_ptr< EgressProtocol > proto,
TargetInfo remoteInfo )

Construct a new RDMInitiatorEndpoint object.

Parameters
epThe endpoint to use for posting transfers.
addrThe fabric address of the remote endpoint.
regionsThe remote memory regions to transfer data to.

Definition at line 35 of file RDMInitiator.cpp.

36 : _state(Idle{})
37 , _proto(std::move(proto))
38 , _remoteInfo(std::move(remoteInfo))
39 {}
std::unique_ptr< EgressProtocol > _proto

Member Function Documentation

◆ activate()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::activate ( Endpoint & ep)

Try to activate the endpoint.

The endpoint is activated by adding the remote address to the address vector.

Definition at line 46 of file RDMInitiator.cpp.

47 {
48 _state = std::visit(
49 overloaded{
50 [&](Idle) -> State
51 {
52 auto fiAddr = ep.addressVector()->insert(_remoteInfo.fabricAddress);
53 return Activated{.fiAddr = fiAddr};
54 },
55 [](Activated state) -> State { return state; },
56 [](Removing state) -> State { return state; },
57 [](Done) -> State { throw Exception::invalidState("Endpoint has been shutdown and can no longer be used."); },
58 },
59 std::move(_state));
60 }
static Exception invalidState(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_STATE exception.
Definition Exception.hpp:59
std::variant< Idle, Activated, Removing, Done > State
The various states that the endpoint can be in are stored inside a variant that we move from and then...
The endpoint is done and can be evicted from the initiator.

◆ canEvict()

bool mxl::lib::fabrics::ofi::RDMInitiatorTarget::canEvict ( ) const
nodiscardnoexcept

Returns true if the target was shut down and can be evicted from the initiator.

Definition at line 110 of file RDMInitiator.cpp.

111 {
112 return std::holds_alternative<Done>(_state);
113 }

◆ finishRemoval()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::finishRemoval ( Endpoint & ep)

Complete the removal once all outstanding writes have completed or RemoveTimeout has elapsed.

Removes the address vector entry and moves the target to the done state. In any other state than the removing state, this is a no-op.

Definition at line 88 of file RDMInitiator.cpp.

89 {
90 auto const state = std::get_if<Removing>(&_state);
91 if (state == nullptr)
92 {
93 return;
94 }
95
96 if (std::chrono::steady_clock::now() >= state->deadline)
97 {
98 MXL_WARN("Writes to the removed target did not complete within {} ms, removing it anyway.",
99 std::chrono::duration_cast<std::chrono::milliseconds>(RemoveTimeout).count());
100 }
101 else
102 {
103 return;
104 }
105
106 ep.addressVector()->remove(state->fiAddr);
107 _state = Done{};
108 }
#define MXL_WARN(...)
Definition Logging.hpp:56
static constexpr auto RemoveTimeout
Upper bound for the removing state. A target that disappears may never complete the outstanding write...
std::size_t count(uuids::uuid id) const noexcept
Returns the number of writers registered for flow id 'id'.

◆ handleCompletion()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::handleCompletion ( Endpoint & ep,
Completion completion )

Handle a completion event for this endpoint.

Definition at line 144 of file RDMInitiator.cpp.

145 {
146 if (auto error = completion.tryErr(); error)
147 {
148 MXL_ERROR("Received a completion error: {}", error->toString());
149 }
150
151 std::visit(
152 overloaded{
153 [](Idle const&) {},
154 [&](Activated const&) { _proto->processCompletion(completion); },
155 [&](Removing const&) { _proto->processCompletion(completion); },
156 [](Done const&) {},
157 },
158 _state);
159 }
#define MXL_ERROR(...)
Definition Logging.hpp:67

◆ hasPendingWork()

bool mxl::lib::fabrics::ofi::RDMInitiatorTarget::hasPendingWork ( ) const
nodiscardnoexcept

Returns true if there's pending work for this target.

Definition at line 132 of file RDMInitiator.cpp.

133 {
134 return std::visit(
135 overloaded{
136 [](Idle const&) { return true; },
137 [&](Activated const&) { return _proto->hasPendingWork(); },
138 [](Removing const&) { return true; },
139 [](Done const&) { return false; },
140 },
141 _state);
142 }

◆ isIdle()

bool mxl::lib::fabrics::ofi::RDMInitiatorTarget::isIdle ( ) const
nodiscardnoexcept

Returns true if the endpoint is idle and could be actived.

Definition at line 41 of file RDMInitiator.cpp.

42 {
43 return std::holds_alternative<Idle>(_state);
44 }

◆ shutdown()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::shutdown ( Endpoint & ep)

Stop transfers to this target.

If writes are still outstanding, the target goes to the removing state. It keeps its address vector entry and its protocol instance until finishRemoval() finds that the writes have completed. Otherwise the address vector entry is removed right away and the target can be evicted.

Definition at line 62 of file RDMInitiator.cpp.

63 {
64 _state = std::visit(
65 overloaded{
66 [](Idle) -> State
67 {
68 MXL_WARN("Shutdown requested while waiting to activate, aborting.");
69 return Done{};
70 },
71 [&](Activated state) -> State
72 {
73 if (_proto->hasPendingWork())
74 {
75 MXL_INFO("Target removed that had outstanding writes, transitioning to removing state.");
76 return Removing{.fiAddr = state.fiAddr, .deadline = std::chrono::steady_clock::now() + RemoveTimeout};
77 }
78
79 ep.addressVector()->remove(state.fiAddr);
80 return Done{};
81 },
82 [](Removing state) -> State { return state; },
83 [](Done state) -> State { return state; },
84 },
85 std::move(_state));
86 }
#define MXL_INFO(...)
Definition Logging.hpp:45

◆ transferGrain()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::transferGrain ( Endpoint const & ep,
std::uint64_t localIndex,
std::uint64_t remoteIndex,
std::uint64_t remotePayloadOffset,
SliceRange const & sliceRange )

Post a grain data transfer request to this endpoint.

Definition at line 115 of file RDMInitiator.cpp.

117 {
118 if (auto const state = std::get_if<Activated>(&_state); state != nullptr)
119 {
120 _proto->transferGrain(ep, localIndex, remoteIndex, remotePayloadOffset, sliceRange, state->fiAddr);
121 }
122 }

◆ transferSamples()

void mxl::lib::fabrics::ofi::RDMInitiatorTarget::transferSamples ( Endpoint const & ep,
std::uint64_t headIndex,
std::size_t count )

Post a sample data transfer request to this endpoint.

Definition at line 124 of file RDMInitiator.cpp.

125 {
126 if (auto const state = std::get_if<Activated>(&_state); state != nullptr)
127 {
128 _proto->transferSamples(ep, headIndex, count, state->fiAddr);
129 }
130 }

Member Data Documentation

◆ _proto

std::unique_ptr<EgressProtocol> mxl::lib::fabrics::ofi::RDMInitiatorTarget::_proto
private

Definition at line 127 of file RDMInitiator.hpp.

◆ _remoteInfo

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

Definition at line 129 of file RDMInitiator.hpp.

◆ _state

State mxl::lib::fabrics::ofi::RDMInitiatorTarget::_state
private

The current state of the endpoint.

Definition at line 126 of file RDMInitiator.hpp.

◆ RemoveTimeout

auto mxl::lib::fabrics::ofi::RDMInitiatorTarget::RemoveTimeout = std::chrono::seconds(2)
staticconstexpr

Upper bound for the removing state. A target that disappears may never complete the outstanding writes.

Definition at line 67 of file RDMInitiator.hpp.


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