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 "hcclCommProfiling.h"
12 : #include "profiling_reporter.h"
13 : #include "profiling_handler.h"
14 : #include "../../../../legacy/ascend950/framework/dfx/profiling/dlprof_function_v2.h"
15 : namespace hccl {
16 :
17 0 : HcclResult HcclCommProfiling::ReportKernel(
18 : uint64_t beginTime, const std::string& commTag, const std::string& kernelName, uint32_t threadId,
19 : bool cachedReq) const
20 : {
21 0 : u64 endTime = Hccl::DlProfFunction::GetInstance().dlMsprofSysCycleTime();
22 0 : uint64_t cmdItemId = Hccl::DlProfFunction::GetInstance().dlMsprofStr2Id(kernelName.c_str(), kernelName.length());
23 0 : EXCEPTION_CATCH(
24 : Hccl::ProfilingHandler::GetInstance().ReportNodeApi(beginTime, endTime, cmdItemId, threadId, cachedReq),
25 : return HCCL_E_PTR);
26 0 : EXCEPTION_CATCH(
27 : Hccl::ProfilingHandler::GetInstance().ReportNodeBasicInfo(endTime, cmdItemId, threadId, cachedReq),
28 : return HCCL_E_PTR);
29 0 : HCCL_INFO(
30 : "[HcclCommProfiling][ReportKernel] beginTime [%llu] endTime[%llu] kernelName[%s] commTag[%s] threadId[%u]",
31 : beginTime, endTime, kernelName.c_str(), commTag.c_str(), threadId);
32 0 : return HCCL_SUCCESS;
33 : }
34 :
35 182 : HcclCommProfiling::HcclCommProfiling(u32 deviceId, Hccl::MirrorTaskManager* mirrorTaskManager)
36 182 : : mirrorTaskManager_(mirrorTaskManager)
37 : {
38 : (void)deviceId;
39 182 : }
40 :
41 171 : HcclResult HcclCommProfiling::Init()
42 : {
43 171 : if (initializedFlag_) {
44 1 : return HCCL_SUCCESS;
45 : }
46 170 : CHK_RET(Hccl::ProfilingHandler::GetInstance().Init());
47 : profilingReporter_
48 170 : = std::make_unique<Hccl::ProfilingReporter>(mirrorTaskManager_, &Hccl::ProfilingHandler::GetInstance());
49 170 : CHK_RET(profilingReporter_->Init());
50 170 : initializedFlag_ = true;
51 170 : return HCCL_SUCCESS;
52 : }
53 :
54 : // HcclCommProfiling任务上报
55 147 : void HcclCommProfiling::ReportAllTasks(bool cachedReq) const { profilingReporter_->ReportAllTasks(cachedReq); }
56 :
57 : // HcclCommProfiling::ReportOp实现
58 1 : void HcclCommProfiling::ReportOp(uint64_t beginTime, bool cachedReq, bool isOpBase)
59 : {
60 1 : profilingReporter_->ReportOp(beginTime, cachedReq, isOpBase);
61 1 : }
62 :
63 7 : void HcclCommProfiling::ReportMc2CommInfo(const Mc2CommInfo& mc2CommInfo)
64 : {
65 7 : profilingReporter_->CallReportMc2CommInfo(
66 7 : mc2CommInfo.FreeStreamId, mc2CommInfo.streamsId, mc2CommInfo.groupname, mc2CommInfo.myRankId,
67 7 : mc2CommInfo.rankSize, mc2CommInfo.parentRankId);
68 7 : }
69 :
70 1 : void HcclCommProfiling::SetCurrDfxOpInfo(std::shared_ptr<Hccl::DfxOpInfo> dfxOpInfo)
71 : {
72 1 : profilingReporter_->SetCurrDfxOpInfo(dfxOpInfo);
73 1 : }
74 :
75 : // HcclCommProfiling::UpdateProfStat实现
76 1 : void HcclCommProfiling::UpdateProfStat() { profilingReporter_->UpdateProfStat(); }
77 2 : Hccl::MirrorTaskManager* HcclCommProfiling::GetMirrorTaskManager() const { return mirrorTaskManager_; }
78 : } // namespace hccl
|