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 <memory>
12 : #include "task_exception_handler.h"
13 : #include "log.h"
14 : #include "communicator_impl.h"
15 : #include "coll_service_device_mode.h"
16 : #include "mc2_global_mirror_tasks.h"
17 : #include "ccu_dev_mgr.h"
18 : #include "acl/acl_rt.h"
19 : #include "orion_adapter_hccp.h"
20 : #include <adapter_error_manager_pub.h>
21 : #include "hccl_common_v2.h"
22 : #include "hal.h"
23 : #include "orion_adapter_rts.h"
24 : #include "runtime_api_exception.h"
25 :
26 : namespace Hccl {
27 :
28 : using namespace std;
29 : using namespace CcuRep;
30 :
31 : constexpr uint32_t AIV_FLAG_UB_ALIGN_SIZE = 32; // aiv flag对齐规则
32 : constexpr uint32_t TASK_CONTEXT_SIZE = 50;
33 : constexpr uint32_t TASK_CONTEXT_INFO_SIZE = LOG_TMPBUF_SIZE - 50; // task 执行失败时打印前序task信息的长度限制
34 : constexpr int BYTE = 8; // 一字节的位数
35 : constexpr uint64_t CCU_MSG_256MB_LEN = 256 * 1024 * 1024; // CCU消息长度不能大于256MB
36 :
37 : std::array<TaskExceptionHandler*, MAX_MODULE_DEVICE_NUM> TaskExceptionHandlerManager::handlers_;
38 :
39 : std::mutex g_communicatorCallbackMapMutexV2;
40 : array<map<s32, GetAicpuTaskExceptionCallBack>, MAX_MODULE_DEVICE_NUM> g_communicatorCallbackMapV2;
41 : std::mutex g_commHadCallbackArrayMutexV2;
42 : array<bool, MAX_MODULE_DEVICE_NUM> g_commHadCallbackArrayV2 = {false};
43 :
44 : #ifdef __cplusplus
45 : extern "C" {
46 : #endif // __cplusplus
47 4 : void RegisterGetAicpuTaskExceptionCallBackV2(s32 streamId, u32 deviceLogicId, Hccl::GetAicpuTaskExceptionCallBack p1)
48 : {
49 4 : lock_guard<mutex> lock(Hccl::g_communicatorCallbackMapMutexV2);
50 4 : Hccl::g_communicatorCallbackMapV2[deviceLogicId][streamId] = p1;
51 8 : return;
52 4 : }
53 : #ifdef __cplusplus
54 : }
55 : #endif // __cplusplus
56 :
57 6 : TaskExceptionHandler::TaskExceptionHandler(int deviceId) : devId_(deviceId) { Register(); }
58 :
59 5 : TaskExceptionHandler::~TaskExceptionHandler() { UnRegister(); }
60 :
61 7 : void TaskExceptionHandler::Register() const
62 : {
63 7 : HrtRegTaskFailCallbackByModule(Process);
64 21 : HCCL_INFO("[TaskExceptionHandler]exception process func registered.");
65 7 : }
66 :
67 6 : void TaskExceptionHandler::UnRegister() const { HrtUnregTaskFailCallbackByModule(Process); }
68 :
69 44 : TaskExceptionHandler* TaskExceptionHandlerManager::GetHandler(size_t devId)
70 : {
71 : // 检查 devId 是否越界
72 44 : if (devId >= MAX_MODULE_DEVICE_NUM) {
73 3 : HCCL_ERROR("[TaskExceptionHandler][GetInstance] deviceLogicID[%lu] is invalid", devId);
74 1 : return nullptr;
75 : }
76 : // 如果对应位置的实例为空,则创建新实例
77 43 : if (handlers_[devId] == nullptr) {
78 2 : handlers_[devId] = new (std::nothrow) TaskExceptionHandler(devId);
79 2 : if (handlers_[devId] == nullptr) {
80 0 : HCCL_ERROR(
81 : "[TaskExceptionHandler][GetInstance] new TaskExceptionHandler failed due to OOM, devId[%lu]", devId);
82 0 : return nullptr;
83 : }
84 : }
85 43 : return handlers_[devId];
86 : }
87 0 : TaskExceptionHandlerManager::TaskExceptionHandlerManager() { handlers_.fill(nullptr); }
88 :
89 0 : TaskExceptionHandlerManager::~TaskExceptionHandlerManager()
90 : {
91 0 : for (auto& instance : handlers_) {
92 0 : if (instance != nullptr) {
93 0 : delete instance;
94 0 : instance = nullptr;
95 : }
96 : }
97 0 : }
98 :
99 5 : static std::pair<u32, u32> GetOpCounter(const TaskInfo& taskInfo)
100 : {
101 5 : std::pair<float, float> floatCounter;
102 8 : if (taskInfo.dfxOpInfo_ != nullptr && taskInfo.dfxOpInfo_->headOpCounterAddr_ != 0
103 8 : && taskInfo.dfxOpInfo_->tailOpCounterAddr_ != 0) {
104 0 : u64 size = 4;
105 0 : void* headAddr = reinterpret_cast<void*>(taskInfo.dfxOpInfo_->headOpCounterAddr_);
106 0 : void* tailAddr = reinterpret_cast<void*>(taskInfo.dfxOpInfo_->tailOpCounterAddr_);
107 0 : HrtMemcpy(&floatCounter.first, size, headAddr, size, RT_MEMCPY_DEVICE_TO_HOST);
108 0 : HrtMemcpy(&floatCounter.second, size, tailAddr, size, RT_MEMCPY_DEVICE_TO_HOST);
109 : }
110 :
111 5 : std::pair<u32, u32> counter;
112 5 : counter.first = static_cast<u32>(floatCounter.first);
113 5 : counter.second = static_cast<u32>(floatCounter.second);
114 15 : HCCL_INFO("[GetOpCounter] end, head:%u, tail:%u", counter.first, counter.second);
115 5 : return counter;
116 : }
117 :
118 5 : static void PrintOpCounterInfo(const TaskInfo& taskInfo)
119 : {
120 5 : auto count = GetOpCounter(taskInfo);
121 5 : if (taskInfo.dfxOpInfo_ == nullptr) {
122 6 : HCCL_ERROR(
123 : "[TaskExceptionHandler][%s] dfxOpInfo is nullptr, skip opIndex. "
124 : "headOpCounter[%u] tailOpCounter[%u].",
125 : __func__, static_cast<u32>(count.first), static_cast<u32>(count.second));
126 2 : return;
127 : }
128 9 : HCCL_ERROR(
129 : "[TaskExceptionHandler][%s]Task run failed, headOpCounter[%u] tailOpCounter[%u] opIndex[%u].", __func__,
130 : static_cast<u32>(count.first), static_cast<u32>(count.second), taskInfo.dfxOpInfo_->opIndex_);
131 : }
132 :
133 7 : static bool IsMC2Exception(rtExceptionInfo_t* exceptionInfo)
134 : {
135 7 : return exceptionInfo != nullptr && exceptionInfo->expandInfo.type == RT_EXCEPTION_FUSION
136 14 : && exceptionInfo->expandInfo.u.fusionInfo.type == RT_FUSION_AICORE_CCU;
137 : }
138 :
139 0 : void PrintUbRegisters(s32 devLogicId, const RdmaHandle rdmaHandle)
140 : {
141 0 : HCCL_INFO("[PrintUbRegisters] start");
142 0 : AuxInfoIn in;
143 0 : in.cqe.status = 0xffffffff; // 0xffffffff代表查询所有寄存器
144 0 : in.auxInfoInType = AuxInfoInType::AUX_INFO_IN_TYPE_CQE;
145 0 : in.cqe.sR = 0;
146 0 : AuxInfoOut auxInfo;
147 0 : auto ret = RaGetAuxInfo(rdmaHandle, in, auxInfo);
148 0 : if (ret != HCCL_SUCCESS) {
149 0 : HCCL_ERROR("[PrintUbRegister]GetUbRegisterInfo failed.");
150 : }
151 :
152 0 : bool isAuxInfoExisted = false;
153 0 : for (u32 i = 0; i < auxInfo.auxInfoNum; i++) {
154 0 : if (auxInfo.auxInfoValues[i] != 0) { // 非零进行打印
155 0 : isAuxInfoExisted = true;
156 0 : HCCL_ERROR(
157 : "devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]", devLogicId, auxInfo.auxInfoTypes[i],
158 : auxInfo.auxInfoValues[i]);
159 : } else {
160 0 : HCCL_INFO(
161 : "devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]", devLogicId, auxInfo.auxInfoTypes[i],
162 : auxInfo.auxInfoValues[i]);
163 : }
164 : }
165 0 : if (!isAuxInfoExisted) {
166 0 : HCCL_ERROR("devLogicId[%d], all aux_info values are zero.", devLogicId);
167 : }
168 0 : }
169 :
170 0 : void PrintCcuUbRegisters(s32 devLogicId, const ParaCcu& ccuTaskParam)
171 : {
172 0 : std::vector<CcuJetty*> ccuJettys;
173 0 : HcclResult ret = GetCcuJettys(devLogicId, ccuTaskParam, ccuJettys);
174 0 : if (ret != HCCL_SUCCESS) {
175 0 : HCCL_ERROR("PrintCcuUbRegisters failed");
176 : }
177 0 : u32 jettyNum = ccuJettys.size();
178 :
179 0 : std::vector<JettyHandle> jettyHandles;
180 0 : for (auto& ccuJetty : ccuJettys) {
181 0 : jettyHandles.push_back(ccuJetty->GetJettyHandle());
182 : }
183 :
184 0 : std::vector<JettyStatus> jettyStatusVec;
185 0 : RaBatchQueryJettyStatus(jettyHandles, jettyStatusVec, jettyNum);
186 :
187 0 : for (u32 i = 0; i < jettyNum; ++i) {
188 0 : if (jettyStatusVec[i] == JettyStatus::ERROR) {
189 0 : auto rdmaHandle = ccuJettys[i]->GetRdmaHandle();
190 0 : HCCL_ERROR("PrintCcuUbRegisters jettyId[%u]", ccuJettys[i]->GetJettyId());
191 0 : PrintUbRegisters(devLogicId, rdmaHandle);
192 0 : break;
193 : }
194 : }
195 0 : }
196 :
197 7 : void TaskExceptionHandler::Process(rtExceptionInfo_t* exceptionInfo)
198 : {
199 : // Task Exception 入口,使用宏捕获执行间异常
200 13 : TRY_CATCH_PRINT_ERROR(
201 : if (exceptionInfo == nullptr) {
202 : HCCL_ERROR("Exception process failed, rtExceptionInfo is nullptr.");
203 : return;
204 : }
205 :
206 : if (IsMC2Exception(exceptionInfo)) {
207 : ProcessCcuMC2Exception(exceptionInfo);
208 : return;
209 : }
210 :
211 : const auto curTask
212 : = GlobalMirrorTasks::Instance().GetTaskInfo(
213 : exceptionInfo->deviceid, exceptionInfo->streamid, exceptionInfo->taskid);
214 : if (curTask == nullptr) {
215 : // 未找到异常对应的TaskInfo
216 : HCCL_ERROR(
217 : "Exception task not found. deviceId[%u], streamId[%u], taskId[%u].", exceptionInfo->deviceid,
218 : exceptionInfo->streamid, exceptionInfo->taskid);
219 : return;
220 : }
221 :
222 : if (curTask->taskParam_.taskType == TaskParamType::TASK_CCU) {
223 : ProcessCcuException(exceptionInfo, *curTask);
224 : } else if (curTask->taskParam_.taskType == TaskParamType::TASK_AIV) {
225 : ProcessAivException(exceptionInfo, *curTask);
226 : } else { ProcessException(exceptionInfo, *curTask); });
227 : }
228 :
229 : /*
230 : @Desc: AIV 算子异常DFX
231 : */
232 3 : void TaskExceptionHandler::ProcessAivException(rtExceptionInfo_t* exceptionInfo, const TaskInfo& taskInfo)
233 : {
234 9 : HCCL_ERROR("[TaskExceptionHandler][%s]Task from HCCL run failed.", __func__);
235 :
236 9 : HCCL_ERROR(
237 : "[TaskExceptionHandler][AIV]Task run failed, para information is "
238 : "deviceId[%u] streamId[%u], TaskId[%u], cmdType[%u], "
239 : "tag[%u],rank[%u],rankSize[%u], dataCount[%u], numBlocks[%u],"
240 : "dataType:[%u], beginTime:[%llu], flagMem[%p]",
241 : exceptionInfo->deviceid, exceptionInfo->streamid, exceptionInfo->taskid,
242 : taskInfo.taskParam_.taskPara.Aiv.cmdType, taskInfo.taskParam_.taskPara.Aiv.tag,
243 : taskInfo.taskParam_.taskPara.Aiv.rank, taskInfo.taskParam_.taskPara.Aiv.rankSize,
244 : taskInfo.taskParam_.taskPara.Aiv.count, taskInfo.taskParam_.taskPara.Aiv.numBlocks,
245 : taskInfo.taskParam_.taskPara.Aiv.dataType, taskInfo.taskParam_.beginTime,
246 : taskInfo.taskParam_.taskPara.Aiv.flagMem);
247 :
248 : // 打印算子flag 区域, flag区域比较大,需要通过LOG_TMPBUF_SIZE控制打印的长度
249 3 : void* flag_buff_temp = nullptr;
250 : try {
251 3 : flag_buff_temp = HrtMallocHost(taskInfo.taskParam_.taskPara.Aiv.flagMemSize);
252 2 : HrtMemcpy(
253 2 : flag_buff_temp, taskInfo.taskParam_.taskPara.Aiv.flagMemSize, taskInfo.taskParam_.taskPara.Aiv.flagMem,
254 2 : taskInfo.taskParam_.taskPara.Aiv.flagMemSize, RT_MEMCPY_DEVICE_TO_HOST);
255 2 : } catch (const RuntimeApiException& e) {
256 6 : HCCL_ERROR("[TaskExceptionHandler] [%s] host memory operation fail: %s", __func__, e.what());
257 2 : if (flag_buff_temp != nullptr) {
258 0 : HrtFreeHost(flag_buff_temp);
259 : }
260 2 : return;
261 2 : }
262 :
263 1 : std::stringstream flagStr;
264 1 : int32_t* flagMemInt32 = static_cast<int32_t*>(flag_buff_temp);
265 1 : u64 flagCount = taskInfo.taskParam_.taskPara.Aiv.flagMemSize / sizeof(int32_t);
266 : // aiv 内部是32 byte对齐,即每32字节首位存放一个4字节的有效flag
267 1 : u64 alignstep = AIV_FLAG_UB_ALIGN_SIZE / sizeof(int32_t);
268 1 : flagStr << "[TaskExceptionHandler][AIV]Task run failed, para information is deviceId[" << exceptionInfo->deviceid
269 1 : << "], streamId[" << exceptionInfo->streamid << "], TaskId[" << exceptionInfo->taskid << "], flag:";
270 1 : for (u64 i = 0; (flag_buff_temp != nullptr) && (i < flagCount) && (flagStr.str().size() <= LOG_TMPBUF_SIZE); i++) {
271 0 : if (i % alignstep == 0) {
272 0 : flagStr << flagMemInt32[i] << " ";
273 : }
274 : }
275 3 : HCCL_ERROR(flagStr.str().c_str());
276 :
277 1 : if (flag_buff_temp != nullptr) {
278 0 : HrtFreeHost(flag_buff_temp);
279 : }
280 1 : PrintAivPreviousTaskException(exceptionInfo);
281 1 : }
282 :
283 0 : void TaskExceptionHandler::PrintAivPreviousTaskException(rtExceptionInfo_t* exceptionInfo)
284 : {
285 : // 倒序打印前序AIV task信息,找到当前异常task的前50个task(至多)
286 0 : auto queue = GlobalMirrorTasks::Instance().GetQueue(exceptionInfo->deviceid, exceptionInfo->streamid);
287 0 : if (queue == nullptr) {
288 : // 未找到异常对应的TaskQueue
289 0 : HCCL_ERROR(
290 : "Exception task queue not found. deviceId[%u], streamId[%u].", exceptionInfo->deviceid,
291 : exceptionInfo->streamid);
292 0 : return;
293 : }
294 :
295 0 : u32 taskId = exceptionInfo->taskid;
296 0 : auto func = [taskId](const unique_ptr<TaskInfo>& task) {
297 0 : return task->taskId_ == taskId;
298 0 : };
299 0 : auto taskItorPtr = queue->Find(func);
300 0 : if (taskItorPtr == nullptr || *taskItorPtr == *queue->End()) {
301 : // 在队列中未找到异常对应的TaskInfo
302 0 : HCCL_ERROR(
303 : "Exception task not found. deviceId[%u], streamId[%u], taskId[%u].", exceptionInfo->deviceid,
304 : exceptionInfo->streamid, exceptionInfo->taskid);
305 0 : return;
306 : }
307 :
308 0 : HCCL_ERROR(
309 : "[TaskExceptionHandler][AIV]Task run failed, para information is "
310 : "deviceId[%u] streamId[%u], TaskId[%u].",
311 : exceptionInfo->deviceid, exceptionInfo->streamid, exceptionInfo->taskid);
312 :
313 0 : for (uint32_t i = 0; i < TASK_CONTEXT_SIZE && *taskItorPtr != *queue->Begin(); --(*taskItorPtr)) {
314 0 : if ((**taskItorPtr)->taskId_ > taskId) {
315 0 : break;
316 : }
317 0 : if ((**taskItorPtr)->taskId_ != taskId && (**taskItorPtr)->taskParam_.taskType == TaskParamType::TASK_AIV) {
318 0 : HCCL_ERROR(
319 : "[TaskExceptionHandler][AIV] "
320 : "previous TaskId[%u],streamId[%u], cmdType[%u], "
321 : "tag[%u],rank[%u],rankSize[%u], dataCount[%u], numBlocks[%u],"
322 : "dataType:[%u], beginTime:[%llu], flagMem[%p]",
323 : (**taskItorPtr)->taskId_, (**taskItorPtr)->streamId_, (**taskItorPtr)->taskParam_.taskPara.Aiv.cmdType,
324 : (**taskItorPtr)->taskParam_.taskPara.Aiv.tag, (**taskItorPtr)->taskParam_.taskPara.Aiv.rank,
325 : (**taskItorPtr)->taskParam_.taskPara.Aiv.rankSize, (**taskItorPtr)->taskParam_.taskPara.Aiv.count,
326 : (**taskItorPtr)->taskParam_.taskPara.Aiv.numBlocks, (**taskItorPtr)->taskParam_.taskPara.Aiv.dataType,
327 : (**taskItorPtr)->taskParam_.beginTime, (**taskItorPtr)->taskParam_.taskPara.Aiv.flagMem);
328 : }
329 0 : i++;
330 : }
331 0 : }
332 :
333 12 : string TaskExceptionHandler::GetGroupRankInfo(const TaskInfo& taskInfo)
334 : {
335 12 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
336 15 : HCCL_ERROR("[TaskInfo][%s]TaskInfo communicator is nullptr.", __func__);
337 10 : return "";
338 : }
339 7 : const CommunicatorImpl* communicator = static_cast<CommunicatorImpl*>(taskInfo.dfxOpInfo_->comm_);
340 : return StringFormat(
341 14 : "group:[%s], rankSize[%u], rankId[%d]", communicator->GetId().c_str(), communicator->GetRankSize(),
342 7 : communicator->GetMyRank());
343 : }
344 :
345 3 : void TaskExceptionHandler::ProcessException(rtExceptionInfo_t* exceptionInfo, const TaskInfo& taskInfo)
346 : {
347 9 : HCCL_RUN_INFO("[TaskExceptionHandler][%s]begin to execute hccl task exception callback function.", __func__);
348 3 : bool isExistAicpuError = false;
349 3 : if (exceptionInfo == nullptr) {
350 0 : HCCL_ERROR("[TaskExceptionHandler][ProcessException] exceptionInfo is nullptr.");
351 0 : return;
352 : }
353 3 : PrintAicpuErrorMessage(exceptionInfo, isExistAicpuError);
354 3 : if (isExistAicpuError) {
355 : // 如果已经有AICPU上报的task exception, 则host侧无需再次重复上报
356 0 : return;
357 : }
358 9 : HCCL_ERROR("[TaskExceptionHandler][%s]Task from HCCL run failed.", __func__);
359 3 : if (taskInfo.taskParam_.taskType == TaskParamType::TASK_NOTIFY_WAIT) {
360 3 : PrintTaskContextInfo(exceptionInfo->deviceid, exceptionInfo->streamid, exceptionInfo->taskid);
361 9 : HCCL_ERROR("[TaskExceptionHandler][ProcessException] EI0002");
362 48 : RPT_INPUT_ERR(
363 : true, "EI0002",
364 : std::vector<std::string>({"remote_rankid", "base_information", "task_information", "group_rank_content"}),
365 : std::vector<std::string>(
366 : {std::to_string(taskInfo.remoteRank_), taskInfo.GetBaseInfo(), taskInfo.GetParaInfo(),
367 : GetGroupRankInfo(taskInfo)}));
368 : }
369 9 : HCCL_ERROR(
370 : "[TaskExceptionHandler][%s]Task run failed, base information is deviceID:[%u], %s.", __func__,
371 : exceptionInfo->deviceid, taskInfo.GetBaseInfo().c_str());
372 9 : HCCL_ERROR(
373 : "[TaskExceptionHandler][%s]Task run failed, para information is %s.", __func__, taskInfo.GetParaInfo().c_str());
374 9 : HCCL_ERROR(
375 : "[TaskExceptionHandler][%s]Task run failed, groupRank information is %s.", __func__,
376 : GetGroupRankInfo(taskInfo).c_str());
377 3 : PrintOpCounterInfo(taskInfo);
378 9 : HCCL_ERROR(
379 : "[TaskExceptionHandler][%s]Task run failed, opData information is %s.", __func__, taskInfo.GetOpInfo().c_str());
380 3 : }
381 :
382 3 : void TaskExceptionHandler::PrintTaskContextInfo(uint32_t deviceId, uint32_t streamId, uint32_t taskId)
383 : {
384 3 : auto queue = GlobalMirrorTasks::Instance().GetQueue(deviceId, streamId);
385 3 : if (queue == nullptr) {
386 : // 未找到异常对应的TaskQueue
387 0 : HCCL_ERROR("Exception task queue not found. deviceId[%u], streamId[%u].", deviceId, streamId);
388 1 : return;
389 : }
390 :
391 64 : auto func = [taskId](const unique_ptr<TaskInfo>& task) {
392 64 : return task->taskId_ == taskId;
393 3 : };
394 3 : auto taskItorPtr = queue->Find(func);
395 3 : if (taskItorPtr == nullptr || *taskItorPtr == *queue->End()) {
396 : // 在队列中未找到异常对应的TaskInfo
397 0 : HCCL_ERROR("Exception task not found. deviceId[%u], streamId[%u], taskId[%u].", deviceId, streamId, taskId);
398 0 : return;
399 : }
400 :
401 : // 找到当前异常task的前50个task(至多)
402 3 : vector<TaskInfo*> taskContext{};
403 64 : for (uint32_t i = 0; i < TASK_CONTEXT_SIZE && *taskItorPtr != *queue->Begin(); ++i, --(*taskItorPtr)) {
404 61 : if ((**taskItorPtr)->taskId_ > taskId) {
405 0 : break;
406 : }
407 61 : if ((**taskItorPtr)->taskId_ != taskId) {
408 59 : taskContext.emplace_back((**taskItorPtr).get());
409 : }
410 : }
411 :
412 3 : if (taskContext.empty()) {
413 1 : return;
414 : }
415 :
416 6 : HCCL_ERROR("[TaskExceptionHandler]Task run failed, context sequence before error task is "
417 : "[SDMA:M(rank), RDMA:RS(rank,id), SendPayload:SP(rank), InlineReduce:IR(rank), Reduce:R(rank), "
418 : "NotifyRecord:NR(rank,id), NotifyWait:NW(rank,id), SendNotify:SN(rank,id), "
419 : "WriteWithNotify:WN(rank,id), WriteReduceWithNotify:WRN(rank,id)]:");
420 :
421 2 : string taskContextInfo = "";
422 61 : for (auto it = taskContext.rbegin(); it != taskContext.rend(); ++it) {
423 59 : string conciseInfo = (*it)->GetConciseBaseInfo();
424 59 : conciseInfo += ",";
425 :
426 59 : if (taskContextInfo.size() + conciseInfo.size() >= TASK_CONTEXT_INFO_SIZE) {
427 6 : HCCL_ERROR("[TaskExceptionHandler]%s", taskContextInfo.c_str());
428 2 : taskContextInfo = "";
429 : }
430 :
431 59 : taskContextInfo += conciseInfo;
432 59 : }
433 6 : HCCL_ERROR("[TaskExceptionHandler]%s end.", taskContextInfo.c_str());
434 4 : }
435 :
436 : struct ccum_dfx_info {
437 : unsigned int query_result; // 0:success, 1:fail
438 : unsigned int ccum_sqe_recv_cnt;
439 : unsigned int ccum_sqe_send_cnt;
440 : unsigned int ccum_mission_dfx;
441 : unsigned int ccum_sqe_drop_cnt;
442 : unsigned int ccum_sqe_addr_len_err_drop_cnt;
443 : unsigned int lqc_ccu_sec_reg0;
444 : unsigned int ccum_tif_sqe_cnt;
445 : unsigned int ccum_tif_cqe_cnt;
446 : unsigned int ccum_cif_sqe_cnt;
447 : unsigned int ccum_cif_cqe_cnt;
448 : };
449 :
450 0 : void PrintPanicLogInfo(const uint8_t* panicLog)
451 : {
452 0 : struct ccum_dfx_info* info = reinterpret_cast<struct ccum_dfx_info*>(const_cast<uint8_t*>(panicLog));
453 0 : const uint16_t ccumIsEnable = info->lqc_ccu_sec_reg0 & 1;
454 0 : if (info->query_result != 0) {
455 0 : HCCL_ERROR("get ccu dfx info fail, ccu dfx info not all correct");
456 : }
457 0 : HCCL_ERROR(
458 : "CCU DFX INFO: SQE_RECV_CNT[%u] SQE_SEND_CNT[%u] MISSION_DFX[%u]"
459 : "TIF_SQE_CNT[%u] TIF_CQE_CNT[%u] CIF_SQE_CNT[%u] CIF_CQE_CNT[%u]"
460 : "SQE_DROP_CNT[%u] SQE_ADDR_LEN_ERR_DROP_CNT[%u] ccumIsEnable[%u]",
461 : info->ccum_sqe_recv_cnt, info->ccum_sqe_send_cnt, info->ccum_mission_dfx, info->ccum_tif_sqe_cnt,
462 : info->ccum_tif_cqe_cnt, info->ccum_cif_sqe_cnt, info->ccum_cif_cqe_cnt, info->ccum_sqe_drop_cnt,
463 : info->ccum_sqe_addr_len_err_drop_cnt, ccumIsEnable);
464 0 : }
465 :
466 2 : void TaskExceptionHandler::ProcessCcuMC2Exception(rtExceptionInfo_t* exceptionInfo)
467 : {
468 2 : set<uint8_t> exDieIds{};
469 2 : auto& ccuExDetailInfo = exceptionInfo->expandInfo.u.fusionInfo.u.aicoreCcuInfo.ccuDetailMsg;
470 4 : for (uint32_t i = 0; i < ccuExDetailInfo.ccuMissionNum; ++i) {
471 2 : const auto& missionInfo = ccuExDetailInfo.missionInfo[i]; // 异常sqe
472 6 : HCCL_INFO(
473 : "[%s] Exception missionInfo: dieId[%u], missionId[%u], startInstrId[%u], status[0x%x], subStatus[0x%x]",
474 : __func__, missionInfo.dieId, missionInfo.missionId, missionInfo.instrId, missionInfo.status,
475 : missionInfo.subStatus);
476 2 : exDieIds.insert(missionInfo.dieId);
477 2 : uint16_t status = static_cast<uint16_t>(missionInfo.status) << BYTE | missionInfo.subStatus;
478 2 : if (status == 0) {
479 6 : HCCL_INFO("CCU exception status is 0, no need to process.");
480 2 : continue;
481 2 : }
482 0 : PrintPanicLogInfo(missionInfo.panicLog);
483 :
484 0 : auto serverTaskInfo = MC2GlobalMirrorTasks::GetInstance().GetTaskInfo(
485 0 : exceptionInfo->deviceid, missionInfo.dieId, missionInfo.missionId, missionInfo.instrId);
486 0 : if (serverTaskInfo == nullptr) {
487 0 : HCCL_ERROR(
488 : "MC2 TaskInfo not found, deviceId[%u], dieId[%u], missionId[%u], instrId[%u].", exceptionInfo->deviceid,
489 : missionInfo.dieId, missionInfo.missionId, missionInfo.instrId);
490 0 : continue;
491 0 : }
492 :
493 0 : DisplayRPCMsg(*serverTaskInfo);
494 0 : ParaCcu serverParam = serverTaskInfo->taskParam_.taskPara.Ccu;
495 0 : serverParam.execMissionId = missionInfo.missionId;
496 0 : vector<CcuErrorInfo> serverErrorInfos{};
497 0 : if (GetCcuErrorMsg(
498 0 : exceptionInfo->deviceid, status, serverParam, GetGroupRankInfo(*serverTaskInfo), serverErrorInfos)
499 0 : != HcclResult::HCCL_SUCCESS) {
500 0 : HCCL_ERROR("Get CCU error info failed.");
501 0 : continue;
502 0 : }
503 :
504 0 : if (!serverErrorInfos.empty()) {
505 0 : HCCL_INFO("Exception instr is in MC2 Server.");
506 0 : PrintCcuErrorLog(serverErrorInfos, *serverTaskInfo);
507 0 : continue;
508 0 : }
509 :
510 0 : vector<CcuTaskParam> algoTaskParams = GetMC2AlgTaskParam(*serverTaskInfo);
511 0 : for (const auto& algoTaskParam : algoTaskParams) {
512 0 : HCCL_INFO(
513 : "MC2 algo TaskParam: dieId[%u], missionId[%u], instrId[%u]", algoTaskParam.dieId,
514 : algoTaskParam.missionId, algoTaskParam.instStartId);
515 :
516 0 : auto algoTaskInfo = MC2GlobalMirrorTasks::GetInstance().GetTaskInfo(
517 0 : exceptionInfo->deviceid, algoTaskParam.dieId, algoTaskParam.missionId, algoTaskParam.instStartId);
518 0 : if (algoTaskInfo == nullptr) {
519 0 : HCCL_ERROR(
520 : "MC2 TaskInfo not found, deviceId[%u], dieId[%u], missionId[%u], instrId[%u].",
521 : exceptionInfo->deviceid, algoTaskParam.dieId, algoTaskParam.missionId, algoTaskParam.instStartId);
522 0 : continue;
523 0 : }
524 0 : ParaCcu algoParam = algoTaskInfo->taskParam_.taskPara.Ccu;
525 0 : algoParam.execMissionId = missionInfo.missionId;
526 0 : vector<CcuErrorInfo> algoErrorInfos{};
527 0 : if (GetCcuErrorMsg(
528 0 : exceptionInfo->deviceid, status, algoParam, GetGroupRankInfo(*algoTaskInfo), algoErrorInfos)
529 0 : != HcclResult::HCCL_SUCCESS) {
530 0 : HCCL_ERROR("Get CCU error info failed.");
531 0 : continue;
532 0 : }
533 0 : PrintCcuErrorLog(algoErrorInfos, *algoTaskInfo);
534 0 : }
535 0 : }
536 :
537 : // 清除TaskKill状态, 清除CKE
538 2 : const int32_t devLogicId = static_cast<int32_t>(exceptionInfo->deviceid);
539 2 : if (CcuCleanTaskKillState(devLogicId) != HcclResult::HCCL_SUCCESS) {
540 0 : HCCL_ERROR(
541 : "[TaskExceptionHandler][%s] failed to clean ccu task kill state, "
542 : "devLogicId[%d].",
543 : __func__, devLogicId);
544 : }
545 :
546 4 : for (const uint8_t dieId : exDieIds) {
547 2 : if (CcuCleanDieCkes(devLogicId, dieId) != HcclResult::HCCL_SUCCESS) {
548 0 : HCCL_ERROR(
549 : "[TaskExceptionHandler][%s] failed to clean ccu die ckes, "
550 : "dieId[%u], devLogicId[%d].",
551 : __func__, dieId, devLogicId);
552 : }
553 : }
554 2 : }
555 :
556 4 : vector<CcuTaskParam> TaskExceptionHandler::GetMC2AlgTaskParam(const TaskInfo& taskInfo)
557 : {
558 4 : if (taskInfo.taskParam_.taskType != TaskParamType::TASK_CCU) {
559 3 : HCCL_ERROR("[TaskInfo][%s]Get MC2 Alg TaskParam failed, task type error.", __func__);
560 1 : return {};
561 : }
562 3 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
563 3 : HCCL_ERROR("[TaskInfo][%s]Get MC2 Alg TaskParam failed, communicator is nullptr.", __func__);
564 1 : return {};
565 : }
566 2 : const CommunicatorImpl* communicator = (CommunicatorImpl*)taskInfo.dfxOpInfo_->comm_;
567 2 : auto* collServiceBase = communicator->GetCcuCollService();
568 2 : if (collServiceBase == nullptr) {
569 0 : HCCL_ERROR("[TaskInfo][%s]Failed to get collService from communicator.", __func__);
570 0 : return {};
571 : }
572 2 : auto* collServiceCcu = static_cast<CollServiceDeviceMode*>(collServiceBase);
573 2 : return collServiceCcu->GetMc2Compont().GetAlgoCcuTaskInfo(taskInfo.taskParam_.taskPara.Ccu.executeId);
574 : }
575 :
576 2 : void TaskExceptionHandler::ProcessCcuException(const rtExceptionInfo_t* exceptionInfo, const TaskInfo& taskInfo)
577 : {
578 2 : auto deviceId = exceptionInfo->deviceid;
579 6 : HCCL_ERROR("[TaskExceptionHandler][%s]Task from HCCL run failed.", __func__);
580 6 : HCCL_ERROR(
581 : "[TaskExceptionHandler]Task run failed, base information is deviceID:[%u], %s.", deviceId,
582 : taskInfo.GetBaseInfo().c_str());
583 6 : HCCL_ERROR(
584 : "[TaskExceptionHandler]Task run failed, groupRank information is %s.", GetGroupRankInfo(taskInfo).c_str());
585 2 : PrintOpCounterInfo(taskInfo);
586 6 : HCCL_ERROR("[TaskExceptionHandler]Task run failed, opData information is %s.", taskInfo.GetOpInfo().c_str());
587 2 : auto& ccuExDetailInfo = exceptionInfo->expandInfo.u.ccuInfo;
588 2 : for (uint32_t i = 0; i < ccuExDetailInfo.ccuMissionNum; ++i) { // ccuExDetailInfo.ccuMissionNum为1
589 2 : const auto& missionInfo = ccuExDetailInfo.missionInfo[i]; // 异常mission
590 2 : uint16_t status = static_cast<uint16_t>(missionInfo.status) << BYTE | missionInfo.subStatus;
591 : std::tuple<std::string, std::string, std::string, std::string> ipInfo
592 2 : = TaskExceptionHandler::GetCcuErrorIpInfo(deviceId, status, taskInfo);
593 2 : std::string localServerId = std::get<0>(ipInfo);
594 2 : std::string localIp = std::get<1>(ipInfo);
595 2 : std::string remoteIp = std::get<2>(ipInfo);
596 2 : std::string remoteId = std::get<3>(ipInfo);
597 46 : RPT_INPUT_ERR(
598 : true, "EI0018",
599 : std::vector<std::string>(
600 : {"localServerId", "localDeviceId", "localDeviceIp", "remoteServerId", "remoteDeviceId",
601 : "remoteDeviceIp"}),
602 : std::vector<std::string>({localServerId, std::to_string(deviceId), localIp, "", remoteId, remoteIp}));
603 2 : PrintCcuErrorInfo(deviceId, status, taskInfo);
604 : // 打印寄存器信息
605 0 : PrintPanicLogInfo(missionInfo.panicLog);
606 10 : }
607 :
608 0 : const int32_t devLogicId = static_cast<int32_t>(deviceId);
609 0 : if (CcuCleanTaskKillState(devLogicId) != HcclResult::HCCL_SUCCESS) {
610 0 : HCCL_ERROR(
611 : "[TaskExceptionHandler][%s] failed to clean ccu task kill state, "
612 : "devLogicId[%d].",
613 : __func__, devLogicId);
614 : }
615 :
616 0 : const uint8_t dieId = taskInfo.taskParam_.taskPara.Ccu.dieId;
617 0 : if (CcuCleanDieCkes(devLogicId, dieId) != HcclResult::HCCL_SUCCESS) {
618 0 : HCCL_ERROR(
619 : "[TaskExceptionHandler][%s] failed to clean ccu die ckes, "
620 : "dieId[%u], devLogicId[%d].",
621 : __func__, dieId, devLogicId);
622 : }
623 4 : }
624 :
625 0 : inline void PrintBaseErrorLog(const std::string& stageErrInfo, const std::string& baseInfo)
626 : {
627 0 : HCCL_ERROR("%sTask run failed, base information is %s", stageErrInfo.c_str(), baseInfo.c_str());
628 0 : }
629 :
630 0 : inline void PrintParaErrorLog(const std::string& stageErrInfo, const std::string& paraInfoStr)
631 : {
632 0 : HCCL_ERROR("%sTask run failed, para information is %s.", stageErrInfo.c_str(), paraInfoStr.c_str());
633 0 : }
634 :
635 0 : inline void PrintOpDataErrorLog(const std::string& stageErrInfo, const std::string& opDataContent)
636 : {
637 0 : HCCL_ERROR("%sTask run failed, opData information is %s", stageErrInfo.c_str(), opDataContent.c_str());
638 0 : }
639 :
640 0 : inline void PrintGroupErrorLog(const std::string& stageErrInfo, const std::string& groupRankContent)
641 : {
642 0 : HCCL_ERROR("%sTask run failed, groupRank information is %s.", stageErrInfo.c_str(), groupRankContent.c_str());
643 0 : }
644 :
645 0 : void TaskExceptionHandler::PrintGroupErrorMessage(
646 : ErrorMessageReport& errorMessage, [[maybe_unused]] const TaskInfo& exceptionTaskInfo, string& groupRankContent,
647 : string& stageErrInfo)
648 : {
649 0 : groupRankContent += "group:[";
650 0 : groupRankContent += std::string(errorMessage.group);
651 0 : groupRankContent += "], rankSize[";
652 0 : groupRankContent += std::to_string(errorMessage.rankSize);
653 0 : groupRankContent += "], localRank[";
654 0 : groupRankContent += std::to_string(errorMessage.rankId);
655 0 : groupRankContent += "], remoteRank[";
656 0 : groupRankContent += std::to_string(errorMessage.remoteUserRank);
657 0 : groupRankContent += "]";
658 :
659 0 : PrintGroupErrorLog(stageErrInfo, groupRankContent);
660 0 : return;
661 : }
662 :
663 : const std::map<HcclReduceOp, std::string> HCOM_REDUCE_OP_STR_MAP{
664 : {HcclReduceOp::HCCL_REDUCE_SUM, "sum"},
665 : {HcclReduceOp::HCCL_REDUCE_PROD, "prod"},
666 : {HcclReduceOp::HCCL_REDUCE_MAX, "max"},
667 : {HcclReduceOp::HCCL_REDUCE_MIN, "min"},
668 : {HcclReduceOp::HCCL_REDUCE_RESERVED, "invalid"}};
669 :
670 0 : inline std::string GetReduceOpEnumStr(HcclReduceOp reduceOp)
671 : {
672 0 : auto iter = HCOM_REDUCE_OP_STR_MAP.find(reduceOp);
673 0 : if (iter == HCOM_REDUCE_OP_STR_MAP.end()) {
674 0 : return "HcclReduceOp(" + std::to_string(reduceOp) + ")";
675 : } else {
676 0 : return iter->second;
677 : }
678 : }
679 :
680 : const std::map<HcclDataType, std::string> HCOM_DATA_TYPE_STR_MAP{
681 : {HcclDataType::HCCL_DATA_TYPE_INT8, "int8"}, {HcclDataType::HCCL_DATA_TYPE_INT16, "int16"},
682 : {HcclDataType::HCCL_DATA_TYPE_INT32, "int32"}, {HcclDataType::HCCL_DATA_TYPE_INT64, "int64"},
683 : {HcclDataType::HCCL_DATA_TYPE_UINT64, "uint64"}, {HcclDataType::HCCL_DATA_TYPE_FP16, "float16"},
684 : {HcclDataType::HCCL_DATA_TYPE_FP32, "float32"}, {HcclDataType::HCCL_DATA_TYPE_UINT8, "uint8"},
685 : {HcclDataType::HCCL_DATA_TYPE_UINT16, "uint16"}, {HcclDataType::HCCL_DATA_TYPE_UINT32, "uint32"},
686 : {HcclDataType::HCCL_DATA_TYPE_FP64, "float64"}, {HcclDataType::HCCL_DATA_TYPE_BFP16, "bfloat16"},
687 : {HcclDataType::HCCL_DATA_TYPE_INT128, "int128"}, {HcclDataType::HCCL_DATA_TYPE_FP8E4M3, "fp8e4m3"},
688 : {HcclDataType::HCCL_DATA_TYPE_FP8E5M2, "fp8e5m2"}, {HcclDataType::HCCL_DATA_TYPE_RESERVED, "reserved"}};
689 :
690 0 : inline std::string GetDataTypeEnumStr(HcclDataType dataType)
691 : {
692 0 : auto iter = HCOM_DATA_TYPE_STR_MAP.find(dataType);
693 0 : if (iter == HCOM_DATA_TYPE_STR_MAP.end()) {
694 0 : return "HcclDataType(" + std::to_string(dataType) + ")";
695 : } else {
696 0 : return iter->second;
697 : }
698 : }
699 :
700 0 : inline std::string GetDataTypeEnumStr(u32 dataType)
701 : {
702 0 : auto hcclDataType = static_cast<HcclDataType>(dataType);
703 0 : return GetDataTypeEnumStr(hcclDataType);
704 : }
705 :
706 0 : inline std::string GetOpTypeEnumStr(u32 opType)
707 : {
708 0 : OpType hcclOpType = static_cast<OpType::Value>(opType);
709 0 : return hcclOpType.Describe();
710 : }
711 :
712 0 : void TaskExceptionHandler::PrintOpDataErrorMessage(u32 deviceId, ErrorMessageReport& errorMessage, string& stageErrInfo)
713 : {
714 0 : stringstream opDataStr;
715 0 : opDataStr << "src" << "[0x" << std::hex << errorMessage.srcAddr << "], dst[0x" << std::hex << errorMessage.dstAddr
716 0 : << "], ";
717 :
718 0 : string opStr;
719 0 : if (errorMessage.reduceType != HcclReduceOp::HCCL_REDUCE_RESERVED) {
720 0 : opStr += "reduceType[";
721 0 : opStr += GetReduceOpEnumStr(static_cast<HcclReduceOp>(errorMessage.reduceType));
722 0 : opStr += "], ";
723 : }
724 :
725 0 : string opDataContent;
726 0 : opDataContent += "deviceId:[";
727 0 : opDataContent += std::to_string(deviceId);
728 0 : opDataContent += "], index[";
729 0 : opDataContent += std::to_string(errorMessage.opIndex);
730 0 : opDataContent += "], opType[";
731 0 : opDataContent += GetOpTypeEnumStr(errorMessage.opType);
732 0 : opDataContent += "], count[";
733 0 : opDataContent += std::to_string(errorMessage.count);
734 0 : opDataContent += "], ";
735 0 : opDataContent += opStr;
736 0 : opDataContent += opDataStr.str();
737 0 : opDataContent += "dataType[";
738 0 : opDataContent += GetDataTypeEnumStr(errorMessage.dataType);
739 0 : opDataContent += "].";
740 :
741 0 : PrintOpDataErrorLog(stageErrInfo, opDataContent);
742 0 : return;
743 0 : }
744 :
745 3 : void ReportErrorMsg(
746 : const TaskInfo& exceptionTaskInfo, const string& groupRankContent, const ErrorMessageReport& errorMessage,
747 : const rtExceptionInfo_t* exceptionInfo)
748 : {
749 9 : HCCL_INFO("[ReportErrorMsg] start");
750 3 : if (exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_NOTIFY_WAIT) {
751 3 : HCCL_ERROR("[ReportErrorMsg] EI0002");
752 17 : RPT_INPUT_ERR(
753 : true, "EI0002",
754 : std::vector<std::string>({"remote_rankid", "base_information", "task_information", "group_rank_content"}),
755 : std::vector<std::string>(
756 : {std::to_string(exceptionTaskInfo.remoteRank_), exceptionTaskInfo.GetBaseInfo().c_str(),
757 : (exceptionTaskInfo.GetParaInfo()).c_str(), groupRankContent}));
758 2 : } else if (
759 2 : exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_WRITE_REDUCE_WITH_NOTIFY
760 2 : || exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_WRITE_WITH_NOTIFY
761 1 : || exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_UB_INLINE_WRITE
762 1 : || exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_UB_REDUCE_INLINE
763 4 : || exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_UB) {
764 6 : HCCL_ERROR("[ReportErrorMsg] EI0018");
765 44 : RPT_INPUT_ERR(
766 : true, "EI0018",
767 : std::vector<std::string>(
768 : {"localServerId", "localDeviceId", "localDeviceIp", "remoteServerId", "remoteDeviceId",
769 : "remoteDeviceIp"}),
770 : std::vector<std::string>(
771 : {"", std::to_string(exceptionInfo->deviceid), errorMessage.locEid.Describe().c_str(), "", "",
772 : errorMessage.rmtEid.Describe().c_str()}));
773 : }
774 9 : }
775 :
776 0 : void GetTaskParam(TaskParam& taskParam, const ErrorMessageReport& errorMessage)
777 : {
778 0 : if (errorMessage.taskType == TaskParamType::TASK_NOTIFY_WAIT) {
779 0 : taskParam.taskPara.Notify.notifyID = errorMessage.notifyId;
780 0 : taskParam.taskPara.Notify.value = errorMessage.notifyValue;
781 0 : } else if (
782 0 : errorMessage.taskType == TaskParamType::TASK_UB_REDUCE_INLINE
783 0 : || errorMessage.taskType == TaskParamType::TASK_WRITE_REDUCE_WITH_NOTIFY) {
784 0 : taskParam.taskPara.Reduce.notifyID = errorMessage.notifyId;
785 0 : taskParam.taskPara.Reduce.notifyValue = errorMessage.notifyValue;
786 0 : taskParam.taskPara.Reduce.src = reinterpret_cast<void*>(errorMessage.taskSrcAddr);
787 0 : taskParam.taskPara.Reduce.dst = reinterpret_cast<void*>(errorMessage.taskDstAddr);
788 0 : taskParam.taskPara.Reduce.linkType = errorMessage.linkType;
789 0 : taskParam.taskPara.Reduce.size = errorMessage.size;
790 0 : } else if (
791 0 : errorMessage.taskType == TaskParamType::TASK_UB_INLINE_WRITE
792 0 : || errorMessage.taskType == TaskParamType::TASK_WRITE_WITH_NOTIFY) {
793 0 : taskParam.taskPara.DMA.notifyID = errorMessage.notifyId;
794 0 : taskParam.taskPara.DMA.notifyValue = errorMessage.notifyValue;
795 0 : taskParam.taskPara.DMA.src = reinterpret_cast<void*>(errorMessage.taskSrcAddr);
796 0 : taskParam.taskPara.DMA.dst = reinterpret_cast<void*>(errorMessage.taskDstAddr);
797 0 : taskParam.taskPara.DMA.linkType = errorMessage.linkType;
798 0 : taskParam.taskPara.DMA.size = errorMessage.size;
799 : }
800 0 : }
801 :
802 0 : void TaskExceptionHandler::PrintAicpuErrorMessage(rtExceptionInfo_t* exceptionInfo, bool& isExistAicpuError)
803 : {
804 0 : ErrorMessageReport errorMessage;
805 0 : unique_lock<std::mutex> lock(Hccl::g_commHadCallbackArrayMutexV2);
806 0 : if (Hccl::g_commHadCallbackArrayV2[exceptionInfo->deviceid]) {
807 : // 防止同一个device上出现通信主流和kernel流均出现task exception时runtime调用两次callback
808 : // HDC通道信息不是读清,防止aicpu task exception重复上报
809 0 : HCCL_WARNING("aicpu error message been reported. deviceid[%u]", exceptionInfo->deviceid);
810 0 : return;
811 : }
812 0 : lock.unlock();
813 0 : if (Hccl::g_communicatorCallbackMapV2[exceptionInfo->deviceid].find(exceptionInfo->streamid)
814 0 : != Hccl::g_communicatorCallbackMapV2[exceptionInfo->deviceid].end()) {
815 : // 找到对应的通信域,并调用回调函数从HDC通道获取AICPU异常信息
816 0 : errorMessage = (Hccl::g_communicatorCallbackMapV2[exceptionInfo->deviceid])[exceptionInfo->streamid]();
817 0 : if (strlen(errorMessage.tag) > 0) {
818 0 : isExistAicpuError = true;
819 0 : std::string groupRankContent;
820 0 : u32 streamId = static_cast<u32>(errorMessage.streamId);
821 0 : TaskParam taskParam{};
822 0 : taskParam.taskType = errorMessage.taskType;
823 :
824 0 : GetTaskParam(taskParam, errorMessage);
825 :
826 0 : std::shared_ptr<DfxOpInfo> dfxOpInfo = std::make_shared<DfxOpInfo>();
827 0 : dfxOpInfo->tag_ = std::string(errorMessage.tag);
828 : TaskInfo exceptionTaskInfo(
829 0 : streamId, errorMessage.taskId, errorMessage.remoteUserRank, taskParam, dfxOpInfo);
830 0 : auto logKeywordL2 = exceptionTaskInfo.taskParam_.taskType == TaskParamType::TASK_NOTIFY_WAIT ?
831 : LOG_KEYWORDS_TIMEOUT :
832 0 : LOG_KEYWORDS_RUN_FAILED;
833 0 : auto stageErrInfo = "[" + LOG_KEYWORDS_TASK_EXEC + "][" + logKeywordL2 + "][" + LOG_KEYWORDS_AICPU + "]";
834 0 : HCCL_ERROR("%sTask from HCCL run failed.", stageErrInfo.c_str());
835 : // 防止tag字符串过长, 信息分开打印
836 0 : PrintBaseErrorLog(stageErrInfo, exceptionTaskInfo.GetBaseInfo());
837 0 : PrintParaErrorLog(stageErrInfo, exceptionTaskInfo.GetParaInfo());
838 0 : PrintGroupErrorMessage(errorMessage, exceptionTaskInfo, groupRankContent, stageErrInfo);
839 0 : PrintOpDataErrorMessage(exceptionInfo->deviceid, errorMessage, stageErrInfo);
840 0 : HCCL_ERROR(
841 : "errorMessage taskType[%s], rtCqErrorType[%u], rtCqErrorCode[%u]. ",
842 : errorMessage.taskType.Describe().c_str(), static_cast<u32>(errorMessage.rtCqErrorType),
843 : errorMessage.rtCqErrorCode);
844 :
845 : // 打印UB DFX寄存器信息
846 0 : if (errorMessage.taskType == TaskParamType::TASK_WRITE_WITH_NOTIFY
847 0 : || errorMessage.taskType == TaskParamType::TASK_WRITE_REDUCE_WITH_NOTIFY
848 0 : || errorMessage.taskType == TaskParamType::TASK_UB_INLINE_WRITE
849 0 : || errorMessage.taskType == TaskParamType::TASK_UB_REDUCE_INLINE
850 0 : || errorMessage.taskType == TaskParamType::TASK_UB) {
851 0 : HCCL_ERROR(
852 : "errorMessage ubCqeStatus[%u], localEid[%s], remoteEid[%s]. ",
853 : static_cast<u32>(errorMessage.ubCqeStatus), errorMessage.locEid.Describe().c_str(),
854 : errorMessage.rmtEid.Describe().c_str());
855 0 : auto addr = IpAddress(errorMessage.locEid);
856 0 : u32 devPhyId = HrtGetDevicePhyIdByIndex(exceptionInfo->deviceid);
857 0 : auto rdmaHandle = RdmaHandleManager::GetInstance().GetByIp(devPhyId, addr);
858 0 : PrintUbRegisters(static_cast<s32>(exceptionInfo->deviceid), rdmaHandle);
859 : }
860 :
861 0 : ReportErrorMsg(exceptionTaskInfo, groupRankContent, errorMessage, exceptionInfo);
862 :
863 0 : lock.lock();
864 0 : Hccl::g_commHadCallbackArrayV2[exceptionInfo->deviceid] = true;
865 0 : } else {
866 0 : HCCL_WARNING("PrintAicpuErrorMessage No Vaild errorMessage!");
867 : }
868 : } else {
869 0 : HCCL_INFO("PrintAicpuErrorMessage streamId[%u] is not found.", exceptionInfo->streamid);
870 : }
871 0 : }
872 :
873 2 : void TaskExceptionHandler::PrintCcuErrorInfo(uint32_t deviceId, uint16_t status, const TaskInfo& taskInfo)
874 : {
875 2 : const ParaCcu& ccuTaskParam = taskInfo.taskParam_.taskPara.Ccu;
876 2 : vector<CcuErrorInfo> errorInfos{};
877 4 : HcclResult ret = GetCcuErrorMsg(deviceId, status, ccuTaskParam, GetGroupRankInfo(taskInfo), errorInfos);
878 0 : const uint8_t missionStatus = (status >> 8) & 0xFF;
879 0 : if (ret != HcclResult::HCCL_SUCCESS || errorInfos.empty()) {
880 0 : HCCL_ERROR(
881 : "Get CCU error info failed. deviceId[%u], dieId[%u], missionId[%u], executeId[%llu].", deviceId,
882 : ccuTaskParam.dieId, ccuTaskParam.missionId, ccuTaskParam.executeId);
883 0 : return;
884 : }
885 0 : PrintCcuErrorLog(errorInfos, taskInfo);
886 :
887 0 : if (missionStatus >= 0x01
888 0 : && missionStatus <= 0x05) { // 如果是UB错误(missionStatus为[0x01, 0x05]),打印Ub Dfx寄存器信息
889 0 : PrintCcuUbRegisters(static_cast<s32>(deviceId), taskInfo.taskParam_.taskPara.Ccu);
890 : }
891 2 : }
892 :
893 0 : void TaskExceptionHandler::PrintCcuErrorLog(const std::vector<CcuErrorInfo>& errorInfos, const TaskInfo& taskInfo)
894 : {
895 0 : if (errorInfos.empty()) {
896 0 : return;
897 : }
898 0 : HCCL_ERROR("[TaskExceptionHandler]Task run failed, ccu runtime information is: %s", __func__);
899 0 : for (const auto& errorInfo : errorInfos) {
900 0 : HCCL_ERROR("[TaskExceptionHandler][%s]", GetCcuErrorMsgByType(errorInfo, taskInfo).c_str());
901 : }
902 : }
903 :
904 8 : string TaskExceptionHandler::GetCcuLenErrorMsg(const uint64_t len)
905 : {
906 8 : if ((0 < len) && (len <= CCU_MSG_256MB_LEN)) {
907 0 : return "";
908 : }
909 8 : return StringFormat("ccu transMem Len[%llu]B > 256MB or is zero, not support!", len);
910 : }
911 :
912 1 : string TaskExceptionHandler::GetCcuErrorMsgLoop(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
913 : {
914 : (void)taskInfo;
915 : return StringFormat(
916 : "InstrId[%u]: Loop startInstrId[%u], endInstrId[%u], executorId[%u], "
917 : "totalIter[%u], curIter[%u], addressStride[0x%llx]",
918 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.loop.startInstrId, ccuErrorInfo.msg.loop.endInstrId,
919 1 : ccuErrorInfo.msg.loop.loopEngineId, ccuErrorInfo.msg.loop.loopCnt, ccuErrorInfo.msg.loop.loopCurrentCnt,
920 1 : ccuErrorInfo.msg.loop.addrStride);
921 : }
922 :
923 1 : string TaskExceptionHandler::GetCcuErrorMsgLoopGroup(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
924 : {
925 : (void)taskInfo;
926 : return StringFormat(
927 : "InstrId[%u]: LoopGroup startLoopInsId[%u], loopInsCnt[%u], "
928 : "expandOffset[%u], expandCnt[%u]",
929 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.loopGroup.startLoopInsId, ccuErrorInfo.msg.loopGroup.loopInsCnt,
930 1 : ccuErrorInfo.msg.loopGroup.expandOffset, ccuErrorInfo.msg.loopGroup.expandCnt);
931 : }
932 :
933 1 : string TaskExceptionHandler::GetCcuErrorMsgLocPostSem(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
934 : {
935 : (void)taskInfo;
936 : return StringFormat(
937 1 : "InstrId[%u]: Set sem[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
938 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
939 1 : ccuErrorInfo.msg.waitSignal.signalMask);
940 : }
941 :
942 1 : string TaskExceptionHandler::GetCcuErrorMsgLocWaitSem(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
943 : {
944 : (void)taskInfo;
945 : return StringFormat(
946 1 : "InstrId[%u]: Wait sem[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
947 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
948 1 : ccuErrorInfo.msg.waitSignal.signalMask);
949 : }
950 :
951 1 : string TaskExceptionHandler::GetCcuErrorMsgRemPostSem(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
952 : {
953 : return StringFormat(
954 1 : "InstrId[%u]: Post, Use sem[%u], mask[0x%04x], rankId[%d]", ccuErrorInfo.instrId,
955 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask,
956 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo));
957 : }
958 :
959 1 : string TaskExceptionHandler::GetCcuErrorMsgRemWaitSem(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
960 : {
961 : return StringFormat(
962 1 : "InstrId[%u]: Wait, Use sem[%u], semValue[0x%04x], mask[0x%04x], rankId[%d]", ccuErrorInfo.instrId,
963 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
964 1 : ccuErrorInfo.msg.waitSignal.signalMask,
965 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo));
966 : }
967 :
968 1 : string TaskExceptionHandler::GetCcuErrorMsgRemPostVar(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
969 : {
970 : return StringFormat(
971 : "InstrId[%u]: Post Variable[0x%016llx] To Param[%u], Use sem[%u], mask[0x%04x], rankId[%d]",
972 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.paramValue, ccuErrorInfo.msg.waitSignal.paramId,
973 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask,
974 1 : GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo));
975 : }
976 :
977 1 : string TaskExceptionHandler::GetCcuErrorMsgRemWaitGroup(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
978 : {
979 1 : stringstream ranks;
980 5 : for (uint32_t i = 0; i < WAIT_SIGNAL_CHANNEL_SIZE; ++i) {
981 5 : const auto channelId = ccuErrorInfo.msg.waitSignal.channelId[i];
982 5 : if (channelId == UINT16_MAX) {
983 1 : break;
984 : }
985 4 : const auto rankId = GetRankIdByChannelId(channelId, taskInfo);
986 4 : if (i != 0) {
987 3 : ranks << ", ";
988 : }
989 4 : ranks << to_string(rankId);
990 : }
991 : return StringFormat(
992 1 : "InstrId[%u]: Wait Group, Use sem[%u], semValue[0x%04x], mask[0x%04x], rankIds[%s]", ccuErrorInfo.instrId,
993 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
994 2 : ccuErrorInfo.msg.waitSignal.signalMask, ranks.str().c_str());
995 1 : }
996 :
997 1 : string TaskExceptionHandler::GetCcuErrorMsgPostSharedVar(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
998 : {
999 : (void)taskInfo;
1000 : return StringFormat(
1001 : "InstrId[%u]: Post Shared Variable[%u] from Variable[0x%016llx], "
1002 : "Use sem[%u], mask[0x%04x]",
1003 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.paramId, ccuErrorInfo.msg.waitSignal.paramValue,
1004 1 : ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask);
1005 : }
1006 :
1007 1 : string TaskExceptionHandler::GetCcuErrorMsgPostSharedSem(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1008 : {
1009 : (void)taskInfo;
1010 : return StringFormat(
1011 1 : "InstrId[%u]: Post, Use sem[%u], mask[0x%04x]", ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.signalId,
1012 1 : ccuErrorInfo.msg.waitSignal.signalMask);
1013 : }
1014 :
1015 1 : string TaskExceptionHandler::GetCcuErrorMsgRead(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1016 : {
1017 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo);
1018 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1019 : return StringFormat(
1020 : "InstrId[%u]: Read Memory[0x%016llx] To Memory[0x%016llx], Len[%llu], "
1021 : "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1022 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.rmtAddr, ccuErrorInfo.msg.transMem.locAddr,
1023 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1024 2 : GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo), pair.first.Describe().c_str(),
1025 4 : pair.second.Describe().c_str(), printMsg.c_str());
1026 1 : }
1027 :
1028 1 : string TaskExceptionHandler::GetCcuErrorMsgWrite(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1029 : {
1030 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo);
1031 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1032 : return StringFormat(
1033 : "InstrId[%u]: Write Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1034 : "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1035 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1036 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1037 2 : GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo), pair.first.Describe().c_str(),
1038 4 : pair.second.Describe().c_str(), printMsg.c_str());
1039 1 : }
1040 :
1041 1 : string TaskExceptionHandler::GetCcuErrorMsgLocalCpy(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1042 : {
1043 : (void)taskInfo;
1044 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1045 : return StringFormat(
1046 : "InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1047 : "Set sem[%u] with mask[0x%04x] %s",
1048 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1049 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1050 2 : printMsg.c_str());
1051 1 : }
1052 :
1053 1 : string TaskExceptionHandler::GetCcuErrorMsgLocalReduce(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1054 : {
1055 : (void)taskInfo;
1056 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
1057 : return StringFormat(
1058 : "InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
1059 : "Set sem[%u] with mask[0x%04x], dataType[%u], opType[%u] %s",
1060 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
1061 1 : ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
1062 2 : ccuErrorInfo.msg.transMem.dataType, ccuErrorInfo.msg.transMem.opType, printMsg.c_str());
1063 1 : }
1064 :
1065 1 : string TaskExceptionHandler::GetCcuErrorMsgBufRead(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1066 : {
1067 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo);
1068 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1069 : return StringFormat(
1070 : "InstrId[%u]: Read Rmt Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], "
1071 : "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1072 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
1073 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1074 2 : ccuErrorInfo.msg.bufTransMem.signalMask, GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo),
1075 3 : pair.first.Describe().c_str(), pair.second.Describe().c_str(), printMsg.c_str());
1076 1 : }
1077 :
1078 1 : string TaskExceptionHandler::GetCcuErrorMsgBufWrite(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1079 : {
1080 1 : auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo);
1081 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1082 : return StringFormat(
1083 : "InstrId[%u]: Write CcuBuffer[%u] To Rmt Mem[0x%016llx], Len[%llu], "
1084 : "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
1085 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
1086 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1087 2 : ccuErrorInfo.msg.bufTransMem.signalMask, GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo),
1088 3 : pair.first.Describe().c_str(), pair.second.Describe().c_str(), printMsg.c_str());
1089 1 : }
1090 :
1091 1 : string TaskExceptionHandler::GetCcuErrorMsgBufLocRead(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1092 : {
1093 : (void)taskInfo;
1094 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1095 : return StringFormat(
1096 : "InstrId[%u]: Read Loc Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], sem[%u], mask[0x%04x] %s",
1097 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
1098 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1099 2 : ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
1100 1 : }
1101 :
1102 1 : string TaskExceptionHandler::GetCcuErrorMsgBufLocWrite(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1103 : {
1104 : (void)taskInfo;
1105 1 : string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
1106 : return StringFormat(
1107 : "InstrId[%u]: Write CcuBuffer[%u] To Loc Mem[0x%016llx], Len[%llu], sem[%u], mask[0x%04x] %s",
1108 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
1109 1 : ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
1110 2 : ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
1111 1 : }
1112 :
1113 1 : string TaskExceptionHandler::GetCcuErrorMsgBufReduce(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1114 : {
1115 : (void)taskInfo;
1116 1 : stringstream buffIds;
1117 5 : for (uint32_t i = 0; i < BUF_REDUCE_ID_SIZE; ++i) {
1118 5 : const auto buffId = ccuErrorInfo.msg.bufReduce.bufIds[i];
1119 5 : if (buffId == UINT16_MAX) {
1120 1 : break;
1121 : }
1122 4 : if (i != 0) {
1123 3 : buffIds << ", ";
1124 : }
1125 4 : buffIds << to_string(buffId);
1126 : }
1127 :
1128 : return StringFormat(
1129 : "InstrId[%u]: Buffer Reduce count[%u], dataType[%u], outputDataType[%u], opType[%u], "
1130 : "sem[%u], mask[0x%04x], CcuBuffers[%s]",
1131 1 : ccuErrorInfo.instrId, ccuErrorInfo.msg.bufReduce.count, ccuErrorInfo.msg.bufReduce.dataType,
1132 1 : ccuErrorInfo.msg.bufReduce.outputDataType, ccuErrorInfo.msg.bufReduce.opType,
1133 2 : ccuErrorInfo.msg.bufReduce.signalId, ccuErrorInfo.msg.bufReduce.signalMask, buffIds.str().c_str());
1134 1 : }
1135 :
1136 1 : string TaskExceptionHandler::GetCcuErrorMsgDefault(const CcuErrorInfo& ccuErrorInfo)
1137 : {
1138 1 : return StringFormat("InstrId[%u]: CcuErrorType[%s]", ccuErrorInfo.instrId, ccuErrorInfo.type.Describe().c_str());
1139 : }
1140 :
1141 1 : string TaskExceptionHandler::GetCcuErrorMsgMission(const CcuErrorInfo& ccuErrorInfo)
1142 : {
1143 : return StringFormat(
1144 1 : "InstrId[%u]: dieId[%u], missionId[%u], missionError[%s]", ccuErrorInfo.instrId, ccuErrorInfo.dieId,
1145 1 : ccuErrorInfo.missionId, ccuErrorInfo.msg.mission.missionError);
1146 : }
1147 :
1148 21 : string TaskExceptionHandler::GetCcuErrorMsgByType(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo)
1149 : {
1150 21 : if (ccuErrorInfo.type == CcuErrorType::MISSION) {
1151 1 : return GetCcuErrorMsgMission(ccuErrorInfo);
1152 : }
1153 :
1154 : using GetCcuErrorMsgFunc = string (*)(const CcuErrorInfo& ccuErrorInfo, const TaskInfo& taskInfo);
1155 : static const map<CcuRepType, GetCcuErrorMsgFunc> handlerMap{
1156 : {CcuRepType::LOOP, &TaskExceptionHandler::GetCcuErrorMsgLoop},
1157 : {CcuRepType::LOOPGROUP, &TaskExceptionHandler::GetCcuErrorMsgLoopGroup},
1158 : {CcuRepType::LOC_POST_SEM, &TaskExceptionHandler::GetCcuErrorMsgLocPostSem},
1159 : {CcuRepType::LOC_WAIT_SEM, &TaskExceptionHandler::GetCcuErrorMsgLocWaitSem},
1160 : {CcuRepType::REM_POST_SEM, &TaskExceptionHandler::GetCcuErrorMsgRemPostSem},
1161 : {CcuRepType::REM_WAIT_SEM, &TaskExceptionHandler::GetCcuErrorMsgRemWaitSem},
1162 : {CcuRepType::REM_POST_VAR, &TaskExceptionHandler::GetCcuErrorMsgRemPostVar},
1163 : {CcuRepType::REM_WAIT_GROUP, &TaskExceptionHandler::GetCcuErrorMsgRemWaitGroup},
1164 : {CcuRepType::POST_SHARED_VAR, &TaskExceptionHandler::GetCcuErrorMsgPostSharedVar},
1165 : {CcuRepType::POST_SHARED_SEM, &TaskExceptionHandler::GetCcuErrorMsgPostSharedSem},
1166 : {CcuRepType::READ, &TaskExceptionHandler::GetCcuErrorMsgRead},
1167 : {CcuRepType::WRITE, &TaskExceptionHandler::GetCcuErrorMsgWrite},
1168 : {CcuRepType::LOCAL_CPY, &TaskExceptionHandler::GetCcuErrorMsgLocalCpy},
1169 : {CcuRepType::LOCAL_REDUCE, &TaskExceptionHandler::GetCcuErrorMsgLocalReduce},
1170 : {CcuRepType::BUF_READ, &TaskExceptionHandler::GetCcuErrorMsgBufRead},
1171 : {CcuRepType::BUF_WRITE, &TaskExceptionHandler::GetCcuErrorMsgBufWrite},
1172 : {CcuRepType::BUF_LOC_READ, &TaskExceptionHandler::GetCcuErrorMsgBufLocRead},
1173 : {CcuRepType::BUF_LOC_WRITE, &TaskExceptionHandler::GetCcuErrorMsgBufLocWrite},
1174 22 : {CcuRepType::BUF_REDUCE, &TaskExceptionHandler::GetCcuErrorMsgBufReduce}};
1175 :
1176 20 : const auto funcIt = handlerMap.find(ccuErrorInfo.repType);
1177 20 : if (funcIt == handlerMap.end()) {
1178 1 : return GetCcuErrorMsgDefault(ccuErrorInfo);
1179 : } else {
1180 19 : return funcIt->second(ccuErrorInfo, taskInfo);
1181 : }
1182 : }
1183 :
1184 5 : void TaskExceptionHandler::DisplayRPCMsg(const TaskInfo& taskInfo)
1185 : {
1186 5 : if (taskInfo.taskParam_.taskType != TaskParamType::TASK_CCU) {
1187 3 : HCCL_ERROR("[TaskInfo][%s]Get MC2 Alg TaskParam failed, task type error.", __func__);
1188 1 : return;
1189 : }
1190 4 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
1191 6 : HCCL_ERROR("[TaskInfo][%s]Get MC2 Alg TaskParam failed, communicator is nullptr.", __func__);
1192 2 : return;
1193 : }
1194 2 : const CommunicatorImpl* communicator = static_cast<CommunicatorImpl*>(taskInfo.dfxOpInfo_->comm_);
1195 2 : auto* collServiceBase = communicator->GetCcuCollService();
1196 2 : if (collServiceBase == nullptr) {
1197 3 : HCCL_ERROR("[TaskInfo][%s]Failed to get collService from communicator.", __func__);
1198 1 : return;
1199 : }
1200 1 : auto* collServiceCcu = static_cast<CollServiceDeviceMode*>(collServiceBase);
1201 1 : collServiceCcu->GetMc2Compont().DisplayRPCMsg();
1202 : }
1203 :
1204 5 : RankId TaskExceptionHandler::GetRankIdByChannelId(uint16_t channelId, const TaskInfo& taskInfo)
1205 : {
1206 5 : if (taskInfo.taskParam_.taskType != TaskParamType::TASK_CCU) {
1207 3 : HCCL_ERROR("[TaskException][%s]Get RankId failed, task type error.", __func__);
1208 1 : return INVALID_RANKID;
1209 : }
1210 4 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
1211 3 : HCCL_ERROR("[TaskException][%s]Get RankId failed, communicator is nullptr.", __func__);
1212 1 : return INVALID_RANKID;
1213 : }
1214 3 : const CommunicatorImpl* communicator = (CommunicatorImpl*)taskInfo.dfxOpInfo_->comm_;
1215 3 : auto* collServiceBase = communicator->GetCcuCollService();
1216 2 : if (collServiceBase == nullptr) {
1217 3 : HCCL_ERROR("[TaskException][%s]Failed to get collService from communicator.", __func__);
1218 1 : return INVALID_RANKID;
1219 : }
1220 1 : auto* collServiceCcu = static_cast<CollServiceDeviceMode*>(collServiceBase);
1221 1 : const uint8_t dieId = taskInfo.taskParam_.taskPara.Ccu.dieId;
1222 1 : return collServiceCcu->GetCcuInsPreprocessor()->GetCcuComm()->GetCcuJettyMgr()->GetRemoteRankIdByChannelId(
1223 1 : dieId, channelId);
1224 : }
1225 :
1226 : std::pair<IpAddress, IpAddress>
1227 4 : TaskExceptionHandler::GetAddrPairByChannelId(uint16_t channelId, const TaskInfo& taskInfo)
1228 : {
1229 4 : std::pair<IpAddress, IpAddress> dummy = {IpAddress(), IpAddress()};
1230 4 : if (taskInfo.taskParam_.taskType != TaskParamType::TASK_CCU) {
1231 12 : HCCL_ERROR(
1232 : "[TaskException][%s]Get AddrPair failed, task type error[%s]", __func__,
1233 : taskInfo.taskParam_.Describe().c_str());
1234 4 : return dummy;
1235 : }
1236 0 : if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
1237 0 : HCCL_ERROR("[TaskException][%s]Get AddrPair failed, communicator is nullptr.", __func__);
1238 0 : return dummy;
1239 : }
1240 0 : const CommunicatorImpl* communicator = (CommunicatorImpl*)taskInfo.dfxOpInfo_->comm_;
1241 0 : auto* collServiceBase = communicator->GetCcuCollService();
1242 0 : if (collServiceBase == nullptr) {
1243 0 : HCCL_ERROR("[TaskException][%s]Failed to get collService from communicator.", __func__);
1244 0 : return dummy;
1245 : }
1246 0 : auto* collServiceCcu = static_cast<CollServiceDeviceMode*>(collServiceBase);
1247 0 : const uint8_t dieId = taskInfo.taskParam_.taskPara.Ccu.dieId;
1248 0 : return collServiceCcu->GetCcuInsPreprocessor()->GetCcuComm()->GetCcuJettyMgr()->GetAddrPairByChannelId(
1249 0 : dieId, channelId);
1250 : }
1251 :
1252 2 : std::tuple<std::string, std::string, std::string, std::string> TaskExceptionHandler::GetCcuErrorIpInfo(
1253 : [[maybe_unused]] uint32_t deviceId, [[maybe_unused]] uint16_t status, const TaskInfo& taskInfo)
1254 : {
1255 4 : std::string localServerId = "";
1256 4 : std::string localIp = "";
1257 4 : std::string remoteIp = "";
1258 2 : std::string remoteId = "";
1259 :
1260 2 : char serverIdBuf[64] = {0};
1261 2 : if (get_server_id(serverIdBuf, sizeof(serverIdBuf)) == 0) {
1262 2 : localServerId = serverIdBuf;
1263 : }
1264 :
1265 2 : auto ccuDetailInfo = taskInfo.taskParam_.ccuDetailInfo;
1266 2 : if (ccuDetailInfo != nullptr && !ccuDetailInfo->empty()
1267 2 : && ccuDetailInfo->at(0).channelId[0] != INVALID_VALUE_CHANNELID) {
1268 0 : uint16_t channelId = ccuDetailInfo->at(0).channelId[0];
1269 0 : auto addrPair = GetAddrPairByChannelId(channelId, taskInfo);
1270 0 : localIp = addrPair.first.Describe();
1271 0 : remoteIp = addrPair.second.Describe();
1272 0 : remoteId = std::to_string(taskInfo.remoteRank_);
1273 : }
1274 4 : return std::make_tuple(localServerId, localIp, remoteIp, remoteId);
1275 2 : }
1276 :
1277 : } // namespace Hccl
|