LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/data - ccu_rep_bufreduce.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.5 % 31 29
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 3 3

            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              : 
      15              : namespace Hccl {
      16              : namespace CcuRep {
      17              : 
      18           14 : CcuRepBufReduce::CcuRepBufReduce(const std::vector<CcuBuffer> &mem, uint16_t count, uint16_t dataType,
      19              :                                  uint16_t outputDataType, uint16_t opType, MaskSignal sem, const CcuRep::Variable &len,
      20           14 :                                  uint16_t mask)
      21           14 :     : mem(mem), count(count), dataType(dataType), outputDataType(outputDataType), opType(opType), sem(sem),
      22           28 :       xnIdLength_(len), mask(mask)
      23              : {
      24           14 :     type       = CcuRepType::BUF_REDUCE;
      25           14 :     instrCount = 1;
      26           14 : }
      27              : 
      28            7 : bool CcuRepBufReduce::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      29              : {
      30            7 :     this->instrId = instrId;
      31            7 :     translated    = true;
      32              : 
      33            7 :     if (count > CCU_REDUCE_MAX_MS || mem.size() > CCU_REDUCE_MAX_MS) {
      34            0 :         THROW<CcuApiException>("count and mem size must less than %u", CCU_REDUCE_MAX_MS);
      35              :     }
      36            7 :     if (count < CCU_REDUCE_MIN_MS) {
      37            0 :         THROW<Hccl::CcuApiException>("count must be at least %u", CCU_REDUCE_MIN_MS);
      38              :     }
      39              : 
      40              :     // 这里需要注意,在数据格式膨胀的情况下,需要传入用来存放输出的MSId
      41              :     // 特别是2P场景,输入MS的数目为2,但是在8bit进,32bit出的场景,输出MS的数目为4
      42              :     // 传入的MS中已经包含了需要使用的输入输出的最大量,因此,这里应该直接去MS的size
      43            7 :     uint16_t msId[CCU_REDUCE_MAX_MS] = {0};
      44           43 :     for (uint16_t i = 0; i < mem.size(); i++) {
      45           36 :         msId[i] = mem[i].Id();
      46              :     }
      47              : 
      48            7 :     if (opType == CCU_REDUCE_SUM) {
      49            5 :         if (outputDataType == 1) { // 1是fp16
      50            1 :             AddInstr(instr++, msId, count, outputDataType, dataType, sem.Id(), mask, 0, 0, 1, xnIdLength_.Id());
      51            4 :         } else if (outputDataType == 2) { // 2是bf16
      52            1 :             AddInstr(instr++, msId, count, outputDataType, dataType, sem.Id(), mask, 0, 0, 1, xnIdLength_.Id());
      53              :         } else {
      54            3 :             AddInstr(instr++, msId, count, 0, dataType, sem.Id(), mask, 0, 0, 1, xnIdLength_.Id());
      55              :         }
      56            2 :     } else if (opType == CCU_REDUCE_MAX) {
      57            1 :         MaxInstr(instr++, msId, count, dataType, sem.Id(), mask, 0, 0, 1, xnIdLength_.Id());
      58            1 :     } else if (opType == CCU_REDUCE_MIN) {
      59            1 :         MinInstr(instr++, msId, count, dataType, sem.Id(), mask, 0, 0, 1, xnIdLength_.Id());
      60              :     }
      61            7 :     instrId += instrCount;
      62              : 
      63            7 :     return translated;
      64              : }
      65              : 
      66            9 : std::string CcuRepBufReduce::Describe()
      67              : {
      68            9 :     return StringFormat("Reduce");
      69              : }
      70              : 
      71              : }; // namespace CcuRep
      72              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1