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

Generated by: LCOV version 2.0-1