LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/loop - ccu_rep_loopcall.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.3 % 59 58
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 14 14

            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_v1.h"
      12              : 
      13              : #include "string_util.h"
      14              : #include "exception_util.h"
      15              : #include "ccu_api_exception.h"
      16              : #include "ccu_ins_generator_base.h"
      17              : #include "ccu_kernel.h"
      18              : 
      19              : namespace hcomm {
      20              : namespace CcuRep {
      21              : 
      22              :     using namespace Hccl;
      23              : 
      24           12 :     CcuRepLoopCall::CcuRepLoopCall(CcuInsGeneratorBase* insGeneratorPtr, const std::string& label)
      25           12 :         : insGeneratorPtr_(insGeneratorPtr),
      26           12 :           label(label)
      27              :     {
      28           12 :         type = CcuRepType::LOOP_CALL;
      29           12 :     }
      30              : 
      31            2 :     const std::string& CcuRepLoopCall::GetLabel() const { return label; }
      32              : 
      33            2 :     void CcuRepLoopCall::Reference(std::shared_ptr<CcuRepLoopBlock> refRep) { loopBlock = refRep; }
      34              : 
      35            2 :     void CcuRepLoopCall::SetInArg(const Variable& var)
      36              :     {
      37            2 :         inArgCount++;
      38            2 :         inArgInstrCount++;
      39            2 :         inArgs.push_back(CcuRepArg(var));
      40            2 :     }
      41              : 
      42            1 :     void CcuRepLoopCall::SetInArg(const std::vector<Variable>& varList)
      43              :     {
      44            1 :         inArgCount += varList.size();
      45            1 :         inArgInstrCount += varList.size();
      46            1 :         inArgs.push_back(CcuRepArg(varList));
      47            1 :     }
      48              : 
      49            1 :     void CcuRepLoopCall::SetInArg(const Memory& mem)
      50              :     {
      51            1 :         inArgCount++;
      52            1 :         inArgInstrCount += 2; // 传递Memory需要2条指令
      53            1 :         inArgs.push_back(CcuRepArg(mem));
      54            1 :     }
      55              : 
      56            1 :     void CcuRepLoopCall::SetInArg(const std::vector<Memory>& memList)
      57              :     {
      58            1 :         inArgCount += memList.size();
      59            1 :         inArgInstrCount += memList.size() * 2; // 传递Memory需要2条指令
      60            1 :         inArgs.push_back(CcuRepArg(memList));
      61            1 :     }
      62              : 
      63              :     /*【新增】*/
      64            2 :     void CcuRepLoopCall::SetInArg(const LocalAddr& addr)
      65              :     {
      66            2 :         inArgCount++;
      67            2 :         inArgInstrCount += 2; // 传递LocalAddr需要2条指令
      68            2 :         inArgs.push_back(CcuRepArg(addr));
      69            2 :     }
      70              : 
      71            1 :     void CcuRepLoopCall::SetInArg(const std::vector<LocalAddr>& addrList)
      72              :     {
      73            1 :         inArgCount += addrList.size();
      74            1 :         inArgInstrCount += addrList.size() * 2; // 传递LocalAddr需要2条指令
      75            1 :         inArgs.push_back(CcuRepArg(addrList));
      76            1 :     }
      77              : 
      78            1 :     void CcuRepLoopCall::SetInArg(const RemoteAddr& addr)
      79              :     {
      80            1 :         inArgCount++;
      81            1 :         inArgInstrCount += 2; // 传递RemoteAddr需要2条指令
      82            1 :         inArgs.push_back(CcuRepArg(addr));
      83            1 :     }
      84              : 
      85            1 :     void CcuRepLoopCall::SetInArg(const std::vector<RemoteAddr>& addrList)
      86              :     {
      87            1 :         inArgCount += addrList.size();
      88            1 :         inArgInstrCount += addrList.size() * 2; // 传递RemoteAddr需要2条指令
      89            1 :         inArgs.push_back(CcuRepArg(addrList));
      90            1 :     }
      91              : 
      92            9 :     uint16_t CcuRepLoopCall::InstrCount()
      93              :     {
      94            9 :         instrCount = inArgInstrCount;
      95            9 :         return instrCount;
      96              :     }
      97              : 
      98            1 :     bool CcuRepLoopCall::Translate(
      99              :         [[maybe_unused]] CcuKernel* ccuKernel, [[maybe_unused]] CcuInstr*& instr, uint16_t& instrId,
     100              :         [[maybe_unused]] const TransDep& dep)
     101              :     {
     102            1 :         this->instrId = instrId;
     103            1 :         translated = true;
     104              : 
     105            1 :         Hccl::CHECK_NULLPTR(loopBlock, "[CcuRepLoopCall::Translate] LoopBlock is nullptr!");
     106              : 
     107            1 :         if (!loopBlock->Translated()) {
     108            0 :             Hccl::THROW<Hccl::CcuApiException>("Reference To Invalid LoopBlock");
     109              :         }
     110              : 
     111            1 :         instrId += InstrCount();
     112              : 
     113            1 :         return translated;
     114              :     }
     115              : 
     116            1 :     std::string CcuRepLoopCall::Describe() { return Hccl::StringFormat("LoopCall[%s]", label.c_str()); }
     117              : 
     118              : }; // namespace CcuRep
     119              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1