LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/data - ccu_rep_loccpy.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.8 % 59 40
Test Date: 2026-08-18 17:47:01 Functions: 62.5 % 8 5

            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              : #include "string_util.h"
      13              : #include "ccu_ins_generator_v1.h"
      14              : #include "ccu_ins_generator_base.h"
      15              : #include "ccu_kernel.h"
      16              : 
      17              : #include "ccu_api_exception.h"
      18              : 
      19              : namespace hcomm {
      20              : namespace CcuRep {
      21              : 
      22            4 :     CcuRepLocCpy::CcuRepLocCpy(
      23            4 :         CcuInsGeneratorBase* insGenPtr, LocalAddr dst, LocalAddr src, Variable len, CompletedEvent sem, uint16_t mask)
      24            4 :         : insGenPtr(insGenPtr),
      25            4 :           dst(dst),
      26            4 :           src(src),
      27            4 :           len(len),
      28            4 :           sem(sem),
      29            8 :           mask(mask)
      30              :     {
      31            4 :         type = CcuRepType::LOCAL_CPY;
      32            4 :         instrCount = insGenPtr->GetInstrCount(type);
      33            4 :         useCcuBuffer = false;
      34            4 :     }
      35              : 
      36            2 :     CcuRepLocCpy::CcuRepLocCpy(
      37              :         CcuInsGeneratorBase* insGenPtr, LocalAddr dst, LocalAddr src, Variable len, uint16_t dataType, uint16_t opType,
      38            2 :         CompletedEvent sem, uint16_t mask)
      39            2 :         : insGenPtr(insGenPtr),
      40            2 :           dst(dst),
      41            2 :           src(src),
      42            2 :           len(len),
      43            2 :           sem(sem),
      44            2 :           mask(mask),
      45            2 :           dataType(dataType),
      46            4 :           opType(opType)
      47              :     {
      48            2 :         type = CcuRepType::LOCAL_REDUCE;
      49            2 :         instrCount = insGenPtr->GetInstrCount(type);
      50            2 :         reduceFlag = 1;
      51              :         // A5和A6都走环回
      52            2 :         useCcuBuffer = false;
      53            2 :     }
      54              : 
      55            0 :     CcuRepLocCpy::CcuRepLocCpy(
      56              :         CcuInsGeneratorBase* insGenPtr, LocalAddr dst, LocalAddr src, Variable len, const std::vector<CcuBuf>& bufs,
      57            0 :         CompletedEvent sem, uint16_t mask)
      58            0 :         : insGenPtr(insGenPtr),
      59            0 :           dst(dst),
      60            0 :           src(src),
      61            0 :           len(len),
      62            0 :           bufs(bufs),
      63            0 :           sem(sem),
      64            0 :           mask(mask)
      65              :     {
      66            0 :         type = CcuRepType::LOCAL_CPY;
      67            0 :         instrCount = insGenPtr->GetInstrCount(type);
      68            0 :         useCcuBuffer = true;
      69            0 :     }
      70              : 
      71            3 :     void CcuRepLocCpy::ValidateInsGeneratorForLocCpy()
      72              :     {
      73            3 :         CcuInsGeneratorV1* tmpPtrV1 = dynamic_cast<CcuInsGeneratorV1*>(insGenPtr);
      74            3 :         if (tmpPtrV1 && useCcuBuffer) {
      75              :             // 使用了A6场景的ms中转搬运
      76            0 :             Hccl::THROW<Hccl::CcuApiException>("Cannot translate CcuRepLocCpy for A5 when useCcuBuffer is true!");
      77              :         }
      78            3 :     }
      79              : 
      80            0 :     uint16_t CcuRepLocCpy::GetFirstBufId()
      81              :     {
      82            0 :         if (bufs.size() == 0) {
      83            0 :             Hccl::THROW<Hccl::CcuApiException>("The length of CcuBuffer is 0!");
      84              :         }
      85            0 :         return bufs[0].Id();
      86              :     }
      87              : 
      88            0 :     uint16_t CcuRepLocCpy::GetUsedBufNum() { return bufs.size(); }
      89              : 
      90            3 :     bool CcuRepLocCpy::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
      91              :     {
      92            3 :         ValidateInsGeneratorForLocCpy();
      93              : 
      94            3 :         this->instrId = instrId;
      95            3 :         translated = true;
      96              : 
      97            3 :         CHK_PRT_THROW(
      98              :             insGenPtr->CcuRepLocCpyTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
      99              :             HCCL_ERROR("[CcuRepLocCpy][Translate] failed to translate for instrId[%u]", instrId), Hccl::CcuApiException,
     100              :             "CcuRepLocCpy translate failed");
     101            3 :         instrId += instrCount;
     102              : 
     103            3 :         return translated;
     104              :     }
     105              : 
     106            2 :     std::string CcuRepLocCpy::Describe()
     107              :     {
     108              :         return Hccl::StringFormat(
     109              :             "Read LocalAddr[%u] to LocalAddr[%u], length[%u], set sem[%u] with mask[%04x], dataType[%u], opType[%u]",
     110            2 :             src.addr.Id(), dst.addr.Id(), len.Id(), sem.Id(), mask, dataType, opType);
     111              :     }
     112              : 
     113              : }; // namespace CcuRep
     114              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1