12#include <infiniband/verbs.h>
15#include "rdmapp/device.h"
17#include "rdmapp/srq.h"
19#include "rdmapp/detail/noncopyable.h"
20#include "rdmapp/detail/serdes.h"
26 static constexpr size_t kSerializedSize =
27 sizeof(uint16_t) + 3 *
sizeof(uint32_t) +
sizeof(
union ibv_gid);
31 uint32_t user_data_size;
36 detail::deserialize(it, des_qp.header.lid);
37 detail::deserialize(it, des_qp.header.qp_num);
38 detail::deserialize(it, des_qp.header.sq_psn);
39 detail::deserialize(it, des_qp.header.user_data_size);
40 detail::deserialize(it, des_qp.header.gid);
43 std::vector<uint8_t> user_data;
51 static std::atomic<uint32_t> next_sq_psn;
53 struct ibv_srq *raw_srq_;
55 void (
qp::*post_recv_fn)(
struct ibv_recv_wr
const &recv_wr,
56 struct ibv_recv_wr *&bad_recv_wr)
const;
58 std::shared_ptr<pd> pd_;
59 std::shared_ptr<cq> recv_cq_;
60 std::shared_ptr<cq> send_cq_;
61 std::shared_ptr<srq> srq_;
62 std::vector<uint8_t> user_data_;
81 std::shared_ptr<qp> qp_;
82 std::shared_ptr<local_mr> local_mr_;
83 std::exception_ptr exception_;
85 uint64_t compare_add_;
89 const enum ibv_wr_opcode opcode_;
93 enum ibv_wr_opcode opcode);
104 uint64_t compare, uint64_t swap);
106 enum ibv_wr_opcode opcode);
117 uint64_t compare, uint64_t swap);
118 bool await_ready()
const noexcept;
119 bool await_suspend(std::coroutine_handle<> h)
noexcept;
120 uint32_t await_resume()
const;
121 constexpr bool is_rdma()
const;
122 constexpr bool is_atomic()
const;
126 std::shared_ptr<qp> qp_;
127 std::shared_ptr<local_mr> local_mr_;
128 std::exception_ptr exception_;
130 enum ibv_wr_opcode opcode_;
135 bool await_ready()
const noexcept;
136 bool await_suspend(std::coroutine_handle<> h)
noexcept;
137 std::pair<uint32_t, std::optional<uint32_t>> await_resume()
const;
153 qp(
const uint16_t remote_lid,
const uint32_t remote_qpn,
154 const uint32_t remote_psn,
const union ibv_gid remote_gid,
155 std::shared_ptr<pd>
pd, std::shared_ptr<cq>
cq,
156 std::shared_ptr<srq>
srq =
nullptr);
172 qp(
const uint16_t remote_lid,
const uint32_t remote_qpn,
173 const uint32_t remote_psn,
const union ibv_gid remote_gid,
174 std::shared_ptr<pd>
pd, std::shared_ptr<cq> recv_cq,
175 std::shared_ptr<cq> send_cq, std::shared_ptr<srq>
srq =
nullptr);
186 qp(std::shared_ptr<pd>
pd, std::shared_ptr<cq>
cq,
187 std::shared_ptr<srq>
srq =
nullptr);
199 qp(std::shared_ptr<pd>
pd, std::shared_ptr<cq> recv_cq,
200 std::shared_ptr<cq> send_cq, std::shared_ptr<srq>
srq =
nullptr);
209 void post_send(
struct ibv_send_wr
const &send_wr,
210 struct ibv_send_wr *&bad_send_wr);
221 void post_recv(
struct ibv_recv_wr
const &recv_wr,
222 struct ibv_recv_wr *&bad_recv_wr)
const;
259 void *buffer,
size_t length,
287 void *buffer,
size_t length,
303 void *buffer,
size_t length,
337 std::shared_ptr<local_mr>
local_mr);
362 std::shared_ptr<local_mr>
local_mr);
391 std::shared_ptr<local_mr>
local_mr, uint64_t compare,
428 std::shared_ptr<pd>
pd_ptr()
const;
439 void rtr(uint16_t remote_lid, uint32_t remote_qpn, uint32_t remote_psn,
440 union ibv_gid remote_gid);
455 void post_recv_rq(
struct ibv_recv_wr
const &recv_wr,
456 struct ibv_recv_wr *&bad_recv_wr)
const;
464 void post_recv_srq(
struct ibv_recv_wr
const &recv_wr,
465 struct ibv_recv_wr *&bad_recv_wr)
const;
This class is an abstraction of a Completion Queue.
Definition cq.h:22
Definition noncopyable.h:5
This class is an abstraction of a Protection Domain.
Definition pd.h:20
This class is an abstraction of an Infiniband Queue Pair.
Definition qp.h:50
void post_recv(struct ibv_recv_wr const &recv_wr, struct ibv_recv_wr *&bad_recv_wr) const
This function is used to post a recv work request to the Queue Pair. It will be posted to either RQ o...
Definition qp.cc:194
void post_send(struct ibv_send_wr const &send_wr, struct ibv_send_wr *&bad_send_wr)
This function is used to post a send work request to the Queue Pair.
Definition qp.cc:184
send_awaitable compare_and_swap(remote_mr const &remote_mr, void *buffer, size_t length, uint64_t compare, uint64_t swap)
This method performs an atomic compare-and-swap operation on the given remote memory region....
Definition qp.cc:379
recv_awaitable recv(void *buffer, size_t length)
This method posts a recv request on the queue pair. The buffer will be filled with data received....
Definition qp.cc:475
std::vector< uint8_t > serialize() const
This function serializes a Queue Pair prepared to be sent to a buffer.
Definition qp.cc:64
send_awaitable fetch_and_add(remote_mr const &remote_mr, void *buffer, size_t length, uint64_t add)
This method performs an atomic fetch-and-add operation on the given remote memory region....
Definition qp.cc:372
send_awaitable write(remote_mr const &remote_mr, void *buffer, size_t length)
This method writes local buffer to a remote memory region. The local buffer will be registered as a m...
Definition qp.cc:354
send_awaitable write_with_imm(remote_mr const &remote_mr, void *buffer, size_t length, uint32_t imm)
This method writes local buffer to a remote memory region with an immediate value....
Definition qp.cc:360
void rtr(uint16_t remote_lid, uint32_t remote_qpn, uint32_t remote_psn, union ibv_gid remote_gid)
This function transitions the Queue Pair to the RTR state.
Definition qp.cc:126
send_awaitable send(void *buffer, size_t length)
This method sends local buffer to remote. The address will be registered as a memory region first and...
Definition qp.cc:349
std::vector< uint8_t > & user_data()
This function provides access to the extra user data of the Queue Pair.
Definition qp.cc:60
std::shared_ptr< pd > pd_ptr() const
This function provides access to the Protection Domain of the Queue Pair.
Definition qp.cc:62
send_awaitable read(remote_mr const &remote_mr, void *buffer, size_t length)
This method reads to local buffer from a remote memory region. The local buffer will be registered as...
Definition qp.cc:366
void rts()
This function transitions the Queue Pair to the RTS state.
Definition qp.cc:160
This class represents a Shared Receive Queue.
Definition srq.h:15