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 "adapter_verbs.h"
12 : #include <functional>
13 :
14 : #include "log.h"
15 : #include "dlibv_function.h"
16 :
17 : namespace hccl {
18 0 : HcclResult hrtIbvPostSrqRecv(struct ibv_srq* srq, struct ibv_recv_wr* wr, struct ibv_recv_wr** badWr)
19 : {
20 0 : s32 ret = ibv_post_srq_recv(srq, wr, badWr);
21 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("ibv_post_srq_recv failed. errno:%d ret: %d", errno, ret), HCCL_E_NETWORK);
22 0 : return HCCL_SUCCESS;
23 : }
24 :
25 0 : HcclResult hrtIbvPostRecv(struct ibv_qp* qp, struct ibv_recv_wr* wr, struct ibv_recv_wr** badWr)
26 : {
27 0 : s32 ret = ibv_post_recv(qp, wr, badWr);
28 0 : CHK_PRT_RET(ret == ENOMEM, HCCL_WARNING("post recv wqe overflow.[%d]", ret), HCCL_E_AGAIN);
29 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("ibv_post_recv failed. errno:%d ret: %d", errno, ret), HCCL_E_NETWORK);
30 0 : return HCCL_SUCCESS;
31 : }
32 :
33 0 : HcclResult hrtIbvPostSend(struct ibv_qp* qp, struct ibv_send_wr* wr, struct ibv_send_wr** badWr)
34 : {
35 0 : s32 ret = ibv_post_send(qp, wr, badWr);
36 0 : CHK_PRT_RET(ret == ENOMEM, HCCL_WARNING("post send wqe overflow.[%d]", ret), HCCL_E_AGAIN);
37 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("ibv_post_send failed. errno:%d", ret), HCCL_E_NETWORK);
38 0 : return HCCL_SUCCESS;
39 : }
40 :
41 0 : HcclResult hrtIbvPollCq(struct ibv_cq* cq, int maxNum, struct ibv_wc* wc, s32& num)
42 : {
43 0 : int pollNum = 0;
44 0 : pollNum = ibv_poll_cq(cq, maxNum, wc);
45 0 : num = pollNum;
46 0 : CHK_PRT_RET((num < 0), HCCL_ERROR("ibv_poll_cq failed. num:%d", num), HCCL_E_NETWORK);
47 0 : return HCCL_SUCCESS;
48 : }
49 :
50 0 : HcclResult hrtIbvReqNotifyCq(struct ibv_cq* cq, int solicitedOnly)
51 : {
52 0 : s32 ret = ibv_req_notify_cq(cq, solicitedOnly);
53 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("ibv_req_notify_cq failed. errno:%d", ret), HCCL_E_NETWORK);
54 0 : return HCCL_SUCCESS;
55 : }
56 :
57 0 : HcclResult hrtIbvGetCqEvent(struct ibv_comp_channel* channel, struct ibv_cq** cq, void** cq_context)
58 : {
59 0 : s32 ret = DlIbvFunction::GetInstance().dlRcoeGetCqEvent(channel, cq, cq_context);
60 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("hrtIbvGetCqEvent failed. errno:%d", ret), HCCL_E_NETWORK);
61 0 : return HCCL_SUCCESS;
62 : }
63 :
64 0 : void hrtIbvAckCqEvent(struct ibv_cq* qp, unsigned int nevents)
65 : {
66 0 : DlIbvFunction::GetInstance().dlRcoeAckCqEvent(qp, nevents);
67 0 : return;
68 : }
69 :
70 0 : HcclResult hrtIbvQueryQp(struct ibv_qp* qp)
71 : {
72 0 : struct ibv_qp_attr attr {};
73 0 : struct ibv_qp_init_attr init_attr {};
74 0 : CHK_RET(DlIbvFunction::GetInstance().DlIbvFunctionInit());
75 0 : s32 ret = DlIbvFunction::GetInstance().dlRcoeQueryQp(qp, &attr, IBV_QP_STATE, &init_attr);
76 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("hrtIbvQueryQp failed. errno:%d", ret), HCCL_E_NETWORK);
77 0 : return HCCL_SUCCESS;
78 : }
79 :
80 : HcclResult
81 0 : HrtHnsIbvExpPostSend(struct ibv_qp* qp, struct ibv_send_wr* wr, struct ibv_send_wr** badWr, struct WrExpRsp* expRsp)
82 : {
83 0 : CHK_PTR_NULL(qp);
84 0 : CHK_PTR_NULL(wr);
85 0 : CHK_PTR_NULL(badWr);
86 0 : CHK_PTR_NULL(expRsp);
87 : static bool init = false;
88 0 : if (UNLIKELY(!init)) {
89 0 : CHK_RET(DlHnsFunction::GetInstance().DlHnsFunctionInit());
90 0 : init = true;
91 : }
92 :
93 0 : s32 ret = DlHnsFunction::GetInstance().dlHnsIbvExpPostSend(qp, wr, badWr, expRsp);
94 0 : CHK_PRT_RET(
95 : ret == -ENOENT || ret == -EAGAIN || ret == -ENOMEM || ret == ENOENT || ret == EAGAIN || ret == ENOMEM,
96 : HCCL_WARNING("HrtHnsIbvExpPostSend failed. errno:%d", ret), HCCL_E_AGAIN);
97 0 : CHK_PRT_RET(ret != 0, HCCL_ERROR("HrtHnsIbvExpPostSend failed. errno:%d", ret), HCCL_E_NETWORK);
98 0 : return HCCL_SUCCESS;
99 : }
100 : } // namespace hccl
|