MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
mxl::lib::fabrics::ofi::TargetInfo Struct Reference

TargetInfo contains all the information required by an initiator to operate transfers to the given target. More...

#include <TargetInfo.hpp>

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

Public Member Functions

bool operator== (TargetInfo const &other) const noexcept
::mxlFabricsTargetInfo toAPI () noexcept
 Cast a pointer to a TargetInfo instance to an mxlFabricsTargetInfo opaque pointer.
std::string toJSON () const
 Serialize a TargetInfo instance to a JSON representation.

Static Public Member Functions

static TargetInfo * fromAPI (mxlFabricsTargetInfo api) noexcept
 Cast an mxlFabricsTargetInfo opaque pointer to a TargetInfo pointer.
static TargetInfo fromJSON (std::string const &s)
 Construct a TargetInfo instance from a JSON representation.

Public Attributes

std::optional< TargetInfoBounceBufferInfo > bounceBufferInfo
RawFabricAddress fabricAddress
Endpoint::Id id
Provider provider
std::vector< RemoteRegion > remoteRegions

Detailed Description

TargetInfo contains all the information required by an initiator to operate transfers to the given target.

In the context of libfabric this means, the fi_addr, all the buffer addresses and sizes, and the remote protection key.

Definition at line 28 of file TargetInfo.hpp.

Member Function Documentation

◆ fromAPI()

TargetInfo * mxl::lib::fabrics::ofi::TargetInfo::fromAPI ( mxlFabricsTargetInfo api)
staticnodiscardnoexcept

Cast an mxlFabricsTargetInfo opaque pointer to a TargetInfo pointer.

Definition at line 23 of file TargetInfo.cpp.

24 {
25 return reinterpret_cast<TargetInfo*>(api);
26 }

◆ fromJSON()

TargetInfo mxl::lib::fabrics::ofi::TargetInfo::fromJSON ( std::string const & s)
staticnodiscard

Construct a TargetInfo instance from a JSON representation.

Definition at line 65 of file TargetInfo.cpp.

66 {
67 // The target info has one region per grain, so it can be much larger than a flow definition.
68 constexpr auto limits = JsonLimits{.maxInputSize = std::size_t{4} * 1024U * 1024U, .maxDepth = 8U, .maxContainerSize = 65536U};
69
70 auto parsed = picojson::value{};
71 auto const err = parseJson(parsed, s, limits);
72 if (!err.empty())
73 {
74 throw Exception::invalidArgument("Failure when parsing JSON: {} ", err);
75 }
76
77 if (!parsed.is<picojson::object>())
78 {
79 throw Exception::invalidArgument("Expected a JSON object");
80 }
81
82 auto root = parsed.get<picojson::object>();
83
84 // The conversion helpers throw std::invalid_argument, which the C API would report as MXL_ERR_UNKNOWN.
85 try
86 {
87 auto const addressFormat = mustConvertAddressFormat(jsonToInteger<std::uint32_t>(root.at("addressFormat"), "addressFormat"));
88 auto const fabricAddress = RawFabricAddress::fromBase64(root.at("fabricAddress").get<std::string>(), addressFormat);
89
90 auto regions = std::vector<RemoteRegion>{};
91 for (auto const& regionValue : root.at("regions").get<picojson::array>())
92 {
93 auto const regionObj = regionValue.get<picojson::object>();
94
95 // Conversions of types that represent memory addresses to strings is preferred over converting to float
96 // to make sure nobody can reduce precision when converting on the way.
97 auto const addr = jsonStringToInteger<std::uint64_t>(regionObj.at("addr"), "addr");
98 auto const len = jsonStringToInteger<std::size_t>(regionObj.at("len"), "len");
99 auto const rkey = jsonStringToInteger<std::uint64_t>(regionObj.at("rkey"), "rkey");
100 regions.emplace_back(addr, len, rkey);
101 }
102
103 auto bounceBufferInfo = std::optional<TargetInfoBounceBufferInfo>{std::nullopt};
104 if (root.contains("bounceBufferInfo"))
105 {
106 auto const bounceBufferInfoObj = root.at("bounceBufferInfo").get<picojson::object>();
107 auto const entryCount = jsonStringToInteger<std::size_t>(bounceBufferInfoObj.at("entryCount"), "entryCount");
108 auto const entrySize = jsonStringToInteger<std::size_t>(bounceBufferInfoObj.at("entrySize"), "entrySize");
109 bounceBufferInfo = std::make_optional<TargetInfoBounceBufferInfo>(entryCount, entrySize);
110 }
111
112 auto const id = jsonStringToInteger<Endpoint::Id>(root.at("id"), "id");
113 auto const provider = providerFromString(root.at("provider").get<std::string>()).value_or(Provider::ANY);
114 return {.id = id, .fabricAddress = fabricAddress, .provider = provider, .remoteRegions = regions, .bounceBufferInfo = bounceBufferInfo};
115 }
116 catch (std::invalid_argument const& e)
117 {
118 throw Exception::invalidArgument("{}", e.what());
119 }
120 }
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
Definition Exception.hpp:43
static RawFabricAddress fromBase64(std::string_view data, FabricAddressFormat addressFormat)
Parse a fabric address from a base64 encoded string.
Definition Address.cpp:67
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
Definition Provider.cpp:49
FabricAddressFormat mustConvertAddressFormat(std::uint32_t fiAddrFormat)
Convert from libfabric address format value to FabricAddressFormat Never returns FabricAddressFormat:...
T jsonStringToInteger(picojson::value const &value, std::string_view name)
T jsonToInteger(picojson::value const &value, std::string_view name)
std::string parseJson(picojson::value &out, std::string_view text, JsonLimits const &limits={})
std::optional< TargetInfoBounceBufferInfo > bounceBufferInfo

◆ operator==()

bool mxl::lib::fabrics::ofi::TargetInfo::operator== ( TargetInfo const & other) const
noexcept

Definition at line 122 of file TargetInfo.cpp.

123 {
124 return (fabricAddress == other.fabricAddress) && (remoteRegions == other.remoteRegions) && (id == other.id);
125 }
std::vector< RemoteRegion > remoteRegions

◆ toAPI()

mxlFabricsTargetInfo mxl::lib::fabrics::ofi::TargetInfo::toAPI ( )
nodiscardnoexcept

Cast a pointer to a TargetInfo instance to an mxlFabricsTargetInfo opaque pointer.

Definition at line 28 of file TargetInfo.cpp.

29 {
30 return reinterpret_cast<mxlFabricsTargetInfo>(this);
31 }
struct mxlFabricsTargetInfo_t * mxlFabricsTargetInfo
Definition fabrics.h:39

◆ toJSON()

std::string mxl::lib::fabrics::ofi::TargetInfo::toJSON ( ) const
nodiscard

Serialize a TargetInfo instance to a JSON representation.

Definition at line 33 of file TargetInfo.cpp.

34 {
35 auto root = picojson::object{};
36
37 root["fabricAddress"] = picojson::value(fabricAddress.toBase64());
38 root["addressFormat"] = picojson::value{static_cast<double>(fabricAddress.format())};
39
40 auto regions = picojson::array{};
41 for (auto const& remoteRegion : remoteRegions)
42 {
43 auto region = picojson::object{};
44 region["addr"] = picojson::value(std::to_string(remoteRegion.addr));
45 region["len"] = picojson::value(std::to_string(remoteRegion.len));
46 region["rkey"] = picojson::value(std::to_string(remoteRegion.rkey));
47 regions.emplace_back(region);
48 }
49 root["regions"] = picojson::value(regions);
50
52 {
53 auto bounceBufferInfoObj = picojson::object{};
54 bounceBufferInfoObj["entryCount"] = picojson::value(std::to_string(bounceBufferInfo->entryCount));
55 bounceBufferInfoObj["entrySize"] = picojson::value(std::to_string(bounceBufferInfo->entrySize));
56 root["bounceBufferInfo"] = picojson::value(bounceBufferInfoObj);
57 }
58
59 root["id"] = picojson::value(std::to_string(id));
60 root["provider"] = picojson::value{fmt::to_string(provider)};
61
62 return picojson::value(root).serialize(false);
63 }

Member Data Documentation

◆ bounceBufferInfo

std::optional<TargetInfoBounceBufferInfo> mxl::lib::fabrics::ofi::TargetInfo::bounceBufferInfo

Information about the bounce buffer on the target, if the target uses one.

Definition at line 59 of file TargetInfo.hpp.

◆ fabricAddress

RawFabricAddress mxl::lib::fabrics::ofi::TargetInfo::fabricAddress

Target's endpoint libfabric address

Definition at line 55 of file TargetInfo.hpp.

◆ id

Endpoint::Id mxl::lib::fabrics::ofi::TargetInfo::id

A unique identifier of the target's endpoint

Definition at line 54 of file TargetInfo.hpp.

◆ provider

Provider mxl::lib::fabrics::ofi::TargetInfo::provider

Remote targets provider

Definition at line 56 of file TargetInfo.hpp.

◆ remoteRegions

std::vector<RemoteRegion> mxl::lib::fabrics::ofi::TargetInfo::remoteRegions

Target's memory regions (and keys) which an initiator can operate on. This is used only for RMA operations

Definition at line 58 of file TargetInfo.hpp.


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