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

RAII Wrapper to a libfabric fi_av instance. More...

#include <AddressVector.hpp>

Classes

struct  Attributes
 Configuration attributes of the AddressVector. More...

Public Member Functions

 AddressVector (AddressVector &&) noexcept
 AddressVector (AddressVector const &)=delete
std::string addrToString (RawFabricAddress const &addr) const
 Convert a libfabric endpoint address into a human-readable string.
::fi_addr_t insert (RawFabricAddress const &addr)
 Insert an address into the address vector. User of this API are responsible for keeping track of inserted addresses to avoid duplicates.
AddressVector & operator= (AddressVector &&)
void operator= (AddressVector const &)=delete
::fid_av const * raw () const noexcept
 Immutable accessor of the underlying fi_av instance.
::fid_av * raw () noexcept
 Mutable accessor of the underlying fi_av instance.
void remove (::fi_addr_t addr) noexcept
 Remove an address of the address vector.
 ~AddressVector ()

Static Public Member Functions

static std::shared_ptr< AddressVector > open (std::shared_ptr< Domain > domain, Attributes attr=Attributes::defaults())
 Create an AddressVector.

Private Member Functions

 AddressVector (fid_av *raw, std::shared_ptr< Domain > domain)
void close ()
 Close the address vector and release all resources. Called from the destructor and the move assignment operator.

Private Attributes

std::shared_ptr< Domain > _domain
fid_av * _raw

Detailed Description

RAII Wrapper to a libfabric fi_av instance.

Definition at line 18 of file AddressVector.hpp.

Constructor & Destructor Documentation

◆ ~AddressVector()

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

Definition at line 94 of file AddressVector.cpp.

95 {
96 catchAndLogFabricError([this]() { close(); }, "Failed to close address vector");
97 }
void close()
Close the address vector and release all resources. Called from the destructor and the move assignmen...
void catchAndLogFabricError(F &&fun, std::string_view msg)

◆ AddressVector() [1/3]

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

◆ AddressVector() [2/3]

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

Definition at line 99 of file AddressVector.cpp.

100 : _raw(other._raw)
101 , _domain(std::move(other._domain))
102 {
103 other._raw = nullptr;
104 }
std::shared_ptr< Domain > _domain

◆ AddressVector() [3/3]

mxl::lib::fabrics::ofi::AddressVector::AddressVector ( fid_av * raw,
std::shared_ptr< Domain > domain )
private

Member Function Documentation

◆ addrToString()

std::string mxl::lib::fabrics::ofi::AddressVector::addrToString ( RawFabricAddress const & addr) const
nodiscard

Convert a libfabric endpoint address into a human-readable string.

Definition at line 72 of file AddressVector.cpp.

73 {
74 std::string s;
75 std::size_t len = 0;
76
77 ::fi_av_straddr(_raw, addr.raw(), nullptr, &len);
78 s.resize(len);
79
80 auto ret = ::fi_av_straddr(_raw, addr.raw(), s.data(), &len);
81 if (ret == nullptr)
82 {
83 throw Exception::internal("Failed to convert address to string");
84 }
85
86 return s;
87 }
static Exception internal(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INTERNAL exception.
Definition Exception.hpp:51

◆ close()

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

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

Definition at line 117 of file AddressVector.cpp.

118 {
119 if (_raw)
120 {
121 MXL_DEBUG("Closing address vector");
122
123 fiCall(::fi_close, "Failed to close address vector", &_raw->fid);
124 _raw = nullptr;
125 }
126 }
#define MXL_DEBUG(...)
Definition Logging.hpp:34
int fiCall(F &&fun, std::string_view msg, T &&... args)
Call a libfabric function and check its return code.

◆ insert()

fi_addr_t mxl::lib::fabrics::ofi::AddressVector::insert ( RawFabricAddress const & addr)

Insert an address into the address vector. User of this API are responsible for keeping track of inserted addresses to avoid duplicates.

Definition at line 54 of file AddressVector.cpp.

55 {
56 ::fi_addr_t fiAddr{FI_ADDR_UNSPEC};
57
58 if (auto ret = ::fi_av_insert(_raw, addr.raw(), 1, &fiAddr, 0, nullptr); ret != 1)
59 {
60 throw Exception::internal("Failed to insert address into the address vector. {}", ::fi_strerror(ret));
61 }
62 MXL_INFO("Remote endpoint address {} was added to the address vector", addrToString(addr));
63
64 return fiAddr;
65 }
#define MXL_INFO(...)
Definition Logging.hpp:45
std::string addrToString(RawFabricAddress const &addr) const
Convert a libfabric endpoint address into a human-readable string.

◆ open()

std::shared_ptr< AddressVector > mxl::lib::fabrics::ofi::AddressVector::open ( std::shared_ptr< Domain > domain,
Attributes attr = Attributes::defaults() )
static

Create an AddressVector.

Definition at line 35 of file AddressVector.cpp.

36 {
37 fid_av* raw;
38
39 auto fiAttr = attr.toRaw();
40
41 fiCall(::fi_av_open, "Failed to open address vector", domain->raw(), &fiAttr, &raw, nullptr);
42
43 // expose the private constructor to std::make_shared inside this function
44 struct MakeSharedEnabler : public AddressVector
45 {
46 MakeSharedEnabler(fid_av* raw, std::shared_ptr<Domain> domain)
47 : AddressVector(raw, std::move(domain))
48 {}
49 };
50
51 return std::make_shared<MakeSharedEnabler>(raw, domain);
52 }
AddressVector(AddressVector const &)=delete
::fid_av * raw() noexcept
Mutable accessor of the underlying fi_av instance.
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.

◆ operator=() [1/2]

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

Definition at line 106 of file AddressVector.cpp.

107 {
108 close();
109
110 _raw = other._raw;
111 other._raw = nullptr;
112 _domain = std::move(other._domain);
113
114 return *this;
115 }

◆ operator=() [2/2]

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

◆ raw() [1/2]

fid_av const * mxl::lib::fabrics::ofi::AddressVector::raw ( ) const
nodiscardnoexcept

Immutable accessor of the underlying fi_av instance.

Definition at line 133 of file AddressVector.cpp.

134 {
135 return _raw;
136 }

◆ raw() [2/2]

fid_av * mxl::lib::fabrics::ofi::AddressVector::raw ( )
noexcept

Mutable accessor of the underlying fi_av instance.

Definition at line 128 of file AddressVector.cpp.

129 {
130 return _raw;
131 }

◆ remove()

void mxl::lib::fabrics::ofi::AddressVector::remove ( ::fi_addr_t addr)
noexcept

Remove an address of the address vector.

Definition at line 67 of file AddressVector.cpp.

68 {
69 fiCall(::fi_av_remove, "Failed to remove address from address vector", _raw, &addr, 1, 0);
70 }

Member Data Documentation

◆ _domain

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

Definition at line 95 of file AddressVector.hpp.

◆ _raw

fid_av* mxl::lib::fabrics::ofi::AddressVector::_raw
private

Definition at line 94 of file AddressVector.hpp.


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