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