-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathRdma.h
145 lines (112 loc) · 4.82 KB
/
Rdma.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#ifndef _RDMA_H__
#define _RDMA_H__
#define forceinline inline __attribute__((always_inline))
#include <assert.h>
#include <cstring>
#include <infiniband/verbs.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <list>
#include <string>
#include "Debug.h"
#define MAX_POST_LIST 32
#define DCT_ACCESS_KEY 3185
#define UD_PKEY 0x11111111
#define PSN 3185
constexpr int kOroMax = 3;
struct RdmaOpRegion {
uint64_t source;
uint64_t dest;
uint64_t size;
uint32_t lkey;
union {
uint32_t remoteRKey;
bool is_on_chip;
};
};
extern int kMaxDeviceMemorySize;
struct RdmaContext {
uint8_t devIndex;
uint8_t port;
int gidIndex;
ibv_context *ctx;
ibv_pd *pd;
uint16_t lid;
union ibv_gid gid;
RdmaContext() : ctx(NULL), pd(NULL) {}
};
struct Region {
uint64_t source;
uint32_t size;
uint64_t dest;
};
//// Resource.cpp
bool createContext(RdmaContext *context, uint8_t port = 1, int gidIndex = 1,
uint8_t devIndex = 0);
bool destoryContext(RdmaContext *context);
ibv_mr *createMemoryRegion(uint64_t mm, uint64_t mmSize, RdmaContext *ctx);
ibv_mr *createMemoryRegionOnChip(uint64_t mm, uint64_t mmSize,
RdmaContext *ctx);
bool createQueuePair(ibv_qp **qp, ibv_qp_type mode, ibv_cq *cq,
RdmaContext *context, uint32_t qpsMaxDepth = 128,
uint32_t maxInlineData = 0);
bool createQueuePair(ibv_qp **qp, ibv_qp_type mode, ibv_cq *send_cq,
ibv_cq *recv_cq, RdmaContext *context,
uint32_t qpsMaxDepth = 128, uint32_t maxInlineData = 0);
bool createDCTarget(ibv_exp_dct **dct, ibv_cq *cq, RdmaContext *context,
uint32_t qpsMaxDepth = 128, uint32_t maxInlineData = 0);
void fillAhAttr(ibv_ah_attr *attr, uint32_t remoteLid, uint8_t *remoteGid,
RdmaContext *context);
//// StateTrans.cpp
bool modifyQPtoInit(struct ibv_qp *qp, RdmaContext *context);
bool modifyQPtoRTR(struct ibv_qp *qp, uint32_t remoteQPN, uint16_t remoteLid,
uint8_t *gid, RdmaContext *context);
bool modifyQPtoRTS(struct ibv_qp *qp);
bool modifyUDtoRTS(struct ibv_qp *qp, RdmaContext *context);
//// Operation.cpp
int pollWithCQ(ibv_cq *cq, int pollNumber, struct ibv_wc *wc);
int pollOnce(ibv_cq *cq, int pollNumber, struct ibv_wc *wc);
bool rdmaSend(ibv_qp *qp, uint64_t source, uint64_t size, uint32_t lkey,
ibv_ah *ah, uint32_t remoteQPN, bool isSignaled = false);
bool rdmaSend(ibv_qp *qp, uint64_t source, uint64_t size, uint32_t lkey,
int32_t imm = -1);
bool rdmaReceive(ibv_qp *qp, uint64_t source, uint64_t size, uint32_t lkey,
uint64_t wr_id = 0);
bool rdmaReceive(ibv_srq *srq, uint64_t source, uint64_t size, uint32_t lkey);
bool rdmaRead(ibv_qp *qp, uint64_t source, uint64_t dest, uint64_t size,
uint32_t lkey, uint32_t remoteRKey, bool signal = true,
uint64_t wrID = 0);
bool rdmaWrite(ibv_qp *qp, uint64_t source, uint64_t dest, uint64_t size,
uint32_t lkey, uint32_t remoteRKey, int32_t imm = -1,
bool isSignaled = true, uint64_t wrID = 0);
bool rdmaFetchAndAdd(ibv_qp *qp, uint64_t source, uint64_t dest, uint64_t add,
uint32_t lkey, uint32_t remoteRKey);
bool rdmaFetchAndAddBoundary(ibv_qp *qp, uint64_t source, uint64_t dest,
uint64_t add, uint32_t lkey, uint32_t remoteRKey,
uint64_t boundary = 63, bool singal = true,
uint64_t wr_id = 0);
bool rdmaCompareAndSwap(ibv_qp *qp, uint64_t source, uint64_t dest,
uint64_t compare, uint64_t swap, uint32_t lkey,
uint32_t remoteRKey, bool signal = true,
uint64_t wrID = 0);
bool rdmaCompareAndSwapMask(ibv_qp *qp, uint64_t source, uint64_t dest,
uint64_t compare, uint64_t swap, uint32_t lkey,
uint32_t remoteRKey, uint64_t mask = ~(0ull),
bool signal = true);
//// Utility.cpp
void rdmaQueryQueuePair(ibv_qp *qp);
void checkDMSupported(struct ibv_context *ctx);
//// specified
bool rdmaWriteBatch(ibv_qp *qp, RdmaOpRegion *ror, int k, bool isSignaled,
uint64_t wrID = 0);
bool rdmaCasRead(ibv_qp *qp, const RdmaOpRegion &cas_ror,
const RdmaOpRegion &read_ror, uint64_t compare, uint64_t swap,
bool isSignaled, uint64_t wrID = 0);
bool rdmaWriteFaa(ibv_qp *qp, const RdmaOpRegion &write_ror,
const RdmaOpRegion &faa_ror, uint64_t add_val,
bool isSignaled, uint64_t wrID = 0);
bool rdmaWriteCas(ibv_qp *qp, const RdmaOpRegion &write_ror,
const RdmaOpRegion &cas_ror, uint64_t compare, uint64_t swap,
bool isSignaled, uint64_t wrID = 0);
#endif