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 <string>
12 : #include <map>
13 : #include "hccl_dl.h"
14 : #include "log.h"
15 : #include "dltdt_function.h"
16 :
17 : namespace hccl {
18 1746 : DlTdtFunction &DlTdtFunction::GetInstance()
19 : {
20 1746 : static DlTdtFunction hcclDlTdtFunction;
21 1746 : return hcclDlTdtFunction;
22 : }
23 :
24 14 : DlTdtFunction::DlTdtFunction() : handle_(nullptr)
25 : {
26 14 : }
27 :
28 14 : DlTdtFunction::~DlTdtFunction()
29 : {
30 14 : if (handle_ != nullptr) {
31 14 : (void)HcclDlclose(handle_);
32 14 : handle_ = nullptr;
33 : }
34 14 : }
35 1320 : HcclResult DlTdtFunction::DlTdtFunctionInit()
36 : {
37 : #ifndef HCCD
38 1320 : std::lock_guard<std::mutex> lock(handleMutex_);
39 1320 : if (handle_ == nullptr) {
40 14 : handle_ = HcclDlopen("libtsdclient.so", RTLD_NOW);
41 14 : const char* errMsg = dlerror();
42 14 : CHK_PRT_RET(handle_ == nullptr, HCCL_ERROR("dlopen [%s] failed, %s", "libtsdclient.so",\
43 : (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),\
44 : HCCL_E_OPEN_FILE_FAILURE);
45 : }
46 0 : dlTsdCapabilityGet = (uint32_t(*)(uint32_t deviceLogicId, int32_t type, uint64_t ptr))\
47 1320 : HcclDlsym(handle_, "TsdCapabilityGet");
48 1320 : CHK_SMART_PTR_NULL(dlTsdCapabilityGet);
49 1320 : return HCCL_SUCCESS;
50 : #else
51 : HCCL_ERROR("[DlTdtFunctionInit]Does not support this interface.");
52 : return HCCL_E_NOT_SUPPORT;
53 : #endif
54 1320 : }
55 :
56 16 : HcclResult DlTdtFunction::DlTdtFunctionHeterogInit()
57 : {
58 16 : std::lock_guard<std::mutex> lock(handleMutex_);
59 16 : if (handle_ == nullptr) {
60 1 : handle_ = HcclDlopen("libtsdclient.so", RTLD_NOW);
61 1 : const char* errMsg = dlerror();
62 1 : CHK_PRT_RET(handle_ == nullptr, HCCL_ERROR("dlopen [%s] failed, %s", "libtsdclient.so",\
63 : (errMsg == nullptr) ? "please check the file exist or permission denied." : errMsg),\
64 : HCCL_E_OPEN_FILE_FAILURE);
65 : }
66 16 : return HCCL_SUCCESS;
67 16 : }
68 :
69 : }
|