Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "dlra_function.h"
12 :
13 : #include <string>
14 : #include <map>
15 : #include "hccl_dl.h"
16 : #include "log.h"
17 :
18 : namespace hccl {
19 :
20 : std::atomic<unsigned> DlRaFunction::Init::initCount(0);
21 : DlRaFunction* DlRaFunction::hcclDlRaFunction = nullptr;
22 :
23 548 : DlRaFunction::Init::Init()
24 : {
25 548 : if (initCount.fetch_add(1) == 0) {
26 47 : DlRaFunction::hcclDlRaFunction = new (std::nothrow) DlRaFunction;
27 47 : CHK_PRT_CONT(
28 : DlRaFunction::hcclDlRaFunction == nullptr, HCCL_ERROR("[DlRaFunction][Init] hcclDlRaFunction new failed"));
29 : }
30 548 : }
31 :
32 548 : DlRaFunction::Init::~Init()
33 : {
34 548 : if (initCount.fetch_sub(1) == 0) {
35 0 : if (DlRaFunction::GetInstance().handle_ != nullptr) {
36 0 : (void)HcclDlclose(DlRaFunction::GetInstance().handle_);
37 0 : DlRaFunction::GetInstance().handle_ = nullptr;
38 : }
39 0 : delete DlRaFunction::hcclDlRaFunction;
40 : }
41 548 : }
42 :
43 2669 : DlRaFunction& DlRaFunction::GetInstance() { return *hcclDlRaFunction; }
44 :
45 47 : DlRaFunction::DlRaFunction() : handle_(nullptr) {}
46 :
47 0 : DlRaFunction::~DlRaFunction() {}
48 :
49 610 : HcclResult DlRaFunction::DlRaFunctionRdmaInit()
50 : {
51 610 : dlRaGetQpDepth = (int (*)(RdmaHandle, unsigned int*, unsigned int*))HcclDlsym(handle_, "RaGetTsqpDepth");
52 610 : CHK_SMART_PTR_NULL(dlRaGetQpDepth);
53 610 : dlRaSetQpDepth = (int (*)(RdmaHandle, unsigned int, unsigned int*))HcclDlsym(handle_, "RaSetTsqpDepth");
54 610 : CHK_SMART_PTR_NULL(dlRaSetQpDepth);
55 610 : dlRaQpCreate = (int (*)(RdmaHandle, int, int, QpHandle*))HcclDlsym(handle_, "RaQpCreate");
56 610 : CHK_SMART_PTR_NULL(dlRaQpCreate);
57 610 : dlRaQpDestroy = (int (*)(QpHandle))HcclDlsym(handle_, "RaQpDestroy");
58 610 : CHK_SMART_PTR_NULL(dlRaQpDestroy);
59 610 : dlRaQpDestroyWithoutCQ = (int (*)(QpHandle))HcclDlsym(handle_, "RaQpDestroyWithoutCQ");
60 610 : CHK_SMART_PTR_NULL(dlRaQpDestroyWithoutCQ);
61 610 : dlRaGetQpContext = (int (*)(void*, void**, void**, void**))HcclDlsym(handle_, "RaGetQpContext");
62 610 : CHK_SMART_PTR_NULL(dlRaGetQpContext);
63 610 : dlRaQpConnectAsync = (int (*)(QpHandle, const SocketHandle))HcclDlsym(handle_, "RaQpConnectAsync");
64 610 : CHK_SMART_PTR_NULL(dlRaQpConnectAsync);
65 610 : dlRaGetQpStatus = (int (*)(QpHandle, int*))HcclDlsym(handle_, "RaGetQpStatus");
66 610 : CHK_SMART_PTR_NULL(dlRaGetQpStatus);
67 610 : dlRaMrDereg = (int (*)(QpHandle, struct MrInfoT*))HcclDlsym(handle_, "RaMrDereg");
68 610 : CHK_SMART_PTR_NULL(dlRaMrDereg);
69 610 : dlRaMrReg = (int (*)(QpHandle, struct MrInfoT*))HcclDlsym(handle_, "RaMrReg");
70 610 : CHK_SMART_PTR_NULL(dlRaMrReg);
71 610 : dlRaGetNotifyMrInfo = (int (*)(RdmaHandle, struct MrInfoT*))HcclDlsym(handle_, "RaGetNotifyMrInfo");
72 610 : CHK_SMART_PTR_NULL(dlRaGetNotifyMrInfo);
73 610 : dlRaRdmaDeInit = (int (*)(RdmaHandle, u32))HcclDlsym(handle_, "RaRdevDeinit");
74 610 : CHK_SMART_PTR_NULL(dlRaRdmaDeInit);
75 610 : dlRaRdmaInitWithAttr = (int (*)(struct RdevInitInfo, struct rdev, RdmaHandle*))HcclDlsym(handle_, "RaRdevInitV2");
76 610 : CHK_SMART_PTR_NULL(dlRaRdmaInitWithAttr);
77 610 : dlRaRdmaInitWithBackupAttr = (int (*)(struct RdevInitInfo*, struct rdev*, struct rdev*, RdmaHandle*))HcclDlsym(
78 610 : handle_, "RaRdevInitWithBackup");
79 610 : CHK_SMART_PTR_NULL(dlRaRdmaInitWithBackupAttr);
80 610 : dlRaRdmaGetHandle = (int (*)(unsigned int, RdmaHandle*))HcclDlsym(handle_, "RaRdevGetHandle");
81 610 : dlRaRdmaInit = (int (*)(int, u32, struct rdev, RdmaHandle*))HcclDlsym(handle_, "RaRdevInit");
82 610 : CHK_SMART_PTR_NULL(dlRaRdmaInit);
83 610 : dlRaSendWr = (int (*)(QpHandle, struct SendWr*, struct SendWrRsp*))HcclDlsym(handle_, "RaSendWr");
84 610 : CHK_SMART_PTR_NULL(dlRaSendWr);
85 610 : dlRaSendWrV2 = (int (*)(QpHandle, struct SendWrV2*, struct SendWrRsp*))HcclDlsym(handle_, "RaSendWrV2");
86 610 : CHK_SMART_PTR_NULL(dlRaSendWrV2);
87 610 : dlRaSendWrVerbs = (int (*)(QpHandle, struct SendWrVerbs*, struct SendWrRsp*))HcclDlsym(handle_, "RaSendWrVerbs");
88 610 : CHK_SMART_PTR_NULL(dlRaSendWrVerbs);
89 610 : dlRaRecvWrVerbs = (int (*)(QpHandle, struct RecvWrVerbs*))HcclDlsym(handle_, "RaRecvWrVerbs");
90 610 : CHK_SMART_PTR_NULL(dlRaRecvWrVerbs);
91 610 : dlRaPollCq = (int (*)(QpHandle, bool, unsigned int, void*))HcclDlsym(handle_, "RaPollCq");
92 610 : CHK_SMART_PTR_NULL(dlRaPollCq);
93 610 : dlRaPollTypicalCq = (int (*)(void*, unsigned int, void*))HcclDlsym(handle_, "RaPollTypicalCq");
94 610 : CHK_SMART_PTR_NULL(dlRaPollTypicalCq);
95 0 : dlRaSendWrlist = (int (*)(
96 : QpHandle handle, struct SendWrlistData wr[], struct SendWrRsp op_rsp[], unsigned int sendNum,
97 610 : unsigned int* completeNum))HcclDlsym(handle_, "RaSendWrlist");
98 610 : if (dlRaSendWrlist == nullptr) {
99 0 : HCCL_WARNING("dlRaSendWrlist is nullptr, can not use RaSendWrlist");
100 : }
101 0 : dlRaSendWrlistExt = (int (*)(
102 : QpHandle handle, struct SendWrlistDataExt wr[], struct SendWrRsp op_rsp[], unsigned int sendNum,
103 610 : unsigned int* completeNum))HcclDlsym(handle_, "RaSendWrlistExt");
104 610 : if (dlRaSendWrlistExt == nullptr) {
105 0 : HCCL_WARNING("dlRaSendWrlistExt is nullptr, can not use ra_send_wrlist_ext");
106 : }
107 0 : dlRaSendNormalWrlist = (int (*)(
108 : QpHandle handle, struct WrInfo wr[], struct SendWrRsp opRsp[], unsigned int sendNum,
109 610 : unsigned int* completeNum))HcclDlsym(handle_, "RaSendNormalWrlist");
110 610 : CHK_SMART_PTR_NULL(dlRaSendNormalWrlist);
111 : dlRaRegGlobalMr
112 610 : = (int (*)(const RdmaHandle, struct MrInfoT* info, MrHandle* mrHandle))HcclDlsym(handle_, "RaRegisterMr");
113 610 : CHK_SMART_PTR_NULL(dlRaRegGlobalMr);
114 610 : dlRaDeRegGlobalMr = (int (*)(const RdmaHandle, MrHandle mrHandle))HcclDlsym(handle_, "RaDeregisterMr");
115 610 : CHK_SMART_PTR_NULL(dlRaDeRegGlobalMr);
116 610 : dlRaCreateCq = (int (*)(RdmaHandle, struct CqAttr*))HcclDlsym(handle_, "RaCqCreate");
117 610 : CHK_SMART_PTR_NULL(dlRaCreateCq);
118 610 : dlRaDestroyCq = (int (*)(RdmaHandle, struct CqAttr*))HcclDlsym(handle_, "RaCqDestroy");
119 610 : CHK_SMART_PTR_NULL(dlRaDestroyCq);
120 : dlRaNormalQpCreate
121 610 : = (int (*)(RdmaHandle, struct ibv_qp_init_attr*, void**, void**))HcclDlsym(handle_, "RaNormalQpCreate");
122 610 : CHK_SMART_PTR_NULL(dlRaNormalQpCreate);
123 610 : dlRaNormalQpDestroy = (int (*)(QpHandle))HcclDlsym(handle_, "RaNormalQpDestroy");
124 610 : CHK_SMART_PTR_NULL(dlRaNormalQpDestroy);
125 610 : dlRaSetQpAttrQos = (int (*)(QpHandle, struct QosAttr*))HcclDlsym(handle_, "RaSetQpAttrQos");
126 610 : CHK_SMART_PTR_NULL(dlRaSetQpAttrQos);
127 610 : dlRaSetQpAttrTimeOut = (int (*)(QpHandle, u32*))HcclDlsym(handle_, "RaSetQpAttrTimeout");
128 610 : CHK_SMART_PTR_NULL(dlRaSetQpAttrTimeOut);
129 610 : dlRaSetQpAttrRetryCnt = (int (*)(QpHandle, u32*))HcclDlsym(handle_, "RaSetQpAttrRetryCnt");
130 610 : CHK_SMART_PTR_NULL(dlRaSetQpAttrRetryCnt);
131 610 : dlRaCreateCompChannel = (int (*)(const void*, void**))HcclDlsym(handle_, "RaCreateCompChannel");
132 610 : CHK_SMART_PTR_NULL(dlRaCreateCompChannel);
133 610 : dlRaDestroyCompChannel = (int (*)(const void*, void*))HcclDlsym(handle_, "RaDestroyCompChannel");
134 610 : CHK_SMART_PTR_NULL(dlRaDestroyCompChannel);
135 610 : dlRaGetCqeErrInfo = (int (*)(unsigned int phyId, struct CqeErrInfo*))HcclDlsym(handle_, "RaGetCqeErrInfo");
136 610 : CHK_SMART_PTR_NULL(dlRaGetCqeErrInfo);
137 : dlRaGetCqeErrInfoList
138 610 : = (int (*)(RdmaHandle, struct CqeErrInfo*, u32*))HcclDlsym(handle_, "RaRdevGetCqeErrInfoList");
139 610 : CHK_SMART_PTR_NULL(dlRaGetCqeErrInfoList);
140 610 : dlRaGetQpAttr = (int (*)(QpHandle, struct QpAttr*))HcclDlsym(handle_, "RaGetQpAttr");
141 610 : CHK_SMART_PTR_NULL(dlRaGetQpAttr);
142 610 : dlRaCreateSrq = (int (*)(const void*, struct SrqAttr*))HcclDlsym(handle_, "RaCreateSrq");
143 610 : CHK_SMART_PTR_NULL(dlRaCreateSrq);
144 610 : dlRaDestroyeSrq = (int (*)(const void*, struct SrqAttr*))HcclDlsym(handle_, "RaDestroySrq");
145 610 : CHK_SMART_PTR_NULL(dlRaDestroyeSrq);
146 : dlRaQpCreateWithAttrs
147 610 : = (int (*)(RdmaHandle, struct QpExtAttrs*, QpHandle*))HcclDlsym(handle_, "RaQpCreateWithAttrs");
148 610 : CHK_SMART_PTR_NULL(dlRaQpCreateWithAttrs);
149 : dlRaTypicalQpCreate
150 610 : = (int (*)(RdmaHandle, int, int, struct TypicalQp*, QpHandle*))HcclDlsym(handle_, "RaTypicalQpCreate");
151 610 : CHK_SMART_PTR_NULL(dlRaTypicalQpCreate);
152 : dlRaTypicalQpModify
153 610 : = (int (*)(QpHandle, struct TypicalQp*, struct TypicalQp*))HcclDlsym(handle_, "RaTypicalQpModify");
154 610 : CHK_SMART_PTR_NULL(dlRaTypicalQpModify);
155 610 : dlRaTypicalSendWr = (int (*)(QpHandle, struct SendWr*, struct SendWrRsp*))HcclDlsym(handle_, "RaTypicalSendWr");
156 610 : CHK_SMART_PTR_NULL(dlRaTypicalSendWr);
157 : dlRaTypicalCqCreate
158 610 : = (int (*)(RdmaHandle, unsigned int, unsigned int*, void**))HcclDlsym(handle_, "RaTypicalCqCreate");
159 610 : CHK_SMART_PTR_NULL(dlRaTypicalCqCreate);
160 610 : dlRaTypicalCqDestroy = (int (*)(RdmaHandle, unsigned int, void*))HcclDlsym(handle_, "RaTypicalCqDestroy");
161 610 : CHK_SMART_PTR_NULL(dlRaTypicalCqDestroy);
162 : dlRaQpCreateWithCQWithAttrs
163 610 : = (int (*)(RdmaHandle, struct QpExtAttrs*, unsigned int, unsigned int, QpHandle*))HcclDlsym(
164 610 : handle_, "RaQpCreateWithCQWithAttrs");
165 610 : CHK_SMART_PTR_NULL(dlRaQpCreateWithCQWithAttrs);
166 : dlRaAiQpCreate
167 610 : = (int (*)(RdmaHandle, struct QpExtAttrs*, struct AiQpInfo*, QpHandle*))HcclDlsym(handle_, "RaAiQpCreate");
168 610 : CHK_SMART_PTR_NULL(dlRaAiQpCreate);
169 : dlRaRecvWrlist
170 0 : = (int (*)(QpHandle handle, struct RecvWrlistData* wr, unsigned int recvNum, unsigned int* completeNum))
171 610 : HcclDlsym(handle_, "RaRecvWrlist");
172 610 : if (dlRaRecvWrlist == nullptr) {
173 0 : HCCL_WARNING("dlRaRecvWrlist is nullptr, can not use ra_recv_wrlist");
174 : }
175 610 : dlRaGetRdmaLiteStatus = (int (*)(RdmaHandle, int*))HcclDlsym(handle_, "RaRdevGetSupportLite");
176 610 : CHK_SMART_PTR_NULL(dlRaGetRdmaLiteStatus);
177 :
178 610 : dlRaQpBatchModify = (int (*)(RdmaHandle rdmaHandle, void** qpHandle, unsigned int num, int expectStatus))HcclDlsym(
179 610 : handle_, "RaQpBatchModify");
180 610 : if (dlRaQpBatchModify == nullptr) {
181 0 : HCCL_ERROR("dlRaQpBatchModify is nullptr, can not use ra_qp_batch_modify");
182 : }
183 610 : CHK_SMART_PTR_NULL(dlRaQpBatchModify);
184 :
185 610 : dlRaPingInit = (int (*)(struct PingInitAttr*, struct PingInitInfo*, void**))HcclDlsym(handle_, "RaPingInit");
186 610 : if (dlRaPingInit == nullptr) {
187 610 : HCCL_WARNING("Current package doesn't have dlRaPingInit, please check!");
188 : }
189 610 : dlRaPingDeinit = (int (*)(void*))HcclDlsym(handle_, "RaPingDeinit");
190 610 : if (dlRaPingDeinit == nullptr) {
191 610 : HCCL_WARNING("Current package doesn't have dlRaPingDeinit, please check!");
192 : }
193 610 : dlRaPingTargetAdd = (int (*)(void*, struct PingTargetInfo target[], uint32_t))HcclDlsym(handle_, "RaPingTargetAdd");
194 610 : if (dlRaPingTargetAdd == nullptr) {
195 610 : HCCL_WARNING("Current package doesn't have dlRaPingTargetAdd, please check!");
196 : }
197 : dlRaPingTargetDel
198 610 : = (int (*)(void*, struct PingTargetCommInfo target[], uint32_t))HcclDlsym(handle_, "RaPingTargetDel");
199 610 : if (dlRaPingTargetDel == nullptr) {
200 610 : HCCL_WARNING("Current package doesn't have dlRaPingTargetDel, please check!");
201 : }
202 610 : dlRaPingTaskStart = (int (*)(void*, struct PingTaskAttr*))HcclDlsym(handle_, "RaPingTaskStart");
203 610 : if (dlRaPingTaskStart == nullptr) {
204 610 : HCCL_WARNING("Current package doesn't have dlRaPingTaskStart, please check!");
205 : }
206 610 : dlRaPingTaskStop = (int (*)(void*))HcclDlsym(handle_, "RaPingTaskStop");
207 610 : if (dlRaPingTaskStop == nullptr) {
208 610 : HCCL_WARNING("Current package doesn't have dlRaPingTaskStop, please check!");
209 : }
210 : dlRaPingGetResults
211 610 : = (int (*)(void*, struct PingTargetResult target[], uint32_t*))HcclDlsym(handle_, "RaPingGetResults");
212 610 : if (dlRaPingGetResults == nullptr) {
213 610 : HCCL_WARNING("Current package doesn't have dlRaPingGetResults, please check!");
214 : }
215 :
216 610 : dlRaIsFirstUsed = (int (*)(int))HcclDlsym(handle_, "RaIsFirstUsed");
217 610 : CHK_SMART_PTR_NULL(dlRaIsFirstUsed);
218 :
219 610 : dlRaIsLastUsed = (int (*)(int))HcclDlsym(handle_, "RaIsLastUsed");
220 610 : CHK_SMART_PTR_NULL(dlRaIsLastUsed);
221 :
222 610 : dlRaRdevGetPortStatus = (int (*)(RdmaHandle, enum PortStatus*))HcclDlsym(handle_, "RaRdevGetPortStatus");
223 610 : CHK_SMART_PTR_NULL(dlRaRdevGetPortStatus);
224 :
225 610 : dlRaRemapMr = (int (*)(RdmaHandle, struct MemRemapInfo info[], unsigned int num))HcclDlsym(handle_, "RaRemapMr");
226 610 : if (dlRaRemapMr == nullptr) {
227 0 : HCCL_WARNING("Current package doesn't have dlRaRemapMr, please check!");
228 : }
229 :
230 610 : dlH2DTlvInit = (int (*)(struct TlvInitInfo*, uint32_t*, void**))HcclDlsym(handle_, "RaTlvInit");
231 610 : if (dlH2DTlvInit == nullptr) {
232 0 : HCCL_WARNING("Current package doesn't have dlH2DTlvInit, please check!");
233 : }
234 610 : dlH2DTlvDeinit = (int (*)(void*))HcclDlsym(handle_, "RaTlvDeinit");
235 610 : if (dlH2DTlvDeinit == nullptr) {
236 0 : HCCL_WARNING("Current package doesn't have dlH2DTlvDeinit, please check!");
237 : }
238 : dlH2DTlvRequest
239 610 : = (int (*)(void*, unsigned int, struct TlvMsg[], struct TlvMsg[]))HcclDlsym(handle_, "RaTlvRequest");
240 610 : if (dlH2DTlvRequest == nullptr) {
241 0 : HCCL_WARNING("Current package doesn't have H2DTlvRequest, please check!");
242 : }
243 610 : return HCCL_SUCCESS;
244 : }
245 :
246 610 : HcclResult DlRaFunction::DlRaFunctionSocketInit()
247 : {
248 : dlRaGetNotifyBaseAddr
249 610 : = (int (*)(RdmaHandle, unsigned long long*, unsigned long long*))HcclDlsym(handle_, "RaGetNotifyBaseAddr");
250 610 : CHK_SMART_PTR_NULL(dlRaGetNotifyBaseAddr);
251 : dlRaGetSockets
252 610 : = (int (*)(unsigned int, struct SocketInfoT[], unsigned int, unsigned int*))HcclDlsym(handle_, "RaGetSockets");
253 610 : CHK_SMART_PTR_NULL(dlRaGetSockets);
254 610 : dlRaSocketBatchClose = (int (*)(struct SocketCloseInfoT[], unsigned int))HcclDlsym(handle_, "RaSocketBatchClose");
255 610 : CHK_SMART_PTR_NULL(dlRaSocketBatchClose);
256 : dlRaSocketBatchConnect
257 610 : = (int (*)(struct SocketConnectInfoT[], unsigned int num))HcclDlsym(handle_, "RaSocketBatchConnect");
258 610 : CHK_SMART_PTR_NULL(dlRaSocketBatchConnect);
259 : dlRaSocketBatchAbort
260 610 : = (int (*)(struct SocketConnectInfoT[], unsigned int num))HcclDlsym(handle_, "RaSocketBatchAbort");
261 610 : CHK_SMART_PTR_NULL(dlRaSocketBatchAbort);
262 610 : dlRaSocketDeInit = (int (*)(SocketHandle))HcclDlsym(handle_, "RaSocketDeinit");
263 610 : CHK_SMART_PTR_NULL(dlRaSocketDeInit);
264 610 : dlRaSocketInit = (int (*)(int, struct rdev, SocketHandle*))HcclDlsym(handle_, "RaSocketInit");
265 610 : CHK_SMART_PTR_NULL(dlRaSocketInit);
266 610 : dlRaSocketInitV1 = (int (*)(int, struct SocketInitInfoT, SocketHandle*))HcclDlsym(handle_, "RaSocketInitV1");
267 610 : CHK_SMART_PTR_NULL(dlRaSocketInitV1);
268 : dlRaSocketListenStart
269 610 : = (int (*)(struct SocketListenInfoT[], unsigned int))HcclDlsym(handle_, "RaSocketListenStart");
270 610 : CHK_SMART_PTR_NULL(dlRaSocketListenStart);
271 610 : dlRaSocketAcceptCreditAdd = (int (*)(struct SocketListenInfoT[], unsigned int, unsigned int))HcclDlsym(
272 610 : handle_, "RaSocketAcceptCreditAdd");
273 610 : CHK_SMART_PTR_NULL(dlRaSocketAcceptCreditAdd);
274 610 : dlRaSocketListenStop = (int (*)(struct SocketListenInfoT[], unsigned int))HcclDlsym(handle_, "RaSocketListenStop");
275 610 : CHK_SMART_PTR_NULL(dlRaSocketListenStop);
276 610 : dlRaSocketRecv = (int (*)(const FdHandle, const void*, unsigned long long, unsigned long long*))HcclDlsym(
277 610 : handle_, "RaSocketRecv");
278 610 : CHK_SMART_PTR_NULL(dlRaSocketRecv);
279 610 : dlRaSocketSend = (int (*)(const FdHandle, const void*, unsigned long long, unsigned long long*))HcclDlsym(
280 610 : handle_, "RaSocketSend");
281 610 : CHK_SMART_PTR_NULL(dlRaSocketSend);
282 : dlRaSocketSendAsync
283 610 : = (int (*)(const FdHandle, const void*, unsigned long long, unsigned long long*, void**))HcclDlsym(
284 610 : handle_, "RaSocketSendAsync");
285 610 : if (dlRaSocketSendAsync == nullptr) {
286 610 : HCCL_WARNING("dlRaSocketSendAsync is nullptr, can not use RaSocketSendAsync");
287 : }
288 610 : dlRaSocketRecvAsync = (int (*)(const FdHandle, void*, unsigned long long, unsigned long long*, void**))HcclDlsym(
289 610 : handle_, "RaSocketRecvAsync");
290 610 : if (dlRaSocketRecvAsync == nullptr) {
291 610 : HCCL_WARNING("dlRaSocketRecvAsync is nullptr, can not use RaSocketRecvAsync");
292 : }
293 610 : dlRaGetAsyncReqResult = (int (*)(void*, int*))HcclDlsym(handle_, "RaGetAsyncReqResult");
294 610 : if (dlRaGetAsyncReqResult == nullptr) {
295 610 : HCCL_WARNING("dlRaGetAsyncReqResult is nullptr, can not use RaGetAsyncReqResult");
296 : }
297 610 : dlRaSocketSetWhiteListStatus = (int (*)(unsigned int))HcclDlsym(handle_, "RaSocketSetWhiteListStatus");
298 610 : CHK_SMART_PTR_NULL(dlRaSocketSetWhiteListStatus);
299 610 : dlRaSocketGetWhiteListStatus = (int (*)(unsigned int*))HcclDlsym(handle_, "RaSocketGetWhiteListStatus");
300 610 : CHK_SMART_PTR_NULL(dlRaSocketGetWhiteListStatus);
301 : dlRaSocketWhiteListAdd
302 610 : = (int (*)(SocketHandle, struct SocketWlistInfoT[], unsigned int))HcclDlsym(handle_, "RaSocketWhiteListAdd");
303 610 : CHK_SMART_PTR_NULL(dlRaSocketWhiteListAdd);
304 : dlRaSocketWhiteListDel
305 610 : = (int (*)(SocketHandle, struct SocketWlistInfoT[], unsigned int))HcclDlsym(handle_, "RaSocketWhiteListDel");
306 610 : CHK_SMART_PTR_NULL(dlRaSocketWhiteListDel);
307 : /* 考虑兼容性问题,这里不校验dlRaGetIfNum是否为空,在使用处校验 */
308 610 : dlRaGetIfNum = (int (*)(struct RaGetIfattr* config, unsigned int* num))HcclDlsym(handle_, "RaGetIfnum");
309 610 : if (dlRaGetIfNum == nullptr) {
310 0 : HCCL_WARNING("dlRaGetIfNum is nullptr, can not use ra_get_ifnum");
311 : }
312 :
313 : dlRaGetIfAddress
314 610 : = (int (*)(struct RaGetIfattr* config, struct InterfaceInfo interface_infos[], unsigned int* num))HcclDlsym(
315 610 : handle_, "RaGetIfaddrs");
316 610 : CHK_SMART_PTR_NULL(dlRaGetIfAddress);
317 : dlRaGetInterfaceVersion
318 610 : = (int (*)(unsigned int phyId, unsigned int interface_opcode, unsigned int* interface_version))HcclDlsym(
319 610 : handle_, "RaGetInterfaceVersion");
320 610 : if (dlRaGetInterfaceVersion == nullptr) {
321 0 : HCCL_WARNING("dlRaGetInterfaceVersion is nullptr, can not use ra_get_interface_version");
322 : }
323 610 : dlRaEpollCtlAdd = (int (*)(const FdHandle fdHandle, RaEpollEvent event))HcclDlsym(handle_, "RaEpollCtlAdd");
324 610 : CHK_SMART_PTR_NULL(dlRaEpollCtlAdd);
325 610 : dlRaEpollCtlMod = (int (*)(const FdHandle fdHandle, RaEpollEvent event))HcclDlsym(handle_, "RaEpollCtlMod");
326 610 : CHK_SMART_PTR_NULL(dlRaEpollCtlMod);
327 610 : dlRaEpollCtlDel = (int (*)(const FdHandle fdHandle))HcclDlsym(handle_, "RaEpollCtlDel");
328 610 : CHK_SMART_PTR_NULL(dlRaEpollCtlDel);
329 : dlRaSetRecvDataCallback
330 610 : = (int (*)(const SocketHandle socketHandle, const void* callback))HcclDlsym(handle_, "RaSetTcpRecvCallback");
331 610 : CHK_SMART_PTR_NULL(dlRaSetRecvDataCallback);
332 :
333 610 : dlRaCreateEventHandle = (int (*)(int* event_handle))HcclDlsym(handle_, "RaCreateEventHandle");
334 610 : if (dlRaCreateEventHandle == nullptr) {
335 0 : HCCL_WARNING("dlRaCreateEventHandle is nullptr, can not use ra_create_event_handle");
336 : }
337 610 : dlRaCtlEventHandle = (int (*)(int event_handle, const void* fdHandle, int opcode, RaEpollEvent event))HcclDlsym(
338 610 : handle_, "RaCtlEventHandle");
339 610 : if (dlRaCtlEventHandle == nullptr) {
340 0 : HCCL_WARNING("dlRaCtlEventHandle is nullptr, can not use ra_ctl_event_handle");
341 : }
342 0 : dlRaWaitEventHandle = (int (*)(
343 : int event_handle, struct SocketEventInfoT* event_infos, int timeout, unsigned int maxevents,
344 610 : unsigned int* events_num))HcclDlsym(handle_, "RaWaitEventHandle");
345 610 : if (dlRaWaitEventHandle == nullptr) {
346 0 : HCCL_WARNING("dlRaWaitEventHandle is nullptr, can not use ra_wait_event_handle");
347 : }
348 610 : dlRaDestroyEventHandle = (int (*)(int* event_handle))HcclDlsym(handle_, "RaDestroyEventHandle");
349 610 : if (dlRaDestroyEventHandle == nullptr) {
350 0 : HCCL_WARNING("dlRaDestroyEventHandle is nullptr, can not use ra_destroy_event_handle");
351 : }
352 :
353 : dlRaGetSocketVnicIpInfos
354 610 : = (int (*)(unsigned int, enum IdType, unsigned int*, unsigned int, struct IpInfo infos[]))HcclDlsym(
355 610 : handle_, "RaSocketGetVnicIpInfos");
356 610 : CHK_SMART_PTR_NULL(dlRaGetSocketVnicIpInfos);
357 :
358 610 : dlRaRaGetTlsEnable = (int (*)(struct RaInfo*, bool*))HcclDlsym(handle_, "RaGetTlsEnable");
359 610 : if (dlRaRaGetTlsEnable == nullptr) {
360 0 : HCCL_WARNING("dlRaRaGetTlsEnable is nullptr, can not use ra_get_tls_enable");
361 : }
362 :
363 610 : dlRaSaveSnapShot = (int (*)(struct RaInfo*, enum SaveSnapshotAction))HcclDlsym(handle_, "RaSaveSnapshot");
364 610 : CHK_SMART_PTR_NULL(dlRaSaveSnapShot);
365 :
366 610 : dlRaRestoreSnapShot = (int (*)(struct RaInfo*))HcclDlsym(handle_, "RaRestoreSnapshot");
367 610 : CHK_SMART_PTR_NULL(dlRaRestoreSnapShot);
368 :
369 610 : dlRaGetHccnCfg = (int (*)(struct RaInfo*, enum HccnCfgKey, char*, int*))HcclDlsym(handle_, "RaGetHccnCfg");
370 610 : if (dlRaGetHccnCfg == nullptr) {
371 610 : HCCL_WARNING("dlRaGetHccnCfg is nullptr, can not use RaGetHccnCfg");
372 : }
373 610 : dlRaGetSecRandom = (int (*)(struct RaInfo* info, unsigned int*))HcclDlsym(handle_, "RaGetSecRandom");
374 610 : if (dlRaGetSecRandom == nullptr) {
375 610 : HCCL_WARNING("dlRaGetSecRandom is nullptr, can not use RaGetSecRandom");
376 : }
377 610 : dlRaGetDevEidInfoNum = (int (*)(RaInfo info, unsigned int*))HcclDlsym(handle_, "RaGetDevEidInfoNum");
378 610 : if (dlRaGetDevEidInfoNum == nullptr) {
379 610 : HCCL_WARNING("dlRaGetDevEidInfoNum is nullptr, can not use RaGetDevEidInfoNum");
380 : }
381 610 : dlRaGetDevEidInfoList = (int (*)(RaInfo info, struct HccpDevEidInfo* eid_info, unsigned int*))HcclDlsym(
382 610 : handle_, "RaGetDevEidInfoList");
383 610 : if (dlRaGetDevEidInfoList == nullptr) {
384 610 : HCCL_WARNING("dlRaGetDevEidInfoList is nullptr, can not use RaGetDevEidInfoList");
385 : }
386 610 : return HCCL_SUCCESS;
387 : }
388 :
389 610 : HcclResult DlRaFunction::DlRaFunctionInit()
390 : {
391 610 : std::lock_guard<std::mutex> lock(handleMutex_);
392 610 : if (handle_ == nullptr) {
393 8 : handle_ = HcclDlopen("libra.so", RTLD_NOW);
394 8 : const char* errMsg = dlerror();
395 8 : CHK_PRT_RET(
396 : handle_ == nullptr,
397 : HCCL_ERROR(
398 : "dlopen [%s] failed, %s", "libra.so",
399 : (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),
400 : HCCL_E_OPEN_FILE_FAILURE);
401 : }
402 610 : dlRaInit = (int (*)(struct RaInitConfig*))HcclDlsym(handle_, "RaInit");
403 610 : CHK_SMART_PTR_NULL(dlRaInit);
404 610 : dlRaDeInit = (int (*)(struct RaInitConfig*))HcclDlsym(handle_, "RaDeinit");
405 610 : CHK_SMART_PTR_NULL(dlRaDeInit);
406 610 : CHK_RET(DlRaFunctionRdmaInit());
407 610 : CHK_RET(DlRaFunctionSocketInit());
408 :
409 610 : return HCCL_SUCCESS;
410 610 : }
411 : } // namespace hccl
|