7#include <rdma/fabric.h>
22 std::optional<std::string> optStringFromCStr(
char const* source)
24 return source ==
nullptr ? std::nullopt : std::make_optional<std::string>(source);
28 std::string getHostname()
31 ::gethostname(buf,
sizeof(buf));
44 if (requested.empty())
51 return requested.node() == getHostname();
58 return addr.node() == requested.node();
75 auto providerConfigs = std::map<Provider, ProviderConfig>{};
76 auto fabricAddresses = std::map<Provider, std::optional<FabricAddress>>{};
79 auto it = providerConfigs.lower_bound(provider);
80 if ((it == providerConfigs.end()) || (it->first != provider))
88 auto getFabricAddress = [&](
Provider provider) -> std::optional<FabricAddress>
const&
90 auto it = fabricAddresses.lower_bound(provider);
91 if ((it == fabricAddresses.end()) || (it->first != provider))
95 it = fabricAddresses.emplace_hint(it,
98 query ? optStringFromCStr(query.value().get().address.node) : std::nullopt,
99 query ? optStringFromCStr(query.value().get().address.service) : std::nullopt));
103 it = fabricAddresses.emplace_hint(it, provider, std::nullopt);
111 auto const requestedProvider = query
115 if (!requestedProvider)
131 if ((requestedProvider !=
Provider::ANY) && (provider != requestedProvider))
137 auto const& address = getFabricAddress(*provider);
144 if (!matchesRequestedAddress(*address, info))
150 auto const& config = getProviderConfig(*provider);
151 if (config.isSupportedFabricInfo(info))
156 list.push(*description);
174 if ((caps.interfaceCaps & transferCapsMask) == 0)
177 "Unsupported provider constraints: Missing transfer capability. Need either SEND_RECEIVE or REMOTE_WRITE");
181 throw Exception::noFabric(
"Unsupported provider constraints: Only REMOTE_WRITE supported at this time.");
183 if (caps.maxMessageSize == 0)
185 MXL_WARN(
"maxMessageSize is not set. This field will be required in a future version.");
192 if (std::ranges::distance(sourceInterfaces) == 0)
197 return {*sourceInterfaces.begin(), std::move(providerConfig)};
Custom exception type used in the fabrics library.
static Exception invalidArgument(fmt::format_string< T... > fmt, T &&... args)
Make an MXL_ERR_INVALID_ARG exception.
static Exception noFabric(fmt::format_string< T... > fmt, T &&... args)
Owning, type-safe representation of a libfabric address.
static FabricAddress parse(Provider provider, std::optional< std::string > node, std::optional< std::string > service)
Parse a node/service pair into a typed address for the given provider.
static FabricAddress decode(FabricAddressFormat addrFormat, void const *addr, std::size_t len)
Decode a raw libfabric address buffer of the given addr_format.
static FabricInfoList get()
Calls fi_getinfo without any hints and returns the full list of fabric information objects.
static FabricInfoList getSourceInterfaces(ProviderConfig const &providerConfig, std::optional< FabricAddress > const &sourceAddress)
Calls fi_getinfo with FI_SOURCE to get source interface information. Uses hints derived from the prov...
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
static std::optional< FabricInterfaceDescription > create(FabricInfoView info)
static ProviderCapabilities fromAPI(::mxlFabricsInterfaceCaps)
static ProviderConfig create(Provider provider, bool isTarget, std::optional< ProviderCapabilities > capabilities)
@ MXL_FABRICS_IFACE_CAP_SEND_RECEIVE
@ MXL_FABRICS_IFACE_CAP_REMOTE_WRITE
struct mxlFabricsInterfaceConfig_t mxlFabricsInterfaceConfig
std::pair< FabricInfo, ProviderConfig > selectSourceInterface(::mxlFabricsInterfaceConfig const &interfaceConfig, bool isTarget)
FabricInterfaceList probeInterfaces(std::optional< std::reference_wrapper<::mxlFabricsInterfaceConfig const > > query)
std::optional< Provider > providerFromString(std::string const &s) noexcept
Parse a provider name string, and return the enum value.
std::optional< Provider > providerFromAPI(mxlFabricsProvider api) noexcept
Convert between external and internal versions of this type.
Provider
Internal representation of supported libfabric providers.
FabricAddressFormat mustConvertAddressFormat(std::uint32_t fiAddrFormat)
Convert from libfabric address format value to FabricAddressFormat Never returns FabricAddressFormat:...
mxlFabricsProvider provider
mxlFabricsInterfaceCaps caps
mxlFabricsEndpointAddress address