10#include <rdma/fabric.h>
21 std::string getHostname()
24 ::gethostname(buf,
sizeof(buf));
28 void copyStringProperty(picojson::object& destination,
char const* value, std::string
const& name)
30 if ((value !=
nullptr) && (value[0] !=
'\0'))
32 destination[name] = picojson::value{std::string{value}};
36 void copyStringProperty(picojson::object& destination, std::string
const& value, std::string
const& name)
40 destination[name] = picojson::value{value};
45 void copyNumberProperty(picojson::object& destination, T value, std::string
const& name)
47 destination[name] = picojson::value{
static_cast<double>(value)};
50 void copyNicProperties(picojson::object& destination, ::fid_nic* nic)
54 auto const device = nic->device_attr;
55 copyStringProperty(destination, device->name,
"device_name");
56 copyStringProperty(destination, device->device_id,
"device_id");
57 copyStringProperty(destination, device->vendor_id,
"device_vendor_id");
58 copyStringProperty(destination, device->device_version,
"device_version");
59 copyStringProperty(destination, device->driver,
"device_driver");
60 copyStringProperty(destination, device->firmware,
"device_firmware");
62 if (nic->link_attr !=
nullptr)
64 auto const link = nic->link_attr;
65 auto linkState = std::string{};
68 case FI_LINK_UP: linkState =
"up";
break;
69 case FI_LINK_DOWN: linkState =
"down";
break;
70 default: linkState =
"unknown";
72 destination[
"link_state"] = picojson::value{linkState};
75 destination[
"link_speed"] = picojson::value{
static_cast<double>(link->speed)};
77 copyStringProperty(destination, link->address,
"link_address");
78 copyStringProperty(destination, link->network_type,
"link_type");
80 if ((nic->bus_attr) && (nic->bus_attr->bus_type == FI_BUS_PCI))
82 auto const pci = nic->bus_attr->attr.pci;
83 copyNumberProperty(destination, pci.domain_id,
"pci_domain_id");
84 copyNumberProperty(destination, pci.bus_id,
"pci_bus_id");
85 copyNumberProperty(destination, pci.device_id,
"pci_device_id");
86 copyNumberProperty(destination, pci.function_id,
"pci_function_id");
90 void copyDomainProperties(picojson::object& destination, ::fi_domain_attr* domain)
92 copyStringProperty(destination, domain->name,
"fi_domain_name");
93 copyNumberProperty(destination, domain->cq_cnt,
"fi_domain_cq_cnt");
94 copyNumberProperty(destination, domain->ep_cnt,
"fi_domain_ep_cnt");
95 copyNumberProperty(destination, domain->mr_cnt,
"fi_domain_mr_cnt");
101 std::uint64_t maxMessageSize, picojson::object extraInfo)
103 ,
_node{std::move(node)}
107 ,
_attr{std::move(extraInfo)}
112 auto caps = std::uint64_t{};
113 auto attr = picojson::object{};
121 auto node = std::string{};
122 auto service = std::string{};
125 node = getHostname();
126 service = faddr.service().value_or(
"");
130 node = faddr.node().value_or(
"");
133 if ((info->caps & (FI_SEND | FI_RECV)) != 0)
137 if ((info->caps & (FI_REMOTE_WRITE | FI_WRITE | FI_RMA)) != 0)
146 copyStringProperty(attr,
fiToString(&info->addr_format, FI_TYPE_ADDR_FORMAT),
"ep_addr_format");
147 copyStringProperty(attr,
fiToString(&info->ep_attr->protocol, FI_TYPE_PROTOCOL),
"ep_protocol");
148 copyStringProperty(attr,
fiToString(&info->ep_attr->type, FI_TYPE_EP_TYPE),
"ep_type");
149 copyDomainProperties(attr, info->domain_attr);
151 if (info->nic !=
nullptr)
153 copyNicProperties(attr, info->nic);
159 copyStringProperty(attr, info->domain_attr->name,
"device_name");
167 auto attr = std::add_pointer_t<char const>{
nullptr};
170 attr = ::strdup(picojson::value{
_attr}.serialize(
false).c_str());
174 return new ::mxlFabricsInterfaceList{
185 .node = ::strdup(
_node.c_str()),
186 .service = ::strdup(
_service.c_str()),
196 auto interface = list->interface;
197 auto next = list->
next;
198 ::free(
const_cast<char*
>(interface.address.node));
199 ::free(
const_cast<char*
>(interface.address.service));
200 ::free(
const_cast<char*
>(interface.attr));
static bool isWaitObjectSupportedForEFA() noexcept
Check if wait any wait object type supported by the EFA provider for this libfabric version.
static FabricAddress fromSource(FabricInfoView info) noexcept
Build a FabricAddress from the source address of info.
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
static std::optional< FabricInterfaceDescription > create(FabricInfoView info)
::mxlFabricsInterfaceList * freeRawLinkedListNode(::mxlFabricsInterfaceList *)
::mxlFabricsInterfaceList * toRawLinkedListNode(::mxlFabricsInterfaceList *next=nullptr)
FabricInterfaceDescription(Provider, std::string, std::string, std::uint64_t, std::uint64_t, picojson::object)
std::uint64_t caps() const noexcept
Return the raw MXL_FABRICS_IFACE_CAP_* flags for this interface.
std::uint64_t _maxMessageSize
@ MXL_FABRICS_IFACE_CAP_SEND_RECEIVE
@ MXL_FABRICS_IFACE_CAP_BLOCKING_OPERATIONS
@ MXL_FABRICS_IFACE_CAP_REMOTE_WRITE
#define MXL_FABRICS_API_VERSION
struct mxlFabricsInterfaceList_t mxlFabricsInterfaceList
std::string fiToString(void *any, ::fi_type type)
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
void free() noexcept
Called internally to release the fi_info object.
Provider
Internal representation of supported libfabric providers.
mxlFabricsProvider providerToAPI(Provider provider) noexcept
Convert between external and internal versions of this type.
mxlFabricsInterfaceConfig interface
mxlFabricsInterfaceList * next