LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/loop - ccu_rep_loopgroup_bundle.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.6 % 37 35
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 8 8

            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_loopgroup_bundle_v1.h"
      12              : #include "ccu_ins_generator_base.h"
      13              : #include "ccu_api_exception.h"
      14              : #include "exception_util.h"
      15              : #include "string_util.h"
      16              : 
      17              : namespace hcomm {
      18              : namespace CcuRep {
      19              : 
      20              : using namespace Hccl;
      21              : 
      22           18 : CcuRepLoopGroupBundle::CcuRepLoopGroupBundle(CcuInsGeneratorBase* insGenPtr, const CcuLoopGroupCfg &config,
      23           18 :                                              const Variable &parallelVar, const Variable &offsetVar)
      24           18 :     : insGenPtr_(insGenPtr), config_(config), parallelVar_(parallelVar), offsetVar_(offsetVar)
      25              : {
      26           18 :     type = CcuRepType::LOOPGROUP;
      27           18 : }
      28              : 
      29           15 : CcuRepLoopGroupBundle::CcuRepLoopGroupBundle(CcuInsGeneratorBase* insGenPtr,
      30           15 :                                              const Variable &parallelVar, const Variable &offsetVar)
      31           15 :     : insGenPtr_(insGenPtr), parallelVar_(parallelVar), offsetVar_(offsetVar), layout_(Layout::PackedVar)
      32              : {
      33           15 :     type = CcuRepType::LOOPGROUP;
      34           15 : }
      35              : 
      36           58 : void CcuRepLoopGroupBundle::AddLoop(const LoopEntry &entry)
      37              : {
      38           58 :     loops_.push_back(entry);
      39           58 : }
      40              : 
      41            1 : uint16_t CcuRepLoopGroupBundle::LoopGroupInstrOffsetInBundle() const
      42              : {
      43            1 :     uint16_t loopCount = static_cast<uint16_t>(loops_.size());
      44            1 :     uint16_t varBasedLoopCount = 0;
      45            2 :     for (const auto &loop : loops_) {
      46            1 :         if (loop.layout != Layout::Config) {
      47            0 :             varBasedLoopCount++;
      48              :         }
      49              :     }
      50            1 :     return (loopCount - varBasedLoopCount)
      51            1 :          + (varBasedLoopCount * 2)
      52            1 :          + (layout_ != Layout::Config ? 0 : 2);
      53              : }
      54              : 
      55            1 : uint16_t CcuRepLoopGroupBundle::GetStartLoopInstrId() const
      56              : {
      57            1 :     return instrId + LoopGroupInstrOffsetInBundle() + 3;
      58              : }
      59              : 
      60           82 : uint16_t CcuRepLoopGroupBundle::InstrCount()
      61              : {
      62           82 :     instrCount = insGenPtr_->CcuRepLoopGroupBundleInstrCount(this);
      63           82 :     return instrCount;
      64              : }
      65              : 
      66           29 : bool CcuRepLoopGroupBundle::Translate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      67              : {
      68           86 :     for (const auto &loop : loops_) {
      69           57 :         if (!loop.repLoopBlock->Translated()) {
      70            0 :             return false;
      71              :         }
      72              :     }
      73              : 
      74           29 :     this->instrId = instrId;
      75           29 :     translated = true;
      76              : 
      77           29 :     CHK_RET_THROW(Hccl::CcuApiException,
      78              :         Hccl::StringFormat("[CcuRepLoopGroupBundle][%s] failed to translate for instrId[%u]", __func__, instrId),
      79              :             insGenPtr_->CcuRepLoopGroupBundleTranslate(ccuKernel, instr, instrId, this, dep));
      80              : 
      81           29 :     return translated;
      82              : }
      83              : 
      84           28 : std::string CcuRepLoopGroupBundle::Describe()
      85              : {
      86              :     return Hccl::StringFormat("LoopGroupBundle[loops=%zu, totalLoopNum=%lu]",
      87           28 :                               loops_.size(), totalLoopNum_);
      88              : }
      89              : 
      90              : }; // namespace CcuRep
      91              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1