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 "dlprof_func.h"
12 : #include "log.h"
13 :
14 : namespace hccl {
15 1161 : DlProfFunc &DlProfFunc::GetInstance()
16 : {
17 1161 : static DlProfFunc hcclDlProfFunction;
18 1161 : return hcclDlProfFunction;
19 : }
20 :
21 11 : DlProfFunc::DlProfFunc()
22 : {
23 11 : DlProfFunctionStubInit();
24 11 : }
25 :
26 11 : DlProfFunc::~DlProfFunc()
27 : {
28 11 : if (handle_ != nullptr) {
29 0 : (void)dlclose(handle_);
30 0 : handle_ = nullptr;
31 : }
32 11 : }
33 :
34 100 : uint64_t HcclMsprofSysCycleTimeStub()
35 : {
36 100 : HCCL_WARNING("Entry HcclMsprofSysCycleTimeStub");
37 100 : return 0;
38 : }
39 :
40 11 : void DlProfFunc::DlProfFunctionStubInit()
41 : {
42 11 : dlMsprofSysCycleTime = (uint64_t(*)(void))HcclMsprofSysCycleTimeStub;
43 11 : }
44 :
45 0 : HcclResult DlProfFunc::DlProfFunctionInterInit()
46 : {
47 0 : dlMsprofSysCycleTime = (uint64_t(*)(void))dlsym(handle_,
48 0 : "MsprofSysCycleTime");
49 0 : CHK_SMART_PTR_NULL(dlMsprofSysCycleTime);
50 :
51 0 : return HCCL_SUCCESS;
52 : }
53 :
54 1061 : HcclResult DlProfFunc::DlProfFunctionInit()
55 : {
56 1061 : std::lock_guard<std::mutex> lock(handleMutex_);
57 1061 : if (handle_ == nullptr) {
58 1061 : handle_ = dlopen("libprofapi.so", RTLD_NOW);
59 : }
60 1061 : if (handle_ != nullptr) {
61 0 : CHK_RET(DlProfFunctionInterInit());
62 : }
63 1061 : return HCCL_SUCCESS;
64 1061 : }
65 : }
|