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: 48.7 % 1030 502
Test Date: 2026-08-18 17:47:01 Functions: 64.0 % 89 57

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

Generated by: LCOV version 2.0-1