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