MXL : Media eXchange Layer
MXL
Loading...
Searching...
No Matches
Completion.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 <cstdint>
8#include <bit>
9#include <memory>
10#include <optional>
11#include <string>
12#include <variant>
13#include <rdma/fi_eq.h>
14
16{
17 class CompletionQueue;
18
22 {
23 public:
26 using Token = std::uintptr_t;
27
30 class Data
31 {
32 public:
35 [[nodiscard]]
36 std::optional<std::uint64_t> data() const noexcept;
37
40 [[nodiscard]]
41 Completion::Token token() const noexcept;
42
45 [[nodiscard]]
46 bool isRemoteWrite() const noexcept;
47
50 [[nodiscard]]
51 bool isLocalWrite() const noexcept;
52
53 private:
54 friend class CompletionQueue;
55
56 private:
57 explicit Data(::fi_cq_data_entry const& raw);
58
59 private:
60 ::fi_cq_data_entry _raw;
61 };
62
65
66 class Error
67 {
68 public:
71 [[nodiscard]]
72 std::string toString() const;
73
76 [[nodiscard]]
77 Token token() const noexcept;
78
79 private:
80 friend class CompletionQueue;
81
82 private:
83 explicit Error(::fi_cq_err_entry const& raw, std::shared_ptr<CompletionQueue> queue);
84
85 private:
86 ::fi_cq_err_entry _raw;
87 std::shared_ptr<CompletionQueue> _cq;
88 std::string _message;
89 };
90
91 public:
92 explicit Completion(Data entry);
93 explicit Completion(Error entry);
94
95 [[nodiscard]]
96 static Token randomToken();
97
100 [[nodiscard]]
101 constexpr static void* tokenToContextValue(Token token) noexcept
102 {
103 return std::bit_cast<void*>(token);
104 }
105
108 [[nodiscard]]
109 constexpr static Token tokenFromContextValue(void* contextValue) noexcept
110 {
111 return std::bit_cast<Token>(contextValue);
112 }
113
116 [[nodiscard]]
117 Data data() const;
118
121 [[nodiscard]]
122 Error err() const;
123
126 [[nodiscard]]
127 std::optional<Data> tryData() const noexcept;
128
131 [[nodiscard]]
132 std::optional<Error> tryErr() const noexcept;
133
136 [[nodiscard]]
137 bool isDataEntry() const noexcept;
138
141 [[nodiscard]]
142 bool isErrEntry() const noexcept;
143
147 [[nodiscard]]
148 Token token() const noexcept;
149
150 private:
151 friend class CompletionQueue;
152
153 using Inner = std::variant<Data, Error>;
154
155 private:
157 };
158}
RAII Wrapper around a libfabric completion queue (fi_cq).
Data variant of the completion entry instance.
bool isLocalWrite() const noexcept
Indicates whether the completion entry represents a local write operation.
Completion::Token token() const noexcept
This used to associate a completion entry with an endpoint when multiple endpoints use the same compl...
std::optional< std::uint64_t > data() const noexcept
Accessor for the immediate data associated with the completion entry.
Data(::fi_cq_data_entry const &raw)
bool isRemoteWrite() const noexcept
Indicates whether the completion entry represents a remote write operation.
Error variant of the completion entry instance.
std::string toString() const
Generate a hman-readable string representation of the error entry.
Token token() const noexcept
This used to associate a completion entry with an endpoint when multiple endpoints use the same compl...
Error(::fi_cq_err_entry const &raw, std::shared_ptr< CompletionQueue > queue)
std::shared_ptr< CompletionQueue > _cq
Token token() const noexcept
Get the token that was associated with the operation that has completed.
static constexpr Token tokenFromContextValue(void *contextValue) noexcept
Convert between completion tokens and context values that can be written to and read from raw libfabr...
bool isErrEntry() const noexcept
check whether this is an error entry
Data data() const
Accessor for the data variant. Calling this on an error entry will throw.
std::variant< Data, Error > Inner
std::uintptr_t Token
A token used to associate a completion entry with an endpoint.
std::optional< Data > tryData() const noexcept
Attempt to access the data variant. Returns std::nullopt if this is an error entry.
std::optional< Error > tryErr() const noexcept
Attempt to access the error variant. Returns std::nullopt if this is a data entry.
bool isDataEntry() const noexcept
Check whether this is a data entry.
static constexpr void * tokenToContextValue(Token token) noexcept
Convert between completion tokens and context values that can be written to and read from raw libfabr...
Error err() const
Accessor for the error variant. Calling this on a data entry will throw.
::fi_info * raw() noexcept
Returns the raw fi_info object managed by this FabricInfo instance.