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

Generated by: LCOV version 2.0-1