MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
FabricInfo.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Contributors to the Media eXchange Layer project.
2//
3// SPDX-License-Identifier: Apache-2.0
4
5#pragma once
6
7#include <cstddef>
8#include <cstdint>
9#include <string>
10#include <type_traits>
11#include <rdma/fabric.h>
12#include "Provider.hpp"
13
15{
16 template<bool Const>
18
19 class FabricInfoView;
20 class FabricInfoList;
21 class FabricAddress;
22 class ProviderConfig;
23
29 class FabricInfo
30 {
31 public:
34 static FabricInfo clone(::fi_info const*) noexcept;
35
40 static FabricInfo own(::fi_info*) noexcept;
41
44 static FabricInfo empty() noexcept;
45
46 ~FabricInfo() noexcept;
47
51
52 // Copy constructor and assignment operator.
53 FabricInfo(FabricInfo const&) noexcept;
54 void operator=(FabricInfo const& other) noexcept;
55
56 // Move constructor and assignment operator.
57 FabricInfo(FabricInfo&& other) noexcept;
58 FabricInfo& operator=(FabricInfo&&) noexcept;
59
63 [[nodiscard]]
64 ::fi_info& operator*() noexcept;
66 [[nodiscard]]
67 ::fi_info const& operator*() const noexcept;
69 [[nodiscard]]
70 ::fi_info* operator->() noexcept;
71 [[nodiscard]]
73 [[nodiscard]]
74 ::fi_info const* operator->() const noexcept;
75
78 [[nodiscard]]
79 ::fi_info* raw() noexcept;
81 [[nodiscard]]
82 ::fi_info const* raw() const noexcept;
83
86 [[nodiscard]]
87 FabricInfoView view() const noexcept;
88
89 private:
93 explicit FabricInfo(::fi_info*) noexcept;
94
97 void free() noexcept;
98
99 private:
100 ::fi_info* _raw;
101 };
102
106 {
107 public:
110 [[nodiscard]]
111 ::fi_info& operator*() noexcept;
113 [[nodiscard]]
114 ::fi_info const& operator*() const noexcept;
116 [[nodiscard]]
117 ::fi_info* operator->() noexcept;
119 [[nodiscard]]
120 ::fi_info const* operator->() const noexcept;
121
124 ::fi_info* raw() noexcept;
126 [[nodiscard]]
127 ::fi_info const* raw() const noexcept;
128
132 [[nodiscard]]
133 FabricInfo owned() noexcept;
134
137 [[nodiscard]]
138 std::size_t txIovLimit() const noexcept;
139
144 [[nodiscard]]
145 std::size_t txSize() const noexcept;
146
147 [[nodiscard]]
148 ::fi_ep_type endpointType() const noexcept;
149
150 private:
154
156 FabricInfoView(::fi_info const*);
157
158 private:
159 ::fi_info* _raw;
160 };
161
166 template<bool Const>
168 {
169 public:
171
172 // Satisfies ForwardIterator.
173 using difference_type = std::ptrdiff_t;
174 using value_type = std::conditional_t<Const, FabricInfoView const, FabricInfoView>;
175 using raw_type = std::conditional_t<Const, ::fi_info const*, ::fi_info*>;
176
177 public:
179 : _it(nullptr)
180 {}
181
183 {
184 return value_type{_it};
185 }
186
188 {
189 _it = _it->next;
190 return *this;
191 }
192
194 {
195 auto current = _it;
196 ++*this;
197 return FabricInfoIterator{current};
198 }
199
200 bool operator==(FabricInfoIterator const& other) const noexcept
201 {
202 return other._it == _it;
203 }
204
205 bool operator!=(FabricInfoIterator const& other) const noexcept
206 {
207 return !(*this == other);
208 }
209
210 private:
211 explicit FabricInfoIterator(raw_type it) noexcept
212 : _it(it)
213 {}
214
215 private:
217 };
218
226 {
227 public:
228 // Type aliases for const and non-const versions of the iterator template
231
232 public:
234 [[nodiscard]]
235 static FabricInfoList get();
236
238 [[nodiscard]]
239 static FabricInfoList getSourceInterfaces(ProviderConfig const& providerConfig, std::optional<FabricAddress> const& sourceAddress);
240
243 static FabricInfoList own(::fi_info* info) noexcept;
244
248
249 // deleted copy constuctor
252
253 // move semantics
254 FabricInfoList(FabricInfoList&& other) noexcept;
255 FabricInfoList& operator=(FabricInfoList&& other) noexcept;
256
257 // non-const forward iterator
258 iterator begin() noexcept;
259 iterator end() noexcept;
260
261 // const forward iterator
262 [[nodiscard]]
263 const_iterator begin() const noexcept;
264 [[nodiscard]]
265 const_iterator end() const noexcept;
266
267 // const forward iterator
268 [[nodiscard]]
269 const_iterator cbegin() const noexcept;
270 [[nodiscard]]
271 const_iterator cend() const noexcept;
272
273 private:
274 explicit FabricInfoList(::fi_info*) noexcept;
275
276 void free();
277
278 private:
279 ::fi_info* _begin;
280 };
281
282}
Owning, type-safe representation of a libfabric address.
Implements a const/non-const ForwardIterator over a fi_info linked list, for use with range-based for...
std::conditional_t< Const, ::fi_info const *, ::fi_info * > raw_type
std::conditional_t< Const, FabricInfoView const, FabricInfoView > value_type
bool operator==(FabricInfoIterator const &other) const noexcept
bool operator!=(FabricInfoIterator const &other) const noexcept
Wrapper for a linked-list of fi_info objects, mostly returned from fi_getinfo.
FabricInfoIterator< false > iterator
FabricInfoList(FabricInfoList const &)=delete
static FabricInfoList get()
Calls fi_getinfo without any hints and returns the full list of fabric information objects.
const_iterator cbegin() const noexcept
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...
FabricInfoIterator< true > const_iterator
const_iterator cend() const noexcept
FabricInfoList & operator=(FabricInfoList const &)=delete
static FabricInfoList own(::fi_info *info) noexcept
Take ownership over a fi_info raw pointer.
Non-owning view of a FabricInfo. Returned when iterating over a FabricInfoList.
FabricInfo owned() noexcept
Return an owned version that can be moved, copied and dereferenced safely even if the original Fabric...
::fi_ep_type endpointType() const noexcept
FabricInfoView(::fi_info const *)
Private constructor.
std::size_t txSize() const noexcept
Return the transmit queue size of the endpoint.
std::size_t txIovLimit() const noexcept
Return the IOV limit for this fabric info, which is the maximum number of iovecs that can be posted i...
FabricInfo(FabricInfoView) noexcept
Create an owning FabricInfo object from a non-owning view.
FabricInfoView view() const noexcept
Return a non-owning view of the FabricInfo.
static FabricInfo empty() noexcept
Create and empty FabricInfo.
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.
static FabricInfo clone(::fi_info const *) noexcept
RAII wrapper around a libfabric `fi_info`` structure.
::fi_info * operator->() noexcept
Dereferencing the FabricInfo return the raw fi_info object managed by this object.
static FabricInfo own(::fi_info *) noexcept
Own an existing fi_info object.
void free() noexcept
Called internally to release the fi_info object.
::fi_info & operator*() noexcept
Dereferencing the FabricInfo return the raw fi_info object managed by this object.