LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/communicator - comm_ahc_pub.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.7 % 23 22
Test Date: 2026-07-28 12:11:00 Functions: 80.0 % 5 4

            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              : #ifndef COMM_AHC_PUB_H
      12              : #define COMM_AHC_PUB_H
      13              : 
      14              : #include <cmath>
      15              : #include <algorithm>
      16              : #include "device_capacity.h"
      17              : 
      18              : namespace hccl {
      19              : 
      20              : // AHC算法相关
      21              : enum class AHCLevel {
      22              :     AHC_LEVEL_0 = 0,
      23              :     AHC_LEVEL_1,
      24              :     AHC_LEVEL_MAX
      25              : };
      26              :  
      27              : enum class ConcType {
      28              :     CONC_INTRA = 0,
      29              :     CONC_INTER,
      30              :     CONC_RESERVED
      31              : };
      32              :  
      33              : enum class AHCOpType {
      34              :     AHC_OP_TYPE_ALLGATHER = 0,
      35              :     AHC_OP_TYPE_ALLREDUCE,
      36              :     AHC_OP_TYPE_REDUCE_SCATTER,
      37              :     AHC_OP_TYPE_RESERVED
      38              : };
      39              : 
      40              : enum class AHCTemplateType {
      41              :     // AHC 内置template类型
      42              :     AHC_TEMPLATE_NB = 0,
      43              :     AHC_TEMPLATE_RING,
      44              :     AHC_TEMPLATE_NHR,
      45              :     AHC_TEMPLATE_RESERVED
      46              : };
      47              : 
      48              : //AHC prepare 扩展参数定义
      49              : using OXCPreparePara = struct OXCPrepareParaDef {
      50              :     u32 netPlaneId;
      51              :     u32 netPlaneNum;
      52              :     OXCPrepareParaDef(u32 netPlaneId, u32 netPlaneNum) :
      53              :         netPlaneId(netPlaneId),
      54              :         netPlaneNum(netPlaneNum)
      55              :     {}
      56              : };
      57              :  
      58              : union AHCExtendPreparePara {
      59              :     OXCPreparePara  oxcPreparePara;
      60            0 :     AHCExtendPreparePara() {}
      61              : };
      62              : 
      63              : using AHCConcOpType = struct AHCConcOpTypeDef {
      64              :     AHCLevel  ahcLevel;
      65              :     ConcType  concType;
      66              :     AHCOpType ahcOpType;
      67              :  
      68            9 :     AHCConcOpTypeDef()
      69            9 :         : ahcLevel(AHCLevel::AHC_LEVEL_0),
      70            9 :         concType(ConcType::CONC_INTRA),
      71            9 :         ahcOpType(AHCOpType::AHC_OP_TYPE_RESERVED)
      72            9 :     {}
      73              :  
      74         6306 :     AHCConcOpTypeDef(AHCLevel ahcLevel, ConcType  concType,AHCOpType ahcOpType)
      75         6291 :         : ahcLevel(ahcLevel), concType(concType), ahcOpType(ahcOpType)
      76         6291 :     {}
      77              :     
      78              :     // 重载 == 运算符,用于比较两个 MyKey 对象是否相等
      79              :     bool operator==(const AHCConcOpTypeDef& other) const {
      80              :         return ahcLevel == other.ahcLevel && concType == other.concType 
      81              :             && ahcOpType == other.ahcOpType;
      82              :     }
      83              :  
      84              :     // 重载 < 运算符,用于排序
      85        28587 :     bool operator<(const AHCConcOpTypeDef& other) const {
      86        28587 :         if (ahcLevel != other.ahcLevel) {
      87         6990 :             return ahcLevel < other.ahcLevel;
      88              :         }
      89        21597 :         if (concType != other.concType) {
      90         9702 :             return concType < other.concType;
      91              :         }        
      92        11895 :         return ahcOpType < other.ahcOpType;
      93              :     }
      94              : };
      95              : constexpr double AHC_SYM_THRESHOLD = 0.05;
      96              : using AHCAlgSelectParam = struct AHCAlgSelectParamDef {
      97              :     bool enableOXC;
      98              :     bool enableAlgAutoSelect;
      99              :     bool enableSubGroupsSplit;
     100              :     u64 dataSize;
     101              :     AHCOpType opType;
     102              :     float symThreshold;
     103              :  
     104            9 :     AHCAlgSelectParamDef()
     105            9 :         : enableOXC(false),
     106            9 :         enableAlgAutoSelect(true),
     107            9 :         enableSubGroupsSplit(true),
     108            9 :         dataSize(0),
     109            9 :         opType(AHCOpType::AHC_OP_TYPE_RESERVED),
     110            9 :         symThreshold(AHC_SYM_THRESHOLD)
     111            9 :     {}
     112              : };
     113              : 
     114              : } // hccl
     115              : 
     116              : #endif /* COMM_AHC_PUB_H */
        

Generated by: LCOV version 2.0-1