LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/loop - ccu_rep_loopcall.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.6 % 62 50
Test Date: 2026-08-04 10:52:23 Functions: 90.0 % 10 9

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

Generated by: LCOV version 2.0-1