LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/dfx/task_exception - task_exception_handler.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 56.0 % 655 367
Test Date: 2026-08-18 17:47:01 Functions: 69.7 % 66 46

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

Generated by: LCOV version 2.0-1