LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/dfx - ccu_error_handler.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 85.0 % 467 397
Test Date: 2026-08-18 17:47:01 Functions: 96.8 % 31 30

            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 <adapter_error_manager_pub.h>
      12              : #include "ccu_error_handler.h"
      13              : #include "ccu_context_mgr_imp.h"
      14              : #include "orion_adapter_hccp.h"
      15              : #include "orion_adapter_rts.h"
      16              : #include "hccp_tlv_hdc_manager.h"
      17              : 
      18              : namespace Hccl {
      19              : using namespace std;
      20              : using namespace CcuRep;
      21              : constexpr uint8_t CCUM_EXECUTE_ERROR = 0X09;
      22              : constexpr uint8_t CCU_MISSION_TASK_KILLED = 0X02;
      23              : 
      24              : const map<uint8_t, string> MISSION_STATUS_MAP{
      25              :     {0x01, "Unsupported Opcode(0x01)"},      {0x02, "Local Operation Error(0x02)"},
      26              :     {0x03, "Remote Operation Error(0x03)"},  {0x04, "Transaction Retry Counter Exceeded(0x04)"},
      27              :     {0x05, "Transaction ACK Timeout(0x05)"}, {0x06, "Jetty Work Request Flushed(0x06)"},
      28              :     {0x07, "CCUA Alg Task Error(0x07)"},     {0x08, "Memory ECC Error(0x08)"},
      29              :     {0x09, "CCUM Execute Error(0x09)"},      {0x0A, "CCUA Execute Error(0x0A)"},
      30              : };
      31              : 
      32              : const map<uint8_t, map<uint8_t, string>> MISSION_SUB_STATUS_MAP{
      33              :     {0x02,
      34              :      {{0x01, "Local Length Error(0x01)"},
      35              :       {0x02, "Local Access Error(0x02)"},
      36              :       {0x03, "Remote Response Length Error(0x03)"},
      37              :       {0x04, "Local Data Poison(0x04)"}}},
      38              :     {0x03,
      39              :      {{0x01, "Remote Unsupported Request(0x01)"},
      40              :       {0x02, "Remote Access Abort(0x02)"},
      41              :       {0x04, "Remote Data Poison(0x04)"}}},
      42              :     {0x09, {{0x01, "SQE instr and key not match(0x01)"}, {0x02, "CCU Mission Task Killed(0x02)"}}},
      43              :     {0x0A,
      44              :      {{0x01, "EXOKAY(0x01)"},
      45              :       {0x11, "EXOKAY(0x11)"},
      46              :       {0x02, "SLVERR(0x02)"},
      47              :       {0x12, "SLVERR(0x12)"},
      48              :       {0x03, "DECERR(0x03)"},
      49              :       {0x13, "DECERR(0x13)"},
      50              :       {0x04, "Abort(0x04)"},
      51              :       {0x14, "Abort(0x14)"},
      52              :       {0x05, "Write Permission Err(0x05)"},
      53              :       {0x15, "Write Permission Err(0x15)"},
      54              :       {0x06, "Read Permission Err(0x06)"},
      55              :       {0x16, "Read Permission Err(0x16)"},
      56              :       {0x07, "Atomic Permission Err(0x07)"},
      57              :       {0x17, "Atomic Permission Err(0x17)"},
      58              :       {0x08, "Tokenval Err(0x08)"},
      59              :       {0x18, "Tokenval Err(0x18)"},
      60              :       {0x09, "Page Fault(0x09)"},
      61              :       {0x0a, "Page Fault(0x0A)"},
      62              :       {0x0b, "Page Fault(0x0B)"},
      63              :       {0x19, "Page Fault(0x19)"},
      64              :       {0x1a, "Page Fault(0x1A)"},
      65              :       {0x1b, "Page Fault(0x1B)"},
      66              :       {0x0c, "Read Local Mem Poison(0x0C)"}}},
      67              : };
      68              : 
      69            1 : void CcuErrorHandler::GetCcuErrorMsg(
      70              :     int32_t deviceId, uint16_t missionStatus, const ParaCcu& ccuTaskParam, const std::string& groupRankContent,
      71              :     std::vector<CcuErrorInfo>& errorInfo)
      72              : {
      73            1 :     const auto missionContext = GetCcuMissionContext(deviceId, ccuTaskParam.dieId, ccuTaskParam.execMissionId);
      74            1 :     if (missionStatus == 0) {
      75            0 :         HCCL_INFO(
      76              :             "[CcuErrorHandler][%s] no err found, mission status is 0, deviceId[%d], dieId[%u], execMissionId[%u]",
      77              :             __func__, deviceId, static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.execMissionId));
      78            0 :         return;
      79              :     }
      80              : 
      81              :     CcuRepContext* ctx
      82            1 :         = CtxMgrImp::GetInstance(deviceId).GetCtx(ccuTaskParam.executeId, ccuTaskParam.dieId, ccuTaskParam.missionId);
      83            1 :     if (ctx == nullptr) {
      84            1 :         THROW<CcuApiException>(
      85              :             "CcuContext not found, deviceId[%d], dieId[%u], missionId[%u], executeId[%llu]", deviceId,
      86            1 :             static_cast<u32>(ccuTaskParam.dieId), static_cast<u32>(ccuTaskParam.missionId), ccuTaskParam.executeId);
      87              :     }
      88              : 
      89            0 :     const uint16_t currIns = missionContext.GetCurrentIns();
      90              : 
      91            0 :     auto rep = ctx->GetRepByInstrId(currIns);
      92            0 :     auto prevRep = ctx->GetRepByInstrId(currIns - 1);
      93            0 :     if (rep == nullptr) {
      94            0 :         HCCL_WARNING("[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, currIns);
      95            0 :         return;
      96              :     }
      97              : 
      98              :     // 分类处理Rep, 返回异常信息
      99            0 :     ErrorInfoBase baseInfo{deviceId, ccuTaskParam.dieId, ccuTaskParam.missionId, currIns, missionStatus};
     100            0 :     GenStatusInfo(baseInfo, groupRankContent, errorInfo);
     101              : 
     102              :     // 处理Rep为FUNC_BLOCK的场景
     103            0 :     while (rep->Type() == CcuRepType::FUNC_BLOCK) {
     104            0 :         auto blockRep = static_pointer_cast<CcuRepBlock>(rep);
     105            0 :         rep = blockRep->GetRepByInstrId(currIns);
     106            0 :         if (rep == nullptr) {
     107            0 :             THROW<CcuApiException>(
     108            0 :                 "Failed to find REP from FuncBlock, instrId[%u], FuncBlock[%s]", currIns, blockRep->GetLabel().c_str());
     109              :         }
     110            0 :     }
     111              : 
     112            0 :     if ((prevRep != nullptr && prevRep->Type() == CcuRepType::LOOPGROUP) || (rep->Type() == CcuRepType::LOOPGROUP)) {
     113              :         // 处理LoopGroup
     114            0 :         GenErrorInfoLoopGroup(baseInfo, prevRep, *ctx, errorInfo);
     115            0 :     } else if (rep->Type() == CcuRepType::LOC_WAIT_SEM) {
     116            0 :         GenErrorInfoByRepType(baseInfo, rep, errorInfo);
     117            0 :         uint16_t actValue = errorInfo.back().msg.waitSignal.signalValue;
     118            0 :         uint16_t expValue = errorInfo.back().msg.waitSignal.signalMask;
     119            0 :         for (uint16_t i = 0; i < 16; ++i) { // CKE的bit数最多为16
     120            0 :             uint16_t mask = 1 << i;         // 创建一个用于检查第 i 位的掩码
     121            0 :             if ((expValue & mask) != 0 && (actValue & mask) == 0) {
     122            0 :                 auto depRepVec = std::static_pointer_cast<CcuRepLocWaitSem>(rep)->GetDependencyInfo(mask);
     123            0 :                 for (const auto& depRep : depRepVec) {
     124            0 :                     GenErrorInfoByRepType(baseInfo, depRep, errorInfo);
     125              :                 }
     126            0 :             }
     127              :         }
     128              :     } else {
     129              :         // 处理可直接解析的Rep
     130            0 :         GenErrorInfoByRepType(baseInfo, rep, errorInfo);
     131              :     }
     132              : 
     133            0 :     const uint16_t endIns = missionContext.GetEndIns();
     134            0 :     const uint16_t startIns = missionContext.GetStartIns();
     135              :     // 获取异常指令对应的Rep
     136            0 :     HCCL_ERROR(
     137              :         "[CcuErrorHandler]device %d, execMissionId[%u], startIns[%u], endIns[%u], currIns[%u]", deviceId,
     138              :         ccuTaskParam.execMissionId, startIns, endIns, currIns);
     139            0 :     if (endIns == currIns) {
     140            0 :         HCCL_ERROR("[CcuErrorHandler]device %d SQE != CQE, endIns[%u], currIns[%u]", deviceId, endIns, currIns);
     141              :     }
     142              : 
     143              :     // 安全地获取currIns - 10的值
     144            0 :     uint16_t loopUpInstrNum = 10; // 获取出错指令前10条指令
     145            0 :     uint16_t beginIns = (currIns < loopUpInstrNum) ?
     146              :                             startIns :
     147            0 :                             ((currIns - loopUpInstrNum) > startIns ? (currIns - loopUpInstrNum) : startIns);
     148              :     // 打印报错的前10条指令,并且从第一个非空rep开始
     149            0 :     for (uint16_t instrId = currIns - 1; instrId >= beginIns; instrId--) {
     150            0 :         auto rep = ctx->GetRepByInstrId(instrId);
     151            0 :         if (rep == nullptr) {
     152            0 :             beginIns = instrId + 1;
     153            0 :             break;
     154              :         }
     155            0 :     }
     156            0 :     for (uint16_t instrId = beginIns; instrId <= currIns; instrId++) {
     157            0 :         auto rep = ctx->GetRepByInstrId(instrId);
     158            0 :         if (rep == nullptr) {
     159            0 :             HCCL_WARNING(
     160              :                 "[CcuErrorHandler][%s] cannot find REP from current CcuContext, instrId[%u]", __func__, instrId);
     161            0 :             continue;
     162            0 :         }
     163              : 
     164            0 :         GenErrorInfoByRepType(baseInfo, rep, errorInfo);
     165            0 :     }
     166            0 : }
     167              : 
     168            0 : void CcuErrorHandler::GetCcuJettys(int32_t deviceId, const ParaCcu& ccuTaskParam, std::vector<CcuJetty*> ccuJettys)
     169              : {
     170              :     // 获取异常指令对应的Rep
     171              :     CcuContext* ctx
     172            0 :         = CtxMgrImp::GetInstance(deviceId).GetCtx(ccuTaskParam.executeId, ccuTaskParam.dieId, ccuTaskParam.missionId);
     173            0 :     if (ctx == nullptr) {
     174            0 :         THROW<CcuApiException>(
     175              :             "CcuContext not found, deviceId[%d], dieId[%u], missionId[%u], executeId[%llu]", deviceId,
     176            0 :             ccuTaskParam.dieId, ccuTaskParam.missionId, ccuTaskParam.executeId);
     177              :     }
     178              : 
     179            0 :     std::vector<CcuTransport*> ccuTransports = ctx->GetCcuTransports();
     180            0 :     for (auto ccuTransport : ccuTransports) {
     181            0 :         CcuConnection* ccuConn = ccuTransport->GetCcuConnection();
     182            0 :         std::vector<CcuJetty*> ccuJettysOneConn = ccuConn->GetCcuJettys();
     183            0 :         ccuJettys.insert(ccuJettys.end(), ccuJettysOneConn.begin(), ccuJettysOneConn.end());
     184            0 :     }
     185            0 : }
     186              : 
     187            9 : static string StatusCode2Str(uint8_t highPart, uint8_t lowPart)
     188              : {
     189           27 :     HCCL_INFO("Mission Status Code: highPart[0x%02x], lowPart[0x%02x]", highPart, lowPart);
     190            9 :     const auto status = MISSION_STATUS_MAP.find(highPart);
     191            9 :     if (status == MISSION_STATUS_MAP.end()) {
     192            2 :         return "Unknown Status";
     193              :     }
     194            8 :     stringstream result;
     195            8 :     result << status->second;
     196              : 
     197            8 :     const auto lowMap = MISSION_SUB_STATUS_MAP.find(highPart);
     198            8 :     if (lowMap == MISSION_SUB_STATUS_MAP.end()) {
     199            2 :         return result.str();
     200              :     }
     201              : 
     202            6 :     const auto subStatus = lowMap->second.find(lowPart);
     203            7 :     const string subStatusMsg = subStatus == lowMap->second.end() ? "Unknown Status" : subStatus->second;
     204            6 :     result << ", " << subStatusMsg;
     205            6 :     return result.str();
     206            8 : }
     207              : 
     208            9 : void CcuErrorHandler::GenStatusInfo(
     209              :     const ErrorInfoBase& baseInfo, const std::string& groupRankContent, vector<CcuErrorInfo>& errorInfo)
     210              : {
     211            9 :     CcuErrorInfo errorMsg{};
     212            9 :     errorMsg.type = CcuErrorType::MISSION;
     213            9 :     errorMsg.SetBaseInfo(CcuRepType::BASE, baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
     214            9 :     const auto baseInformation = Hccl::StringFormat("dieId[%u], missionId[%u]", baseInfo.dieId, baseInfo.missionId);
     215              :     const auto taskInformation
     216            9 :         = Hccl::StringFormat("currentInsId[%u], status[%u]", baseInfo.currentInsId, baseInfo.status);
     217            9 :     const uint8_t highPart = (baseInfo.status >> 8) & 0xFF; // 高8位
     218            9 :     const uint8_t lowPart = baseInfo.status & 0xFF;         // 低8位
     219            9 :     if (highPart == CCUM_EXECUTE_ERROR && lowPart == CCU_MISSION_TASK_KILLED) {
     220           17 :         RPT_INPUT_ERR(
     221              :             true, "EI0002",
     222              :             std::vector<std::string>({"remote_rankid", "base_information", "task_information", "group_rank_content"}),
     223              :             std::vector<std::string>(
     224              :                 {std::to_string(baseInfo.deviceId), baseInformation.c_str(), taskInformation.c_str(),
     225              :                  groupRankContent.c_str()}));
     226              :     }
     227            9 :     const string statusMsg = StatusCode2Str(highPart, lowPart);
     228              :     const auto sRet
     229            9 :         = strncpy_s(errorMsg.msg.mission.missionError, MISSION_STATUS_MSG_LEN, statusMsg.c_str(), statusMsg.length());
     230            9 :     if (sRet != EOK) {
     231            0 :         HCCL_ERROR("[CcuErrorHandler][%s] strcpy failed, statusMsg: %s.", __func__, statusMsg.c_str());
     232              :     }
     233              : 
     234            9 :     errorInfo.push_back(errorMsg);
     235           11 : }
     236              : 
     237            1 : void CcuErrorHandler::GenErrorInfoLoopGroup(
     238              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, CcuRepContext& ctx, vector<CcuErrorInfo>& errorInfo)
     239              : {
     240            1 :     CcuErrorInfo errorMsg{};
     241            1 :     errorMsg.type = CcuErrorType::LOOP_GROUP;
     242            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     243              : 
     244            1 :     const auto rep = static_pointer_cast<CcuRepLoopGroup>(repBase);
     245            1 :     const auto startLoopInstrId = rep->GetStartLoopInstrId();
     246            1 :     LoopGroupXn loopGroupXn{};
     247            1 :     loopGroupXn.value = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->parallelParam.Id());
     248            1 :     errorMsg.msg.loopGroup.startLoopInsId = startLoopInstrId;
     249            1 :     errorMsg.msg.loopGroup.loopInsCnt = static_cast<uint16_t>(loopGroupXn.loopInsCnt);
     250            1 :     errorMsg.msg.loopGroup.expandOffset = static_cast<uint16_t>(loopGroupXn.expandOffset);
     251            1 :     errorMsg.msg.loopGroup.expandCnt = static_cast<uint16_t>(loopGroupXn.expandCnt);
     252              : 
     253            1 :     errorInfo.push_back(errorMsg);
     254              : 
     255              :     // 处理loop
     256            6 :     for (uint16_t i = 0; i < loopGroupXn.loopInsCnt; ++i) {
     257            5 :         uint16_t loopInsId = startLoopInstrId + i;
     258              :         ErrorInfoBase loopErrInfoBase{
     259            5 :             baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopInsId, baseInfo.status};
     260            5 :         GenErrorInfoLoop(loopErrInfoBase, ctx, errorInfo);
     261              :     }
     262            1 : }
     263              : 
     264            3 : void CcuErrorHandler::GenErrorInfoLoop(
     265              :     const ErrorInfoBase& baseInfo, CcuRepContext& ctx, vector<CcuErrorInfo>& errorInfo)
     266              : {
     267              :     // 找LoopRep
     268            3 :     auto repBase = ctx.GetRepByInstrId(baseInfo.currentInsId);
     269            3 :     if (repBase == nullptr || repBase->Type() != CcuRepType::LOOP) {
     270            1 :         THROW<CcuApiException>("Failed to find Loop REP from CcuContext, instrId[%u]", baseInfo.currentInsId);
     271              :     }
     272            2 :     const auto rep = static_pointer_cast<CcuRepLoop>(repBase);
     273              : 
     274            2 :     CcuErrorInfo errorMsg{};
     275            2 :     errorMsg.type = CcuErrorType::LOOP;
     276            2 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, baseInfo.currentInsId);
     277              : 
     278            2 :     LoopXm loopXm{};
     279            2 :     loopXm.value = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->loopParam.Id());
     280            2 :     const auto ccuLoopContext = GetCcuLoopContext(baseInfo.deviceId, baseInfo.dieId, loopXm.loopCtxId);
     281            2 :     errorMsg.msg.loop.startInstrId = rep->loopBlock->StartInstrId();
     282            2 :     errorMsg.msg.loop.endInstrId = rep->loopBlock->StartInstrId() + rep->loopBlock->InstrCount() - 1;
     283            2 :     errorMsg.msg.loop.loopEngineId = loopXm.loopCtxId;
     284            2 :     errorMsg.msg.loop.loopCnt = static_cast<uint16_t>(loopXm.loopCnt);
     285            2 :     errorMsg.msg.loop.loopCurrentCnt = ccuLoopContext.GetCurrentCnt();
     286            2 :     errorMsg.msg.loop.addrStride = ccuLoopContext.GetAddrStride();
     287              : 
     288            2 :     errorInfo.push_back(errorMsg);
     289              : 
     290              :     // 解析Loop内的异常Rep
     291            3 :     for (uint16_t loopCurrentIns = errorMsg.msg.loop.startInstrId; loopCurrentIns <= errorMsg.msg.loop.endInstrId;
     292              :          loopCurrentIns++) {
     293            2 :         auto inLoopExRep = rep->loopBlock->GetRepByInstrId(loopCurrentIns);
     294            2 :         if (inLoopExRep == nullptr) {
     295            1 :             THROW<CcuApiException>(
     296            1 :                 "Failed to find REP from Loop, instrId[%u], Loop[%s]", loopCurrentIns, rep->GetLabel().c_str());
     297              :         }
     298              :         ErrorInfoBase loopErrBase{
     299            1 :             baseInfo.deviceId, baseInfo.dieId, baseInfo.missionId, loopCurrentIns, baseInfo.status};
     300            1 :         GenErrorInfoByRepType(loopErrBase, inLoopExRep, errorInfo);
     301            2 :     }
     302            4 : }
     303              : 
     304           19 : void CcuErrorHandler::GenErrorInfoByRepType(
     305              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     306              : {
     307              :     using GenErrorInfoFunc
     308              :         = void (*)(const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo);
     309              :     static const map<CcuRepType, GenErrorInfoFunc> handlerMap{
     310              :         // WAIT_SIGNAL
     311              :         {CcuRepType::LOC_POST_SEM, &CcuErrorHandler::GenErrorInfoLocPostSem},
     312              :         {CcuRepType::LOC_WAIT_SEM, &CcuErrorHandler::GenErrorInfoLocWaitSem},
     313              :         {CcuRepType::REM_POST_SEM, &CcuErrorHandler::GenErrorInfoRemPostSem},
     314              :         {CcuRepType::REM_WAIT_SEM, &CcuErrorHandler::GenErrorInfoRemWaitSem},
     315              :         {CcuRepType::REM_POST_VAR, &CcuErrorHandler::GenErrorInfoRemPostVar},
     316              :         {CcuRepType::REM_WAIT_GROUP, &CcuErrorHandler::GenErrorInfoRemWaitGroup},
     317              :         {CcuRepType::POST_SHARED_VAR, &CcuErrorHandler::GenErrorInfoPostSharedVar},
     318              :         {CcuRepType::POST_SHARED_SEM, &CcuErrorHandler::GenErrorInfoPostSharedSem},
     319              :         // TRANS_MEM
     320              :         {CcuRepType::READ, &CcuErrorHandler::GenErrorInfoRead},
     321              :         {CcuRepType::WRITE, &CcuErrorHandler::GenErrorInfoWrite},
     322              :         {CcuRepType::LOCAL_CPY, &CcuErrorHandler::GenErrorInfoLocalCpy},
     323              :         {CcuRepType::LOCAL_REDUCE, &CcuErrorHandler::GenErrorInfoLocalReduce},
     324              :         // BUF_TRANS_MEM
     325              :         {CcuRepType::BUF_READ, &CcuErrorHandler::GenErrorInfoBufRead},
     326              :         {CcuRepType::BUF_WRITE, &CcuErrorHandler::GenErrorInfoBufWrite},
     327              :         {CcuRepType::BUF_LOC_READ, &CcuErrorHandler::GenErrorInfoBufLocRead},
     328              :         {CcuRepType::BUF_LOC_WRITE, &CcuErrorHandler::GenErrorInfoBufLocWrite},
     329              :         // BUF_REDUCE
     330           21 :         {CcuRepType::BUF_REDUCE, &CcuErrorHandler::GenErrorInfoBufReduce}};
     331           19 :     const auto funcIt = handlerMap.find(repBase->Type());
     332           19 :     if (funcIt == handlerMap.end()) {
     333              :         // DEFAULT, chip error
     334            1 :         GenErrorInfoDefault(baseInfo, repBase, errorInfo);
     335              :     } else {
     336           18 :         (funcIt->second)(baseInfo, repBase, errorInfo);
     337              :     }
     338           19 : }
     339              : 
     340            1 : void CcuErrorHandler::GenErrorInfoDefault(
     341              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     342              : {
     343            1 :     CcuErrorInfo errorMsg{};
     344            1 :     errorMsg.type = CcuErrorType::DEFAULT;
     345            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     346            1 :     errorInfo.push_back(errorMsg);
     347            1 : }
     348              : 
     349            2 : void CcuErrorHandler::GenErrorInfoLocPostSem(
     350              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     351              : {
     352            2 :     CcuErrorInfo errorMsg{};
     353            2 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     354            2 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     355              : 
     356            2 :     const auto rep = static_pointer_cast<CcuRepLocPostSem>(repBase);
     357            2 :     errorMsg.msg.waitSignal.signalId = rep->sem.Id();
     358            2 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->sem.Id());
     359            2 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     360              : 
     361            2 :     errorInfo.push_back(errorMsg);
     362            2 : }
     363              : 
     364            1 : void CcuErrorHandler::GenErrorInfoLocWaitSem(
     365              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     366              : {
     367            1 :     CcuErrorInfo errorMsg{};
     368            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     369            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     370              : 
     371            1 :     const auto rep = static_pointer_cast<CcuRepLocWaitSem>(repBase);
     372            1 :     errorMsg.msg.waitSignal.signalId = rep->sem.Id();
     373            1 :     errorMsg.msg.waitSignal.signalValue = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, rep->sem.Id());
     374            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     375              : 
     376            1 :     errorInfo.push_back(errorMsg);
     377            1 : }
     378              : 
     379            1 : void CcuErrorHandler::GenErrorInfoRemPostSem(
     380              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     381              : {
     382            1 :     CcuErrorInfo errorMsg{};
     383            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     384            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     385              : 
     386            1 :     const auto rep = static_pointer_cast<CcuRepRemPostSem>(repBase);
     387            1 :     errorMsg.msg.waitSignal.signalId = rep->transport.GetRmtCntCkeByIndex(rep->semIndex);
     388            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     389            1 :     (void)memset_s(
     390              :         errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     391              :         sizeof(errorMsg.msg.waitSignal.channelId));
     392            1 :     errorMsg.msg.waitSignal.channelId[0] = rep->transport.GetChannelId();
     393              : 
     394            1 :     errorInfo.push_back(errorMsg);
     395            1 : }
     396              : 
     397            1 : void CcuErrorHandler::GenErrorInfoRemWaitSem(
     398              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     399              : {
     400            1 :     CcuErrorInfo errorMsg{};
     401            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     402            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     403              : 
     404            1 :     const auto rep = static_pointer_cast<CcuRepRemWaitSem>(repBase);
     405            1 :     errorMsg.msg.waitSignal.signalId = rep->transport.GetLocCntCkeByIndex(rep->semIndex);
     406              :     errorMsg.msg.waitSignal.signalValue
     407            1 :         = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, errorMsg.msg.waitSignal.signalId);
     408            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     409            1 :     (void)memset_s(
     410              :         errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     411              :         sizeof(errorMsg.msg.waitSignal.channelId));
     412            1 :     errorMsg.msg.waitSignal.channelId[0] = rep->transport.GetChannelId();
     413              : 
     414            1 :     errorInfo.push_back(errorMsg);
     415            1 : }
     416              : 
     417            1 : void CcuErrorHandler::GenErrorInfoRemPostVar(
     418              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     419              : {
     420            1 :     CcuErrorInfo errorMsg{};
     421            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     422            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     423              : 
     424            1 :     const auto rep = static_pointer_cast<CcuRepRemPostVar>(repBase);
     425            1 :     errorMsg.msg.waitSignal.signalId = rep->transport.GetRmtCntCkeByIndex(rep->semIndex);
     426            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     427            1 :     (void)memset_s(
     428              :         errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     429              :         sizeof(errorMsg.msg.waitSignal.channelId));
     430            1 :     errorMsg.msg.waitSignal.channelId[0] = rep->transport.GetChannelId();
     431            1 :     errorMsg.msg.waitSignal.paramId = rep->transport.GetRmtXnByIndex(rep->paramIndex);
     432            1 :     errorMsg.msg.waitSignal.paramValue = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->param.Id());
     433              : 
     434            1 :     errorInfo.push_back(errorMsg);
     435            1 : }
     436              : 
     437            1 : void CcuErrorHandler::GenErrorInfoRemWaitGroup(
     438              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     439              : {
     440            1 :     CcuErrorInfo errorMsg{};
     441            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     442            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     443              : 
     444            1 :     const auto rep = static_pointer_cast<CcuRepWaitGroup>(repBase);
     445            1 :     u32 cntCkeId = 0;
     446            1 :     HcclResult ret = rep->transportGroup.GetCntCkeId(rep->semIndex, cntCkeId);
     447            1 :     if (ret != HcclResult::HCCL_SUCCESS) {
     448              :         string msg = StringFormat(
     449              :             "[GenErrorInfoRemWaitGroup]rt get CntCkeId failed. "
     450              :             "semIndex[%u], cntCkeId[%u] return[%d].",
     451            0 :             rep->semIndex, cntCkeId, ret);
     452            0 :         MACRO_THROW(CcuApiException, msg);
     453            0 :     }
     454            1 :     errorMsg.msg.waitSignal.signalId = cntCkeId;
     455              :     errorMsg.msg.waitSignal.signalValue
     456            1 :         = GetCcuCKEValue(baseInfo.deviceId, baseInfo.dieId, errorMsg.msg.waitSignal.signalId);
     457            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     458            1 :     const vector<CcuTransport*>& transports = rep->transportGroup.GetTransports();
     459            1 :     (void)memset_s(
     460              :         errorMsg.msg.waitSignal.channelId, sizeof(errorMsg.msg.waitSignal.channelId), 0xFF,
     461              :         sizeof(errorMsg.msg.waitSignal.channelId));
     462            4 :     for (uint32_t i = 0; i < transports.size() && i < WAIT_SIGNAL_CHANNEL_SIZE; ++i) {
     463            3 :         errorMsg.msg.waitSignal.channelId[i] = transports[i]->GetChannelId();
     464              :     }
     465              : 
     466            1 :     errorInfo.push_back(errorMsg);
     467            1 : }
     468              : 
     469            1 : void CcuErrorHandler::GenErrorInfoPostSharedVar(
     470              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     471              : {
     472            1 :     CcuErrorInfo errorMsg{};
     473            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     474            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     475              : 
     476            1 :     const auto rep = static_pointer_cast<CcuRepPostSharedVar>(repBase);
     477            1 :     errorMsg.msg.waitSignal.signalId = rep->sem.Id();
     478            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     479            1 :     errorMsg.msg.waitSignal.paramId = rep->dstVar.Id();
     480            1 :     errorMsg.msg.waitSignal.paramValue = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->srcVar.Id());
     481              : 
     482            1 :     errorInfo.push_back(errorMsg);
     483            1 : }
     484              : 
     485            1 : void CcuErrorHandler::GenErrorInfoPostSharedSem(
     486              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     487              : {
     488            1 :     CcuErrorInfo errorMsg{};
     489            1 :     errorMsg.type = CcuErrorType::WAIT_SIGNAL;
     490            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     491              : 
     492            1 :     const auto rep = static_pointer_cast<CcuRepPostSharedSem>(repBase);
     493            1 :     errorMsg.msg.waitSignal.signalId = rep->sem.Id();
     494            1 :     errorMsg.msg.waitSignal.signalMask = rep->mask;
     495              : 
     496            1 :     errorInfo.push_back(errorMsg);
     497            1 : }
     498              : 
     499            1 : void CcuErrorHandler::GenErrorInfoRead(
     500              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     501              : {
     502            1 :     CcuErrorInfo errorMsg{};
     503            1 :     errorMsg.type = CcuErrorType::TRANS_MEM;
     504            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     505              : 
     506            1 :     const auto rep = static_pointer_cast<CcuRepRead>(repBase);
     507            1 :     errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->loc.addr.Id());
     508            1 :     errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->loc.token.Id());
     509            1 :     errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->rem.addr.Id());
     510            1 :     errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->rem.token.Id());
     511            1 :     errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     512            1 :     errorMsg.msg.transMem.signalId = rep->sem.Id();
     513            1 :     errorMsg.msg.transMem.signalMask = rep->mask;
     514            1 :     errorMsg.msg.transMem.channelId = rep->transport.GetChannelId();
     515              : 
     516            1 :     errorInfo.push_back(errorMsg);
     517            1 : }
     518              : 
     519            1 : void CcuErrorHandler::GenErrorInfoWrite(
     520              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     521              : {
     522            1 :     CcuErrorInfo errorMsg{};
     523            1 :     errorMsg.type = CcuErrorType::TRANS_MEM;
     524            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     525              : 
     526            1 :     const auto rep = static_pointer_cast<CcuRepWrite>(repBase);
     527            1 :     errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->loc.addr.Id());
     528            1 :     errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->loc.token.Id());
     529            1 :     errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->rem.addr.Id());
     530            1 :     errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->rem.token.Id());
     531            1 :     errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     532            1 :     errorMsg.msg.transMem.signalId = rep->sem.Id();
     533            1 :     errorMsg.msg.transMem.signalMask = rep->mask;
     534            1 :     errorMsg.msg.transMem.channelId = rep->transport.GetChannelId();
     535              : 
     536            1 :     errorInfo.push_back(errorMsg);
     537            1 : }
     538              : 
     539            1 : void CcuErrorHandler::GenErrorInfoLocalCpy(
     540              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     541              : {
     542            1 :     CcuErrorInfo errorMsg{};
     543            1 :     errorMsg.type = CcuErrorType::TRANS_MEM;
     544            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     545              : 
     546            1 :     const auto rep = static_pointer_cast<CcuRepLocCpy>(repBase);
     547            1 :     errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->src.addr.Id());
     548            1 :     errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->src.token.Id());
     549            1 :     errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.addr.Id());
     550            1 :     errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.token.Id());
     551            1 :     errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     552            1 :     errorMsg.msg.transMem.signalId = rep->sem.Id();
     553            1 :     errorMsg.msg.transMem.signalMask = rep->mask;
     554              : 
     555            1 :     errorInfo.push_back(errorMsg);
     556            1 : }
     557              : 
     558            1 : void CcuErrorHandler::GenErrorInfoLocalReduce(
     559              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     560              : {
     561            1 :     CcuErrorInfo errorMsg{};
     562            1 :     errorMsg.type = CcuErrorType::TRANS_MEM;
     563            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     564              : 
     565            1 :     const auto rep = static_pointer_cast<CcuRepLocCpy>(repBase);
     566            1 :     errorMsg.msg.transMem.locAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->src.addr.Id());
     567            1 :     errorMsg.msg.transMem.locToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->src.token.Id());
     568            1 :     errorMsg.msg.transMem.rmtAddr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.addr.Id());
     569            1 :     errorMsg.msg.transMem.rmtToken = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.token.Id());
     570            1 :     errorMsg.msg.transMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     571            1 :     errorMsg.msg.transMem.signalId = rep->sem.Id();
     572            1 :     errorMsg.msg.transMem.signalMask = rep->mask;
     573            1 :     errorMsg.msg.transMem.opType = rep->opType;
     574            1 :     errorMsg.msg.transMem.dataType = rep->dataType;
     575              : 
     576            1 :     errorInfo.push_back(errorMsg);
     577            1 : }
     578              : 
     579              : /**
     580              :  * @brief Convert a unified (per-device) MSId into a per-die MSId.
     581              :  *
     582              :  * In the instruction format, MSId is encoded in a unified address space for
     583              :  * two dies. The most significant bit (bit 15) is used to encode the DieId,
     584              :  * and the remaining 15 bits represent the per-die MS/buffer identifier.
     585              :  *
     586              :  * When generating error information or human-readable output, the DieId
     587              :  * component must be removed so that the MSId is reported relative to the
     588              :  * current die only.
     589              :  */
     590            8 : inline uint16_t GetMSIdPerDie(uint16_t msId)
     591              : {
     592              :     // Mask off the DieId bit (bit 15, value 0x8000), keeping only the lower
     593              :     // 15 bits that encode the per-die MS/buffer identifier.
     594            8 :     return msId & 0x7fff;
     595              : }
     596              : 
     597            1 : void CcuErrorHandler::GenErrorInfoBufRead(
     598              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     599              : {
     600            1 :     CcuErrorInfo errorMsg{};
     601            1 :     errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
     602            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     603              : 
     604            1 :     const auto rep = static_pointer_cast<CcuRepBufRead>(repBase);
     605            1 :     errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->dst.Id());
     606            1 :     errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->src.addr.Id());
     607            1 :     errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->src.token.Id());
     608            1 :     errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     609            1 :     errorMsg.msg.bufTransMem.signalId = rep->sem.Id();
     610            1 :     errorMsg.msg.bufTransMem.signalMask = rep->mask;
     611            1 :     errorMsg.msg.bufTransMem.channelId = rep->transport.GetChannelId();
     612              : 
     613            1 :     errorInfo.push_back(errorMsg);
     614            1 : }
     615              : 
     616            1 : void CcuErrorHandler::GenErrorInfoBufWrite(
     617              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     618              : {
     619            1 :     CcuErrorInfo errorMsg{};
     620            1 :     errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
     621            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     622              : 
     623            1 :     const auto rep = static_pointer_cast<CcuRepBufWrite>(repBase);
     624            1 :     errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->src.Id());
     625            1 :     errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.addr.Id());
     626            1 :     errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.token.Id());
     627            1 :     errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     628            1 :     errorMsg.msg.bufTransMem.signalId = rep->sem.Id();
     629            1 :     errorMsg.msg.bufTransMem.signalMask = rep->mask;
     630            1 :     errorMsg.msg.bufTransMem.channelId = rep->transport.GetChannelId();
     631              : 
     632            1 :     errorInfo.push_back(errorMsg);
     633            1 : }
     634              : 
     635            1 : void CcuErrorHandler::GenErrorInfoBufLocRead(
     636              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     637              : {
     638            1 :     CcuErrorInfo errorMsg{};
     639            1 :     errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
     640            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     641              : 
     642            1 :     const auto rep = static_pointer_cast<CcuRepBufLocRead>(repBase);
     643            1 :     errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->dst.Id());
     644            1 :     errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->src.addr.Id());
     645            1 :     errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->src.token.Id());
     646            1 :     errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     647            1 :     errorMsg.msg.bufTransMem.signalId = rep->sem.Id();
     648            1 :     errorMsg.msg.bufTransMem.signalMask = rep->mask;
     649              : 
     650            1 :     errorInfo.push_back(errorMsg);
     651            1 : }
     652              : 
     653            1 : void CcuErrorHandler::GenErrorInfoBufLocWrite(
     654              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     655              : {
     656            1 :     CcuErrorInfo errorMsg{};
     657            1 :     errorMsg.type = CcuErrorType::BUF_TRANS_MEM;
     658            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     659              : 
     660            1 :     const auto rep = static_pointer_cast<CcuRepBufLocWrite>(repBase);
     661            1 :     errorMsg.msg.bufTransMem.bufId = GetMSIdPerDie(rep->src.Id());
     662            1 :     errorMsg.msg.bufTransMem.addr = GetCcuGSAValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.addr.Id());
     663            1 :     errorMsg.msg.bufTransMem.token = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->dst.token.Id());
     664            1 :     errorMsg.msg.bufTransMem.len = GetCcuXnValue(baseInfo.deviceId, baseInfo.dieId, rep->len.Id());
     665            1 :     errorMsg.msg.bufTransMem.signalId = rep->sem.Id();
     666            1 :     errorMsg.msg.bufTransMem.signalMask = rep->mask;
     667              : 
     668            1 :     errorInfo.push_back(errorMsg);
     669            1 : }
     670              : 
     671            1 : void CcuErrorHandler::GenErrorInfoBufReduce(
     672              :     const ErrorInfoBase& baseInfo, shared_ptr<CcuRepBase> repBase, vector<CcuErrorInfo>& errorInfo)
     673              : {
     674            1 :     CcuErrorInfo errorMsg{};
     675            1 :     errorMsg.type = CcuErrorType::BUF_REDUCE;
     676            1 :     errorMsg.SetBaseInfo(repBase->Type(), baseInfo.dieId, baseInfo.missionId, repBase->StartInstrId());
     677              : 
     678            1 :     const auto rep = static_pointer_cast<CcuRepBufReduce>(repBase);
     679            1 :     errorMsg.msg.bufReduce.count = rep->count;
     680            1 :     errorMsg.msg.bufReduce.dataType = rep->dataType;
     681            1 :     errorMsg.msg.bufReduce.outputDataType = rep->outputDataType;
     682            1 :     errorMsg.msg.bufReduce.opType = rep->opType;
     683            1 :     errorMsg.msg.bufReduce.signalId = rep->sem.Id();
     684            1 :     errorMsg.msg.bufReduce.signalMask = rep->mask;
     685            1 :     errorMsg.msg.bufReduce.xnIdLength = rep->xnIdLength_.Id();
     686            1 :     const auto& buffs = rep->mem;
     687            1 :     (void)memset_s(
     688              :         errorMsg.msg.bufReduce.bufIds, sizeof(errorMsg.msg.bufReduce.bufIds), 0xFF,
     689              :         sizeof(errorMsg.msg.bufReduce.bufIds));
     690            5 :     for (uint32_t i = 0; i < buffs.size() && i < BUF_REDUCE_ID_SIZE; ++i) {
     691            4 :         errorMsg.msg.bufReduce.bufIds[i] = GetMSIdPerDie(buffs[i].Id());
     692              :     }
     693              : 
     694            1 :     errorInfo.push_back(errorMsg);
     695            1 : }
     696              : 
     697          770 : CcuMissionContext CcuErrorHandler::GetCcuMissionContext(int32_t deviceId, uint32_t dieId, uint32_t missionId)
     698              : {
     699          770 :     auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     700          770 :     CHECK_NULLPTR(
     701         1540 :         tlvHandle, StringFormat("[CcuErrorHandler][%s] tlvHandle is nullptr, deviceId[%d]", __func__, deviceId));
     702              : 
     703          770 :     struct CustomChannelInfoIn inBuff;
     704          770 :     struct CustomChannelInfoOut outBuff;
     705              : 
     706          770 :     inBuff.op = CcuOpcodeType::CCU_U_OP_GET_MISSION_CTX;
     707          770 :     inBuff.data.dataInfo.udieIdx = dieId;
     708          770 :     inBuff.offsetStartIdx = missionId;
     709          770 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个MissionContext
     710          770 :     inBuff.data.dataInfo.dataLen = sizeof(CcuMissionContext) * inBuff.data.dataInfo.dataArraySize;
     711              : 
     712          770 :     HrtRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, &inBuff, &outBuff);
     713              : 
     714          770 :     CcuMissionContext missionCtx{};
     715          770 :     (void)memcpy_s(&missionCtx, sizeof(missionCtx), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     716         1540 :     return missionCtx;
     717              : }
     718              : 
     719            1 : CcuLoopContext CcuErrorHandler::GetCcuLoopContext(int32_t deviceId, uint32_t dieId, uint32_t loopCtxId)
     720              : {
     721            1 :     auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     722            1 :     CHECK_NULLPTR(
     723            2 :         tlvHandle, StringFormat("[CcuErrorHandler][%s] tlvHandle is nullptr, deviceId[%d]", __func__, deviceId));
     724              : 
     725            1 :     struct CustomChannelInfoIn inBuff;
     726            1 :     struct CustomChannelInfoOut outBuff;
     727              : 
     728            1 :     inBuff.op = CcuOpcodeType::CCU_U_OP_GET_LOOP_CTX;
     729            1 :     inBuff.data.dataInfo.udieIdx = dieId;
     730            1 :     inBuff.offsetStartIdx = loopCtxId;
     731            1 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个LoopContext
     732            1 :     inBuff.data.dataInfo.dataLen = sizeof(CcuLoopContext) * inBuff.data.dataInfo.dataArraySize;
     733              : 
     734            1 :     HrtRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, &inBuff, &outBuff);
     735              : 
     736            1 :     CcuLoopContext loopCtx{};
     737            1 :     (void)memcpy_s(&loopCtx, sizeof(loopCtx), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     738            2 :     return loopCtx;
     739              : }
     740              : 
     741            1 : uint64_t CcuErrorHandler::GetCcuXnValue(int32_t deviceId, uint32_t dieId, uint32_t xnId)
     742              : {
     743            1 :     auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     744            1 :     CHECK_NULLPTR(
     745            2 :         tlvHandle, StringFormat("[CcuErrorHandler][%s] tlvHandle is nullptr, deviceId[%d]", __func__, deviceId));
     746              : 
     747            1 :     struct CustomChannelInfoIn inBuff;
     748            1 :     struct CustomChannelInfoOut outBuff;
     749              : 
     750            1 :     inBuff.op = CcuOpcodeType::CCU_U_OP_GET_XN;
     751            1 :     inBuff.data.dataInfo.udieIdx = dieId;
     752            1 :     inBuff.offsetStartIdx = xnId;
     753            1 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个Xn
     754            1 :     inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     755              : 
     756            1 :     HrtRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, &inBuff, &outBuff);
     757              : 
     758            1 :     uint64_t xnVal{0};
     759            1 :     (void)memcpy_s(&xnVal, sizeof(xnVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     760            1 :     return xnVal;
     761              : }
     762              : 
     763            1 : uint64_t CcuErrorHandler::GetCcuGSAValue(int32_t deviceId, uint32_t dieId, uint32_t gsaId)
     764              : {
     765            1 :     auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     766            1 :     CHECK_NULLPTR(
     767            2 :         tlvHandle, StringFormat("[CcuErrorHandler][%s] tlvHandle is nullptr, deviceId[%d]", __func__, deviceId));
     768              : 
     769            1 :     struct CustomChannelInfoIn inBuff;
     770            1 :     struct CustomChannelInfoOut outBuff;
     771              : 
     772            1 :     inBuff.op = CcuOpcodeType::CCU_U_OP_GET_GSA;
     773            1 :     inBuff.data.dataInfo.udieIdx = dieId;
     774            1 :     inBuff.offsetStartIdx = gsaId;
     775            1 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个GSA
     776            1 :     inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     777              : 
     778            1 :     HrtRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, &inBuff, &outBuff);
     779              : 
     780            1 :     uint64_t gsaVal{0};
     781            1 :     (void)memcpy_s(&gsaVal, sizeof(gsaVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     782            1 :     return gsaVal;
     783              : }
     784              : 
     785            1 : uint16_t CcuErrorHandler::GetCcuCKEValue(int32_t deviceId, uint32_t dieId, uint32_t ckeId)
     786              : {
     787            1 :     auto tlvHandle = HccpTlvHdcManager::GetInstance().GetTlvHandle(deviceId);
     788            1 :     CHECK_NULLPTR(
     789            2 :         tlvHandle, StringFormat("[CcuErrorHandler][%s] tlvHandle is nullptr, deviceId[%d]", __func__, deviceId));
     790              : 
     791            1 :     struct CustomChannelInfoIn inBuff;
     792            1 :     struct CustomChannelInfoOut outBuff;
     793              : 
     794            1 :     inBuff.op = CcuOpcodeType::CCU_U_OP_GET_CKE;
     795            1 :     inBuff.data.dataInfo.udieIdx = dieId;
     796            1 :     inBuff.offsetStartIdx = ckeId;
     797            1 :     inBuff.data.dataInfo.dataArraySize = 1; // 读1个CKE
     798            1 :     inBuff.data.dataInfo.dataLen = sizeof(uint64_t) * inBuff.data.dataInfo.dataArraySize;
     799              : 
     800            1 :     HrtRaTlvRequestForCustomChannel(tlvHandle, MSG_TYPE_CCU_DISPATCH_CMD, &inBuff, &outBuff);
     801              : 
     802            1 :     uint64_t ckeVal{0};
     803            1 :     (void)memcpy_s(&ckeVal, sizeof(ckeVal), outBuff.data.dataInfo.dataArray, inBuff.data.dataInfo.dataLen);
     804            1 :     return static_cast<uint16_t>(ckeVal);
     805              : }
     806              : 
     807              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1