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

Generated by: LCOV version 2.0-1