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 "dlibv_function.h"
12 :
13 : #include <string>
14 : #include <map>
15 : #include "hccl_dl.h"
16 : #include "log.h"
17 :
18 : namespace hccl {
19 0 : DlIbvFunction &DlIbvFunction::GetInstance()
20 : {
21 0 : static DlIbvFunction hcclDlIbvFunction;
22 0 : return hcclDlIbvFunction;
23 : }
24 :
25 0 : DlIbvFunction::DlIbvFunction() : handle_(nullptr)
26 : {
27 0 : }
28 :
29 0 : DlIbvFunction::~DlIbvFunction()
30 : {
31 0 : if (handle_ != nullptr) {
32 0 : (void)HcclDlclose(handle_);
33 0 : handle_ = nullptr;
34 : }
35 0 : }
36 :
37 0 : HcclResult DlIbvFunction::DlIbvFunctionApiInit()
38 : {
39 0 : dlRcoeGetCqEvent = (s32(*)(struct ibv_comp_channel *channel, struct ibv_cq **cq, void **cq_context))
40 0 : HcclDlsym(handle_, "ibv_get_cq_event");
41 0 : CHK_SMART_PTR_NULL(dlRcoeGetCqEvent);
42 :
43 0 : dlRcoeAckCqEvent = (void(*)(struct ibv_cq *qp, unsigned int nevents))
44 0 : HcclDlsym(handle_, "ibv_ack_cq_events");
45 0 : CHK_SMART_PTR_NULL(dlRcoeAckCqEvent);
46 :
47 0 : dlRcoeQueryQp = (s32(*)(struct ibv_qp *qp, struct ibv_qp_attr *attr, int attr_mask,
48 0 : struct ibv_qp_init_attr *init_attr)) HcclDlsym(handle_, "ibv_query_qp");
49 0 : CHK_SMART_PTR_NULL(dlRcoeQueryQp);
50 :
51 0 : return HCCL_SUCCESS;
52 : }
53 :
54 0 : HcclResult DlIbvFunction::DlIbvFunctionInit()
55 : {
56 0 : std::lock_guard<std::mutex> lock(handleMutex_);
57 0 : if (handle_ == nullptr) {
58 0 : handle_ = HcclDlopen("libibverbs.so", RTLD_NOW);
59 0 : const char* errMsg = dlerror();
60 0 : CHK_PRT_RET(handle_ == nullptr, HCCL_ERROR("dlopen [%s] failed, %s", "libibverbs.so",\
61 : (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),\
62 : HCCL_E_OPEN_FILE_FAILURE);
63 : }
64 :
65 0 : CHK_RET(DlIbvFunctionApiInit());
66 0 : return HCCL_SUCCESS;
67 0 : }
68 : }
|