RDMA read with verb call

1,Include the necessary header files:

#include <infiniband/verbs.h>

2,Initialize the InfiniBand resources:

struct ibv_context* context;
struct ibv_pd* pd;
struct ibv_mr* mr;
struct ibv_qp* qp;

// Open the InfiniBand device and create a context
context = ibv_open_device(...);

// Allocate protection domain (pd)
pd = ibv_alloc_pd(context);

// Register memory region for RDMA read
mr = ibv_reg_mr(pd, buffer, buffer_size, IBV_ACCESS_REMOTE_READ);

// Create a queue pair (qp)
qp = ibv_create_qp(pd, ...);

3,Exchange necessary information with the target machine:

// Perform the necessary communication with the target machine to exchange information required for RDMA read.
// This may involve exchanging the QP information, memory addresses, and other connection details.

4,Post an RDMA read operation:

struct ibv_sge sge;
struct ibv_send_wr wr;
struct ibv_send_wr* bad_wr;
struct ibv_wc wc;

// Set up Scatter-Gather Entry (SGE)
sge.addr = (uintptr_t)local_buffer;  // Local buffer address
sge.length = buffer_size;            // Length of the buffer
sge.lkey = mr->lkey;                 // Local memory region key

// Set up Work Request (WR) for RDMA read
wr.wr_id = ...;                      // Optional work request identifier
wr.next = nullptr;                   // Pointer to next work request (if chaining)
wr.sg_list = &sge;                   // Scatter-Gather Entry array
wr.num_sge = 1;                      // Number of Scatter-Gather Entries
wr.opcode = IBV_WR_RDMA_READ;        // RDMA read operation
wr.send_flags = IBV_SEND_SIGNALED;   // Enable completion notification
wr.wr.rdma.remote_addr = remote_addr;  // Remote memory region address
wr.wr.rdma.rkey = remote_key;        // Remote memory region key

// Post the Work Request to the send queue
ibv_post_send(qp, &wr, &bad_wr);

// Wait for the completion of the RDMA read operation
ibv_poll_cq(qp->send_cq, 1, &wc);
5, Cleanup and release resources:

ibv_destroy_qp(qp);
ibv_dereg_mr(mr);
ibv_dealloc_pd(pd);
ibv_close_device(context);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值