LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/loop - ccu_rep_loop.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 79.6 % 49 39
Test Date: 2026-07-28 12:11:00 Functions: 87.5 % 8 7

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) Huawei Technologies Co., Ltd. 2024-2024. All rights reserved.
       3              :  * Description: ccu representation implementation file
       4              :  * Author: sunzhepeng
       5              :  * Create: 2024-06-17
       6              :  */
       7              : 
       8              : #include "ccu_rep_v1.h"
       9              : #include <climits>
      10              : 
      11              : #include "exception_util.h"
      12              : #include "ccu_api_exception.h"
      13              : #include "ccu_ins_generater_base.h"
      14              : #include "ccu_ins_generater_v1.h"
      15              : 
      16              : namespace hcomm {
      17              : namespace CcuRep {
      18              : 
      19              : using namespace Hccl;
      20              : 
      21           10 : CcuRepLoop::CcuRepLoop(CcuInsGeneraterBase* insGeneratorPtr, const std::string &label, const Variable &loopParam) :
      22           10 :     insGeneratorPtr_(insGeneratorPtr), label(label), loopParam(loopParam)
      23              : {
      24           10 :     type       = CcuRepType::LOOP;
      25           10 :     instrCount = insGeneratorPtr_->GetInstrCount(type);
      26           10 :     supportCcuV1 = true;
      27           10 : }
      28              : 
      29            0 : CcuRepLoop::CcuRepLoop(CcuInsGeneraterBase* insGeneratorPtr, const std::string &label,
      30            0 :     const Variable &loopParam, const Variable &loopIterNum, const Variable &loopGsaOffset) :
      31            0 :     insGeneratorPtr_(insGeneratorPtr), label(label), loopParam(loopParam), loopIterNum(loopIterNum), loopGsaOffset(loopGsaOffset)
      32              : {
      33            0 :     type       = CcuRepType::LOOP;
      34            0 :     instrCount = insGeneratorPtr_->GetInstrCount(type);
      35            0 :     supportCcuV1 = false;  // loopParam按照A6格式填写,不适用A5
      36            0 : }
      37              : 
      38            5 : void CcuRepLoop::ValidateInsGeneratorForLoop()
      39              : {
      40            5 :     CcuInsGeneraterV1* tmpPtrV1 = dynamic_cast<CcuInsGeneraterV1*>(insGeneratorPtr_);
      41            5 :     if (tmpPtrV1 && !supportCcuV1) {
      42              :         // 在A5场景下没有使用A5的loop调用方式
      43            0 :         Hccl::THROW<Hccl::CcuApiException>("Cannot translate CcuRepLoop for A5 when supportCcuV1 is false!");
      44              :     }
      45            5 : }
      46              : 
      47            1 : const std::string &CcuRepLoop::GetLabel() const
      48              : {
      49            1 :     return label;
      50              : }
      51              : 
      52            5 : void CcuRepLoop::Reference(std::shared_ptr<CcuRepLoopBlock> refRep)
      53              : {
      54            5 :     loopBlock = refRep;
      55            5 : }
      56              : 
      57            1 : std::shared_ptr<CcuRepBase> CcuRepLoop::SetLoopParam(Executor executor, Variable var)
      58              : {
      59            1 :     return std::make_shared<CcuRepSetLoop>(insGeneratorPtr_, loopParam, executor, var);
      60              : }
      61              : 
      62            5 : bool CcuRepLoop::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      63              : {
      64              :     (void)dep;
      65            5 :     ValidateInsGeneratorForLoop();
      66              : 
      67            5 :     this->instrId = instrId;
      68            5 :     translated    = true;
      69              : 
      70            6 :     Hccl::CHECK_NULLPTR(loopBlock, "[CcuRepLoop::Translate] LoopBlock is nullptr!");
      71              : 
      72            4 :     if (!loopBlock->Translated()) {
      73            1 :         Hccl::THROW<Hccl::CcuApiException>("Reference To Invalid LoopBlock");
      74              :     }
      75              : 
      76            3 :     uint16_t startInstrId = loopBlock->StartInstrId();
      77            3 :     uint16_t loopBlockInstrCount = loopBlock->InstrCount();
      78            3 :     if (loopBlockInstrCount == 0) {
      79            1 :         HCCL_ERROR("[CcuRepLoop][Translate] loopBlockInstrCount[%u] is 0, which causes underflow in endInstrId calculation.",
      80              :                     loopBlockInstrCount);
      81            1 :         return false;
      82              :     }
      83            2 :     if (startInstrId > USHRT_MAX - loopBlockInstrCount) {
      84            0 :         HCCL_ERROR("[CcuRepLoop][Translate] startInstrId[%u] + loopBlockInstrCount[%u] exceeds the maximum value of unsigned short int.",
      85              :                     startInstrId, loopBlockInstrCount);
      86            0 :         return false;
      87              :     }
      88              : 
      89            2 :     if (instrId > USHRT_MAX - instrCount) {
      90            1 :         HCCL_ERROR("[CcuRepLoop][Translate] instrId[%u] exceeds the maximum value of unsigned short int.", instrId);
      91            1 :         return false;
      92              :     }
      93              :     
      94            1 :     uint16_t endInstrId = startInstrId + loopBlockInstrCount - 1;
      95              : 
      96            1 :     LoopInstr(instr++, startInstrId, endInstrId, loopParam.Id());
      97              : 
      98              : 
      99            1 :     instrId += instrCount;
     100              : 
     101            1 :     return translated;
     102              : }
     103              : 
     104            1 : std::string CcuRepLoop::Describe()
     105              : {
     106            1 :     return Hccl::StringFormat("Loop reference to [%s]", label.c_str());
     107              : }
     108              : 
     109              : }; // namespace CcuRep
     110              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1