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 "dfx_profiling_handler_lite.h"
11 : #include "res_pub.h"
12 : #include "log.h"
13 : #include "sqe_a5.h"
14 : #include "prof_sal_lite.h"
15 : #include <limits>
16 : #include <map>
17 :
18 : namespace aicpu {
19 : enum DfxStatusT : uint8_t { AICPU_ERROR_NONE = 0, AICPU_ERROR_FAILED = 1 };
20 : DfxStatusT __attribute__((weak)) GetTaskAndStreamId(uint64_t& taskId, uint32_t& streamId);
21 : } // namespace aicpu
22 :
23 : namespace Hccl {
24 :
25 : static constexpr u32 aging = 1;
26 : constexpr std::uint32_t HCCLINFO_REPORT_BATCH_NUM = 2;
27 : DfxProfilingHandlerLite DfxProfilingHandlerLite::instance_;
28 :
29 : static const std::map<OpTypeVal, std::string> OP_TYPE_NAME_MAP = {
30 : {OpTypeVal::OP_TYPE_ALLREDUCE, "OpType::ALLREDUCE"},
31 : {OpTypeVal::OP_TYPE_BROADCAST, "OpType::BROADCAST"},
32 : {OpTypeVal::OP_TYPE_ALLGATHER, "OpType::ALLGATHER"},
33 : {OpTypeVal::OP_TYPE_REDUCESCATTER, "OpType::REDUCESCATTER"},
34 : {OpTypeVal::OP_TYPE_SEND, "OpType::SEND"},
35 : {OpTypeVal::OP_TYPE_RECV, "OpType::RECV"},
36 : {OpTypeVal::OP_TYPE_BARRIER, "OpType::BARRIER"},
37 : {OpTypeVal::OP_TYPE_ALLTOALL, "OpType::ALLTOALL"},
38 : {OpTypeVal::OP_TYPE_REDUCE, "OpType::REDUCE"},
39 : {OpTypeVal::OP_TYPE_GATHER, "OpType::GATHER"},
40 : {OpTypeVal::OP_TYPE_SCATTER, "OpType::SCATTER"},
41 : {OpTypeVal::OP_TYPE_ALLTOALLV, "OpType::ALLTOALLV"},
42 : {OpTypeVal::OP_TYPE_ALLTOALLVC, "OpType::ALLTOALLVC"},
43 : {OpTypeVal::OP_TYPE_HALFALLTOALLV, "OpType::HALFALLTOALLV"},
44 : {OpTypeVal::OP_TYPE_BATCHSENDRECV, "OpType::BATCHSENDRECV"},
45 : {OpTypeVal::OP_TYPE_BATCHGET, "OpType::BATCHGET"},
46 : {OpTypeVal::OP_TYPE_BATCHPUT, "OpType::BATCHPUT"},
47 : {OpTypeVal::OP_TYPE_ALLGATHERV, "OpType::ALLGATHERV"},
48 : {OpTypeVal::OP_TYPE_REDUCESCATTERV, "OpType::REDUCESCATTERV"},
49 : };
50 :
51 : static const std::map<TaskParamTypeVal, std::string> TASK_PARAM_TYPE_NAME_MAP = {
52 : {TaskParamTypeVal::TASK_SDMA, "Memcpy"},
53 : {TaskParamTypeVal::TASK_RDMA, "RDMASend"},
54 : {TaskParamTypeVal::TASK_REDUCE_INLINE, "Reduce_Inline"},
55 : {TaskParamTypeVal::TASK_REDUCE_TBE, "Reduce_TBE"},
56 : {TaskParamTypeVal::TASK_NOTIFY_RECORD, "Notify_Record"},
57 : {TaskParamTypeVal::TASK_NOTIFY_WAIT, "Notify_Wait"},
58 : {TaskParamTypeVal::TASK_SEND_NOTIFY, "Send_Notify"},
59 : {TaskParamTypeVal::TASK_SEND_PAYLOAD, "Send_Payload"},
60 : {TaskParamTypeVal::TASK_WRITE_WITH_NOTIFY, "Write_With_Notify"},
61 : {TaskParamTypeVal::TASK_UB_INLINE_WRITE, "Ub_Inline_Write"},
62 : {TaskParamTypeVal::TASK_UB_REDUCE_INLINE, "Ub_Reduce_Inline"},
63 : {TaskParamTypeVal::TASK_UB, "Ub_Write_Or_Read"},
64 : {TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY, "Reuce_With_Notify"},
65 : {TaskParamTypeVal::TASK_CCU, "Ccu"},
66 : {TaskParamTypeVal::TASK_AICPU_KERNEL, "AicpuKernel"},
67 : {TaskParamTypeVal::TASK_AICPU_REDUCE, "Aicpu_Reduce"},
68 : {TaskParamTypeVal::TASK_AIV, "AivKernel"},
69 : {TaskParamTypeVal::TASK_DPU_KERNEL, "DpuKernel"},
70 : {TaskParamTypeVal::TASK_DPU_THREAD_FENCE, "Dpu_ThreadFence"},
71 : {TaskParamTypeVal::TASK_DPU_CHANNEL_FENCE, "Dpu_ChannelFence"},
72 : {TaskParamTypeVal::TASK_DPU_INLINE_WRITE, "Dpu_Notify_Record"},
73 : {TaskParamTypeVal::TASK_DPU_NOTIFY_WAIT, "Dpu_Notify_Wait"},
74 : {TaskParamTypeVal::TASK_DPU_WRITE_WITH_NOTIFY, "Dpu_Write_With_Notify"},
75 : };
76 :
77 : static const std::map<AlgTypeVal, std::string> ALG_TYPE_NAME_MAP = {
78 : {AlgTypeVal::ALG_TYPE_NOT_SPECIFIED, "AlgType::NOT_SPECIFIED"},
79 : {AlgTypeVal::ALG_TYPE_RING, "AlgType::RING"},
80 : {AlgTypeVal::ALG_TYPE_MULTI_RING, "AlgType::MULTI_RING"},
81 : {AlgTypeVal::ALG_TYPE_MESH, "AlgType::MESH"},
82 : {AlgTypeVal::ALG_TYPE_RECURSIVE_HD, "AlgType::RECURSIVE_HD"},
83 : {AlgTypeVal::ALG_TYPE_BINARY_HD, "AlgType::BINARY_HD"},
84 : {AlgTypeVal::ALG_TYPE_PAIR_WISE, "AlgType::PAIR_WISE"},
85 : };
86 :
87 47 : DfxProfilingHandlerLite::DfxProfilingHandlerLite() {}
88 :
89 47 : DfxProfilingHandlerLite::~DfxProfilingHandlerLite() {}
90 :
91 215 : DfxProfilingHandlerLite& DfxProfilingHandlerLite::GetInstance() { return instance_; }
92 :
93 33 : void DfxProfilingHandlerLite::SetCachedCommInfo(u64 groupName, u32 localRank, u32 rankSize)
94 : {
95 33 : cachedGroupName_ = groupName;
96 33 : cachedLocalRank_ = localRank;
97 33 : cachedRankSize_ = rankSize;
98 33 : }
99 :
100 29 : void DfxProfilingHandlerLite::SetCachedChannelRemoteRankIdMap(const std::unordered_map<u64, u32>* mapPtr)
101 : {
102 29 : cachedChannelRemoteRankIdMap_ = mapPtr;
103 29 : }
104 :
105 4 : HcclResult DfxProfilingHandlerLite::SetCurrDfxOpInfo(const DfxDfxOpInfo* dfxOpInfo)
106 : {
107 4 : currDfxOpInfo_ = dfxOpInfo;
108 4 : return HCCL_SUCCESS;
109 : }
110 :
111 2 : const DfxDfxOpInfo* DfxProfilingHandlerLite::GetCurrDfxOpInfo() const { return currDfxOpInfo_; }
112 :
113 33 : void DfxProfilingHandlerLite::BindProfilingHandles()
114 : {
115 33 : if (MsprofReportBatchAdditionalInfo == nullptr) {
116 33 : if (AdprofReportAdditionalInfo != nullptr) {
117 33 : reportAdditionalInfo_ = AdprofReportAdditionalInfo;
118 : }
119 33 : if (AdprofGetHashId != nullptr) {
120 33 : getProfHashId_ = AdprofGetHashId;
121 : }
122 33 : if (AdprofReportBatchAdditionalInfo != nullptr) {
123 33 : reportBatchAdditionalInfo_ = AdprofReportBatchAdditionalInfo;
124 : }
125 : } else {
126 0 : if (MsprofReportAdditionalInfo != nullptr) {
127 0 : reportAdditionalInfo_ = [](uint32_t flag, const void* data, uint32_t len) -> int32_t {
128 0 : return MsprofReportAdditionalInfo(flag, const_cast<void*>(data), len);
129 : };
130 : }
131 0 : if (MsprofStr2Id != nullptr) {
132 0 : getProfHashId_ = MsprofStr2Id;
133 : }
134 0 : reportBatchAdditionalInfo_ = [](uint32_t flag, const void* data, uint32_t len) -> int32_t {
135 0 : return MsprofReportBatchAdditionalInfo(flag, const_cast<void*>(data), len);
136 : };
137 : }
138 33 : }
139 :
140 33 : void DfxProfilingHandlerLite::InitHashCaches()
141 : {
142 792 : for (const auto& item : TASK_PARAM_TYPE_NAME_MAP) {
143 759 : u8 taskTypeValue = static_cast<u8>(item.first);
144 0 : taskTypeHashCache_[static_cast<uint32_t>(taskTypeValue)]
145 759 : = GetProfHashId(item.second.c_str(), item.second.length());
146 : }
147 33 : cachedAlgTypeHashId_ = GetProfHashId("AlgType::NHR", strlen("AlgType::NHR"));
148 660 : for (const auto& item : OP_TYPE_NAME_MAP) {
149 627 : u8 opTypeValue = static_cast<u8>(item.first);
150 627 : if (opTypeHashCache_.find(opTypeValue) == opTypeHashCache_.end()) {
151 627 : opTypeHashCache_[opTypeValue] = GetProfHashId(item.second.c_str(), item.second.length());
152 : }
153 : }
154 264 : for (const auto& item : ALG_TYPE_NAME_MAP) {
155 231 : u8 algTypeValue = static_cast<u8>(item.first);
156 231 : if (algTypeHashCache_.find(algTypeValue) == algTypeHashCache_.end()) {
157 231 : algTypeHashCache_[algTypeValue] = GetProfHashId(item.second.c_str(), item.second.length());
158 : }
159 : }
160 33 : }
161 :
162 59 : HcclResult DfxProfilingHandlerLite::Init()
163 : {
164 59 : if (initializedFlag_) {
165 26 : return HCCL_SUCCESS;
166 : }
167 33 : cachedTid_ = SalGetTidLite();
168 33 : BindProfilingHandles();
169 33 : if (reportAdditionalInfo_ == nullptr) {
170 0 : HCCL_ERROR(
171 : "[DfxProfilingHandlerLite][Init] reportAdditionalInfo_ is nullptr, profiling report will be skipped");
172 0 : return HCCL_E_PROFILING;
173 : }
174 33 : if (getProfHashId_ == nullptr) {
175 0 : HCCL_ERROR("[DfxProfilingHandlerLite][Init] getProfHashId_ is nullptr, profiling hash will be invalid");
176 0 : return HCCL_E_PROFILING;
177 : }
178 33 : InitHashCaches();
179 33 : initializedFlag_ = true;
180 33 : return HCCL_SUCCESS;
181 : }
182 :
183 2 : void DfxProfilingHandlerLite::ReportHcclOpInfo(const DfxDfxOpInfo& opInfo) const
184 : {
185 2 : if (!GetProfL0State()) {
186 1 : HCCL_INFO("[DfxProfilingHandlerLite][ReportHcclOpInfo] l0 is false.");
187 1 : return;
188 : }
189 1 : if (aicpu::GetTaskAndStreamId == nullptr) {
190 0 : HCCL_WARNING("[DfxProfilingHandlerLite][ReportHcclOpInfo] GetTaskAndStreamId is nullptr.");
191 0 : return;
192 : }
193 1 : uint64_t taskId = 0U;
194 1 : uint32_t streamId = 0;
195 1 : if (aicpu::GetTaskAndStreamId(taskId, streamId) != aicpu::DfxStatusT::AICPU_ERROR_NONE) {
196 0 : HCCL_ERROR("[DfxProfilingHandlerLite][ReportHcclOpInfo] Failed to get task id and stream id.");
197 0 : return;
198 : }
199 1 : if (taskId > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
200 0 : HCCL_ERROR("[DfxProfilingHandlerLite][ReportHcclOpInfo] taskId is larger than u32.");
201 0 : return;
202 : }
203 1 : MsprofAdditionalInfo reporterData{};
204 1 : reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
205 1 : reporterData.type = MSPROF_REPORT_AICPU_HCCL_OP_INFO;
206 1 : reporterData.threadId = cachedTid_;
207 1 : reporterData.dataLen = sizeof(MsprofAicpuHCCLOPInfo);
208 1 : reporterData.timeStamp = ProfGetCurCpuTimestampLite();
209 1 : auto* hcclOpInfo = reinterpret_cast<MsprofAicpuHCCLOPInfo*>(reporterData.data);
210 :
211 1 : hcclOpInfo->algType = cachedAlgTypeHashId_;
212 1 : hcclOpInfo->taskId = static_cast<uint32_t>(taskId);
213 1 : hcclOpInfo->streamId = streamId;
214 1 : hcclOpInfo->count = opInfo.count;
215 1 : hcclOpInfo->dataType = opInfo.dataType;
216 1 : hcclOpInfo->groupName = cachedGroupName_;
217 1 : hcclOpInfo->ranksize = cachedRankSize_;
218 1 : HCCL_INFO(
219 : "[DfxProfilingHandlerLite][ReportHcclOpInfo] relay:%u, retry:%u, dataType:%u, algType:%u, count:%llu, "
220 : "groupName:%lu, ranksize:%u, taskId:%u, streamId:%u",
221 : hcclOpInfo->relay, hcclOpInfo->retry, hcclOpInfo->dataType, hcclOpInfo->algType, hcclOpInfo->count,
222 : hcclOpInfo->groupName, hcclOpInfo->ranksize, hcclOpInfo->taskId, hcclOpInfo->streamId);
223 1 : ReportAdditionInfo(reporterData);
224 : }
225 :
226 2 : void DfxProfilingHandlerLite::ReportMainStreamTask(const DfxFlagTaskInfo& flagTaskInfo) const
227 : {
228 2 : if (!GetProfL0State()) {
229 1 : HCCL_INFO("[DfxProfilingHandlerLite][ReportMainStreamTask] l0 is false.");
230 1 : return;
231 : }
232 1 : if (aicpu::GetTaskAndStreamId == nullptr) {
233 0 : HCCL_WARNING("[DfxProfilingHandlerLite][ReportMainStreamTask] aicpu::GetTaskAndStreamId is nullptr.");
234 0 : return;
235 : }
236 1 : uint64_t aicpuKernelTaskId = 0U;
237 1 : uint32_t aicpuKernelStreamId = 0;
238 1 : if (aicpu::GetTaskAndStreamId(aicpuKernelTaskId, aicpuKernelStreamId) != aicpu::DfxStatusT::AICPU_ERROR_NONE) {
239 0 : HCCL_ERROR("[DfxProfilingHandlerLite][ReportMainStreamTask] Failed to get task id and stream id.");
240 0 : return;
241 : }
242 1 : if (aicpuKernelTaskId > static_cast<uint64_t>(std::numeric_limits<uint32_t>::max())) {
243 0 : HCCL_ERROR("[DfxProfilingHandlerLite][ReportMainStreamTask] aicpuKernelTaskId is larger than u32.");
244 0 : return;
245 : }
246 1 : MsprofAdditionalInfo reporterData{};
247 1 : reporterData.level = MSPROF_REPORT_AICPU_LEVEL;
248 1 : reporterData.type = MSPROF_REPORT_AICPU_HCCL_FLAG_TASK;
249 1 : reporterData.threadId = cachedTid_;
250 1 : reporterData.dataLen = sizeof(MsprofAicpuHcclMainStreamTask);
251 1 : reporterData.timeStamp = ProfGetCurCpuTimestampLite();
252 1 : auto* flagtask = reinterpret_cast<MsprofAicpuHcclMainStreamTask*>(reporterData.data);
253 1 : flagtask->taskId = static_cast<uint16_t>(flagTaskInfo.taskId >> 16);
254 1 : flagtask->streamId = static_cast<uint16_t>(flagTaskInfo.taskId);
255 1 : flagtask->type = flagTaskInfo.type;
256 1 : uint32_t aicpuKernelTaskIdLow32 = static_cast<uint32_t>(aicpuKernelTaskId);
257 1 : flagtask->aicpuTaskId = static_cast<uint16_t>(aicpuKernelTaskIdLow32 >> 16);
258 1 : flagtask->aicpuStreamId = static_cast<uint16_t>(aicpuKernelTaskIdLow32);
259 1 : HCCL_INFO(
260 : "[DfxProfilingHandlerLite][ReportMainStreamTask] streamId:%u, taskId:%u, type:%u,"
261 : "aicpuStreamId:%u, aicpuTaskId:%u",
262 : flagtask->streamId, flagtask->taskId, flagtask->type, flagtask->aicpuStreamId, flagtask->aicpuTaskId);
263 1 : ReportAdditionInfo(reporterData);
264 : }
265 :
266 3 : void DfxProfilingHandlerLite::ReportAdditionInfo(const MsprofAdditionalInfo& reporterData) const
267 : {
268 3 : if (reportAdditionalInfo_(aging, &reporterData, sizeof(MsprofAdditionalInfo)) != 0) {
269 0 : HCCL_ERROR("[DfxProfilingHandlerLite] ReportAdditionalInfo failed.");
270 : }
271 3 : }
272 :
273 7 : bool DfxProfilingHandlerLite::FillBatchReporterData(
274 : uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo& addInfo) const
275 : {
276 7 : addInfo.level = MSPROF_REPORT_AICPU_LEVEL;
277 7 : addInfo.type = MSPROF_REPORT_AICPU_MC2_BATCH_HCCL_INFO;
278 7 : addInfo.threadId = cachedTid_;
279 7 : addInfo.timeStamp = 0;
280 7 : addInfo.dataLen = sizeof(MsprofAicpuHcclTaskInfo) * batchId;
281 7 : s32 sret = memcpy_s(addInfo.data, sizeof(addInfo.data), taskInfos, addInfo.dataLen);
282 7 : if (sret != 0) {
283 0 : HCCL_WARNING("[DfxProfilingHandlerLite][FillBatchReporterData] memcpy failed, sret[%d]", sret);
284 0 : return false;
285 : }
286 7 : return true;
287 : }
288 :
289 5 : bool DfxProfilingHandlerLite::ReportBatchAddInfo(
290 : uint32_t batchId, const MsprofAicpuHcclTaskInfo* taskInfos, MsprofAdditionalInfo* addInfoVec, uint32_t& addInfoIndx,
291 : uint32_t maxBatchNum, bool isLastBatch) const
292 : {
293 5 : if (!FillBatchReporterData(batchId, taskInfos, addInfoVec[addInfoIndx])) {
294 0 : return false;
295 : }
296 5 : addInfoIndx++;
297 5 : if (addInfoIndx == maxBatchNum || isLastBatch) {
298 3 : if (reportBatchAdditionalInfo_(aging, addInfoVec, addInfoIndx * sizeof(MsprofAdditionalInfo)) != 0) {
299 0 : HCCL_WARNING("[DfxProfilingHandlerLite][ReportStreamTaskDetails] reportBatchAdditionalInfo failed");
300 0 : return false;
301 : }
302 3 : addInfoIndx = 0;
303 : }
304 5 : return true;
305 : }
306 :
307 1 : void DfxProfilingHandlerLite::UpdateProfSwitch()
308 : {
309 1 : IsProfSwitchOn(DfxProfilingLevel::L0);
310 1 : IsProfSwitchOn(DfxProfilingLevel::L1);
311 1 : }
312 :
313 4 : bool DfxProfilingHandlerLite::IsProfOn(uint64_t feature) const
314 : {
315 4 : if (MsprofReportBatchAdditionalInfo == nullptr) {
316 4 : if (AdprofCheckFeatureIsOn == nullptr) {
317 0 : return false;
318 : }
319 4 : return AdprofCheckFeatureIsOn(feature) > 0;
320 : } else {
321 0 : if (feature == ADPROF_TASK_TIME_L1) {
322 0 : return enableHcclL1_;
323 0 : } else if (feature == ADPROF_TASK_TIME_L0) {
324 0 : return enableHcclL0_;
325 : }
326 : }
327 0 : return false;
328 : }
329 :
330 3 : bool DfxProfilingHandlerLite::IsProfSwitchOn(DfxProfilingLevel level)
331 : {
332 3 : bool res = false;
333 3 : if (level == DfxProfilingLevel::L0) {
334 1 : res = IsProfOn(ADPROF_TASK_TIME_L0);
335 1 : enableHcclL0_ = res;
336 2 : } else if (level == DfxProfilingLevel::L1) {
337 2 : res = IsProfOn(ADPROF_TASK_TIME_L1);
338 2 : enableHcclL1_ = res;
339 : }
340 3 : return res;
341 : }
342 :
343 4 : void DfxProfilingHandlerLite::SetProL1On(bool val)
344 : {
345 4 : HCCL_INFO("[%s] val = [%d]", __func__, val);
346 4 : enableHcclL1_ = val;
347 4 : }
348 :
349 4 : void DfxProfilingHandlerLite::SetProL0On(bool val)
350 : {
351 4 : HCCL_INFO("[%s] val = [%d]", __func__, val);
352 4 : enableHcclL0_ = val;
353 4 : }
354 :
355 1679 : uint64_t DfxProfilingHandlerLite::GetProfHashId(const char* name, uint32_t len) const
356 : {
357 1679 : if (name == nullptr || len == 0) {
358 3 : HCCL_WARNING("HashData is empty. name:%s, len:%u", name, len);
359 3 : return DFX_INVALID_U64;
360 : }
361 1676 : if (getProfHashId_ != nullptr) {
362 1676 : return getProfHashId_(name, len);
363 : }
364 0 : return DFX_INVALID_U64;
365 : }
366 :
367 2 : uint64_t DfxProfilingHandlerLite::GetCachedAlgTypeHashId() const { return cachedAlgTypeHashId_; }
368 :
369 22 : void DfxProfilingHandlerLite::GetTaskDetailInfosFromDfxTaskInfo(
370 : const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
371 : {
372 22 : if (!it->IsTaskTypeValid()) {
373 1 : HCCL_WARNING("[DfxProfilingHandlerLite] invalid taskType[%u], skip task detail", it->taskType);
374 1 : return;
375 : }
376 :
377 21 : auto cacheIt = taskTypeHashCache_.find(static_cast<uint32_t>(it->taskType));
378 21 : taskDetailsInfos.itemId = (cacheIt != taskTypeHashCache_.end()) ? cacheIt->second : DFX_INVALID_U64;
379 :
380 21 : FillCclTagAndRemoteRank(it, taskDetailsInfos);
381 :
382 21 : taskDetailsInfos.groupName = cachedGroupName_;
383 21 : taskDetailsInfos.localRank = cachedLocalRank_;
384 21 : taskDetailsInfos.rankSize = cachedRankSize_;
385 21 : taskDetailsInfos.stage = 0;
386 21 : taskDetailsInfos.timeStamp = ProfGetCurCpuTimestampLite();
387 21 : taskDetailsInfos.durationEstimated = 0;
388 :
389 21 : switch (static_cast<TaskParamTypeVal>(it->taskType)) {
390 8 : case TaskParamTypeVal::TASK_SDMA:
391 : case TaskParamTypeVal::TASK_RDMA:
392 8 : FillSdmaRdmaDetail(it, taskDetailsInfos);
393 8 : break;
394 2 : case TaskParamTypeVal::TASK_REDUCE_INLINE:
395 2 : FillReduceInlineDetail(it, taskDetailsInfos);
396 2 : break;
397 7 : case TaskParamTypeVal::TASK_UB:
398 : case TaskParamTypeVal::TASK_UB_INLINE_WRITE:
399 : case TaskParamTypeVal::TASK_UB_REDUCE_INLINE:
400 : case TaskParamTypeVal::TASK_WRITE_WITH_NOTIFY:
401 : case TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY:
402 7 : FillUbDmaDetail(it, taskDetailsInfos);
403 7 : break;
404 3 : case TaskParamTypeVal::TASK_NOTIFY_RECORD:
405 : case TaskParamTypeVal::TASK_NOTIFY_WAIT:
406 3 : FillNotifyDetail(it, taskDetailsInfos);
407 3 : break;
408 1 : default:
409 1 : FillDefaultDetail(it, taskDetailsInfos);
410 1 : break;
411 : }
412 :
413 21 : FillCommonTailFields(it, taskDetailsInfos);
414 : }
415 :
416 4 : void DfxProfilingHandlerLite::ReportStreamTaskDetailsLog(TaskInfoCircularQueue& taskQueue) const
417 : {
418 4 : if (LIKELY(HcclCheckLogLevel(HCCL_LOG_INFO) == 0)) {
419 0 : return;
420 : }
421 4 : u16 begin = taskQueue.GetBegin();
422 4 : u16 count = taskQueue.GetCount();
423 9 : for (u16 idx = begin, i = 0; i < count; idx = (idx + 1) % taskQueue.GetCapacity(), i++) {
424 5 : DfxTaskInfo* ptr = taskQueue.GetSlot(idx);
425 5 : if (ptr == nullptr) {
426 0 : continue;
427 : }
428 5 : HCCL_INFO(
429 : "[DfxProfilingHandlerLite] DumpTaskDetails sqId:%u, taskId:%u, taskType:%u", ptr->sqId, ptr->taskId,
430 : ptr->taskType);
431 : }
432 : }
433 :
434 3 : void DfxProfilingHandlerLite::ReportStreamTaskDetails(TaskInfoCircularQueue& taskQueue) const
435 : {
436 3 : u16 begin = taskQueue.GetBegin();
437 3 : u16 count = taskQueue.GetCount();
438 3 : if (taskQueue.IsEmpty()) {
439 1 : return;
440 : }
441 :
442 2 : ReportStreamTaskDetailsLog(taskQueue);
443 :
444 2 : MsprofAicpuHcclTaskInfo taskInfos[HCCLINFO_REPORT_BATCH_NUM] = {};
445 2 : bool isSupportBatchReport = (reportBatchAdditionalInfo_ != nullptr);
446 2 : constexpr int32_t MAX_BATCH_REPORT_NUM = 512;
447 1024 : MsprofAdditionalInfo addInfoVec[MAX_BATCH_REPORT_NUM] = {};
448 2 : uint32_t addInfoIndx = 0;
449 2 : uint32_t batchId = 0;
450 2 : u32 totalTasks = count;
451 2 : u32 reportedTasks = 0;
452 :
453 6 : for (u16 idx = begin, i = 0; i < count; idx = (idx + 1) % taskQueue.GetCapacity(), i++) {
454 4 : DfxTaskInfo* ptr = taskQueue.GetSlot(idx);
455 4 : if (ptr == nullptr) {
456 0 : continue;
457 : }
458 4 : GetTaskDetailInfosFromDfxTaskInfo(ptr, taskInfos[batchId++]);
459 4 : reportedTasks++;
460 4 : if (batchId == HCCLINFO_REPORT_BATCH_NUM || reportedTasks == totalTasks) {
461 3 : if (!isSupportBatchReport) {
462 0 : MsprofAdditionalInfo reporterData{};
463 0 : if (!FillBatchReporterData(batchId, taskInfos, reporterData)) {
464 0 : return;
465 : }
466 0 : ReportAdditionInfo(reporterData);
467 : } else {
468 3 : if (!ReportBatchAddInfo(
469 : batchId, taskInfos, addInfoVec, addInfoIndx, MAX_BATCH_REPORT_NUM,
470 : reportedTasks == totalTasks)) {
471 0 : return;
472 : }
473 : }
474 3 : batchId = 0;
475 3 : memset_s(taskInfos, sizeof(taskInfos), 0, sizeof(taskInfos));
476 : }
477 : }
478 : }
479 :
480 2 : void DfxProfilingHandlerLite::FillReduceInlineDetail(
481 : const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
482 : {
483 2 : taskDetailsInfos.notifyID = it->taskPara.Reduce.notifyId;
484 2 : taskDetailsInfos.srcAddr = it->taskPara.Reduce.srcAddr;
485 2 : taskDetailsInfos.dstAddr = it->taskPara.Reduce.dstAddr;
486 2 : taskDetailsInfos.dataSize = static_cast<uint64_t>(it->taskPara.Reduce.size);
487 2 : taskDetailsInfos.linkType = it->linkType;
488 2 : taskDetailsInfos.opType = it->taskPara.Reduce.reduceOp;
489 2 : }
490 :
491 8 : void DfxProfilingHandlerLite::FillSdmaRdmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
492 : {
493 8 : taskDetailsInfos.linkType = it->linkType;
494 8 : taskDetailsInfos.opType = 0;
495 8 : taskDetailsInfos.notifyID = DFX_INVALID_U64;
496 8 : void* sqePtr = reinterpret_cast<void*>(it->taskPara.Dma.sqeAddr);
497 8 : if (sqePtr != nullptr) {
498 0 : auto* header = reinterpret_cast<Hccl::Rt91095StarsSqeHeader*>(sqePtr);
499 0 : if (static_cast<Hccl::Rt91095StarsSqeType>(header->type) == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_SDMA) {
500 0 : auto* dmaSqe = reinterpret_cast<Hccl::Rt91095StarsMemcpySqe*>(sqePtr);
501 : taskDetailsInfos.srcAddr
502 0 : = (static_cast<u64>(dmaSqe->u.strideMode0.srcAddrHigh) << 32) | dmaSqe->u.strideMode0.srcAddrLow;
503 : taskDetailsInfos.dstAddr
504 0 : = (static_cast<u64>(dmaSqe->u.strideMode0.dstAddrHigh) << 32) | dmaSqe->u.strideMode0.dstAddrLow;
505 0 : taskDetailsInfos.dataSize = dmaSqe->u.strideMode0.lengthMove;
506 : }
507 : }
508 8 : }
509 :
510 7 : void DfxProfilingHandlerLite::FillUbDmaDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
511 : {
512 7 : taskDetailsInfos.notifyID = it->taskPara.ubDma.notifyId;
513 7 : taskDetailsInfos.srcAddr = it->taskPara.ubDma.srcAddr;
514 7 : taskDetailsInfos.dstAddr = it->taskPara.ubDma.dstAddr;
515 7 : taskDetailsInfos.dataSize = static_cast<uint64_t>(it->taskPara.ubDma.size);
516 7 : taskDetailsInfos.linkType = it->linkType;
517 7 : if (it->taskType == static_cast<u8>(TaskParamTypeVal::TASK_UB_REDUCE_INLINE)
518 5 : || it->taskType == static_cast<u8>(TaskParamTypeVal::TASK_WRITE_REDUCE_WITH_NOTIFY)) {
519 3 : taskDetailsInfos.opType = it->taskPara.Reduce.reduceOp;
520 : } else {
521 4 : taskDetailsInfos.opType = 0;
522 : }
523 7 : }
524 :
525 3 : void DfxProfilingHandlerLite::FillNotifyDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
526 : {
527 3 : taskDetailsInfos.linkType = it->linkType;
528 3 : taskDetailsInfos.notifyID = DFX_INVALID_U64;
529 3 : void* sqePtr = reinterpret_cast<void*>(it->taskPara.Notify.sqeAddr);
530 3 : if (sqePtr != nullptr) {
531 0 : auto* header = reinterpret_cast<Hccl::Rt91095StarsSqeHeader*>(sqePtr);
532 0 : if (static_cast<Hccl::Rt91095StarsSqeType>(header->type)
533 0 : == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD
534 0 : || static_cast<Hccl::Rt91095StarsSqeType>(header->type)
535 0 : == Hccl::Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT) {
536 0 : auto* notifySqe = reinterpret_cast<Hccl::Rt91095StarsNotifySqe*>(sqePtr);
537 0 : taskDetailsInfos.notifyID = notifySqe->notifyId;
538 : }
539 : }
540 3 : }
541 :
542 1 : void DfxProfilingHandlerLite::FillDefaultDetail(const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
543 : {
544 1 : taskDetailsInfos.linkType = it->linkType;
545 1 : taskDetailsInfos.notifyID = DFX_INVALID_U64;
546 1 : }
547 :
548 24 : void DfxProfilingHandlerLite::FillCclTagAndRemoteRank(
549 : const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
550 : {
551 24 : if (it->dfxOpInfo != DFX_INVALID_U64) {
552 3 : auto* opInfo = reinterpret_cast<const DfxDfxOpInfo*>(it->dfxOpInfo);
553 3 : auto opTypeCclTagIt = opTypeHashCache_.find(opInfo->opType);
554 3 : taskDetailsInfos.cclTag = (opTypeCclTagIt != opTypeHashCache_.end()) ? opTypeCclTagIt->second : DFX_INVALID_U64;
555 3 : taskDetailsInfos.remoteRank = INVALID_U32;
556 3 : if (cachedChannelRemoteRankIdMap_ != nullptr && it->channelHandle != DFX_INVALID_U64) {
557 2 : auto rankIt = cachedChannelRemoteRankIdMap_->find(it->channelHandle);
558 2 : if (rankIt != cachedChannelRemoteRankIdMap_->end()) {
559 2 : taskDetailsInfos.remoteRank = rankIt->second;
560 : }
561 : }
562 : } else {
563 21 : taskDetailsInfos.cclTag = DFX_INVALID_U64;
564 21 : taskDetailsInfos.remoteRank = INVALID_U32;
565 : }
566 24 : }
567 :
568 24 : void DfxProfilingHandlerLite::FillCommonTailFields(
569 : const DfxTaskInfo* it, MsprofAicpuHcclTaskInfo& taskDetailsInfos) const
570 : {
571 24 : taskDetailsInfos.taskId = it->taskId;
572 24 : taskDetailsInfos.streamId = it->sqId;
573 24 : taskDetailsInfos.planeID = 0;
574 24 : if (it->dfxOpInfo != DFX_INVALID_U64) {
575 2 : taskDetailsInfos.dataType = reinterpret_cast<const DfxDfxOpInfo*>(it->dfxOpInfo)->dataType;
576 : }
577 24 : taskDetailsInfos.transportType = static_cast<int32_t>(it->transportType);
578 24 : if (taskDetailsInfos.remoteRank == Hccl::DFX_INVALID_RANKID) {
579 21 : taskDetailsInfos.remoteRank = taskDetailsInfos.localRank;
580 : }
581 24 : taskDetailsInfos.rdmaType = 0;
582 24 : taskDetailsInfos.role = static_cast<uint32_t>(DfxTaskRole::NEW_TASK_ROLE_DST);
583 24 : taskDetailsInfos.workFlowMode = static_cast<uint32_t>(DfxWorkflowMode::NEW_WORKFLOW_MODE_OP_BASE);
584 24 : }
585 :
586 : } // namespace Hccl
|