LCOV - code coverage report
Current view: top level - coll_communicator_mgr/dfx/taskException/host - ccuTaskException.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 49.2 % 1035 509
Test Date: 2026-08-04 10:52:23 Functions: 63.6 % 88 56

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : #include "ccuTaskException.h"
      11              : #include "ccu_dfx_schema.h"
      12              : #include <memory>
      13              : #include "log.h"
      14              : #include "comm_addr_logger.h"
      15              : #include "coll_comm.h"
      16              : #include <adapter_error_manager_pub.h>
      17              : #include "task_param.h"
      18              : #include "ccu_kernel_mgr.h"
      19              : #include "hcomm_c_adpt.h"
      20              : #include "../../endpoint_pairs/channels/ccu/ccu_urma_channel.h"
      21              : #include "orion_adpt_utils.h"
      22              : #include "hcomm_adapter_hccp.h"
      23              : #include "hccp_tlv_hdc_manager.h"
      24              : #include "adapter_rts_common.h"
      25              : #include "ccu_rep_loopgroup_bundle_v1.h"
      26              : #include "ccu_rep_type_v1.h"
      27              : #include "ccu_rep_loc_record_event.h"
      28              : #include "ccu_rep_v1.h"
      29              : #include "ccu_comp.h"
      30              : #include "string_util.h"
      31              : 
      32              : #include "net_instance.h"
      33              : #include "hccl_communicator.h"
      34              : 
      35              : #include "sal.h"
      36              : 
      37              : namespace hcomm {
      38              : 
      39              : using namespace std;
      40              : constexpr int BYTE = 8;
      41              : constexpr size_t CCU_CTX_RAW_CAPACITY = 64;
      42              : constexpr uint64_t CCU_MSG_256MB_LEN = 256ULL * 1024 * 1024; // CCU消息长度不能大于256MB
      43              : constexpr uint16_t INVALID_U16 = 65535;
      44              : constexpr uint8_t CCUM_EXECUTE_ERROR = 0X09;
      45              : constexpr uint8_t CCU_MISSION_TASK_KILLED = 0X02;
      46              : 
      47              : const map<uint8_t, string> MISSION_STATUS_MAP {
      48              :     {0x01, "Unsupported Opcode(0x01)"},      {0x02, "Local Operation Error(0x02)"},
      49              :     {0x03, "Remote Operation Error(0x03)"},  {0x04, "Transaction Retry Counter Exceeded(0x04)"},
      50              :     {0x05, "Transaction ACK Timeout(0x05)"}, {0x06, "Jetty Work Request Flushed(0x06)"},
      51              :     {0x07, "CCUA Alg Task Error(0x07)"},     {0x08, "Memory ECC Error(0x08)"},
      52              :     {0x09, "CCUM Execute Error(0x09)"},      {0x0A, "CCUA Execute Error(0x0A)"},
      53              : };
      54              : 
      55              : const map<uint8_t, map<uint8_t, string>> MISSION_SUB_STATUS_MAP {
      56              :     {0x02,
      57              :      {{0x01, "Local Length Error(0x01)"},
      58              :       {0x02, "Local Access Error(0x02)"},
      59              :       {0x03, "Remote Response Length Error(0x03)"},
      60              :       {0x04, "Local Data Poison(0x04)"}}},
      61              :     {0x03,
      62              :      {{0x01, "Remote Unsupported Request(0x01)"},
      63              :       {0x02, "Remote Access Abort(0x02)"},
      64              :                {0x04, "Remote Data Poison(0x04)"}}},
      65              :     {0x07, {{0x01, "Overflow(0x01)"}, {0x02, "Underflow(0x02)"}, {0x04, "NaN(0x04)"}, {0x08, "Inf(0x08)"},
      66              :                {0x09, "Inf Overflow(0x09)"}}},
      67              :     {0x09, {{0x01, "SQE instr and key not match(0x01)"}, {0x02, "CCU Mission Task Killed(0x02)"}}},
      68              :     {0x0A,
      69              :      {{0x01, "EXOKAY(0x01)"},
      70              :       {0x11, "EXOKAY(0x11)"},
      71              :       {0x02, "SLVERR(0x02)"},
      72              :       {0x12, "SLVERR(0x12)"},
      73              :       {0x03, "DECERR(0x03)"},
      74              :       {0x13, "DECERR(0x13)"},
      75              :       {0x04, "Abort(0x04)"},
      76              :       {0x14, "Abort(0x14)"},
      77              :       {0x05, "Write Permission Err(0x05)"},
      78              :       {0x15, "Write Permission Err(0x15)"},
      79              :       {0x06, "Read Permission Err(0x06)"},
      80              :       {0x16, "Read Permission Err(0x16)"},
      81              :       {0x07, "Atomic Permission Err(0x07)"},
      82              :       {0x17, "Atomic Permission Err(0x17)"},
      83              :       {0x08, "Tokenval Err(0x08)"},
      84              :       {0x18, "Tokenval Err(0x18)"},
      85              :       {0x09, "Page Fault(0x09)"},
      86              :       {0x0a, "Page Fault(0x0A)"},
      87              :       {0x0b, "Page Fault(0x0B)"},
      88              :       {0x19, "Page Fault(0x19)"},
      89              :       {0x1a, "Page Fault(0x1A)"},
      90              :       {0x1b, "Page Fault(0x1B)"},
      91              :       {0x0c, "Read Local Mem Poison(0x0C)"}}},
      92              : };
      93              : 
      94              : const unordered_set<CcuRep::CcuRepType> REP_WITH_CHANNEL = {
      95              :     {CcuRep::CcuRepType::REM_POST_SEM},
      96              :     {CcuRep::CcuRepType::REM_WAIT_SEM},
      97              :     {CcuRep::CcuRepType::REM_POST_VAR},
      98              :     {CcuRep::CcuRepType::READ},
      99              :     {CcuRep::CcuRepType::WRITE},
     100              :     {CcuRep::CcuRepType::BUF_READ},
     101              :     {CcuRep::CcuRepType::BUF_WRITE},
     102              : };
     103              : 
     104            0 : MAKE_ENUM(AuxInfoInType, AUX_INFO_IN_TYPE_CQE, AUX_INFO_IN_TYPE_AE, AUX_INFO_IN_TYPE_MAX);
     105              : struct AuxInfoIn {
     106              :     AuxInfoInType auxInfoInType;
     107              :     union {
     108              :         struct {
     109              :             uint32_t status;
     110              :             uint8_t sR;
     111              :         } cqe;
     112              :         struct {
     113              :             uint32_t eventType;
     114              :         } ae;
     115              :     };
     116              :     u8 resv[7];
     117              : };
     118              : 
     119              : constexpr u32 MAX_AUX_INFO_NUM = 256;
     120              : struct AuxInfoOut {
     121              :     uint32_t auxInfoTypes[MAX_AUX_INFO_NUM];
     122              :     uint32_t auxInfoValues[MAX_AUX_INFO_NUM];
     123              :     uint32_t auxInfoNum{0};
     124              : };
     125              : 
     126              : std::mutex g_channelMapMutex;
     127              : std::unordered_map<uint16_t, uint64_t> g_channelIdToHandle;
     128              : std::atomic<bool> isGetCqeErrInfo(false); // 是否已获取过CQE错误信息,获取过后再次获取的概率较小,且获取过程可能较慢,因此设置标志位避免重复获取
     129              : CcuGetErrStatusVecCallBack g_CcuGetErrStatusVecCallBack = nullptr;
     130              : GetCcuCqeErrInfoCallBackHcomm g_getCqeErrInfoCallBack = nullptr;
     131              : 
     132           43 : void RegisterCcuGetErrStatusVecCallBack(CcuGetErrStatusVecCallBack callback)
     133              : {
     134           43 :     g_CcuGetErrStatusVecCallBack = callback;
     135           43 :     return;
     136              : }
     137              : 
     138           12 : std::vector<std::string> CcuGetErrStatusVec(s32 deviceLogicID)
     139              : {
     140           12 :     if (g_CcuGetErrStatusVecCallBack != nullptr) {
     141           12 :         return g_CcuGetErrStatusVecCallBack(deviceLogicID);
     142              :     } else {
     143            0 :         HCCL_RUN_WARNING("[GetErrStatusVec]g_CcuGetErrStatusVecCallBack is nullptr.");
     144              :     }
     145            0 :     return std::vector<std::string>();
     146              : }
     147              : 
     148           12 : std::string CcuGetAndPrintClusterMonitorErr(const u32 deviceId)
     149              : {
     150           12 :     auto errStatusVec = CcuGetErrStatusVec(deviceId);
     151           12 :     std::string errMsg = "";
     152           12 :     int errSize = errStatusVec.size();
     153           12 :     if (errSize > 0) {
     154            0 :         int maxListSize = 3;  // 放入errMsg中的异常事件最多只有3个
     155            0 :         if (errSize <= maxListSize) {
     156            0 :             errMsg = "\nthere are(is) " + std::to_string(errSize) + " abnormal device(s):\n";
     157              :         } else {
     158            0 :             errMsg = "\nthere are " + std::to_string(errSize) + " abnormal device(s), " +
     159            0 :                 "only the first 3 devices are listed:\n";
     160              :         }
     161              : 
     162            0 :         for (int i = 0; i < errSize; i++) {
     163            0 :             HCCL_ERROR("%s", errStatusVec[i].c_str());
     164            0 :             if (i < maxListSize) {
     165            0 :                 errMsg += ("\t" + errStatusVec[i] + "\n");
     166              :             }
     167              :         }
     168              :     }
     169           12 :     return errMsg;
     170           12 : }
     171              : 
     172           43 : void RegisterGetCcuCqeErrInfoCallBackHcomm(GetCcuCqeErrInfoCallBackHcomm p1)
     173              : {
     174           43 :     g_getCqeErrInfoCallBack = p1;
     175           43 :     return;
     176              : }
     177            0 : void CcuTaskException::ClusterMoniterGetCcuCqeErrInfo(u32 RemoteDeviceId, u32 locDeviceId, uint16_t status, std::string LocalEid, std::string RemoteEid, std::string RemoteInsId)
     178              : {
     179            0 :     if (g_getCqeErrInfoCallBack != nullptr) {
     180            0 :         g_getCqeErrInfoCallBack(RemoteDeviceId, locDeviceId, status, LocalEid, RemoteEid, RemoteInsId);
     181              :     }
     182            0 :     return;
     183              : }
     184              : 
     185              : 
     186            5 : static void PrintPanicLogWithOps(const uint8_t *panicLog, const CcuVersionOps *ops)
     187              : {
     188            5 :     if (panicLog == nullptr) {
     189            0 :         HCCL_ERROR("[CcuTaskException][PrintPanicLogWithOps] panicLog is nullptr.");
     190            5 :         return;
     191              :     }
     192            5 :     if (ops == nullptr || ops->printCcumDfxInfo == nullptr) {
     193            5 :         HCCL_ERROR("[CcuTaskException][PrintPanicLogWithOps] ops or printCcumDfxInfo is nullptr.");
     194            5 :         return;
     195              :     }
     196            0 :     std::ostringstream oss;
     197            0 :     oss << "[CCU DFX][ops=" << ops->name << "] CCU DFX INFO:";
     198            0 :     ops->printCcumDfxInfo(panicLog, oss);
     199            0 :     std::string logStr = oss.str();
     200            0 :     HCCL_ERROR("%s", logStr.c_str());
     201            0 : }
     202              : 
     203            4 : void CcuTaskException::ProcessCcuException(const rtExceptionInfo_t* exceptionInfo, const Hccl::TaskInfo& taskInfo)
     204              : {
     205            4 :     auto deviceId = exceptionInfo->deviceid;
     206            4 :     HCCL_ERROR("[CcuTaskException][%s]Task from HCCL run failed.", __func__);
     207            4 :     HCCL_ERROR("[CcuTaskException]Task run failed, base information is deviceID:[%u], %s.",
     208              :         deviceId, taskInfo.GetIndopBaseInfo().c_str());
     209            4 :     HCCL_ERROR("[CcuTaskException]Task run failed, groupRank information is %s.",
     210              :         GetGroupRankInfo(taskInfo).c_str());
     211            4 :     HCCL_ERROR("[CcuTaskException]Task run failed, opData information is %s.", taskInfo.GetIndopDataInfo().c_str());
     212            4 :     CHK_PRT(InitChannelMap(deviceId, taskInfo.taskParam_.taskPara.Ccu.ccuKernelHandle));
     213            4 :     auto& ccuExDetailInfo = exceptionInfo->expandInfo.u.ccuInfo;
     214            4 :     isGetCqeErrInfo = true;
     215              : 
     216            4 :     const CcuVersionOps *ops = nullptr;
     217            4 :     if (GetCcuOps(ops) != HCCL_SUCCESS) {
     218            4 :         ops = nullptr;
     219              :     }
     220              : 
     221            9 :     for (uint32_t i = 0; i < ccuExDetailInfo.ccuMissionNum; ++i) { // ccuExDetailInfo.ccuMissionNum为1
     222            5 :         const auto& missionInfo = ccuExDetailInfo.missionInfo[i]; // 异常mission
     223            5 :         uint16_t status = static_cast<uint16_t>(missionInfo.status) << BYTE | missionInfo.subStatus;
     224            5 :         PrintCcuErrorInfo(deviceId, status, taskInfo);
     225              :         // 打印寄存器信息
     226            5 :         PrintPanicLogWithOps(missionInfo.panicLog, ops);
     227              :     }
     228              : 
     229            4 :     const int32_t devLogicId = static_cast<int32_t>(deviceId);
     230            4 :     if (CcuComponent::GetInstance(devLogicId).CleanTaskKillState() != HcclResult::HCCL_SUCCESS) {
     231            1 :         HCCL_ERROR("[CcuTaskException][%s] failed to clean ccu task kill state, devLogicId[%d].", __func__, devLogicId);
     232              :     }
     233              : 
     234            4 :     const uint8_t dieId = taskInfo.taskParam_.taskPara.Ccu.dieId;
     235            4 :     if (CcuComponent::GetInstance(devLogicId).CleanDieCkes(dieId) != HcclResult::HCCL_SUCCESS) {
     236            1 :         HCCL_ERROR("[CcuTaskException][%s] failed to clean ccu die ckes, dieId[%u], devLogicId[%d].",
     237              :             __func__, dieId, devLogicId);
     238              :     }
     239            4 : }
     240              : 
     241           10 : HcclResult CcuTaskException::InitChannelMap(s32 deviceId, u64 ccuKernelHandle)
     242              : {
     243           10 :     std::lock_guard<std::mutex> lock(g_channelMapMutex);
     244              : 
     245           10 :     auto &kernelMgr = hcomm::CcuKernelMgr::GetInstance(deviceId);
     246           10 :     auto *kernel = kernelMgr.GetKernel(ccuKernelHandle);
     247           10 :     CHK_PRT_RET(kernel == nullptr, HCCL_ERROR("[%s]GetKernel nullptr, deviceId[%d], ccuKernelHandle[0x%llx]",
     248              :         __func__, deviceId, ccuKernelHandle), HCCL_E_PARA);
     249              : 
     250            5 :     const auto& ccuChannels = kernel->GetChannels();
     251            8 :     for (const auto& it : ccuChannels) {
     252            5 :         void *channelPtr = nullptr;
     253            6 :         CHK_RET(static_cast<HcclResult>(HcommChannelGet(it, &channelPtr)));
     254            4 :         auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     255            4 :         CHK_PTR_NULL(channelImpl);
     256            3 :         g_channelIdToHandle[channelImpl->GetChannelId()] = it;
     257            3 :         HCCL_RUN_INFO("[%s]deviceId[%d], ccuKernelHandle[0x%llx], channelId[%u], channelHandle[0x%llx]",
     258              :             __func__, deviceId, ccuKernelHandle, channelImpl->GetChannelId(), it);
     259              :     }
     260            3 :     return HCCL_SUCCESS;
     261           10 : }
     262              : 
     263            7 : std::string CcuTaskException::GetGroupRankInfo(const Hccl::TaskInfo& taskInfo)
     264              : {
     265            7 :     if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
     266            5 :         HCCL_ERROR("[TaskInfo][%s]TaskInfo communicator is nullptr.", __func__);
     267           10 :         return "";
     268              :     }
     269              : 
     270            2 :     hccl::CollComm *communicator = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
     271              :     return Hccl::StringFormat("group:[%s], rankSize[%u], rankId[%u]",
     272            2 :         communicator->GetCommId().c_str(), communicator->GetRankSize(), communicator->GetMyRankId());
     273              : }
     274              : 
     275            4 : void CcuTaskException::PrintPanicLogInfo(const uint8_t *panicLog)
     276              : {
     277            4 :     if (panicLog == nullptr) {
     278            2 :         HCCL_ERROR("[CcuTaskException][%s] panicLog is nullptr.", __func__);
     279            4 :         return;
     280              :     }
     281              : 
     282            2 :     const CcuVersionOps *ops = nullptr;
     283            2 :     if (GetCcuOps(ops) != HCCL_SUCCESS) {
     284            2 :         HCCL_ERROR("[CcuTaskException][%s] Failed to get printer ops for ccum_dfxInfo", __func__);
     285            2 :         return;
     286              :     }
     287            0 :     PrintPanicLogWithOps(panicLog, ops);
     288              : }
     289              : 
     290              : namespace {
     291           19 : HcclResult QueryCcuCtxRaw(int32_t deviceId, uint32_t dieId, uint32_t ctxId, CcuOpcodeType op, const char *tag,
     292              :     uint8_t *buf, size_t bufLen, size_t &copiedLen)
     293              : {
     294           19 :     copiedLen = 0;
     295           19 :     if (buf == nullptr || bufLen < CCU_CTX_RAW_CAPACITY) {
     296            3 :         HCCL_ERROR("[%s] invalid buffer: buf=%p, bufLen=%zu, required=%zu", tag, buf, bufLen, CCU_CTX_RAW_CAPACITY);
     297            3 :         return HCCL_E_PARA;
     298              :     }
     299           16 :     const auto memsetRet = memset_s(buf, bufLen, 0, bufLen);
     300           16 :     if (memsetRet != EOK) {
     301            0 :         HCCL_ERROR("[%s] memset_s failed, ret[%d]", tag, memsetRet);
     302            0 :         return HCCL_E_INTERNAL;
     303              :     }
     304              : 
     305           16 :     auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     306           16 :     CHK_PRT_RET(tlvHandle == nullptr,
     307              :         HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), HCCL_E_PTR);
     308              : 
     309           16 :     CustomChannelInfoIn  inBuff{};
     310           16 :     CustomChannelInfoOut outBuff{};
     311           16 :     inBuff.op                          = op;
     312           16 :     inBuff.data.dataInfo.udieIdx       = dieId;
     313           16 :     inBuff.offsetStartIdx              = ctxId;
     314           16 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个MissionContext
     315           16 :     inBuff.data.dataInfo.dataLen       = CCU_CTX_RAW_CAPACITY;
     316              : 
     317           16 :     HcclResult ret = HccpRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
     318              : 
     319           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%u]", tag, ret), ret);
     320            7 :     const auto sret = memcpy_s(buf, bufLen, outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     321            7 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy_s failed, ret[%d]", tag, sret), HCCL_E_MEMORY);
     322            7 :     copiedLen = inBuff.data.dataInfo.dataLen;
     323            7 :     return HCCL_SUCCESS;
     324              : }
     325              : } // namespace
     326              : 
     327              : using GetMissionRawFunc = HcclResult (*)(
     328              :     int32_t deviceId, uint32_t dieId, uint32_t missionId, uint8_t *buf, size_t bufLen, size_t &copiedLen);
     329              : using GenErrorInfoLoopGroupFunc = HcclResult (*)(const ErrorInfoBase &baseInfo,
     330              :     std::shared_ptr<CcuRep::CcuRepBase> repBase, CcuRep::CcuRepContext &ctx, std::vector<CcuErrorInfo> &errorInfo);
     331              : using GenErrorInfoByRepTypeFunc = void (*)(
     332              :     const ErrorInfoBase &baseInfo, std::shared_ptr<CcuRep::CcuRepBase> repBase, std::vector<CcuErrorInfo> &errorInfo);
     333              : 
     334            5 : static HcclResult DecodeRawMissionInfo(const uint8_t *raw, CcuMissionInfo &out)
     335              : {
     336            5 :     const CcuVersionOps *ops = nullptr;
     337            5 :     if (GetCcuOps(ops) != HCCL_SUCCESS) {
     338            5 :         HCCL_ERROR("[DecodeRawMissionInfo] Failed to get ops for mission context");
     339            5 :         return HCCL_E_INTERNAL;
     340              :     }
     341            0 :     if (ops->getMissionInfo == nullptr) {
     342            0 :         HCCL_ERROR("[DecodeRawMissionInfo] getMissionInfo is nullptr, ops[%s]", ops->name);
     343            0 :         return HCCL_E_INTERNAL;
     344              :     }
     345            0 :     return ops->getMissionInfo(raw, &out);
     346              : }
     347              : 
     348            0 : static HcclResult FetchAndDecodeLoopInfo(int32_t deviceId, uint32_t dieId, uint32_t loopCtxId, CcuLoopInfo &out)
     349              : {
     350            0 :     uint8_t loopRaw[CCU_CTX_RAW_CAPACITY] = {0};
     351            0 :     size_t loopRawLen = 0;
     352            0 :     if (QueryCcuCtxRaw(deviceId, dieId, loopCtxId, CcuOpcodeType::CCU_U_OP_GET_LOOP_CTX, "FetchAndDecodeLoopInfo",
     353              :             loopRaw, sizeof(loopRaw), loopRawLen)
     354            0 :         != HCCL_SUCCESS) {
     355            0 :         HCCL_ERROR("[FetchAndDecodeLoopInfo] Failed to fetch loop raw context, deviceId[%d]", deviceId);
     356            0 :         return HCCL_E_INTERNAL;
     357              :     }
     358            0 :     const CcuVersionOps *ops = nullptr;
     359            0 :     if (GetCcuOps(ops) != HCCL_SUCCESS) {
     360            0 :         HCCL_ERROR("[FetchAndDecodeLoopInfo] Failed to get ops for loop context");
     361            0 :         return HCCL_E_INTERNAL;
     362              :     }
     363            0 :     if (ops->getLoopInfo == nullptr) {
     364            0 :         HCCL_ERROR("[FetchAndDecodeLoopInfo] getLoopInfo is nullptr, ops[%s]", ops->name);
     365            0 :         return HCCL_E_INTERNAL;
     366              :     }
     367            0 :     return ops->getLoopInfo(loopRaw, &out);
     368              : }
     369              : 
     370              : // 计算报错指令附近可用 Rep 的起始指令,提取自 GetCcuErrorMsg 以降低其圈复杂度
     371            0 : static uint16_t FindSurroundingBeginInstr(CcuRep::CcuRepContext &ctx, uint16_t startIns, uint16_t currIns)
     372              : {
     373            0 :     uint16_t loopUpInstrNum = 10; // 出错指令前 10 条
     374            0 :     uint16_t beginIns = (currIns < loopUpInstrNum)
     375              :                             ? startIns
     376            0 :                             : ((currIns - loopUpInstrNum) > startIns ? (currIns - loopUpInstrNum) : startIns);
     377              :     // 从第一个非空 rep 开始,使用有符号变量避免 uint16_t 下溢无限循环
     378            0 :     for (int32_t instrId = static_cast<int32_t>(currIns); instrId >= static_cast<int32_t>(beginIns); instrId--) {
     379            0 :         if (ctx.GetRepByInstrId(static_cast<uint16_t>(instrId)) == nullptr) {
     380            0 :             beginIns = static_cast<uint16_t>(instrId) + 1U;
     381            0 :             break;
     382              :         }
     383              :     }
     384            0 :     return beginIns;
     385              : }
     386              : 
     387            5 : static HcclResult ValidateAndDecodeMissionContext(int32_t deviceId, uint16_t missionStatus,
     388              :     const Hccl::ParaCcu &ccuTaskParam, GetMissionRawFunc getMissionRaw, CcuMissionInfo &missionInfo)
     389              : {
     390            5 :     CHK_PRT_RET((deviceId < 0 || static_cast<u32>(deviceId) >= MAX_MODULE_DEVICE_NUM),
     391              :         HCCL_ERROR("[CcuTaskException][GetCcuErrorMsg]deviceId[%d] error.", deviceId), HcclResult::HCCL_E_PARA);
     392              : 
     393            5 :     if (missionStatus == 0) {
     394            0 :         HCCL_ERROR(
     395              :             "[CcuErrorHandler][%s] no err found, mission status is 0, deviceId[%d], dieId[%u], execMissionId[%u]",
     396              :             __func__, deviceId, static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.execMissionId));
     397            0 :         return HCCL_E_PARA;
     398              :     }
     399              : 
     400            5 :     uint8_t missionRaw[CCU_CTX_RAW_CAPACITY] = {0};
     401            5 :     size_t missionRawLen = 0;
     402           10 :     if (getMissionRaw(
     403            5 :             deviceId, ccuTaskParam.dieId, ccuTaskParam.execMissionId, missionRaw, sizeof(missionRaw), missionRawLen)
     404            5 :         != HCCL_SUCCESS) {
     405            0 :         HCCL_ERROR("[CcuErrorHandler][%s] Failed to fetch mission raw context, deviceId[%d]", __func__, deviceId);
     406            0 :         return HCCL_E_INTERNAL;
     407              :     }
     408            5 :     if (DecodeRawMissionInfo(missionRaw, missionInfo) != HCCL_SUCCESS) {
     409            5 :         HCCL_ERROR("[CcuErrorHandler][%s] Failed to decode mission info, deviceId[%d]", __func__, deviceId);
     410            5 :         return HCCL_E_INTERNAL;
     411              :     }
     412            0 :     return HCCL_SUCCESS;
     413              : }
     414              : 
     415            0 : static HcclResult ResolveRepContextAndCurrentRep(int32_t deviceId, const Hccl::ParaCcu &ccuTaskParam, uint16_t currIns,
     416              :     CcuRep::CcuRepContext *&ctx, std::shared_ptr<CcuRep::CcuRepBase> &rep, std::shared_ptr<CcuRep::CcuRepBase> &prevRep)
     417              : {
     418            0 :     auto &kernelMgr = hcomm::CcuKernelMgr::GetInstance(deviceId);
     419            0 :     auto *kernel = kernelMgr.GetKernel(ccuTaskParam.ccuKernelHandle);
     420            0 :     CHK_PRT_RET(kernel == nullptr,
     421              :         HCCL_ERROR("[%s]GetKernel nullptr, deviceId[%d], ccuKernelHandle[0x%llx]", __func__, deviceId,
     422              :             ccuTaskParam.ccuKernelHandle),
     423              :         HCCL_E_PARA);
     424              : 
     425            0 :     ctx = reinterpret_cast<CcuRep::CcuRepContext *>(kernel);
     426            0 :     CHK_PRT_RET(ctx == nullptr,
     427              :         HCCL_ERROR("CcuContext not found, deviceId[%d], dieId[%u], missionId[%u], executeId[%llu]", deviceId,
     428              :             static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.missionId), ccuTaskParam.executeId),
     429              :         HCCL_E_PARA);
     430              : 
     431            0 :     rep = ctx->GetRepByInstrId(currIns);
     432            0 :     CHK_PRT_RET(rep == nullptr,
     433              :         HCCL_ERROR("[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, currIns),
     434              :         HCCL_E_PARA);
     435              : 
     436            0 :     prevRep = nullptr;
     437            0 :     if (currIns > 0) {
     438            0 :         prevRep = ctx->GetRepByInstrId(currIns - 1);
     439              :     }
     440              : 
     441            0 :     while (rep->Type() == CcuRep::CcuRepType::FUNC_BLOCK) {
     442            0 :         auto blockRep = static_pointer_cast<CcuRepBlock>(rep);
     443            0 :         rep = blockRep->GetRepByInstrId(currIns);
     444            0 :         CHK_PRT_RET(rep == nullptr,
     445              :             HCCL_ERROR(
     446              :                 "Failed to find REP from FuncBlock, instrId[%u], FuncBlock[%s]", currIns, blockRep->GetLabel().c_str()),
     447              :             HcclResult::HCCL_E_PARA);
     448            0 :     }
     449            0 :     return HCCL_SUCCESS;
     450              : }
     451              : 
     452            0 : static void HandleSurroundingRepErrorInfo(int32_t deviceId, uint32_t execMissionId, const ErrorInfoBase &baseInfo,
     453              :     CcuRep::CcuRepContext &ctx, uint16_t startIns, uint16_t endIns, uint16_t currIns,
     454              :     GenErrorInfoByRepTypeFunc genByRepType, std::vector<CcuErrorInfo> &errorInfo)
     455              : {
     456            0 :     HCCL_ERROR("[CcuErrorHandler]device %d, execMissionId[%u], startIns[%u], endIns[%u], currIns[%u]", deviceId,
     457              :         execMissionId, startIns, endIns, currIns);
     458            0 :     if (endIns == currIns) {
     459            0 :         HCCL_ERROR("[CcuErrorHandler]device %d SQE != CQE, endIns[%u], currIns[%u]", deviceId, endIns, currIns);
     460              :     }
     461              : 
     462            0 :     const uint16_t beginIns = FindSurroundingBeginInstr(ctx, startIns, currIns);
     463            0 :     for (uint16_t instrId = beginIns; instrId <= currIns; instrId++) {
     464            0 :         auto surroundingRep = ctx.GetRepByInstrId(instrId);
     465            0 :         if (surroundingRep == nullptr) {
     466            0 :             HCCL_WARNING(
     467              :                 "[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, instrId);
     468            0 :             continue;
     469              :         }
     470            0 :         genByRepType(baseInfo, surroundingRep, errorInfo);
     471            0 :     }
     472            0 : }
     473              : 
     474           13 : HcclResult CcuTaskException::GetCcuMissionContextRaw(
     475              :     int32_t deviceId, uint32_t dieId, uint32_t missionId, uint8_t *buf, size_t bufLen, size_t &copiedLen)
     476              : {
     477           13 :     return QueryCcuCtxRaw(deviceId, dieId, missionId, CcuOpcodeType::CCU_U_OP_GET_MISSION_CTX,
     478           13 :         "GetCcuMissionContextRaw", buf, bufLen, copiedLen);
     479              : }
     480              : 
     481           12 : static string StatusCode2Str(uint8_t highPart, uint8_t lowPart)
     482              : {
     483           12 :     HCCL_INFO("Mission Status Code: highPart[0x%02x], lowPart[0x%02x]", highPart, lowPart);
     484           12 :     const auto status = MISSION_STATUS_MAP.find(highPart);
     485           12 :     if (status == MISSION_STATUS_MAP.end()) {
     486            2 :         return "Unknown Status";
     487              :     }
     488           11 :     stringstream result;
     489           11 :     result << status->second;
     490              : 
     491           11 :     const auto lowMap = MISSION_SUB_STATUS_MAP.find(highPart);
     492           11 :     if (lowMap == MISSION_SUB_STATUS_MAP.end()) {
     493            6 :         return result.str();
     494              :     }
     495              : 
     496            5 :     const auto subStatus = lowMap->second.find(lowPart);
     497            6 :     const string subStatusMsg = subStatus == lowMap->second.end() ? "Unknown Status" : subStatus->second;
     498            5 :     result << ", " << subStatusMsg;
     499            5 :     return result.str();
     500           11 : }
     501              : 
     502           12 : void CcuTaskException::GenStatusInfo(const ErrorInfoBase &baseInfo, vector<CcuErrorInfo> &errorInfo)
     503              : {
     504           12 :     CcuErrorInfo errorMsg{};
     505           12 :     errorMsg.type = CcuErrorType::MISSION;
     506           12 :     errorMsg.SetBaseInfo(CcuRep::CcuRepType::BASE, baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
     507           12 :     const auto baseInformation = Hccl::StringFormat("dieId[%u], missionId[%u]", baseInfo.dieId, baseInfo.missionId);
     508           12 :     const auto taskInformation = Hccl::StringFormat("currentInsId[%u], status[%u]", baseInfo.currentInsId, baseInfo.status);
     509           12 :     const uint8_t highPart  = (baseInfo.status >> 8) & 0xFF; // 高8位
     510           12 :     const uint8_t lowPart   = baseInfo.status & 0xFF;        // 低8位
     511           12 :     string clusterMonitorErrMsg = CcuGetAndPrintClusterMonitorErr(baseInfo.deviceId);
     512              : 
     513           12 :     if (highPart == CCUM_EXECUTE_ERROR && lowPart == CCU_MISSION_TASK_KILLED) {
     514            0 :         RPT_INPUT_ERR(true,
     515              :             "EI0002",
     516              :             std::vector<std::string>({"remote_rankid", "base_information", "task_information", "group_rank_content"}),
     517              :             std::vector<std::string>({
     518              :                 std::to_string(baseInfo.deviceId),
     519              :                 baseInformation.c_str(), (taskInformation + clusterMonitorErrMsg).c_str(),
     520              :                 "none"})
     521              :         );
     522              :     }
     523           12 :     const string  statusMsg = StatusCode2Str(highPart, lowPart);
     524              :     const auto    sRet
     525           12 :         = strncpy_s(errorMsg.msg.mission.missionError, MISSION_STATUS_MSG_LEN, statusMsg.c_str(), statusMsg.length());
     526           12 :     if (sRet != EOK) {
     527            0 :         HCCL_ERROR("[CcuErrorHandler][%s] strcpy failed, statusMsg: [%s].sRet:[%d]", __func__, statusMsg.c_str(), sRet);
     528              :     }
     529              : 
     530           12 :     errorInfo.push_back(errorMsg);
     531           12 : }
     532              : 
     533            4 : uint16_t CcuTaskException::GetCcuCKEValue(int32_t deviceId, uint32_t dieId, uint32_t ckeId)
     534              : {
     535            4 :     CustomChannelInfoIn  inBuff{};
     536            4 :     CustomChannelInfoOut outBuff{};
     537            4 :     auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     538            4 :     CHK_PRT_RET(tlvHandle == nullptr,
     539              :         HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), INVALID_U16);
     540              : 
     541            4 :     inBuff.op                          = CcuOpcodeType::CCU_U_OP_GET_CKE;
     542            4 :     inBuff.data.dataInfo.udieIdx       = dieId;
     543            4 :     inBuff.offsetStartIdx              = ckeId;
     544            4 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个CKE
     545            4 :     inBuff.data.dataInfo.dataLen       = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     546              : 
     547            4 :     HcclResult ret = HccpRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
     548            4 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret), INVALID_U16);
     549              : 
     550            2 :     uint64_t ckeVal{0};
     551            2 :     s32 sret = memcpy_s(&ckeVal, sizeof(ckeVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     552            2 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), INVALID_U16);
     553            2 :     return static_cast<uint16_t>(ckeVal);
     554              : }
     555              : 
     556           13 : HcclResult CcuTaskException::GetChannelIdByHandle(const ChannelHandle &channel, uint32_t &channelId)
     557              : {
     558           13 :     void *channelPtr = nullptr;
     559           13 :     CHK_RET(static_cast<HcclResult>(HcommChannelGet(channel, &channelPtr)));
     560           11 :     CHK_PTR_NULL(channelPtr);
     561           10 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     562           10 :     CHK_PTR_NULL(channelImpl);
     563           10 :     channelId = channelImpl->GetChannelId();
     564           10 :     return HCCL_SUCCESS;
     565              : }
     566              : 
     567           10 : HcclResult CcuTaskException::GetSignalIdByHandle(const ChannelHandle &channel, uint16_t semIdx, bool isRmtSig, uint32_t &signalId)
     568              : {
     569           10 :     void *channelPtr = nullptr;
     570           10 :     CHK_RET(static_cast<HcclResult>(HcommChannelGet(channel, &channelPtr)));
     571           10 :     CHK_PTR_NULL(channelPtr);
     572            9 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     573            9 :     CHK_PTR_NULL(channelImpl);
     574            9 :     if (isRmtSig) {
     575            6 :         CHK_PRT_RET(channelImpl->GetRmtCkeByIndex(semIdx, signalId) != HcclResult::HCCL_SUCCESS,
     576              :             HCCL_ERROR("[%s] failed to get remote cke id, channelHandle[0x%llx].",
     577              :                 __func__, channel), HCCL_E_UNAVAIL);
     578              :     } else {
     579            3 :         CHK_PRT_RET(channelImpl->GetLocCkeByIndex(semIdx, signalId) != HcclResult::HCCL_SUCCESS,
     580              :             HCCL_ERROR("[%s] failed to get local cke id, channelHandle[0x%llx]--sem[%u].",
     581              :                 __func__, channel, semIdx), HCCL_E_UNAVAIL);
     582              :     }
     583            6 :     return HCCL_SUCCESS;
     584              : }
     585              : 
     586            5 : HcclResult CcuTaskException::GetVariableIdByHandle(const ChannelHandle &channel, uint16_t varIdx, uint32_t &varId)
     587              : {
     588            5 :     void *channelPtr = nullptr;
     589            5 :     CHK_RET(static_cast<HcclResult>(HcommChannelGet(channel, &channelPtr)));
     590            5 :     CHK_PTR_NULL(channelPtr);
     591            4 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
     592            4 :     CHK_PTR_NULL(channelImpl);
     593            4 :     CHK_PRT_RET(channelImpl->GetRmtXnByIndex(varIdx, varId) != HcclResult::HCCL_SUCCESS,
     594              :         HCCL_ERROR("[%s] failed to get remote xn id, channelHandle[0x%llx]--var[%u].",
     595              :             __func__, channel, varIdx), HCCL_E_UNAVAIL);
     596            2 :     return HCCL_SUCCESS;
     597              : }
     598              : 
     599            0 : void CcuTaskException::GenErrorInfoLocRecordEvent(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     600              :                                              vector<CcuErrorInfo> &errorInfo)
     601              : {
     602            0 :     CcuErrorInfo errorMsg{};
     603            0 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     604            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     605              : 
     606            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepLocRecordEvent>(repBase);
     607            0 :     errorMsg.msg.waitSignal.signalId    = rep->GetEventId();
     608            0 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetEventId());
     609            0 :     errorMsg.msg.waitSignal.signalMask  = rep->GetMask();
     610              : 
     611            0 :     errorInfo.push_back(errorMsg);
     612            0 : }
     613              : 
     614            0 : void CcuTaskException::GenErrorInfoLocWaitEvent(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     615              :                                              vector<CcuErrorInfo> &errorInfo)
     616              : {
     617            0 :     CcuErrorInfo errorMsg{};
     618            0 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     619            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     620              : 
     621            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepLocWaitEvent>(repBase);
     622            0 :     errorMsg.msg.waitSignal.signalId    = rep->GetEventId();
     623            0 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetEventId());
     624            0 :     errorMsg.msg.waitSignal.signalMask  = rep->GetMask();
     625              : 
     626            0 :     errorInfo.push_back(errorMsg);
     627            0 : }
     628              : 
     629            0 : void CcuTaskException::GenErrorInfoLocWaitNotify(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     630              :                                              vector<CcuErrorInfo> &errorInfo)
     631              : {
     632            0 :     CcuErrorInfo errorMsg{};
     633            0 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     634            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     635              : 
     636            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepLocWaitNotify>(repBase);
     637            0 :     errorMsg.msg.waitSignal.signalId    = rep->GetNotifyId();
     638            0 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->GetNotifyId());
     639            0 :     errorMsg.msg.waitSignal.signalMask  = rep->GetMask();
     640              : 
     641            0 :     errorInfo.push_back(errorMsg);
     642            0 : }
     643              : 
     644            9 : uint64_t CcuTaskException::GetCcuGSAValue(int32_t deviceId, uint32_t dieId, uint32_t gsaId)
     645              : {
     646            9 :     uint64_t gsaVal{0};
     647              : 
     648            9 :     auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     649            9 :     CHK_PRT_RET(tlvHandle == nullptr,
     650              :         HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), INVALID_U64);
     651              : 
     652            9 :     CustomChannelInfoIn  inBuff{};
     653            9 :     CustomChannelInfoOut outBuff{};
     654              : 
     655            9 :     inBuff.op                          = CcuOpcodeType::CCU_U_OP_GET_GSA;
     656            9 :     inBuff.data.dataInfo.udieIdx       = dieId;
     657            9 :     inBuff.offsetStartIdx              = gsaId;
     658            9 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个GSA
     659            9 :     inBuff.data.dataInfo.dataLen       = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     660              : 
     661            9 :     HcclResult ret = HccpRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
     662            9 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret), INVALID_U64);
     663              : 
     664            7 :     auto sret = memcpy_s(&gsaVal, sizeof(gsaVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     665            7 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), INVALID_U64);
     666            7 :     return gsaVal;
     667              : }
     668              : 
     669           14 : uint64_t CcuTaskException::GetCcuXnValue(int32_t deviceId, uint32_t dieId, uint32_t xnId)
     670              : {
     671           14 :     auto tlvHandle = Hccl::HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     672           14 :     CHK_PRT_RET(tlvHandle == nullptr,
     673              :         HCCL_ERROR("[%s]tlvHandle is null, deviceId[%d]", __func__, deviceId), INVALID_U64);
     674           14 :     uint64_t xnVal{0};
     675              : 
     676           14 :     CustomChannelInfoIn  inBuff{};
     677           14 :     CustomChannelInfoOut outBuff{};
     678              : 
     679           14 :     inBuff.op                          = CcuOpcodeType::CCU_U_OP_GET_XN;
     680           14 :     inBuff.data.dataInfo.udieIdx       = dieId;
     681           14 :     inBuff.offsetStartIdx              = xnId;
     682           14 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个Xn
     683           14 :     inBuff.data.dataInfo.dataLen       = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     684              : 
     685           14 :     HcclResult ret = HccpRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, static_cast<void*>(&inBuff), static_cast<void*>(&outBuff));
     686              : 
     687           14 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[%s]HccpRaTlvRequestForCustomChannel fail, ret[%d]", __func__, ret), INVALID_U64);
     688              : 
     689           12 :     auto sret = memcpy_s(&xnVal, sizeof(xnVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     690           12 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memcpy failed. errorno[%d]:", __func__, sret), INVALID_U64);
     691           12 :     return xnVal;
     692              : }
     693              : 
     694            2 : void CcuTaskException::GenErrorInfoRemPostSem(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     695              :                                              vector<CcuErrorInfo> &errorInfo)
     696              : {
     697            2 :     CcuErrorInfo errorMsg{};
     698            2 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     699            2 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     700            2 :     const auto rep                     = static_pointer_cast<CcuRep::CcuRepRemPostSem>(repBase);
     701              : 
     702            2 :     uint32_t channelId = 0;
     703            2 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     704              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     705            1 :     uint32_t signalId = 0;
     706            1 :     CHK_PRT_RET(GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 1, signalId) != HcclResult::HCCL_SUCCESS,
     707              :         HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()),);
     708              : 
     709            1 :     errorMsg.msg.waitSignal.signalId   = signalId;
     710            1 :     errorMsg.msg.waitSignal.signalMask = rep->GetMask();
     711            1 :     auto sret = memset_s(errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     712              :         sizeof(errorMsg.msg.waitSignal.channelId));
     713            1 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret),);
     714            1 :     errorMsg.msg.waitSignal.channelId[0] = channelId;
     715              : 
     716            1 :     errorInfo.push_back(errorMsg);
     717            2 : }
     718              : 
     719            1 : void CcuTaskException::GenErrorInfoRemWaitSem(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     720              :                                              vector<CcuErrorInfo> &errorInfo)
     721              : {
     722            1 :     CcuErrorInfo errorMsg{};
     723            1 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     724            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     725            1 :     const auto rep                     = static_pointer_cast<CcuRep::CcuRepRemWaitSem>(repBase);
     726              : 
     727            1 :     uint32_t channelId = 0;
     728            1 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     729              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     730            1 :     uint32_t signalId = 0;
     731            1 :     CHK_PRT_RET(GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 0, signalId) != HcclResult::HCCL_SUCCESS,
     732              :         HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()),);
     733              : 
     734            1 :     errorMsg.msg.waitSignal.signalId    = signalId;
     735            2 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId,
     736            1 :         errorMsg.msg.waitSignal.signalId);
     737            1 :     errorMsg.msg.waitSignal.signalMask  = rep->GetMask();
     738            1 :     auto sret = memset_s(errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     739              :         sizeof(errorMsg.msg.waitSignal.channelId));
     740            1 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret),);
     741              : 
     742            1 :     errorMsg.msg.waitSignal.channelId[0] = channelId;
     743              : 
     744            1 :     errorInfo.push_back(errorMsg);
     745            1 : }
     746              : 
     747            3 : void CcuTaskException::GenErrorInfoRemPostVar(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     748              :                                                 vector<CcuErrorInfo> &errorInfo)
     749              : {
     750            3 :     CcuErrorInfo errorMsg{};
     751            3 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     752            3 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     753            3 :     const auto rep                     = static_pointer_cast<CcuRep::CcuRepRemPostVar>(repBase);
     754              : 
     755              :     // 通过channelHandle从rep中获取channelId,rmtCkeId,rmtXnId
     756            3 :     uint32_t channelId = 0;
     757            3 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     758              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     759            3 :     uint32_t rmtCkeId = 0;
     760            3 :     CHK_PRT_RET(GetSignalIdByHandle(rep->GetChannel(), rep->GetSemIndex(), 1, rmtCkeId) != HcclResult::HCCL_SUCCESS,
     761              :         HCCL_ERROR("GetSignalIdByHandle[0x%llx]--SemIdx[%d] failed", rep->GetChannel(), rep->GetSemIndex()),);
     762            2 :     uint32_t rmtXnId = 0;
     763            2 :     CHK_PRT_RET(GetVariableIdByHandle(rep->GetChannel(), rep->GetParamIndex(), rmtXnId) != HcclResult::HCCL_SUCCESS,
     764              :         HCCL_ERROR("GetVariableIdByHandle[0x%llx]--VarIdx[%d] failed", rep->GetChannel(), rep->GetParamIndex()),);
     765              : 
     766            1 :     errorMsg.msg.waitSignal.signalId   = rmtCkeId;
     767            1 :     errorMsg.msg.waitSignal.signalMask = rep->GetMask();
     768            1 :     auto sret = memset_s(errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     769              :         sizeof(errorMsg.msg.waitSignal.channelId));
     770            1 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset_s failed. errorno[%d]:", __func__, sret),);
     771              : 
     772            1 :     errorMsg.msg.waitSignal.channelId[0] = channelId;
     773            1 :     errorMsg.msg.waitSignal.paramId = rmtXnId;
     774            1 :     errorMsg.msg.waitSignal.paramValue = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetParam().Id());
     775              : 
     776            1 :     errorInfo.push_back(errorMsg);
     777            3 : }
     778              : 
     779            0 : void CcuTaskException::GenErrorInfoPostSharedSem(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     780              :                                                 vector<CcuErrorInfo> &errorInfo)
     781              : {
     782            0 :     CcuErrorInfo errorMsg{};
     783            0 :     errorMsg.type    = CcuErrorType::WAIT_SIGNAL;
     784            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     785              : 
     786            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepRecordSharedNotify>(repBase);
     787            0 :     errorMsg.msg.waitSignal.signalId    = rep->GetNotifyId();
     788            0 :     errorMsg.msg.waitSignal.signalMask  = rep->GetMask();
     789              : 
     790            0 :     errorInfo.push_back(errorMsg);
     791            0 : }
     792              : 
     793            1 : void CcuTaskException::GenErrorInfoRead(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     794              :                                        vector<CcuErrorInfo> &errorInfo)
     795              : {
     796            1 :     CcuErrorInfo errorMsg{};
     797            1 :     errorMsg.type = CcuErrorType::TRANS_MEM;
     798            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     799            1 :     const auto rep                   = static_pointer_cast<CcuRep::CcuRepRead>(repBase);
     800              : 
     801            1 :     uint32_t channelId = 0;
     802            1 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     803              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     804              : 
     805            1 :     errorMsg.msg.transMem.locAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocAddrId());
     806            1 :     errorMsg.msg.transMem.locToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocTokenId());
     807            1 :     errorMsg.msg.transMem.rmtAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemAddrId());
     808            1 :     errorMsg.msg.transMem.rmtToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemTokenId());
     809            1 :     errorMsg.msg.transMem.len        = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     810            1 :     errorMsg.msg.transMem.signalMask = rep->GetMask();
     811            1 :     errorMsg.msg.transMem.signalId   = rep->GetSemId();
     812            1 :     errorMsg.msg.transMem.channelId = channelId;
     813            1 :     errorInfo.push_back(errorMsg);
     814            1 : }
     815              : 
     816            1 : void CcuTaskException::GenErrorInfoWrite(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     817              :                                         vector<CcuErrorInfo> &errorInfo)
     818              : {
     819            1 :     CcuErrorInfo errorMsg{};
     820            1 :     errorMsg.type    = CcuErrorType::TRANS_MEM;
     821            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     822            1 :     const auto rep                   = static_pointer_cast<CcuRep::CcuRepWrite>(repBase);
     823              : 
     824            1 :     uint32_t channelId = 0;
     825            1 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     826              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     827              : 
     828            1 :     errorMsg.msg.transMem.locAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocAddrId());
     829            1 :     errorMsg.msg.transMem.locToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLocTokenId());
     830            1 :     errorMsg.msg.transMem.rmtAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemAddrId());
     831            1 :     errorMsg.msg.transMem.rmtToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetRemTokenId());
     832            1 :     errorMsg.msg.transMem.len        = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     833            1 :     errorMsg.msg.transMem.signalId   = rep->GetSemId();
     834            1 :     errorMsg.msg.transMem.signalMask = rep->GetMask();
     835            1 :     errorMsg.msg.transMem.channelId  = channelId;
     836              : 
     837            1 :     errorInfo.push_back(errorMsg);
     838            1 : }
     839              : 
     840            0 : void CcuTaskException::GenErrorInfoLocalCpy(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     841              :                                            vector<CcuErrorInfo> &errorInfo)
     842              : {
     843            0 :     CcuErrorInfo errorMsg{};
     844            0 :     errorMsg.type    = CcuErrorType::TRANS_MEM;
     845            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     846              : 
     847            0 :     const auto rep                   = static_pointer_cast<CcuRep::CcuRepLocCpy>(repBase);
     848            0 :     errorMsg.msg.transMem.locAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
     849            0 :     errorMsg.msg.transMem.rmtAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
     850            0 :     errorMsg.msg.transMem.locToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
     851            0 :     errorMsg.msg.transMem.rmtToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
     852            0 :     errorMsg.msg.transMem.len        = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     853            0 :     errorMsg.msg.transMem.signalId   = rep->GetSemId();
     854            0 :     errorMsg.msg.transMem.signalMask = rep->GetMask();
     855              : 
     856            0 :     errorInfo.push_back(errorMsg);
     857            0 : }
     858              : 
     859            0 : void CcuTaskException::GenErrorInfoLocalReduce(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     860              :                                               vector<CcuErrorInfo> &errorInfo)
     861              : {
     862            0 :     CcuErrorInfo errorMsg{};
     863            0 :     errorMsg.type    = CcuErrorType::TRANS_MEM;
     864            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     865              : 
     866            0 :     const auto rep                   = static_pointer_cast<CcuRep::CcuRepLocCpy>(repBase);
     867            0 :     errorMsg.msg.transMem.locAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
     868            0 :     errorMsg.msg.transMem.locToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
     869            0 :     errorMsg.msg.transMem.rmtAddr    = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
     870            0 :     errorMsg.msg.transMem.rmtToken   = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
     871            0 :     errorMsg.msg.transMem.len        = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     872            0 :     errorMsg.msg.transMem.signalId   = rep->GetSemId();
     873            0 :     errorMsg.msg.transMem.signalMask = rep->GetMask();
     874            0 :     errorMsg.msg.transMem.opType     = rep->GetOpType();
     875            0 :     errorMsg.msg.transMem.dataType   = rep->GetDataType();
     876              : 
     877            0 :     errorInfo.push_back(errorMsg);
     878            0 : }
     879              : 
     880            1 : void CcuTaskException::GenErrorInfoBufRead(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     881              :                                           vector<CcuErrorInfo> &errorInfo)
     882              : {
     883            1 :     CcuErrorInfo errorMsg{};
     884            1 :     errorMsg.type    = CcuErrorType::BUF_TRANS_MEM;
     885            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     886            1 :     const auto rep                    = static_pointer_cast<CcuRep::CcuRepBufRead>(repBase);
     887              : 
     888            1 :     uint32_t channelId = 0;
     889            1 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     890              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     891              : 
     892            1 :     errorMsg.msg.bufTransMem.bufId    = GetMSIdPerDie(rep->GetDstAddrId());
     893            1 :     errorMsg.msg.bufTransMem.addr     = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
     894            1 :     errorMsg.msg.bufTransMem.token    = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
     895            1 :     errorMsg.msg.bufTransMem.len      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     896            1 :     errorMsg.msg.bufTransMem.signalId = rep->GetSemId();
     897            1 :     errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
     898            1 :     errorMsg.msg.bufTransMem.channelId = channelId;
     899            1 :     errorInfo.push_back(errorMsg);
     900            1 : }
     901              : 
     902            1 : void CcuTaskException::GenErrorInfoBufWrite(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     903              :                                            vector<CcuErrorInfo> &errorInfo)
     904              : {
     905            1 :     CcuErrorInfo errorMsg{};
     906            1 :     errorMsg.type    = CcuErrorType::BUF_TRANS_MEM;
     907            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     908            1 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepBufWrite>(repBase);
     909              : 
     910            1 :     uint32_t channelId = 0;
     911            1 :     CHK_PRT_RET(GetChannelIdByHandle(rep->GetChannel(), channelId) != HcclResult::HCCL_SUCCESS,
     912              :         HCCL_ERROR("GetChannelIdByHandle[0x%llx] failed", rep->GetChannel()),);
     913              : 
     914            1 :     errorMsg.msg.bufTransMem.bufId      = GetMSIdPerDie(rep->GetSrcId());
     915            1 :     errorMsg.msg.bufTransMem.addr       = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
     916            1 :     errorMsg.msg.bufTransMem.token      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
     917            1 :     errorMsg.msg.bufTransMem.len      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     918            1 :     errorMsg.msg.bufTransMem.signalId   = rep->GetSemId();
     919            1 :     errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
     920            1 :     errorMsg.msg.bufTransMem.channelId  = channelId;
     921              : 
     922            1 :     errorInfo.push_back(errorMsg);
     923            1 : }
     924              : 
     925            0 : void CcuTaskException::GenErrorInfoBufLocRead(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     926              :                                              vector<CcuErrorInfo> &errorInfo)
     927              : {
     928            0 :     CcuErrorInfo errorMsg{};
     929            0 :     errorMsg.type    = CcuErrorType::BUF_TRANS_MEM;
     930            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     931              : 
     932            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepBufLocRead>(repBase);
     933            0 :     errorMsg.msg.bufTransMem.bufId      = GetMSIdPerDie(rep->GetDstId());
     934            0 :     errorMsg.msg.bufTransMem.addr       = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcAddrId());
     935            0 :     errorMsg.msg.bufTransMem.token      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetSrcTokenId());
     936            0 :     errorMsg.msg.bufTransMem.len      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     937            0 :     errorMsg.msg.bufTransMem.signalId   = rep->GetSemId();
     938            0 :     errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
     939              : 
     940            0 :     errorInfo.push_back(errorMsg);
     941            0 : }
     942              : 
     943            0 : void CcuTaskException::GenErrorInfoBufLocWrite(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     944              :                                               vector<CcuErrorInfo> &errorInfo)
     945              : {
     946            0 :     CcuErrorInfo errorMsg{};
     947            0 :     errorMsg.type    = CcuErrorType::BUF_TRANS_MEM;
     948            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     949              : 
     950            0 :     const auto rep                      = static_pointer_cast<CcuRep::CcuRepBufLocWrite>(repBase);
     951            0 :     errorMsg.msg.bufTransMem.bufId      = GetMSIdPerDie(rep->GetSrcAddrId());
     952            0 :     errorMsg.msg.bufTransMem.addr       = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstAddrId());
     953            0 :     errorMsg.msg.bufTransMem.token      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetDstTokenId());
     954            0 :     errorMsg.msg.bufTransMem.len      = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLenId());
     955            0 :     errorMsg.msg.bufTransMem.signalId   = rep->GetSemId();
     956            0 :     errorMsg.msg.bufTransMem.signalMask = rep->GetMask();
     957              : 
     958            0 :     errorInfo.push_back(errorMsg);
     959            0 : }
     960              : 
     961            0 : void CcuTaskException::GenErrorInfoBufReduce(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     962              :                                             vector<CcuErrorInfo> &errorInfo)
     963              : {
     964            0 :     CcuErrorInfo errorMsg{};
     965            0 :     errorMsg.type    = CcuErrorType::BUF_REDUCE;
     966            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     967              : 
     968            0 :     const auto rep                        = static_pointer_cast<CcuRep::CcuRepBufReduce>(repBase);
     969            0 :     errorMsg.msg.bufReduce.count          = rep->GetCount();
     970            0 :     errorMsg.msg.bufReduce.dataType       = rep->GetDataType();
     971            0 :     errorMsg.msg.bufReduce.outputDataType = rep->GetOutputDataType();
     972            0 :     errorMsg.msg.bufReduce.opType         = rep->GetOpType();
     973            0 :     errorMsg.msg.bufReduce.signalId       = rep->GetSemId();
     974            0 :     errorMsg.msg.bufReduce.signalMask     = rep->GetMask();
     975            0 :     errorMsg.msg.bufReduce.xnIdLength     = rep->GetXnLengthId();
     976            0 :     const auto &buffs                     = rep->GetMem();
     977            0 :     auto sret = memset_s(errorMsg.msg.bufReduce.bufIds, sizeof(errorMsg.msg.bufReduce.bufIds), 0xFF,
     978              :                    sizeof(errorMsg.msg.bufReduce.bufIds));
     979            0 :     CHK_PRT_RET(sret != EOK, HCCL_ERROR("[%s]memset failed. errorno[%d]:", __func__, sret), );
     980            0 :     for (uint32_t i = 0; i < buffs.size() && i < BUF_REDUCE_ID_SIZE; ++i) {
     981            0 :         errorMsg.msg.bufReduce.bufIds[i] = GetMSIdPerDie(buffs[i].Id());
     982              :     }
     983              : 
     984            0 :     errorInfo.push_back(errorMsg);
     985            0 : }
     986            0 : void CcuTaskException::GenErrorInfoDefault(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     987              :     vector<CcuErrorInfo> &errorInfo)
     988              : {
     989            0 :     CcuErrorInfo errorMsg{};
     990            0 :     errorMsg.type    = CcuErrorType::DEFAULT;
     991            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     992            0 :     errorInfo.push_back(errorMsg);
     993            0 : }
     994              : 
     995            0 : void CcuTaskException::GenErrorInfoByRepType(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     996              :                                             vector<CcuErrorInfo> &errorInfo)
     997              : {
     998              :     using GenErrorInfoFunc = void (*)(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
     999              :                                                        vector<CcuErrorInfo> &errorInfo);
    1000              :     static const map<CcuRep::CcuRepType, GenErrorInfoFunc> HANDLER_MAP {
    1001              :         // WAIT_SIGNAL
    1002              :         {CcuRep::CcuRepType::LOC_RECORD_EVENT, &CcuTaskException::GenErrorInfoLocRecordEvent},
    1003              :         {CcuRep::CcuRepType::LOC_WAIT_EVENT, &CcuTaskException::GenErrorInfoLocWaitEvent},
    1004              :         {CcuRep::CcuRepType::LOC_WAIT_NOTIFY, &CcuTaskException::GenErrorInfoLocWaitNotify},
    1005              :         {CcuRep::CcuRepType::REM_POST_SEM, &CcuTaskException::GenErrorInfoRemPostSem},
    1006              :         {CcuRep::CcuRepType::REM_WAIT_SEM, &CcuTaskException::GenErrorInfoRemWaitSem},
    1007              :         {CcuRep::CcuRepType::REM_POST_VAR, &CcuTaskException::GenErrorInfoRemPostVar},
    1008              :         {CcuRep::CcuRepType::RECORD_SHARED_NOTIFY, &CcuTaskException::GenErrorInfoPostSharedSem},
    1009              :         // TRANS_MEM
    1010              :         {CcuRep::CcuRepType::READ, &CcuTaskException::GenErrorInfoRead},
    1011              :         {CcuRep::CcuRepType::WRITE, &CcuTaskException::GenErrorInfoWrite},
    1012              :         {CcuRep::CcuRepType::LOCAL_CPY, &CcuTaskException::GenErrorInfoLocalCpy},
    1013              :         {CcuRep::CcuRepType::LOCAL_REDUCE, &CcuTaskException::GenErrorInfoLocalReduce},
    1014              :         // BUF_TRANS_MEM
    1015              :         {CcuRep::CcuRepType::BUF_READ, &CcuTaskException::GenErrorInfoBufRead},
    1016              :         {CcuRep::CcuRepType::BUF_WRITE, &CcuTaskException::GenErrorInfoBufWrite},
    1017              :         {CcuRep::CcuRepType::BUF_LOC_READ, &CcuTaskException::GenErrorInfoBufLocRead},
    1018              :         {CcuRep::CcuRepType::BUF_LOC_WRITE, &CcuTaskException::GenErrorInfoBufLocWrite},
    1019              :         // BUF_REDUCE
    1020              :         {CcuRep::CcuRepType::BUF_REDUCE, &CcuTaskException::GenErrorInfoBufReduce}
    1021            0 :     };
    1022            0 :     const auto funcIt = HANDLER_MAP.find(repBase->Type());
    1023            0 :     HCCL_INFO("[%s]type[%d]", __func__, repBase->Type());
    1024            0 :     if (funcIt == HANDLER_MAP.end()) {
    1025              :         // DEFAULT, chip error
    1026            0 :         GenErrorInfoDefault(baseInfo, repBase, errorInfo);
    1027              :     } else {
    1028            0 :         (funcIt->second)(baseInfo, repBase, errorInfo);
    1029              :     }
    1030            0 : }
    1031              : 
    1032            6 : HcclResult CcuTaskException::GetCcuLoopContextRaw(
    1033              :     int32_t deviceId, uint32_t dieId, uint32_t loopCtxId, uint8_t *buf, size_t bufLen, size_t &copiedLen)
    1034              : {
    1035            6 :     return QueryCcuCtxRaw(deviceId, dieId, loopCtxId, CcuOpcodeType::CCU_U_OP_GET_LOOP_CTX, "GetCcuLoopContextRaw", buf,
    1036            6 :         bufLen, copiedLen);
    1037              : }
    1038              : 
    1039            0 : HcclResult CcuTaskException::GenErrorInfoLoop(const ErrorInfoBase &baseInfo, CcuRep::CcuRepContext &ctx,
    1040              :                                        vector<CcuErrorInfo> &errorInfo)
    1041              : {
    1042              :     // 找LoopRep
    1043            0 :     auto repBase = ctx.GetRepByInstrId(baseInfo.currentInsId);
    1044            0 :     if (repBase == nullptr || repBase->Type() != CcuRep::CcuRepType::LOOP) {
    1045            0 :         HCCL_ERROR("Failed to find Loop REP from CcuContext, instrId[%u]", baseInfo.currentInsId);
    1046            0 :         return HCCL_E_PARA;
    1047              :     }
    1048            0 :     const auto rep = static_pointer_cast<CcuRep::CcuRepLoop>(repBase);
    1049              : 
    1050            0 :     CcuErrorInfo errorMsg{};
    1051            0 :     errorMsg.type    = CcuErrorType::LOOP;
    1052            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
    1053              : 
    1054            0 :     LoopXm loopXm{};
    1055            0 :     loopXm.value                     = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetLoopParam()->Id());
    1056            0 :     CcuLoopInfo loopInfo{};
    1057            0 :     if (FetchAndDecodeLoopInfo(baseInfo.deviceId, baseInfo.dieId, loopXm.loopCtxId, loopInfo) != HCCL_SUCCESS) {
    1058            0 :         HCCL_ERROR("[GenErrorInfoLoop] Failed to fetch/decode loop info, deviceId[%d]", baseInfo.deviceId);
    1059            0 :         return HCCL_E_INTERNAL;
    1060              :     }
    1061            0 :     errorMsg.msg.loop.startInstrId   = rep->GetLoopBlock()->StartInstrId();
    1062            0 :     errorMsg.msg.loop.endInstrId     = rep->GetLoopBlock()->StartInstrId() + rep->GetLoopBlock()->InstrCount() - 1;
    1063            0 :     errorMsg.msg.loop.loopEngineId   = loopXm.loopCtxId;
    1064            0 :     errorMsg.msg.loop.loopCnt        = static_cast<uint16_t>(loopXm.loopCnt);
    1065            0 :     errorMsg.msg.loop.loopCurrentCnt = loopInfo.currentCnt;
    1066            0 :     errorMsg.msg.loop.addrStride     = loopInfo.addrStride;
    1067              : 
    1068            0 :     errorInfo.push_back(errorMsg);
    1069              : 
    1070              :     // 解析Loop内的异常Rep
    1071            0 :     for (uint16_t loopCurrentIns = errorMsg.msg.loop.startInstrId; loopCurrentIns <= errorMsg.msg.loop.endInstrId;
    1072              :         loopCurrentIns++) {
    1073            0 :         auto inLoopExRep = rep->GetLoopBlock()->GetRepByInstrId(loopCurrentIns);
    1074            0 :         if (inLoopExRep == nullptr) {
    1075            0 :             HCCL_ERROR("Failed to find REP from Loop, instrId[%u], Loop[%s]", loopCurrentIns, rep->GetLabel().c_str());
    1076            0 :             return HCCL_E_PARA;
    1077              :         }
    1078            0 :         ErrorInfoBase loopErrBase{baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopCurrentIns,
    1079            0 :                                   baseInfo.status};
    1080            0 :         GenErrorInfoByRepType(loopErrBase, inLoopExRep, errorInfo);
    1081            0 :     }
    1082            0 :     return HCCL_SUCCESS;
    1083            0 : }
    1084              : 
    1085            0 : HcclResult CcuTaskException::GenErrorInfoLoopGroup(const ErrorInfoBase &baseInfo, shared_ptr<CcuRep::CcuRepBase> repBase,
    1086              :     CcuRep::CcuRepContext &ctx, vector<CcuErrorInfo> &errorInfo)
    1087              : {
    1088            0 :     CcuErrorInfo errorMsg{};
    1089            0 :     errorMsg.type    = CcuErrorType::LOOP_GROUP;
    1090            0 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
    1091              : 
    1092            0 :     const auto  rep              = static_pointer_cast<CcuRep::CcuRepLoopGroupBundle>(repBase);
    1093            0 :     const auto  startLoopInstrId = rep->GetStartLoopInstrId();
    1094            0 :     LoopGroupXn loopGroupXn{};
    1095            0 :     loopGroupXn.value                     = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->GetOffsetParam().Id());
    1096            0 :     errorMsg.msg.loopGroup.startLoopInsId = startLoopInstrId;
    1097            0 :     errorMsg.msg.loopGroup.loopInsCnt     = static_cast<uint16_t>(loopGroupXn.loopInsCnt);
    1098            0 :     errorMsg.msg.loopGroup.expandOffset   = static_cast<uint16_t>(loopGroupXn.expandOffset);
    1099            0 :     errorMsg.msg.loopGroup.expandCnt      = static_cast<uint16_t>(loopGroupXn.expandCnt);
    1100              : 
    1101            0 :     errorInfo.push_back(errorMsg);
    1102              : 
    1103              :     // 处理loop
    1104            0 :     for (uint16_t i = 0; i < loopGroupXn.loopInsCnt; ++i) {
    1105            0 :         uint16_t      loopInsId = startLoopInstrId + i;
    1106            0 :         ErrorInfoBase loopErrInfoBase{baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopInsId,
    1107            0 :                                       baseInfo.status};
    1108            0 :         CHK_RET(GenErrorInfoLoop(loopErrInfoBase, ctx, errorInfo));
    1109              :     }
    1110            0 :     return HCCL_SUCCESS;
    1111            0 : }
    1112              : 
    1113            0 : static HcclResult HandleCurrentRepErrorInfo(const ErrorInfoBase &baseInfo, CcuRep::CcuRepContext &ctx,
    1114              :     const std::shared_ptr<CcuRep::CcuRepBase> &rep, const std::shared_ptr<CcuRep::CcuRepBase> &prevRep,
    1115              :     GenErrorInfoLoopGroupFunc genLoopGroup, GenErrorInfoByRepTypeFunc genByRepType,
    1116              :     std::vector<CcuErrorInfo> &errorInfo)
    1117              : {
    1118            0 :     if ((prevRep != nullptr && prevRep->Type() == CcuRep::CcuRepType::LOOPGROUP)
    1119            0 :         || (rep->Type() == CcuRep::CcuRepType::LOOPGROUP)) {
    1120            0 :         CHK_RET(genLoopGroup(baseInfo, prevRep, ctx, errorInfo));
    1121            0 :         return HCCL_SUCCESS;
    1122              :     }
    1123              : 
    1124            0 :     if (rep->Type() == CcuRep::CcuRepType::LOC_WAIT_EVENT || rep->Type() == CcuRep::CcuRepType::LOC_WAIT_NOTIFY) {
    1125            0 :         genByRepType(baseInfo, rep, errorInfo);
    1126            0 :         uint16_t actValue = errorInfo.back().msg.waitSignal.signalValue;
    1127            0 :         uint16_t expValue = errorInfo.back().msg.waitSignal.signalMask;
    1128            0 :         for (uint16_t i = 0; i < 16; ++i) { // CKE的bit数最多为16
    1129            0 :             uint16_t mask = 1 << i;         // 创建一个用于检查第 i 位的掩码
    1130            0 :             if ((expValue & mask) != 0 && (actValue & mask) == 0) {
    1131            0 :                 auto depRepVec = static_pointer_cast<CcuRep::CcuRepLocWaitEvent>(rep)->GetDependencyInfo(mask);
    1132            0 :                 for (const auto& depRep : depRepVec) {
    1133            0 :                     genByRepType(baseInfo, depRep, errorInfo);
    1134              :                 }
    1135            0 :             }
    1136              :         }
    1137            0 :         return HCCL_SUCCESS;
    1138              :     }
    1139              : 
    1140            0 :     genByRepType(baseInfo, rep, errorInfo);
    1141            0 :     return HCCL_SUCCESS;
    1142              : }
    1143              : 
    1144            5 : HcclResult CcuTaskException::GetCcuErrorMsg(int32_t deviceId, uint16_t missionStatus, const Hccl::ParaCcu &ccuTaskParam,
    1145              :     std::vector<CcuErrorInfo> &errorInfo)
    1146              : {
    1147            5 :     HCCL_INFO("[CcuTaskException]%s: deviceId[%d], dieId[%u], missionId[%u], execMissionId[%u], executeId[%llu].",
    1148              :             __func__, deviceId, static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.missionId),
    1149              :             static_cast<u32>(ccuTaskParam.execMissionId), ccuTaskParam.executeId);
    1150              : 
    1151            5 :     CcuMissionInfo missionInfo{};
    1152            5 :     CHK_RET(
    1153              :         ValidateAndDecodeMissionContext(deviceId, missionStatus, ccuTaskParam, GetCcuMissionContextRaw, missionInfo));
    1154              : 
    1155            0 :     const uint16_t currIns = missionInfo.currentIns;
    1156            0 :     CcuRep::CcuRepContext *ctx = nullptr;
    1157            0 :     std::shared_ptr<CcuRep::CcuRepBase> rep = nullptr;
    1158            0 :     std::shared_ptr<CcuRep::CcuRepBase> prevRep = nullptr;
    1159            0 :     CHK_RET(ResolveRepContextAndCurrentRep(deviceId, ccuTaskParam, currIns, ctx, rep, prevRep));
    1160              : 
    1161              :     // 分类处理Rep, 返回异常信息
    1162            0 :     ErrorInfoBase baseInfo{deviceId, ccuTaskParam.dieId, ccuTaskParam.missionId, currIns, missionStatus};
    1163            0 :     GenStatusInfo(baseInfo, errorInfo);
    1164            0 :     CHK_RET(HandleCurrentRepErrorInfo(
    1165              :         baseInfo, *ctx, rep, prevRep, GenErrorInfoLoopGroup, GenErrorInfoByRepType, errorInfo));
    1166              : 
    1167            0 :     const uint16_t endIns = missionInfo.endIns;
    1168            0 :     const uint16_t startIns = missionInfo.startIns;
    1169            0 :     HandleSurroundingRepErrorInfo(deviceId, ccuTaskParam.execMissionId, baseInfo, *ctx, startIns, endIns, currIns,
    1170              :         GenErrorInfoByRepType, errorInfo);
    1171            0 :     return HCCL_SUCCESS;
    1172            0 : }
    1173              : 
    1174            0 : void CcuTaskException::GetCcuCqeErrRemoteLocalIdByRankId(hccl::CollComm* collComm, uint32_t rankid, u32 &remoteLocalId)
    1175              : {
    1176            0 :     if (collComm == nullptr) {
    1177            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] collComm is nullptr");
    1178            0 :         return;
    1179              :     }
    1180              : 
    1181            0 :     if (rankid == INVALID_VALUE_RANKID) {
    1182            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] RemoteLocalId is already set, rankId[%u]", rankid);
    1183            0 :         return;
    1184              :     }
    1185              : 
    1186            0 :     Hccl::HcclCommunicator* commV2 = static_cast<Hccl::HcclCommunicator *>(collComm->GetCommunicatorV2());
    1187            0 :     if (commV2 == nullptr) {
    1188            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] commV2 is nullptr");
    1189            0 :         return;
    1190              :     }
    1191            0 :     void *rankGraph = nullptr;
    1192            0 :     HcclResult ret = commV2->GetRankGraphV2(rankGraph);
    1193            0 :     if (ret != HCCL_SUCCESS) {
    1194            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId]GetRankGraphV2 failed, rankId[%u], ret[%d]", rankid, ret);
    1195            0 :         return;
    1196              :     }
    1197            0 :     if (rankGraph == nullptr) {
    1198            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] rankGraph is nullptr for rankid[%u]", rankid);
    1199            0 :         return;
    1200              :     }
    1201              :  
    1202            0 :     Hccl::RankGraph *rankGraphv2 = static_cast<Hccl::RankGraph *>(rankGraph);
    1203            0 :     if (rankGraphv2 == nullptr) {
    1204            0 :         HCCL_ERROR("[GetCcuCqeErrRemoteLocalIdByRankId] rankGraphv2 is nullptr for rankid[%u]", rankid);
    1205            0 :         return;
    1206              :     }
    1207            0 :     u32 LocalId = rankGraphv2->GetLocalId(rankid);
    1208            0 :     remoteLocalId = LocalId;
    1209            0 :     return;
    1210              : }
    1211              : 
    1212            0 : void CcuTaskException::GetCcuCqeErrNetInstanceByRankId(hccl::CollComm* collComm, uint32_t rankid, std::string &netInstanceId)
    1213              : {
    1214            0 :     if (collComm == nullptr) {
    1215            0 :         HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] collComm is nullptr");
    1216            0 :         return;
    1217              :     }
    1218            0 :     if (rankid == INVALID_VALUE_RANKID) {
    1219            0 :         HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] RemoteLocalId is already set, rankId[%u]", rankid);
    1220            0 :         return;
    1221              :     }
    1222            0 :     Hccl::HcclCommunicator* commV2 = static_cast<Hccl::HcclCommunicator *>(collComm->GetCommunicatorV2());
    1223            0 :     if (commV2 == nullptr) {
    1224            0 :         HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] commV2 is nullptr");
    1225            0 :         return;
    1226              :     }
    1227            0 :     void *rankGraph = nullptr;
    1228            0 :     HcclResult ret = commV2->GetRankGraphV2(rankGraph);
    1229            0 :     if (ret != HCCL_SUCCESS) {
    1230            0 :         HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId]GetRankGraphV2 failed, rankId[%u], ret[%d]", rankid, ret);
    1231            0 :         return;
    1232              :     }
    1233            0 :     Hccl::RankGraph *rankGraphv2 = static_cast<Hccl::RankGraph *>(rankGraph);
    1234            0 :     const Hccl::NetInstance *netInstance = rankGraphv2->GetNetInstanceByRankId(0, rankid);
    1235            0 :     if (netInstance == nullptr) {
    1236            0 :         HCCL_ERROR("[GetCcuCqeErrNetInstanceByRankId] netInstance is nullptr for rankid[%u]", rankid);
    1237            0 :         return;
    1238              :     }
    1239            0 :     std::string netInsId = netInstance->GetNetInstId();
    1240            0 :     netInstanceId = netInsId;
    1241            0 :     return;
    1242            0 : }
    1243              : 
    1244            0 : void CcuTaskException::GetCcuCqeErrorInfo(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 locDeviceId, uint8_t missionStatus)
    1245              : {
    1246            0 :     uint16_t channelId = GetChannleIdByCcuErrorInfo(ccuErrorInfo);
    1247            0 :     if (channelId == INVALID_U16) {
    1248            0 :         HCCL_ERROR("[%s]cannot get channelId from repType[%d]", __func__, ccuErrorInfo.repType);
    1249            0 :         return;
    1250              :     }
    1251            0 :     auto pair = GetAddrPairByChannelId(channelId, taskInfo, locDeviceId);
    1252            0 :     RankId remoteRankId = GetRankIdByChannelId(channelId, taskInfo, locDeviceId);
    1253            0 :     hccl::CollComm *collComm = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
    1254            0 :     u32 remoteLocalId = INVALID_VALUE_RANKID;
    1255            0 :     GetCcuCqeErrRemoteLocalIdByRankId(collComm, remoteRankId, remoteLocalId);
    1256            0 :     std::string netInstanceId = "";
    1257            0 :     GetCcuCqeErrNetInstanceByRankId(collComm, remoteRankId, netInstanceId);
    1258            0 :     std::string srcEid = pair.first.Describe();
    1259            0 :     std::string dstEid = pair.second.Describe();
    1260            0 :     ClusterMoniterGetCcuCqeErrInfo(remoteLocalId, locDeviceId, missionStatus, srcEid, dstEid, netInstanceId);
    1261            0 :     return;
    1262            0 : }
    1263              : 
    1264              : 
    1265            5 : void CcuTaskException::PrintCcuErrorInfo(uint32_t deviceId, uint16_t status, const Hccl::TaskInfo& taskInfo)
    1266              : {
    1267            5 :     const Hccl::ParaCcu& ccuTaskParam = taskInfo.taskParam_.taskPara.Ccu;
    1268            5 :     vector<CcuErrorInfo> errorInfos {};
    1269            5 :     HcclResult ret = GetCcuErrorMsg(deviceId, status, ccuTaskParam, errorInfos);
    1270            5 :     if (ret != HcclResult::HCCL_SUCCESS || errorInfos.empty()) {
    1271            5 :         HCCL_ERROR("Get CCU error info failed. deviceId[%u], dieId[%u], missionId[%u], executeId[%llu].",
    1272              :             deviceId, ccuTaskParam.dieId, ccuTaskParam.missionId, ccuTaskParam.executeId);
    1273            5 :         return;
    1274              :     }
    1275            0 :     PrintCcuErrorLog(errorInfos, taskInfo, deviceId);
    1276            0 :     const uint8_t missionStatus = (status >> 8) & 0xFF;
    1277            0 :     if (missionStatus >= 0x01 && missionStatus <= 0x05) { // 如果是UB错误(missionStatus为[0x01, 0x05]),打印Ub Dfx寄存器信息
    1278            0 :         PrintCcuUbRegisters(errorInfos, static_cast<s32>(deviceId), taskInfo);
    1279            0 :         if (isGetCqeErrInfo) {
    1280            0 :             isGetCqeErrInfo = false; // 只获取一次CQE错误信息,避免重复获取
    1281            0 :             for (const auto& errorInfo : errorInfos) {
    1282            0 :                 if (errorInfo.repType == CcuRep::CcuRepType::READ || errorInfo.repType == CcuRep::CcuRepType::WRITE || errorInfo.repType == CcuRep::CcuRepType::BUF_READ || errorInfo.repType == CcuRep::CcuRepType::BUF_WRITE) {
    1283            0 :                     GetCcuCqeErrorInfo(errorInfo, taskInfo, deviceId, missionStatus);//添加注释errorInfos[0]对应missionStatus异常
    1284              :                 }
    1285              :             }        
    1286              :         }
    1287              :     }
    1288            5 : }
    1289              : 
    1290            0 : void CcuTaskException::PrintCcuErrorLog(const std::vector<CcuErrorInfo>& errorInfos, const Hccl::TaskInfo& taskInfo,
    1291              :     u32 deviceId)
    1292              : {
    1293            0 :     if (errorInfos.empty()) {
    1294            0 :         return;
    1295              :     }
    1296            0 :     HCCL_ERROR("[CcuTaskException]Task run failed, ccu runtime information is: %s", __func__);
    1297            0 :     for (const auto& errorInfo : errorInfos) {
    1298            0 :         HCCL_ERROR("[CcuTaskException][%s]", GetCcuErrorMsgByType(errorInfo, taskInfo, deviceId).c_str());
    1299              :     }
    1300              : }
    1301              : 
    1302            0 : HcclResult CcuTaskException::PrintCcuUbRegisters(const std::vector<CcuErrorInfo>& errorInfos, s32 devLogicId,
    1303              :     const Hccl::TaskInfo& taskInfo)
    1304              : {
    1305            0 :     std::vector<CcuJetty *> ccuJettys;
    1306            0 :     for (const CcuErrorInfo& errorInfo : errorInfos) {
    1307            0 :         if (REP_WITH_CHANNEL.find(errorInfo.repType) == REP_WITH_CHANNEL.end()) {
    1308            0 :             HCCL_INFO("[%s]repType[%d] not found in REP_WITH_CHANNEL, skip", __func__, errorInfo.repType);
    1309            0 :             continue;
    1310              :         }
    1311              : 
    1312            0 :         std::pair<CcuChannelInfo, std::vector<CcuJetty *>> ctx;
    1313            0 :         (void)GetCcuJettys(errorInfo, ctx);
    1314            0 :         ccuJettys.insert(ccuJettys.end(), ctx.second.begin(), ctx.second.end());
    1315            0 :     }
    1316              : 
    1317            0 :     u32 jettyNum = ccuJettys.size();
    1318            0 :     CHK_PRT_RET(jettyNum == 0, HCCL_RUN_INFO("[%s]jettyNum[%u], skip", __func__, jettyNum), HCCL_SUCCESS);
    1319              : 
    1320            0 :     std::vector<JettyHandle> jettyHandles;
    1321            0 :     jettyHandles.reserve(jettyNum);
    1322            0 :     for (auto &ccuJetty : ccuJettys) {
    1323            0 :         jettyHandles.push_back(ccuJetty->GetJettyHandle());
    1324              :     }
    1325              : 
    1326            0 :     std::vector<JettyStatus> jettyStatusVec;
    1327            0 :     CHK_RET(RaBatchQueryJettyStatus(jettyHandles, jettyStatusVec, jettyNum));
    1328              : 
    1329            0 :     for (u32 i = 0; i < jettyNum; ++i) {
    1330            0 :         if (jettyStatusVec[i] == JettyStatus::ERROR || jettyStatusVec[i] == JettyStatus::SUSPENDED) {
    1331            0 :             HrtRaDumpJettyContext(ccuJettys[i]->GetJettyHandle(), ccuJettys[i]->GetJettyId());
    1332              :         }
    1333              :     }
    1334              : 
    1335            0 :     for (u32 i = 0; i < jettyNum; ++i) {
    1336            0 :         if (jettyStatusVec[i] == JettyStatus::ERROR || jettyStatusVec[i] == JettyStatus::SUSPENDED) {
    1337            0 :             auto rdmaHandle = ccuJettys[i]->GetRdmaHandle();
    1338            0 :             HCCL_ERROR("[%s]jettyId[%u]", __func__, ccuJettys[i]->GetJettyId());
    1339            0 :             PrintUbRegisters(devLogicId, rdmaHandle);
    1340            0 :             break;
    1341              :         }
    1342              :     }
    1343            0 :     return HCCL_SUCCESS;
    1344            0 : }
    1345              : 
    1346            4 : uint16_t CcuTaskException::GetChannleIdByCcuErrorInfo(const CcuErrorInfo& errorInfo)
    1347              : {
    1348            4 :     uint16_t channelId = INVALID_U16;
    1349            4 :     switch (errorInfo.repType) {
    1350            1 :         case CcuRep::CcuRepType::REM_POST_SEM:
    1351              :         case CcuRep::CcuRepType::REM_WAIT_SEM:
    1352              :         case CcuRep::CcuRepType::REM_POST_VAR:
    1353            1 :             channelId = errorInfo.msg.waitSignal.channelId[0];
    1354            1 :             break;
    1355            1 :         case CcuRep::CcuRepType::READ:
    1356              :         case CcuRep::CcuRepType::WRITE:
    1357            1 :             channelId = errorInfo.msg.transMem.channelId;
    1358            1 :             break;
    1359            1 :         case CcuRep::CcuRepType::BUF_READ:
    1360              :         case CcuRep::CcuRepType::BUF_WRITE:
    1361            1 :             channelId = errorInfo.msg.bufTransMem.channelId;
    1362            1 :             break;
    1363            1 :         default:
    1364            1 :             HCCL_ERROR("[%s]repType[%d] does not have jetty", __func__, errorInfo.repType);
    1365            1 :             break;
    1366              :     }
    1367            4 :     HCCL_INFO("[%s]repType[%d], channelId[%u]", __func__, errorInfo.repType, channelId);
    1368            4 :     return channelId;
    1369              : }
    1370              : 
    1371            0 : HcclResult CcuTaskException::GetCcuJettys(const CcuErrorInfo& errorInfo, std::pair<CcuChannelInfo, std::vector<CcuJetty *>> &ctx)
    1372              : {
    1373            0 :     if (REP_WITH_CHANNEL.find(errorInfo.repType) == REP_WITH_CHANNEL.end()) {
    1374            0 :         HCCL_INFO("[%s]repType[%d] does not need to get jettys, skip", __func__, errorInfo.repType);
    1375            0 :         return HCCL_SUCCESS;
    1376              :     }
    1377            0 :     uint16_t channelId = GetChannleIdByCcuErrorInfo(errorInfo);
    1378              : 
    1379              :     // channelId -> channelHandle
    1380            0 :     u64 channelHandle = INVALID_U64;
    1381            0 :     CHK_RET(GetCcuChannelHandleById(channelId, channelHandle));
    1382              : 
    1383              :     // channelHandle -> CcuUrmaChannel
    1384            0 :     void *channelPtr{nullptr};
    1385            0 :     CHK_RET(static_cast<HcclResult>(HcommChannelGet(channelHandle, &channelPtr)));
    1386            0 :     CHK_PTR_NULL(channelPtr);
    1387            0 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
    1388              : 
    1389              :     // CcuUrmaChannel -> UrmaEndpoint
    1390            0 :     EndpointHandle locEndPointHandle = channelImpl->GetlocEndPointHandle();
    1391            0 :     void *endpoint{nullptr};
    1392            0 :     CHK_RET(static_cast<HcclResult>(HcommEndpointGet(locEndPointHandle, &endpoint)));
    1393            0 :     CHK_PTR_NULL(endpoint);
    1394            0 :     UrmaEndpoint *ccuEndpoint = dynamic_cast<UrmaEndpoint *>(static_cast<Endpoint *>(endpoint));
    1395              : 
    1396              :     // 打印localEid和remoteEid
    1397            0 :     CHK_PTR_NULL(ccuEndpoint);
    1398            0 :     HCCL_ERROR("[GetCcuJettys]localEid[%s], remoteEid[%s]",
    1399              :         hcomm::logger::CommAddrLogger::ToString(ccuEndpoint->GetEndpointDesc().commAddr).c_str(),
    1400              :         hcomm::logger::CommAddrLogger::ToString(channelImpl->GetChannelDesc().remoteEndpoint.commAddr).c_str());
    1401              : 
    1402              :     // UrmaEndpoint -> CcuChannelCtxPool
    1403            0 :     CcuChannelCtxPool *ccuChannelCtxPool = ccuEndpoint->GetCcuChannelCtxPool();
    1404            0 :     CHK_PTR_NULL(ccuChannelCtxPool);
    1405              : 
    1406              :     // CcuChannelCtxPool -> CcuJetty
    1407            0 :     auto channelIdKey = std::make_pair(errorInfo.dieId, channelId);
    1408            0 :     CHK_RET(ccuChannelCtxPool->GetCcuChannelCtxById(channelIdKey, ctx));
    1409            0 :     return HCCL_SUCCESS;
    1410              : }
    1411              : 
    1412            0 : HcclResult RaGetAuxInfo(const RdmaHandle rdmaHandle, AuxInfoIn auxInfoIn, AuxInfoOut &auxInfoOut)
    1413              : {
    1414              :     HccpAuxInfoIn in;
    1415            0 :     in.type = static_cast<HccpAuxInfoInType>(static_cast<int>(auxInfoIn.auxInfoInType));
    1416            0 :     if (auxInfoIn.auxInfoInType == AuxInfoInType::AUX_INFO_IN_TYPE_CQE) {
    1417            0 :         in.cqe.status = auxInfoIn.cqe.status;
    1418            0 :         in.cqe.sR = auxInfoIn.cqe.sR;
    1419            0 :     } else if (auxInfoIn.auxInfoInType == AuxInfoInType::AUX_INFO_IN_TYPE_AE) {
    1420            0 :         in.ae.eventType = auxInfoIn.ae.eventType;
    1421              :     }
    1422              : 
    1423              :     HccpAuxInfoOut out;
    1424            0 :     auto ret = RaCtxGetAuxInfo(rdmaHandle, &in, &out);
    1425            0 :     if (ret != 0) {
    1426            0 :         HCCL_ERROR("RaGetAuxInfo failed, ret=[%d]", ret);
    1427            0 :         return HCCL_E_NETWORK;
    1428              :     }
    1429              : 
    1430            0 :     auxInfoOut.auxInfoNum = out.auxInfoNum;
    1431            0 :     for (uint32_t i = 0; i < out.auxInfoNum; i++) {
    1432            0 :         auxInfoOut.auxInfoTypes[i] = out.auxInfoType[i];
    1433            0 :         auxInfoOut.auxInfoValues[i] = out.auxInfoValue[i];
    1434              :     }
    1435            0 :     return HCCL_SUCCESS;
    1436              : }
    1437            0 : HcclResult CcuTaskException::PrintUbRegisters(s32 devLogicId, RdmaHandle rdmaHandle)
    1438              : {
    1439            0 :     HCCL_INFO("[PrintUbRegister] start, devLogicId[%d], rdmaHandle[%p]", devLogicId, rdmaHandle);
    1440            0 :     AuxInfoIn in;
    1441            0 :     in.cqe.status = 0xffffffff; // 0xffffffff代表查询所有寄存器
    1442            0 :     in.auxInfoInType = AuxInfoInType::AUX_INFO_IN_TYPE_CQE;
    1443            0 :     in.cqe.sR = 0;
    1444            0 :     AuxInfoOut auxInfo;
    1445            0 :     auto ret = RaGetAuxInfo(rdmaHandle, in, auxInfo);
    1446            0 :     if (ret != HCCL_SUCCESS) {
    1447            0 :         HCCL_ERROR("[PrintUbRegister] RaGetAuxInfo failed, devLogicId[%d], rdmaHandle[%p], ret[%d]", devLogicId,
    1448              :             rdmaHandle, ret);
    1449            0 :         return ret;
    1450              :     }
    1451              : 
    1452            0 :     uint16_t isAuxInfoExisted{false};
    1453            0 :     for (u32 i = 0; i < auxInfo.auxInfoNum; i++) {
    1454            0 :         if (auxInfo.auxInfoValues[i]) { // 非零进行打印
    1455            0 :             isAuxInfoExisted = true;
    1456            0 :             HCCL_ERROR("devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]", devLogicId,
    1457              :                 auxInfo.auxInfoTypes[i], auxInfo.auxInfoValues[i]);
    1458              :             } else {
    1459            0 :                 HCCL_INFO("devLogicId[%d], cqe_aux_info_type[%u], cqe_aux_info_value[0x%x]",
    1460              :                     devLogicId, auxInfo.auxInfoTypes[i], auxInfo.auxInfoValues[i]);
    1461              :         }
    1462              :     }
    1463            0 :     if (!isAuxInfoExisted) {
    1464            0 :         HCCL_ERROR("devLogicId[%d], all aux_info values are zero.", devLogicId);
    1465              :     }
    1466            0 :     return HCCL_SUCCESS;
    1467              : }
    1468              : 
    1469           14 : string CcuTaskException::GetCcuLenErrorMsg(const uint64_t len)
    1470              : {
    1471           14 :     if ((0 < len) && (len <= CCU_MSG_256MB_LEN)) {
    1472           14 :         return "";
    1473              :     }
    1474            7 :     return Hccl::StringFormat("ccu transMem Len[%llu]B > 256MB or is zero, not support!", len);
    1475              : }
    1476              : 
    1477            1 : string CcuTaskException::GetCcuErrorMsgLoop(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1478              : {
    1479              :     (void)taskInfo;
    1480              :     (void)deviceId;
    1481              :     return Hccl::StringFormat("InstrId[%u]: Loop startInstrId[%u], endInstrId[%u], executorId[%u], "
    1482              :                         "totalIter[%u], curIter[%u], addressStride[0x%llx]",
    1483            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.loop.startInstrId, ccuErrorInfo.msg.loop.endInstrId,
    1484            1 :                         ccuErrorInfo.msg.loop.loopEngineId, ccuErrorInfo.msg.loop.loopCnt,
    1485            1 :                         ccuErrorInfo.msg.loop.loopCurrentCnt, ccuErrorInfo.msg.loop.addrStride);
    1486              : }
    1487              : 
    1488            1 : string CcuTaskException::GetCcuErrorMsgLoopGroup(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1489              : {
    1490              :     (void)taskInfo;
    1491              :     (void)deviceId;
    1492              :     return Hccl::StringFormat("InstrId[%u]: LoopGroup startLoopInsId[%u], loopInsCnt[%u], "
    1493              :                         "expandOffset[%u], expandCnt[%u]",
    1494            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.loopGroup.startLoopInsId,
    1495            1 :                         ccuErrorInfo.msg.loopGroup.loopInsCnt, ccuErrorInfo.msg.loopGroup.expandOffset,
    1496            1 :                         ccuErrorInfo.msg.loopGroup.expandCnt);
    1497              : }
    1498              : 
    1499            1 : string CcuTaskException::GetCcuErrorMsgLocPostSem(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1500              : {
    1501              :     (void)taskInfo;
    1502              :     (void)deviceId;
    1503            1 :     return Hccl::StringFormat("InstrId[%u]: Set sem[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
    1504            1 :                         ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
    1505            1 :                         ccuErrorInfo.msg.waitSignal.signalMask);
    1506              : }
    1507              : 
    1508            1 : string CcuTaskException::GetCcuErrorMsgLocWaitEvent(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1509              : {
    1510              :     (void)taskInfo;
    1511              :     (void)deviceId;
    1512            1 :     return Hccl::StringFormat("InstrId[%u]: LocWaitEvent[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
    1513            1 :                         ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
    1514            1 :                         ccuErrorInfo.msg.waitSignal.signalMask);
    1515              : }
    1516              : 
    1517            1 : string CcuTaskException::GetCcuErrorMsgLocWaitNotify(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1518              : {
    1519              :     (void)taskInfo;
    1520              :     (void)deviceId;
    1521            1 :     return Hccl::StringFormat("InstrId[%u]: LocWaitNotify[%u], semValue[0x%04x], mask[0x%04x]", ccuErrorInfo.instrId,
    1522            1 :                         ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalValue,
    1523            1 :                         ccuErrorInfo.msg.waitSignal.signalMask);
    1524              : }
    1525              : 
    1526            1 : string CcuTaskException::GetCcuErrorMsgRemPostSem(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1527              : {
    1528            1 :     return Hccl::StringFormat("InstrId[%u]: Post, Use sem[%u], mask[0x%04x], rankId[%d]", ccuErrorInfo.instrId,
    1529            1 :                         ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask,
    1530            1 :                         GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
    1531              : }
    1532              : 
    1533            1 : string CcuTaskException::GetCcuErrorMsgRemWaitSem(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1534              : {
    1535              :     return Hccl::StringFormat("InstrId[%u]: Wait, Use sem[%u], semValue[0x%04x], mask[0x%04x], rankId[%d]",
    1536            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.signalId,
    1537            1 :                         ccuErrorInfo.msg.waitSignal.signalValue, ccuErrorInfo.msg.waitSignal.signalMask,
    1538            1 :                         GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
    1539              : }
    1540              : 
    1541            1 : string CcuTaskException::GetCcuErrorMsgRemPostVar(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1542              : {
    1543              :     return Hccl::StringFormat("InstrId[%u]: Post Variable[0x%016llx] To Param[%u], Use sem[%u], mask[0x%04x], rankId[%d]",
    1544            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.waitSignal.paramValue,
    1545            1 :                         ccuErrorInfo.msg.waitSignal.paramId, ccuErrorInfo.msg.waitSignal.signalId,
    1546            1 :                         ccuErrorInfo.msg.waitSignal.signalMask,
    1547            1 :                         GetRankIdByChannelId(ccuErrorInfo.msg.waitSignal.channelId[0], taskInfo, deviceId));
    1548              : }
    1549              : 
    1550            1 : string CcuTaskException::GetCcuErrorMsgPostSharedSem(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1551              : {
    1552              :     (void)taskInfo;
    1553              :     (void)deviceId;
    1554            1 :     return Hccl::StringFormat("InstrId[%u]: Post, Use sem[%u], mask[0x%04x]", ccuErrorInfo.instrId,
    1555            1 :                         ccuErrorInfo.msg.waitSignal.signalId, ccuErrorInfo.msg.waitSignal.signalMask);
    1556              : }
    1557              : 
    1558            1 : string CcuTaskException::GetCcuErrorMsgRead(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1559              : {
    1560            1 :     auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId);
    1561            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
    1562              :     return Hccl::StringFormat(
    1563              :         "InstrId[%u]: Read Memory[0x%016llx] To Memory[0x%016llx], Len[%llu], "
    1564              :         "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
    1565            1 :         ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.rmtAddr, ccuErrorInfo.msg.transMem.locAddr,
    1566            1 :         ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
    1567            1 :         GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId),
    1568            2 :         pair.first.Describe().c_str(),
    1569            4 :         pair.second.Describe().c_str(), printMsg.c_str());
    1570            1 : }
    1571              : 
    1572            1 : string CcuTaskException::GetCcuErrorMsgWrite(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1573              : {
    1574            1 :     auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId);
    1575            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
    1576              :     return Hccl::StringFormat(
    1577              :         "InstrId[%u]: Write Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
    1578              :         "Set sem[%u] with mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
    1579            1 :         ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
    1580            1 :         ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId, ccuErrorInfo.msg.transMem.signalMask,
    1581            1 :         GetRankIdByChannelId(ccuErrorInfo.msg.transMem.channelId, taskInfo, deviceId),
    1582            2 :         pair.first.Describe().c_str(),
    1583            4 :         pair.second.Describe().c_str(), printMsg.c_str());
    1584            1 : }
    1585              : 
    1586            1 : string CcuTaskException::GetCcuErrorMsgLocalCpy(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1587              : {
    1588              :     (void)taskInfo;
    1589              :     (void)deviceId;
    1590            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
    1591              :     return Hccl::StringFormat("InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
    1592              :                         "Set sem[%u] with mask[0x%04x] %s",
    1593            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
    1594            1 :                         ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId,
    1595            2 :                         ccuErrorInfo.msg.transMem.signalMask, printMsg.c_str());
    1596            1 : }
    1597              : 
    1598            1 : string CcuTaskException::GetCcuErrorMsgLocalReduce(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1599              : {
    1600              :     (void)taskInfo;
    1601              :     (void)deviceId;
    1602            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.transMem.len);
    1603              :     return Hccl::StringFormat("InstrId[%u]: Read Memory[0x%016llx] to Memory[0x%016llx], Len[%llu], "
    1604              :                         "Set sem[%u] with mask[0x%04x], dataType[%u], opType[%u] %s",
    1605            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.transMem.locAddr, ccuErrorInfo.msg.transMem.rmtAddr,
    1606            1 :                         ccuErrorInfo.msg.transMem.len, ccuErrorInfo.msg.transMem.signalId,
    1607            1 :                         ccuErrorInfo.msg.transMem.signalMask, ccuErrorInfo.msg.transMem.dataType,
    1608            2 :                         ccuErrorInfo.msg.transMem.opType, printMsg.c_str());
    1609            1 : }
    1610              : 
    1611            1 : string CcuTaskException::GetCcuErrorMsgBufRead(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1612              : {
    1613            1 :     auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId);
    1614            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
    1615              :     return Hccl::StringFormat(
    1616              :         "InstrId[%u]: Read Rmt Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], "
    1617              :         "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
    1618            1 :         ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
    1619            1 :         ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId, ccuErrorInfo.msg.bufTransMem.signalMask,
    1620            1 :         GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId),
    1621            2 :         pair.first.Describe().c_str(),
    1622            4 :         pair.second.Describe().c_str(), printMsg.c_str());
    1623            1 : }
    1624              : 
    1625            1 : string CcuTaskException::GetCcuErrorMsgBufWrite(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1626              : {
    1627            1 :     auto pair = GetAddrPairByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId);
    1628            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
    1629              :     return Hccl::StringFormat(
    1630              :         "InstrId[%u]: Write CcuBuffer[%u] To Rmt Mem[0x%016llx], Len[%llu], "
    1631              :         "sem[%u], mask[0x%04x], remoteRankId[%d], srcEID[%s], dstEID[%s] %s",
    1632            1 :         ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
    1633            1 :         ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId, ccuErrorInfo.msg.bufTransMem.signalMask,
    1634            1 :         GetRankIdByChannelId(ccuErrorInfo.msg.bufTransMem.channelId, taskInfo, deviceId),
    1635            2 :         pair.first.Describe().c_str(),
    1636            4 :         pair.second.Describe().c_str(), printMsg.c_str());
    1637            1 : }
    1638              : 
    1639            1 : string CcuTaskException::GetCcuErrorMsgBufLocRead(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1640              : {
    1641              :     (void)taskInfo;
    1642              :     (void)deviceId;
    1643            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
    1644              :     return Hccl::StringFormat("InstrId[%u]: Read Loc Mem[0x%016llx] To CcuBuffer[%u], Len[%llu], sem[%u], mask[0x%04x] %s",
    1645            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.addr, ccuErrorInfo.msg.bufTransMem.bufId,
    1646            1 :                         ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
    1647            2 :                         ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
    1648            1 : }
    1649              : 
    1650            1 : string CcuTaskException::GetCcuErrorMsgBufLocWrite(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1651              : {
    1652              :     (void)taskInfo;
    1653              :     (void)deviceId;
    1654            1 :     string printMsg = GetCcuLenErrorMsg(ccuErrorInfo.msg.bufTransMem.len);
    1655              :     return Hccl::StringFormat("InstrId[%u]: Write CcuBuffer[%u] To Loc Mem[0x%016llx], Len[%llu], sem[%u], mask[0x%04x] %s",
    1656            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.bufTransMem.bufId, ccuErrorInfo.msg.bufTransMem.addr,
    1657            1 :                         ccuErrorInfo.msg.bufTransMem.len, ccuErrorInfo.msg.bufTransMem.signalId,
    1658            2 :                         ccuErrorInfo.msg.bufTransMem.signalMask, printMsg.c_str());
    1659            1 : }
    1660              : 
    1661            1 : string CcuTaskException::GetCcuErrorMsgBufReduce(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1662              : {
    1663              :     (void)taskInfo;
    1664              :     (void)deviceId;
    1665            1 :     stringstream buffIds;
    1666            9 :     for (uint32_t i = 0; i < BUF_REDUCE_ID_SIZE; ++i) {
    1667            8 :         const auto buffId = ccuErrorInfo.msg.bufReduce.bufIds[i];
    1668            8 :         if (buffId == UINT16_MAX) {
    1669            0 :             break;
    1670              :         }
    1671            8 :         if (i != 0) {
    1672            7 :             buffIds << ", ";
    1673              :         }
    1674            8 :         buffIds << to_string(buffId);
    1675              :     }
    1676              : 
    1677              :     return Hccl::StringFormat("InstrId[%u]: Buffer Reduce count[%u], dataType[%u], outputDataType[%u], opType[%u], "
    1678              :                         "sem[%u], mask[0x%04x], CcuBuffers[%s]",
    1679            1 :                         ccuErrorInfo.instrId, ccuErrorInfo.msg.bufReduce.count, ccuErrorInfo.msg.bufReduce.dataType,
    1680            1 :                         ccuErrorInfo.msg.bufReduce.outputDataType, ccuErrorInfo.msg.bufReduce.opType,
    1681            1 :                         ccuErrorInfo.msg.bufReduce.signalId, ccuErrorInfo.msg.bufReduce.signalMask,
    1682            2 :                         buffIds.str().c_str());
    1683            1 : }
    1684              : 
    1685            2 : string CcuTaskException::GetCcuErrorMsgDefault(const CcuErrorInfo &ccuErrorInfo)
    1686              : {
    1687              :     return Hccl::StringFormat("InstrId[%u]: CcuErrorType[%s]",
    1688            2 :         ccuErrorInfo.instrId, ccuErrorInfo.type.Describe().c_str());
    1689              : }
    1690              : 
    1691            2 : string CcuTaskException::GetCcuErrorMsgMission(const CcuErrorInfo &ccuErrorInfo)
    1692              : {
    1693              :     return Hccl::StringFormat("InstrId[%u]: dieId[%u], missionId[%u], missionError[%s]",
    1694            2 :         ccuErrorInfo.instrId, ccuErrorInfo.dieId, ccuErrorInfo.missionId,
    1695            2 :         ccuErrorInfo.msg.mission.missionError);
    1696              : }
    1697              : 
    1698            0 : HcclResult CcuTaskException::GetCcuChannelHandleById(u16 channelId, u64& channelHandle)
    1699              : {
    1700            0 :     std::lock_guard<std::mutex> lock(g_channelMapMutex);
    1701            0 :     auto it = g_channelIdToHandle.find(channelId);
    1702            0 :     if (it == g_channelIdToHandle.end()) {
    1703            0 :         HCCL_ERROR("[%s]channelId[%u] not found", __func__, channelId);
    1704            0 :         for (auto info : g_channelIdToHandle) {
    1705            0 :             HCCL_ERROR("[%s]g_channelIdToHandle[%u]=[0x%llx]", __func__, info.first, info.second);
    1706              :         }
    1707            0 :         return HCCL_E_NOT_FOUND;
    1708              :     }
    1709            0 :     channelHandle = it->second;
    1710            0 :     return HCCL_SUCCESS;
    1711            0 : }
    1712              : 
    1713            8 : RankId CcuTaskException::GetRankIdByChannelId(uint16_t channelId, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1714              : {
    1715            8 :     if (taskInfo.taskParam_.taskType != Hccl::TaskParamType::TASK_CCU) {
    1716            0 :         HCCL_ERROR("[%s]taskType[%s] is not CCU.", __func__, taskInfo.taskParam_.taskType.Describe().c_str());
    1717            0 :         return INVALID_UINT;
    1718              :     }
    1719            8 :     if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
    1720            8 :         HCCL_ERROR("[%s]dfxOpInfo[%p] or comm is nullptr.", __func__, taskInfo.dfxOpInfo_);
    1721            8 :         return INVALID_UINT;
    1722              :     }
    1723              : 
    1724            0 :     u64 channelHandle = INVALID_U64;
    1725            0 :     if (GetCcuChannelHandleById(channelId, channelHandle) != HCCL_SUCCESS) {
    1726            0 :         HCCL_ERROR("[%s]GetCcuChannelHandleById fail, deviceId[%u], channelId[%u], channelHandle[0x%llx]",
    1727              :             __func__, deviceId, channelId, channelHandle);
    1728            0 :         return INVALID_UINT;
    1729              :     }
    1730              : 
    1731            0 :     hccl::CollComm *collComm = static_cast<hccl::CollComm*>(taskInfo.dfxOpInfo_->comm_);
    1732            0 :     u32 remoteRank = INVALID_UINT;
    1733            0 :     if (hccl::HcclCommDfx::GetChannelRemoteRankId(collComm->GetCommId(), channelHandle, remoteRank) != HCCL_SUCCESS) {
    1734            0 :         HCCL_ERROR("[%s]GetChannelRemoteRankId fail, channelHandle[0x%llx], commId[%s]",
    1735              :             __func__, channelHandle, collComm->GetCommId().c_str());
    1736            0 :         return INVALID_UINT;
    1737              :     }
    1738              : 
    1739            0 :     HCCL_INFO("[%s]channelId[%u], deviceId[%u], channelHandle[0x%llx], commId[%s], remoteRank[%u]",
    1740              :         __func__, channelId, deviceId, channelHandle, collComm->GetCommId().c_str(), remoteRank);
    1741            0 :     return remoteRank;
    1742              : }
    1743              : 
    1744            5 : std::pair<Hccl::IpAddress, Hccl::IpAddress> CcuTaskException::GetAddrPairByChannelId(uint16_t channelId,
    1745              :     const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1746              : {
    1747            5 :     std::pair<Hccl::IpAddress, Hccl::IpAddress> dummy = {Hccl::IpAddress(), Hccl::IpAddress()};
    1748            5 :     if (taskInfo.taskParam_.taskType != Hccl::TaskParamType::TASK_CCU) {
    1749            0 :         HCCL_ERROR("[TaskException][%s]Get AddrPair failed, task type error[%s]", __func__,
    1750              :                    taskInfo.taskParam_.Describe().c_str());
    1751            0 :         return dummy;
    1752              :     }
    1753            5 :     if (taskInfo.dfxOpInfo_ == nullptr || taskInfo.dfxOpInfo_->comm_ == nullptr) {
    1754            5 :         HCCL_ERROR("[TaskException][%s]Get AddrPair failed, communicator is nullptr.", __func__);
    1755            5 :         return dummy;
    1756              :     }
    1757              : 
    1758            0 :     u64 channelHandle = INVALID_U64;
    1759            0 :     if (GetCcuChannelHandleById(channelId, channelHandle) != HCCL_SUCCESS) {
    1760            0 :         HCCL_ERROR("[%s]GetCcuChannelHandleById fail, deviceId[%u], channelId[%u], channelHandle[0x%llx]",
    1761              :             __func__, deviceId, channelId, channelHandle);
    1762            0 :         return dummy;
    1763              :     }
    1764              : 
    1765            0 :     void *channelPtr{nullptr};
    1766            0 :     HcclResult ret = static_cast<HcclResult>(HcommChannelGet(channelHandle, &channelPtr));
    1767            0 :     if (ret != HCCL_SUCCESS || channelPtr == nullptr) {
    1768            0 :         HCCL_ERROR("[%s]HcommChannelGet failed, ret[%d], channelHandle[0x%llx], channelPtr[%p]",
    1769              :             __func__, ret, channelHandle, channelPtr);
    1770            0 :         return dummy;
    1771              :     }
    1772            0 :     auto *channelImpl = dynamic_cast<CcuUrmaChannel *>(static_cast<Channel *>(channelPtr));
    1773              : 
    1774              :     // 获取locAddr
    1775            0 :     EndpointHandle locEndPointHandle = channelImpl->GetlocEndPointHandle();
    1776            0 :     void *endpoint{nullptr};
    1777            0 :     ret = static_cast<HcclResult>(HcommEndpointGet(locEndPointHandle, &endpoint));
    1778            0 :     if (ret != HCCL_SUCCESS || endpoint == nullptr) {
    1779            0 :         HCCL_ERROR("[%s]HcommEndpointGet failed, ret[%d], locEndPointHandle[%p], endpoint[%p], channelId[%u]",
    1780              :             __func__, ret, locEndPointHandle, endpoint, channelId);
    1781            0 :         return dummy;
    1782              :     }
    1783            0 :     UrmaEndpoint *ccuEndpoint = dynamic_cast<UrmaEndpoint *>(static_cast<Endpoint *>(endpoint));
    1784            0 :     const EndpointDesc &locEndpointDesc = ccuEndpoint->GetEndpointDesc();
    1785            0 :     HcclResult locRet = CommAddrToIpAddress(locEndpointDesc.commAddr, dummy.first);
    1786              : 
    1787              :     // 获取remoteAddr
    1788            0 :     HcommChannelDesc remoteChannelDesc = channelImpl->GetChannelDesc();
    1789            0 :     HcclResult remRet = CommAddrToIpAddress(remoteChannelDesc.remoteEndpoint.commAddr, dummy.second);
    1790            0 :     HCCL_INFO("[%s]channelId[%u], channelHandle[0x%llx], locRet[%d], locIpAddr[%s], remRet[%d], remIpAddr[%s]",
    1791              :         __func__, channelId, channelHandle, locRet, dummy.first.Describe().c_str(),
    1792              :         remRet, dummy.second.Describe().c_str());
    1793            0 :     return dummy;
    1794              : }
    1795              : 
    1796            2 : string CcuTaskException::GetCcuErrorMsgByType(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId)
    1797              : {
    1798            2 :     if (ccuErrorInfo.type == CcuErrorType::MISSION) {
    1799            1 :         return GetCcuErrorMsgMission(ccuErrorInfo);
    1800              :     }
    1801              : 
    1802              :     using GetCcuErrorMsgFunc = string (*)(const CcuErrorInfo &ccuErrorInfo, const Hccl::TaskInfo &taskInfo, u32 deviceId);
    1803              :     static const map<CcuRep::CcuRepType, GetCcuErrorMsgFunc> HANDLER_MAP {
    1804              :         {CcuRep::CcuRepType::LOOP, &CcuTaskException::GetCcuErrorMsgLoop},
    1805              :         {CcuRep::CcuRepType::LOOPGROUP, &CcuTaskException::GetCcuErrorMsgLoopGroup},
    1806              :         {CcuRep::CcuRepType::LOC_RECORD_EVENT, &CcuTaskException::GetCcuErrorMsgLocPostSem},
    1807              :         {CcuRep::CcuRepType::LOC_WAIT_EVENT, &CcuTaskException::GetCcuErrorMsgLocWaitEvent},
    1808              :         {CcuRep::CcuRepType::LOC_WAIT_NOTIFY, &CcuTaskException::GetCcuErrorMsgLocWaitNotify},
    1809              :         {CcuRep::CcuRepType::REM_POST_SEM, &CcuTaskException::GetCcuErrorMsgRemPostSem},
    1810              :         {CcuRep::CcuRepType::REM_WAIT_SEM, &CcuTaskException::GetCcuErrorMsgRemWaitSem},
    1811              :         {CcuRep::CcuRepType::REM_POST_VAR, &CcuTaskException::GetCcuErrorMsgRemPostVar},
    1812              :         {CcuRep::CcuRepType::RECORD_SHARED_NOTIFY, &CcuTaskException::GetCcuErrorMsgPostSharedSem},
    1813              :         {CcuRep::CcuRepType::READ, &CcuTaskException::GetCcuErrorMsgRead},
    1814              :         {CcuRep::CcuRepType::WRITE, &CcuTaskException::GetCcuErrorMsgWrite},
    1815              :         {CcuRep::CcuRepType::LOCAL_CPY, &CcuTaskException::GetCcuErrorMsgLocalCpy},
    1816              :         {CcuRep::CcuRepType::LOCAL_REDUCE, &CcuTaskException::GetCcuErrorMsgLocalReduce},
    1817              :         {CcuRep::CcuRepType::BUF_READ, &CcuTaskException::GetCcuErrorMsgBufRead},
    1818              :         {CcuRep::CcuRepType::BUF_WRITE, &CcuTaskException::GetCcuErrorMsgBufWrite},
    1819              :         {CcuRep::CcuRepType::BUF_LOC_READ, &CcuTaskException::GetCcuErrorMsgBufLocRead},
    1820              :         {CcuRep::CcuRepType::BUF_LOC_WRITE, &CcuTaskException::GetCcuErrorMsgBufLocWrite},
    1821              :         {CcuRep::CcuRepType::BUF_REDUCE, &CcuTaskException::GetCcuErrorMsgBufReduce}
    1822            3 :     };
    1823              : 
    1824            1 :     const auto funcIt = HANDLER_MAP.find(ccuErrorInfo.repType);
    1825            1 :     if (funcIt == HANDLER_MAP.end()) {
    1826            1 :         return GetCcuErrorMsgDefault(ccuErrorInfo);
    1827              :     } else {
    1828            0 :         return funcIt->second(ccuErrorInfo, taskInfo, deviceId);
    1829              :     }
    1830              : }
    1831              : }
        

Generated by: LCOV version 2.0-1