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: 54.6 % 656 358
Test Date: 2026-08-04 10:52:23 Functions: 68.2 % 66 45

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

Generated by: LCOV version 2.0-1