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 "dfx_profiling_reporter_lite.h"
12 : #include "aicpu_ts_thread.h"
13 :
14 : namespace Hccl {
15 0 : DfxProfilingReporterLite::DfxProfilingReporterLite(DfxProfilingHandlerLite* profilingHandlerLite)
16 0 : : profilingHandlerLite_(profilingHandlerLite)
17 0 : {}
18 :
19 0 : DfxProfilingReporterLite::~DfxProfilingReporterLite() {}
20 :
21 0 : HcclResult DfxProfilingReporterLite::Init()
22 : {
23 0 : if (initializedFlag_) {
24 0 : return HCCL_SUCCESS;
25 : }
26 0 : if (UNLIKELY(profilingHandlerLite_ == nullptr)) {
27 0 : HCCL_ERROR("[DfxProfilingReporterLite][Init] profilingHandlerLite is nullptr.");
28 0 : return HCCL_E_PTR;
29 : }
30 0 : initializedFlag_ = true;
31 0 : return HCCL_SUCCESS;
32 : }
33 :
34 0 : void DfxProfilingReporterLite::ReportStreamTask(TaskInfoCircularQueue* taskQueue)
35 : {
36 0 : if (taskQueue == nullptr) {
37 0 : return;
38 : }
39 0 : if (!profilingHandlerLite_->GetProfL1State()) {
40 0 : taskQueue->MarkAllRead(); // L1关闭时跳过上报,但仍需标记已读,防止L1重新开启后重复上报
41 0 : return;
42 : }
43 0 : profilingHandlerLite_->ReportStreamTaskDetails(*taskQueue);
44 0 : taskQueue->MarkAllRead(); // 将队列begin推到end,标记已上报的task为已读,下次只遍历新增task
45 : }
46 :
47 1 : void DfxProfilingReporterLite::ReportAllTasksLog(const std::vector<hccl::Thread*>& threads) const
48 : {
49 1 : if (LIKELY(HcclCheckLogLevel(HCCL_LOG_INFO) == 0)) {
50 0 : return;
51 : }
52 1 : for (auto* thread : threads) {
53 0 : auto* aicpuThread = static_cast<hccl::AicpuTsThread*>(thread);
54 0 : if (aicpuThread == nullptr) {
55 0 : continue;
56 : }
57 0 : auto* taskQueue = aicpuThread->GetTaskInfos();
58 0 : if (taskQueue == nullptr || taskQueue->IsEmpty()) {
59 0 : continue;
60 : }
61 0 : profilingHandlerLite_->ReportStreamTaskDetailsLog(*taskQueue);
62 : }
63 : }
64 :
65 0 : void DfxProfilingReporterLite::ReportAllTasks(const std::vector<hccl::Thread*>& threads)
66 : {
67 0 : ReportAllTasksLog(threads);
68 0 : if (!profilingHandlerLite_->GetProfL1State()) {
69 0 : HCCL_DEBUG("[DfxProfilingReporterLite][ReportAllTasks] L1 is off, MarkAllRead and skip report.");
70 0 : for (auto* thread : threads) {
71 0 : auto* aicpuThread = static_cast<hccl::AicpuTsThread*>(thread);
72 0 : if (aicpuThread == nullptr) {
73 0 : continue;
74 : }
75 0 : auto* taskQueue = aicpuThread->GetTaskInfos();
76 0 : if (taskQueue != nullptr) {
77 0 : taskQueue->MarkAllRead(); // L1关闭时跳过上报,但仍需标记已读,防止L1重新开启后重复上报关闭期间的task
78 : }
79 : }
80 0 : return;
81 : }
82 :
83 0 : for (auto* thread : threads) {
84 0 : auto* aicpuThread = static_cast<hccl::AicpuTsThread*>(thread);
85 0 : if (aicpuThread == nullptr) {
86 0 : continue;
87 : }
88 0 : ReportStreamTask(aicpuThread->GetTaskInfos());
89 : }
90 : }
91 :
92 0 : void DfxProfilingReporterLite::UpdateProfStat() { profilingHandlerLite_->UpdateProfSwitch(); }
93 :
94 : } // namespace Hccl
|