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 "dlhns_function.h"
12 :
13 : #include <string>
14 : #include <map>
15 : #include "hccl_dl.h"
16 : #include "log.h"
17 :
18 :
19 : namespace hccl {
20 :
21 5 : DlHnsFunction &DlHnsFunction::GetInstance()
22 : {
23 5 : static DlHnsFunction hcclDlHnsFunction;
24 5 : return hcclDlHnsFunction;
25 : }
26 :
27 2 : DlHnsFunction::DlHnsFunction() : handle_(nullptr)
28 : {
29 2 : }
30 :
31 2 : DlHnsFunction::~DlHnsFunction()
32 : {
33 2 : if (handle_ != nullptr) {
34 0 : (void)HcclDlclose(handle_);
35 0 : handle_ = nullptr;
36 : }
37 2 : }
38 :
39 0 : HcclResult DlHnsFunction::DlHnsFunctionRoceInit()
40 : {
41 0 : dlHnsIbvExtPostSend = (int(*)(struct ibv_qp *, struct ibv_send_wr *,
42 : struct ibv_send_wr **, struct IbvPostSendExtAddt *,
43 0 : struct IbvPostSendExtResp *))HcclDlsym(handle_, "ibv_ext_post_send");
44 0 : CHK_SMART_PTR_NULL(dlHnsIbvExtPostSend);
45 :
46 0 : dlHnsIbvExpPostSend = (int(*)(struct ibv_qp *, struct ibv_send_wr *,
47 0 : struct ibv_send_wr **, struct WrExpRsp *))HcclDlsym(handle_, "ibv_exp_post_send");
48 0 : CHK_SMART_PTR_NULL(dlHnsIbvExpPostSend);
49 0 : return HCCL_SUCCESS;
50 : }
51 :
52 0 : HcclResult DlHnsFunction::DlHnsFunctionSoInit()
53 : {
54 0 : if (handle_ == nullptr) {
55 0 : handle_ = HcclDlopen("libhns-rdmav25.so", RTLD_NOW);
56 0 : if (handle_ != nullptr) {
57 0 : return HCCL_SUCCESS;
58 : }
59 0 : return HCCL_E_INTERNAL;
60 : } else {
61 0 : HCCL_INFO("roce_user_api dlopen again!");
62 : }
63 0 : return HCCL_SUCCESS;
64 : }
65 :
66 0 : HcclResult DlHnsFunction::DlHnsFunctionInit()
67 : {
68 0 : std::lock_guard<std::mutex> lock(handleMutex_);
69 0 : CHK_RET(DlHnsFunctionSoInit());
70 0 : CHK_RET(DlHnsFunctionRoceInit());
71 :
72 0 : return HCCL_SUCCESS;
73 0 : }
74 :
75 : }
|