LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_rep_translator.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 83.4 % 247 206
Test Date: 2026-08-18 17:47:01 Functions: 87.0 % 23 20

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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 "ccu_rep_translator_v1.h"
      12              : 
      13              : #include <algorithm>
      14              : 
      15              : #include "exception_util.h"
      16              : #include "ccu_api_exception.h"
      17              : #include "ccu_rep_loopcall_v1.h"
      18              : #include "ccu_rep_funccall_v1.h"
      19              : #include "ccu_rep_type_v1.h"
      20              : #include "ccu_rep_loop_v1.h"
      21              : #include "ccu_rep_loadarg_v1.h"
      22              : #include "ccu_assist_v1.h"
      23              : 
      24              : #include "ccu_dev_mgr_imp.h"
      25              : #include "dtype_common.h"
      26              : 
      27              : #include "ccu_ins_generator_base.h"
      28              : #include "ccu_ins_generator_v1.h"
      29              : #include "ccu_ins_generator_v2.h"
      30              : #include "../../../ccu_device/ccu_res_specs.h"
      31              : 
      32              : #include "unified_platform/pub_inc/config_plf_log.h"
      33              : 
      34              : namespace hcomm {
      35              : namespace CcuRep {
      36              : 
      37              :     using Hccl::PLF_TASK;
      38              : 
      39              :     template <typename T>
      40              :     bool CheckType(const std::shared_ptr<CcuRepBlock>& refer)
      41              :     {
      42              :         if (refer == nullptr) {
      43              :             HCCL_ERROR("[%s] input refer is nullptr", __func__);
      44              :             return false;
      45              :         }
      46              :         HCCL_INFO("[CheckType] refer->Type() = %d", refer->Type());
      47              :         return false;
      48              :     }
      49              : 
      50              :     template <>
      51            5 :     bool CheckType<CcuRepFuncBlock>(const std::shared_ptr<CcuRepBlock>& refer)
      52              :     {
      53            5 :         if (refer == nullptr) {
      54            0 :             HCCL_ERROR("[%s] input refer is nullptr", __func__);
      55            0 :             return false;
      56              :         }
      57            5 :         return refer->Type() == CcuRepType::FUNC_BLOCK ? true : false;
      58              :     }
      59              : 
      60              :     template <>
      61            0 :     bool CheckType<CcuRepLoopBlock>(const std::shared_ptr<CcuRepBlock>& refer)
      62              :     {
      63            0 :         if (refer == nullptr) {
      64            0 :             HCCL_ERROR("[%s] input refer is nullptr", __func__);
      65            0 :             return false;
      66              :         }
      67            0 :         return refer->Type() == CcuRepType::LOOP_BLOCK ? true : false;
      68              :     }
      69              : 
      70              :     template <typename T1, typename T2>
      71            5 :     void CcuRepTranslator::BuildReference(const std::shared_ptr<CcuRepBase>& rep)
      72              :     {
      73            5 :         auto caller = std::static_pointer_cast<T1>(rep);
      74            5 :         auto label = caller->GetLabel();
      75              :         // 特例:针对函数地址调用,不需要依靠函数名索引
      76            5 :         if (label == "") {
      77            0 :             return;
      78              :         }
      79            5 :         auto refer = refManager->GetRefBlock(label);
      80            5 :         if (CheckType<T2>(refer)) {
      81            5 :             caller->Reference(std::static_pointer_cast<T2>(refer));
      82              :         } else {
      83            0 :             Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      84              :         }
      85            5 :     }
      86              : 
      87         2944 :     CcuRepTranslator::CcuRepTranslator(
      88              :         int32_t deviceLogicId, uint8_t dieId, std::shared_ptr<CcuRepReferenceManager> refManager,
      89              :         std::array<uint16_t, CCU_MAX_IODIE_NUM>& reserverChannalId, std::pair<uint64_t, uint64_t>& ccuTokenInfo,
      90         2944 :         uint64_t hbmTokenInfo)
      91        29440 :         : refManager(refManager)
      92              :     {
      93         2944 :         transDep.logicalId = deviceLogicId;
      94         2944 :         transDep.dieId = dieId;
      95         5888 :         s32 result = memcpy_s(
      96         2944 :             transDep.reserveChannalId, sizeof(transDep.reserveChannalId), reserverChannalId.data(),
      97              :             sizeof(reserverChannalId));
      98         2944 :         if (result != 0) {
      99            0 :             Hccl::THROW<Hccl::InternalException>(Hccl::StringFormat(
     100              :                 "[NsRecovery] CcuRepTranslator::CcuRepTranslator: memcpy_s failed, ret = %d", result));
     101              :         }
     102              : 
     103         2944 :         HcclResult ret = CcuDevMgrImp::GetCcuVersion(transDep.logicalId, ccuVersion);
     104         2944 :         if (ret != HcclResult::HCCL_SUCCESS || ccuVersion == CcuVersion::CCU_INVALID) {
     105            0 :             Hccl::THROW<Hccl::CcuApiException>("[CcuRepTranslator] Constructor: Invalid CCU Type!");
     106              :         }
     107              : 
     108              :         // 获取本die的xn起始地址
     109         2944 :         ret = CcuDevMgrImp::GetXnBaseAddr(deviceLogicId, dieId, transDep.xnBaseAddr[dieId]);
     110         2944 :         if (ret != HcclResult::HCCL_SUCCESS) {
     111            0 :             Hccl::THROW<Hccl::CcuApiException>(
     112              :                 "Failed to get xn base address. deviceLogicId = %d, dieId = %u, ret = %d", deviceLogicId, dieId, ret);
     113              :         }
     114              : 
     115              :         // 若另一die使能,在A6场景下获得其xn起始地址
     116         2944 :         uint8_t anotherDieId = dieId == 0 ? 1 : 0;
     117         2944 :         bool anotherDieEnable = false;
     118         2944 :         if (static_cast<HcclResult>(CcuGetDieEnableInfo(deviceLogicId, anotherDieId, anotherDieEnable))
     119         2944 :             != HcclResult::HCCL_SUCCESS) {
     120            0 :             Hccl::THROW<Hccl::CcuApiException>(
     121              :                 "Failed to get CcuGetDieEnableInfo. deviceLogicId = %d, dieId = %u", deviceLogicId, dieId);
     122              :         }
     123         2944 :         if (ccuVersion == CcuVersion::CCU_V2 && anotherDieEnable == true) {
     124          480 :             ret = CcuDevMgrImp::GetXnBaseAddr(deviceLogicId, anotherDieId, transDep.xnBaseAddr[anotherDieId]);
     125          480 :             if (ret != HcclResult::HCCL_SUCCESS) {
     126            0 :                 Hccl::THROW<Hccl::CcuApiException>(
     127              :                     "Failed to get xn base address. deviceLogicId = %d, dieId = %u, "
     128              :                     "ret = %d",
     129              :                     deviceLogicId, anotherDieId, ret);
     130              :             }
     131              :         }
     132              : 
     133         2944 :         transDep.ccuResSpaceTokenInfo = CcuRep::GetToken(ccuTokenInfo.first, ccuTokenInfo.second, 1);
     134              :         // 获取hbm token信息
     135         2944 :         transDep.memTokenInfo = hbmTokenInfo;
     136         2944 :     }
     137              : 
     138            4 :     CcuRepTranslator::CcuRepTranslator(std::shared_ptr<CcuRepReferenceManager> refManager, const TransDep& transDep)
     139            4 :         : refManager(refManager),
     140           40 :           transDep(transDep)
     141              :     {
     142            4 :         HcclResult ret = CcuDevMgrImp::GetCcuVersion(transDep.logicalId, ccuVersion);
     143            4 :         if (ret != HcclResult::HCCL_SUCCESS || ccuVersion == CcuVersion::CCU_INVALID) {
     144            0 :             Hccl::THROW<Hccl::CcuApiException>("[CcuRepTranslator] Constructor: Invalid CCU Type!");
     145              :         }
     146            4 :     }
     147              : 
     148           98 :     uint32_t CcuRepTranslator::GetInstrNum(const int32_t devLogicId)
     149              :     {
     150           98 :         CcuVersion tempCcuVersion = CcuVersion::CCU_INVALID;
     151           98 :         HcclResult ret = CcuDevMgrImp::GetCcuVersion(devLogicId, tempCcuVersion);
     152           98 :         if (ret != HcclResult::HCCL_SUCCESS || tempCcuVersion == CcuVersion::CCU_INVALID) {
     153            0 :             Hccl::THROW<Hccl::CcuApiException>("[CcuRepTranslator] GetInstrNum: Invalid CCU Type!");
     154              :         }
     155              : 
     156           98 :         return tempCcuVersion == CcuVersion::CCU_V1 ?
     157              :                    4 // 4:翻译器翻译过程中额外需要的指令空间大小(插入3条通用操作指令+1条终止指令)
     158              :                    :
     159           98 :                    13; // 13:翻译器翻译过程中额外需要的指令空间大小(插入3条通用操作指令+1条终止指令+9条repJump)
     160              :     }
     161              : 
     162         2944 :     CcuResReq CcuRepTranslator::GetResReq(const int32_t devLogicId, uint8_t dieId)
     163              :     {
     164              :         // 申请离散 xn 资源
     165              :         // 需要申请若干xn、gsa、cke设置为固定值用于通用操作
     166         2944 :         CcuVersion tempCcuVersion = CcuVersion::CCU_INVALID;
     167         2944 :         HcclResult ret = CcuDevMgrImp::GetCcuVersion(devLogicId, tempCcuVersion);
     168         2944 :         if (ret != HcclResult::HCCL_SUCCESS || tempCcuVersion == CcuVersion::CCU_INVALID) {
     169            0 :             Hccl::THROW<Hccl::CcuApiException>("[CcuRepTranslator] GetResReq: Invalid CCU Type!");
     170              :         }
     171              : 
     172         2944 :         CcuResReq resReq;
     173         2944 :         int varNum = XN_NUM;
     174         2944 :         int gsaNum = tempCcuVersion == CcuVersion::CCU_V1 ? GSA_NUM : 0;
     175         2944 :         resReq.xnReq[dieId] = varNum;
     176         2944 :         resReq.gsaReq[dieId] = gsaNum;
     177         2944 :         resReq.ckeReq[dieId] = CKE_NUM;
     178         5888 :         return resReq;
     179              :     }
     180              : 
     181         2944 :     void CcuRepTranslator::GetRes(CcuRepResource& res)
     182              :     {
     183         2944 :         int varNum = XN_NUM;
     184         2944 :         int gsaNum = ccuVersion == CcuVersion::CCU_V1 ? GSA_NUM : 0;
     185        14720 :         for (int i = 0; i < varNum; i++) {
     186        11776 :             res.variable[transDep.dieId].push_back(var[i]);
     187              :         }
     188        10336 :         for (int i = 0; i < gsaNum; i++) {
     189         7392 :             res.address[transDep.dieId].push_back(addr[i]);
     190              :         }
     191         8832 :         for (int i = 0; i < CKE_NUM; i++) {
     192         5888 :             res.completedEvent[transDep.dieId].push_back(signal[i]);
     193              :         }
     194         2944 :     }
     195              : 
     196         1203 :     void CcuRepTranslator::PreProcess(std::shared_ptr<CcuRepBase> rep)
     197              :     {
     198         1203 :         auto repType = rep->Type();
     199         1203 :         if (repType == CcuRepType::FUNC_BLOCK) {
     200            4 :             auto funcBlock = std::static_pointer_cast<CcuRepFuncBlock>(rep);
     201            4 :             refManager->SetRefBlock(funcBlock->GetLabel(), funcBlock);
     202            4 :             funcBlock->SetFuncManager(refManager.get());
     203         1203 :         } else if (repType == CcuRepType::LOOP_BLOCK) {
     204           42 :             auto loopBlock = std::static_pointer_cast<CcuRepLoopBlock>(rep);
     205           42 :             refManager->SetRefBlock(loopBlock->GetLabel(), loopBlock);
     206         1199 :         } else if (repType == CcuRepType::FUNC_CALL) {
     207            5 :             BuildReference<CcuRepFuncCall, CcuRepFuncBlock>(rep);
     208            5 :             auto funcCall = std::static_pointer_cast<CcuRepFuncCall>(rep);
     209            5 :             funcCall->SetFuncManager(refManager.get());
     210         1157 :         } else if (repType == CcuRepType::LOOP_CALL) {
     211            0 :             BuildReference<CcuRepLoopCall, CcuRepLoopBlock>(rep);
     212         1152 :         } else if (repType == CcuRepType::LOOP) {
     213            0 :             BuildReference<CcuRepLoop, CcuRepLoopBlock>(rep);
     214              :         }
     215         1203 :     }
     216              : 
     217          180 :     void CcuRepTranslator::Translate(
     218              :         CcuKernel* ccuKernel, const std::vector<std::shared_ptr<CcuRepBase>>& repVec, CcuInstr*& instr,
     219              :         uint16_t& instrId, std::function<bool(std::shared_ptr<CcuRepBase>)> filter)
     220              :     {
     221          180 :         constexpr uint32_t maxTryCount = 10; // 最大尝试次数10
     222          180 :         uint32_t tryCount = 0;
     223          180 :         uint32_t restCount = 0;
     224              : 
     225          180 :         auto funcInVar = refManager.get()->GetFuncIn();
     226          180 :         int funcArgIndex = 0;
     227              : 
     228              :         do {
     229          200 :             restCount = 0;
     230         4297 :             for (uint32_t index = 0; index < repVec.size(); index++) {
     231         4098 :                 if (!filter(repVec[index])) {
     232         2128 :                     continue;
     233              :                 }
     234              : 
     235         1970 :                 if (repVec[index]->Translated()) {
     236          767 :                     continue;
     237              :                 }
     238              : 
     239         1203 :                 if (repVec[index]->Type() == CcuRepType::LOAD_ARG && transDep.isFuncBlock) {
     240            0 :                     transDep.loadXnId = funcInVar[funcArgIndex++].Id();
     241              :                 }
     242              : 
     243         1203 :                 PreProcess(repVec[index]);
     244         1203 :                 bool flag = repVec[index]->Translate(ccuKernel, instr, instrId, transDep);
     245         1202 :                 if (!flag) {
     246          126 :                     restCount++;
     247              :                 }
     248              :             }
     249          199 :             tryCount++;
     250          199 :             HCCL_INFO("tryCount = %u, remaining representation = %u", tryCount, restCount);
     251          199 :         } while (restCount > 0 && tryCount < maxTryCount);
     252              : 
     253          179 :         if (tryCount == maxTryCount && restCount > 0) {
     254            0 :             HCCL_ERROR(
     255              :                 "After translation, remaining representation: tryCount = %u, restCount = %u ", tryCount, restCount);
     256            0 :             for (uint32_t index = 0; index < repVec.size(); index++) {
     257            0 :                 if (!repVec[index]->Translated()) {
     258            0 :                     HCCL_ERROR("index[%u], %s", index, repVec[index]->Describe().c_str());
     259              :                 }
     260              :             }
     261            0 :             Hccl::THROW<Hccl::CcuApiException>("Translation Failed");
     262              :         }
     263          180 :     }
     264              : 
     265           44 :     CcuInstrInfo CcuRepTranslator::Translate(
     266              :         CcuKernel* ccuKernel, const std::vector<std::shared_ptr<CcuRepBase>>& repVec, uint16_t startInstrId,
     267              :         bool isFuncBlock)
     268              :     {
     269           44 :         constexpr uint32_t defaultInstrCapacity = 32 * 1024; // 默认最大容量32 * 1024条
     270           44 :         CcuInstrInfo instrInfo;
     271           44 :         instrInfo.instrVec.resize(defaultInstrCapacity);
     272           44 :         CcuInstr* instr = instrInfo.instrVec.data();
     273           44 :         uint16_t curInstrId = startInstrId;
     274              : 
     275           44 :         BindResource(isFuncBlock);
     276              : 
     277              :         // 翻译LoopBlock
     278           44 :         Translate(ccuKernel, repVec, instr, curInstrId, [](std::shared_ptr<CcuRepBase> rep) -> bool {
     279         1087 :             return rep->Type() == CcuRepType::LOOP_BLOCK;
     280              :         });
     281              : 
     282              :         // 翻译funcBlock
     283           44 :         Translate(ccuKernel, repVec, instr, curInstrId, [](std::shared_ptr<CcuRepBase> rep) -> bool {
     284         1087 :             return rep->Type() == CcuRepType::FUNC_BLOCK;
     285              :         });
     286              : 
     287           44 :         uint16_t missionStartInstrId = curInstrId;
     288              : 
     289              :         // 翻译Load:按全局 argId 升序排序后再翻译,确保 LoadSqeArgs 指令在 mission 切分时
     290              :         // 落入与其 slot id 匹配的 mission(避免用户乱序 LoadArg 导致取参错位)
     291           44 :         std::vector<std::shared_ptr<CcuRepBase>> sortedLoadArgReps;
     292           44 :         sortedLoadArgReps.reserve(repVec.size());
     293         1131 :         for (const auto& rep : repVec) {
     294         1087 :             if (rep->Type() == CcuRepType::LOAD_ARG) {
     295           47 :                 sortedLoadArgReps.push_back(rep);
     296              :             }
     297              :         }
     298           44 :         std::stable_sort(
     299              :             sortedLoadArgReps.begin(), sortedLoadArgReps.end(),
     300          115 :             [](const std::shared_ptr<CcuRepBase>& a, const std::shared_ptr<CcuRepBase>& b) {
     301          230 :                 return std::static_pointer_cast<CcuRepLoadArg>(a)->GetFullArgId()
     302          115 :                        < std::static_pointer_cast<CcuRepLoadArg>(b)->GetFullArgId();
     303              :             });
     304           44 :         Translate(ccuKernel, sortedLoadArgReps, instr, curInstrId, [](std::shared_ptr<CcuRepBase> rep) -> bool {
     305           47 :             return rep->Type() == CcuRepType::LOAD_ARG;
     306              :         });
     307              : 
     308              :         // 插入通用操作
     309           44 :         CommonProcess(ccuKernel, instr, curInstrId);
     310              : 
     311              :         // 翻译主体
     312           45 :         Translate(ccuKernel, repVec, instr, curInstrId, []([[maybe_unused]] std::shared_ptr<CcuRepBase> rep) -> bool {
     313         1872 :             return true;
     314              :         });
     315              : 
     316           43 :         FinishMainBlock(instr, curInstrId);
     317              : 
     318           43 :         instrInfo.startInstrId = startInstrId;
     319           43 :         instrInfo.instrCount = curInstrId - startInstrId;
     320           43 :         instrInfo.missionStartInstrId = missionStartInstrId;
     321           43 :         instrInfo.missionInstrCount = curInstrId - missionStartInstrId;
     322           43 :         instrInfo.instrVec.resize(instrInfo.instrCount);
     323              : 
     324           43 :         DumpRep(repVec, instrInfo);
     325           43 :         DumpInstruction(instrInfo);
     326              : 
     327           43 :         return instrInfo;
     328           45 :     }
     329              : 
     330           44 :     void CcuRepTranslator::CommonProcess(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId)
     331              :     {
     332           44 :         if (ccuVersion == CcuVersion::CCU_INVALID) {
     333            0 :             Hccl::THROW<Hccl::InternalException>("[CcuRepTranslator] Unexpected ccuVersion[Invalid]");
     334              :         }
     335           44 :         if (ccuVersion == CcuVersion::CCU_V1) {
     336           29 :             LoadImdToXnInstr(instr++, var[0].Id(), 0);
     337           29 :             LoadImdToGSAInstr(instr++, addr[0].Id(), 0);
     338           29 :             SetCKEInstr(instr++, signal[0].Id(), 0xffff, 0, 0, 1);
     339              :         } else {
     340           15 :             CcuV2::AssignI(instr++, var[0].Id(), 0);
     341           15 :             CcuV2::AssignI(instr++, var[XN_NUM - 1].Id(), 0);
     342           15 :             SetCKEInstr(instr++, signal[0].Id(), 0xffff, 0, 0, 1);
     343              :         }
     344              : 
     345              :         // 遍历需要赋值的常量,A5场景下暂为空表
     346           44 :         std::unordered_map<uint64_t, CcuRep::Variable>& constValue2VarMap = ccuKernel->GetConstValue2VarMap();
     347           44 :         u32 constValueNum = constValue2VarMap.size();
     348           47 :         for (auto elem : constValue2VarMap) {
     349            3 :             uint64_t constValue = elem.first;
     350            3 :             CcuRep::Variable curVariable = elem.second;
     351            3 :             if (ccuVersion == CcuVersion::CCU_V1) {
     352            0 :                 LoadImdToXnInstr(instr++, curVariable.Id(), constValue);
     353              :             } else {
     354            3 :                 CcuV2::AssignI(instr++, curVariable.Id(), constValue);
     355              :             }
     356            3 :         }
     357              : 
     358           44 :         u32 instrNum = 3 + constValueNum;
     359           44 :         if (instrId > UINT16_MAX - instrNum) {
     360            0 :             Hccl::THROW<Hccl::InternalException>("integer overflow occurs");
     361              :         }
     362           44 :         instrId += instrNum; // 插入3条指令
     363           44 :     }
     364              : 
     365           43 :     void CcuRepTranslator::FinishMainBlock(CcuInstr*& instr, uint16_t& instrId)
     366              :     {
     367           43 :         if (ccuVersion == CcuVersion::CCU_V1) {
     368           28 :             if (transDep.isFuncBlock) {
     369            0 :                 JumpInstr(instr++, refManager.get()->GetFuncRet(FUNC_NEST_MAX).Id(), transDep.reserveXnId, 1);
     370              :             } else {
     371           28 :                 LoadImdToXnInstr(instr++, var[0].Id(), 0);
     372              :             }
     373           28 :             instrId++;
     374              :         } else {
     375           15 :             if (transDep.isFuncBlock) {
     376            0 :                 CcuV2::RelJmp(
     377            0 :                     instr, refManager.get()->GetFuncRet(FUNC_NEST_MAX).Id(), instrId + V2_RELJMP_INSTR_NUM,
     378            0 :                     transDep.commXn[0], transDep.commXn[1]);
     379            0 :                 instr += V2_RELJMP_INSTR_NUM;
     380            0 :                 CcuV2::Jump(
     381            0 :                     instr++, refManager.get()->GetFuncRet(FUNC_NEST_MAX).Id(), transDep.reserveXnId,
     382            0 :                     transDep.reserveXnId, 0);
     383              :             } else {
     384          165 :                 for (int i = 0; i < V2_FINISH_BLOCK_INSTR_NUM; i++) {
     385          150 :                     HCCL_INFO("FinishMainBlock Add Nop: index[%d], instrId[%d]", i, instrId);
     386          150 :                     CcuV2::Nop(instr++);
     387              :                 }
     388              :             }
     389           15 :             instrId += V2_FINISH_BLOCK_INSTR_NUM;
     390              :         }
     391              : 
     392           43 :         if (instrId > UINT16_MAX - 1) {
     393            0 :             Hccl::THROW<Hccl::InternalException>("integer overflow occurs");
     394              :         }
     395           43 :     }
     396              : 
     397           43 :     void CcuRepTranslator::DumpInstruction(const CcuInstrInfo& instrInfo) const
     398              :     {
     399           43 :         HCCL_INFO(
     400              :             "CcuInstrInfo: startInstrId = %u, instrCount = %u, missionStartInstrId = %u, missionInstrCount = %u",
     401              :             instrInfo.startInstrId, instrInfo.instrCount, instrInfo.missionStartInstrId, instrInfo.missionInstrCount);
     402         2009 :         for (uint16_t index = 0; index < instrInfo.instrVec.size(); index++) {
     403         1966 :             if (ccuVersion == CcuVersion::CCU_V1) {
     404         1241 :                 HCCL_INFO(
     405              :                     "%d: %s", instrInfo.startInstrId + index, ParseInstr(instrInfo.instrVec.data() + index).c_str());
     406              :             } else {
     407          725 :                 HCCL_INFO(
     408              :                     "%d: %s", instrInfo.startInstrId + index,
     409              :                     CcuV2::ParseInstrV2(instrInfo.instrVec.data() + index).c_str());
     410              :             }
     411              :         }
     412           43 :     }
     413              : 
     414           43 :     void CcuRepTranslator::DumpRep(
     415              :         const std::vector<std::shared_ptr<CcuRepBase>>& repVec, const CcuInstrInfo& instrInfo) const
     416              :     {
     417           43 :         PLF_CONFIG_INFO(PLF_TASK, "Translated Ccu Rep:");
     418         1112 :         for (uint32_t index = 0; index < repVec.size(); index++) {
     419         1069 :             uint16_t startInstrId = repVec[index]->StartInstrId();
     420         1069 :             uint32_t sum = static_cast<uint32_t>(startInstrId) + repVec[index]->InstrCount();
     421         1069 :             if (sum > UINT16_MAX) {
     422            0 :                 HCCL_ERROR(
     423              :                     "instrId overflow: startInstrId[%u] + InstrCount[%u] = %u exceeds UINT16_MAX", startInstrId,
     424              :                     repVec[index]->InstrCount(), sum);
     425            0 :                 continue;
     426              :             }
     427         1069 :             uint16_t endInstrId = static_cast<uint16_t>(sum);
     428         1069 :             PLF_CONFIG_INFO(
     429              :                 PLF_TASK, "rep[%u]: %s Instr[%u--%u]", index, repVec[index]->Describe().c_str(), startInstrId,
     430              :                 endInstrId);
     431         2731 :             for (uint16_t instrId = startInstrId; instrId < endInstrId; instrId++) {
     432         1662 :                 if (instrId < instrInfo.startInstrId) {
     433            0 :                     HCCL_ERROR("instrId[%u] less than startInstrId[%u]", instrId, instrInfo.startInstrId);
     434            0 :                     continue;
     435              :                 }
     436         1662 :                 if (ccuVersion == CcuVersion::CCU_V1) {
     437         1135 :                     PLF_CONFIG_INFO(
     438              :                         PLF_TASK, "microcode[%u]: %s", instrId,
     439              :                         ParseInstr(instrInfo.instrVec.data() + (instrId - instrInfo.startInstrId)).c_str());
     440              :                 } else {
     441          527 :                     PLF_CONFIG_INFO(
     442              :                         PLF_TASK, "microcode[%u]: %s", instrId,
     443              :                         CcuV2::ParseInstrV2(instrInfo.instrVec.data() + (instrId - instrInfo.startInstrId)).c_str());
     444              :                 }
     445              :             }
     446              :         }
     447           43 :     }
     448              : 
     449           44 :     void CcuRepTranslator::BindResource(bool isFuncBlock)
     450              :     {
     451              :         // 在V2场景下不会为addr数组申请资源,故reserveGsaId和commGsa中实际填的都是默认值0
     452           44 :         transDep.reserveXnId = var[0].Id();
     453           44 :         transDep.reserveGsaId = addr[0].Id();
     454           44 :         transDep.reserveCkeId = signal[0].Id();
     455          176 :         for (int i = 0; i < XN_NUM - 1; i++) {
     456          132 :             transDep.commXn[i] = var[i + 1].Id();
     457              :         }
     458          132 :         for (int i = 0; i < GSA_NUM - 1; i++) {
     459           88 :             transDep.commGsa[i] = addr[i + 1].Id();
     460              :         }
     461           44 :         transDep.commSignal = signal[1].Id();
     462           44 :         transDep.isFuncBlock = isFuncBlock;
     463           44 :         HCCL_INFO(
     464              :             "TransDep info: logicalId = %d, dieId = %u, reserveXnId = %u, reserveGsaId = %u, reserveCkeId = %u, "
     465              :             "innerDieChannelId = %u, interDieChannelId = %u",
     466              :             transDep.logicalId, transDep.dieId, transDep.reserveXnId, transDep.reserveGsaId, transDep.reserveCkeId,
     467              :             transDep.reserveChannalId[0], transDep.reserveChannalId[1]);
     468           44 :     }
     469              : }; // namespace CcuRep
     470              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1