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