LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/operator - all_reduce_operator.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 34.9 % 450 157
Test Date: 2026-08-18 17:47:01 Functions: 41.2 % 17 7

            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 "all_reduce_operator.h"
      12              : #include "device_capacity.h"
      13              : #include "coll_alg_utils.h"
      14              : #include "hccl_aiv.h"
      15              : #include "coll_alg_op_registry.h"
      16              : 
      17              : namespace hccl {
      18              : 
      19           17 : AllReduceOperator::AllReduceOperator(
      20              :     AlgConfigurator* algConfigurator, CCLBufferManager& cclBufferManager, HcclDispatcher dispatcher,
      21           17 :     std::unique_ptr<TopoMatcher>& topoMatcher)
      22           17 :     : CollAlgOperator(algConfigurator, cclBufferManager, dispatcher, topoMatcher, HcclCMDType::HCCL_CMD_ALLREDUCE)
      23           20 : {}
      24              : 
      25           40 : AllReduceOperator::~AllReduceOperator() {}
      26              : 
      27              : // 如果逻辑有修改,需同步修改GetAllReduceScratchMemSize()
      28            0 : HcclDataCountType AllReduceOperator::GetCountTypeForDeterAllReduce(const u64 count, const HcclDataType dataType)
      29              : {
      30            0 :     u64 dataSize = SIZE_TABLE[dataType] * count;
      31            0 :     if ((GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB)) {
      32            0 :         if (dataSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
      33            0 :             return HcclDataCountType::HCCL_COUNT_SMALL;
      34            0 :         } else if ((dataSize <= HCCL_MEDIUM_COUNT_GRAPH_4_MB) && (deviceNumPerAggregation_ == DEVICE_EIGHT)) {
      35            0 :             return HcclDataCountType::HCCL_COUNT_MEDIUM;
      36              :         } else {
      37            0 :             return HcclDataCountType::HCCL_COUNT_HUGE;
      38              :         }
      39              :     } else {
      40            0 :         if (dataSize <= HCCL_SMALL_COUNT_128_KB) {
      41            0 :             return HcclDataCountType::HCCL_COUNT_SMALL;
      42              :         } else {
      43            0 :             if (deviceNumPerAggregation_ == DEVICE_EIGHT) {
      44            0 :                 return HcclDataCountType::HCCL_COUNT_MEDIUM;
      45              :             } else {
      46            0 :                 return HcclDataCountType::HCCL_COUNT_HUGE;
      47              :             }
      48              :         }
      49              :     }
      50              : }
      51              : 
      52              : // 如果逻辑有修改,需同步修改GetAllReduceScratchMemSize()
      53            0 : HcclResult AllReduceOperator::GetScratchSizeForDeterAllReduce(
      54              :     const u64 count, const HcclDataType dataType, const u32 rankSize, u64& outScratchSize)
      55              : {
      56              :     // 两卡不需要申请额外内存
      57            0 :     if (rankSize == DEVICE_TWO) {
      58            0 :         outScratchSize = 0;
      59            0 :         return HCCL_SUCCESS;
      60              :     }
      61              : 
      62            0 :     HcclDataCountType countType = GetCountTypeForDeterAllReduce(count, dataType);
      63            0 :     u64 memSize = SIZE_TABLE[dataType] * count;
      64            0 :     switch (countType) {
      65            0 :         case HcclDataCountType::HCCL_COUNT_SMALL:
      66              :             // 小数据量下,八卡选择HD算法、非八卡选择Reduce-Bcast算法
      67            0 :             if (rankSize == DEVICE_EIGHT) {
      68              :                 // one shot HD算法,需要额外的(log2(N)-1)倍内存避免读写冲突
      69            0 :                 outScratchSize = 0;
      70              :             } else {
      71              :                 // Reduce-Bcast算法,需要N-1倍内存来暂存来自其他卡的数据(先收集数据,再本地Reduce到目的内存上)
      72            0 :                 outScratchSize = memSize * (rankSize - 1);
      73              :             }
      74            0 :             break;
      75            0 :         case HcclDataCountType::HCCL_COUNT_MEDIUM:
      76              :             // 中数据量下,八卡选择Local Reduce算法,非八卡选择MeshChunk算法,都不要额外内存
      77            0 :             outScratchSize = 0;
      78            0 :             break;
      79            0 :         case HcclDataCountType::HCCL_COUNT_HUGE:
      80              :             // 大数据量下,统一选择MeshChunk算法,不需要额外内存
      81            0 :             outScratchSize = 0;
      82            0 :             break;
      83            0 :         default:
      84            0 :             return HCCL_E_NOT_SUPPORT;
      85              :     }
      86              : 
      87            0 :     HCCL_DEBUG(
      88              :         "[GetScratchSizeForDeterAllReduce] countType=%u, rankSize=%u, memSize=%llu, outScratchSize=%llu", countType,
      89              :         rankSize, memSize, outScratchSize);
      90            0 :     return HCCL_SUCCESS;
      91              : }
      92              : 
      93            0 : HcclResult AllReduceOperator::GetAllReduceScratchSize(const u64 count, const HcclDataType dataType, u64& scratchSize)
      94              : {
      95              :     // 针对 单机、910B、确定性计算、图模式 的特殊优化
      96            0 :     if (algConfigurator_->SupportDeterministicOptim()) {
      97            0 :         CHK_RET(GetScratchSizeForDeterAllReduce(count, dataType, deviceNumPerAggregation_, scratchSize));
      98              :     } else {
      99            0 :         u64 reservedSize = (userRankSize_ + 1) * (userRankSize_ + 1) * SIZE_TABLE[dataType];
     100              : 
     101            0 :         scratchSize = count * SIZE_TABLE[dataType] * DEVICE_TWO + reservedSize;
     102              :     }
     103              : 
     104            0 :     HCCL_INFO("[AllReduceOperator][GetAllReduceScratchSize] scratchSize %llu, count %llu", scratchSize, count);
     105            0 :     return HCCL_SUCCESS;
     106              : }
     107              : 
     108              : HcclResult
     109           20 : AllReduceOperator::SelectAlg(const std::string& tag, const OpParam& param, std::string& algName, std::string& newTag)
     110              : {
     111           20 :     if (userRankSize_ == 1) {
     112            0 :         algName = "AllReduceSingleExecutor";
     113            0 :         HCCL_INFO("[SelectAlg] AllReduce SelectAlg is algName [%s]", algName.c_str());
     114            0 :         return HCCL_SUCCESS;
     115              :     }
     116              :     HcclResult ret;
     117           20 :     if (isDiffDeviceType_) {
     118            0 :         ret = SelectAlgforMix(param, algName);
     119           20 :     } else if (Is310P3Common(isHaveCpuRank_, deviceType_)) {
     120            0 :         if (is310PDuoCard_) {
     121            0 :             ret = SelectAlgfor310P3DUO(param, algName);
     122              :         } else {
     123            0 :             ret = SelectAlgfor310P3(param, algName);
     124              :         }
     125           20 :     } else if (Is310PDevice()) {
     126            0 :         ret = SelectAlgfor310PHelper(param, algName);
     127           20 :     } else if (deviceType_ == DevType::DEV_TYPE_910) {
     128            0 :         ret = SelectAlgfor910A(param, algName);
     129           20 :     } else if (deviceType_ == DevType::DEV_TYPE_910B) {
     130            4 :         ret = SelectAlgfor910B(param, algName);
     131           16 :     } else if (deviceType_ == DevType::DEV_TYPE_910_93) {
     132           16 :         ret = SelectAlgfor91093(param, algName);
     133              :     } else {
     134            0 :         HCCL_ERROR("[AllReduceOperator][SelectAlg] device type[%d] is out of range for selector.", deviceType_);
     135            0 :         return HCCL_E_NOT_SUPPORT;
     136              :     }
     137           20 :     CHK_PRT_RET(
     138              :         ret != HCCL_SUCCESS,
     139              :         HCCL_ERROR("[AllReduceSelector][SelectAlg]tag[%s], AllReduce failed, return[%d]", tag.c_str(), ret), ret);
     140              : 
     141           20 :     if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     142            5 :         if (Is310P3Common(isHaveCpuRank_, deviceType_)) {
     143            0 :             newTag = tag + algName;
     144              :         } else {
     145            5 :             AlgTypeLevel1 algType1 = algType_.algoLevel1;
     146            5 :             auto level1Iter = HCCL_ALGO_LEVEL1_NAME_MAP.find(algType1);
     147            5 :             CHK_PRT_RET(
     148              :                 level1Iter == HCCL_ALGO_LEVEL1_NAME_MAP.end(), HCCL_ERROR("level1: algType1[%u] is invalid.", algType1),
     149              :                 HCCL_E_INTERNAL);
     150            5 :             newTag = tag + level1Iter->second + algName;
     151              :         }
     152              : 
     153            5 :         bool isInlineReduce = IsSupportSDMAReduce(
     154            5 :             cclBufferManager_.GetInCCLbuffer().ptr(), cclBufferManager_.GetOutCCLbuffer().ptr(), param.DataDes.dataType,
     155            5 :             param.reduceType);
     156            5 :         bool isRdmaReduce = IsSupportRDMAReduce(param.DataDes.dataType, param.reduceType);
     157            5 :         const std::string ALL_REDUCE_NO_INLINE = "_no_inline";
     158           10 :         newTag = (!isDiffDeviceType_ || (isDiffDeviceType_ && isInlineReduce && isRdmaReduce)) ?
     159              :                      newTag :
     160            5 :                      newTag + ALL_REDUCE_NO_INLINE;
     161            5 :     } else {
     162           15 :         newTag = tag;
     163              :     }
     164           18 :     if (algName == "AllReduceARSFor91093Executor") {
     165              :         u32 ringSize
     166            0 :             = CalcOptimalIntraRingsize(param.DataDes.count, param.DataDes.dataType, HcclCMDType::HCCL_CMD_ALLREDUCE);
     167            0 :         newTag += std::to_string(ringSize);
     168              :     }
     169           17 :     newTag += (param.aicpuUnfoldMode ? "_device" : "_host");
     170           20 :     return ret;
     171              : }
     172              : 
     173            0 : HcclResult AllReduceOperator::SelectAlgforMix(const OpParam& param, std::string& algName)
     174              : {
     175              :     (void)param;
     176              : 
     177              :     // 混合组网场景不支持规约保序
     178            0 :     if (IsNeedStrictMode(param)) {
     179            0 :         HCCL_ERROR("[AllReduceOperator][SelectAlgforMix] not support DETERMINISTIC_STRICT mode.");
     180            0 :         return HCCL_E_NOT_SUPPORT;
     181              :     }
     182              : 
     183            0 :     if (gcdDeviceNumPerAggregation_ > 1) {
     184            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_NHR;
     185            0 :         HCCL_WARNING("[AllReduceOperator][SelectAlgforMix] only support NHR in AlgoLevel1 yet, "
     186              :                      "default is algType=NHR.");
     187            0 :         algName = "AllReduceMixExecutor";
     188              :     } else {
     189            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_RING;
     190              :         ;
     191            0 :         HCCL_WARNING("[AllReduceOperator][SelectAlgforMix] only support ring in AlgoComm yet, "
     192              :                      "default is algType=ring.");
     193            0 :         algName = "AllReduceComm";
     194              :     }
     195              : 
     196            0 :     HCCL_INFO("[SelectAlgforMix] AllReduce SelectAlgforMix is algName [%s]", algName.c_str());
     197            0 :     return HCCL_SUCCESS;
     198              : }
     199              : 
     200            0 : HcclResult AllReduceOperator::SelectAlgfor310P3DUO(const OpParam& param, std::string& algName)
     201              : {
     202              :     bool isInlineReduce
     203            0 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     204            0 :     u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * param.DataDes.count;
     205              : 
     206            0 :     bool isPowOfTwo = ((userRankSize_ - 1) & userRankSize_) == 0;
     207            0 :     const u32 RANK_SIZE_TWO = 2;
     208            0 :     const u32 RANK_SIZE_EIGHT = 8;
     209              : 
     210            0 :     if (isInlineReduce) {
     211            0 :         if ((dataSize <= HCCL_SMALL_COUNT_256_KB && isPowOfTwo && userRankSize_ <= RANK_SIZE_EIGHT)
     212            0 :             || userRankSize_ == RANK_SIZE_TWO) {
     213            0 :             algType_.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_NP_HD;
     214            0 :             algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_HD;
     215            0 :             if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     216            0 :                 algName = "AllReduceDoublingDirect";
     217              :             } else {
     218            0 :                 algName = "AllReduceDoubling";
     219              :             }
     220              :         }
     221              :     }
     222            0 :     if (algName.empty()) {
     223            0 :         algType_.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_WHOLE_RING;
     224            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_WHOLE_RING;
     225            0 :         algName = "AllReduceRing";
     226              :     }
     227            0 :     HCCL_INFO("[SelectAlgfor310P3DUO] AllReduce SelectAlgfor310P3DUO is algName [%s].", algName.c_str());
     228            0 :     return HCCL_SUCCESS;
     229              : }
     230              : 
     231            0 : HcclResult AllReduceOperator::SelectAlgfor310P3(const OpParam& param, std::string& algName)
     232              : {
     233            0 :     bool isPowOfTwo = ((userRankSize_ - 1) & userRankSize_) == 0;
     234            0 :     u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * param.DataDes.count;
     235              : 
     236              :     bool isInlineReduce
     237            0 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     238            0 :     if (isInlineReduce) {
     239            0 :         if (dataSize <= HCCL_SMALL_COUNT_256_KB && isPowOfTwo) {
     240            0 :             algType_.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_NP_HD;
     241            0 :             algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_HD;
     242            0 :             algName = "AllReduceDoubling";
     243              :         }
     244              :     }
     245            0 :     if (algName.empty()) {
     246            0 :         algType_.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_WHOLE_RING;
     247            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_WHOLE_RING;
     248            0 :         algName = "AllReduceRing";
     249              :     }
     250            0 :     HCCL_INFO("[SelectAlgfor310P3] AllReduce SelectAlgfor310P3 is algName [%s].", algName.c_str());
     251            0 :     return HCCL_SUCCESS;
     252              : }
     253              : 
     254            0 : HcclResult AllReduceOperator::SelectAlgfor310PHelper(const OpParam& param, std::string& algName)
     255              : {
     256              :     (void)param;
     257            0 :     algName = "AllReduceReducePlusBcast";
     258            0 :     HCCL_INFO("[SelectAlgfor310PHelper] AllReduce SelectAlgfor310PHelper is algName [%s]", algName.c_str());
     259            0 :     return HCCL_SUCCESS;
     260              : }
     261              : 
     262            0 : HcclResult AllReduceOperator::SelectAlgfor910A(const OpParam& param, std::string& algName)
     263              : {
     264            0 :     const u32 RANK_SIZE_FOUR = 4;
     265            0 :     const u32 RANK_SIZE_EIGHT = 8;
     266            0 :     u64 dataSize = SIZE_TABLE[param.DataDes.dataType] * param.DataDes.count;
     267            0 :     bool isOpbase = GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     268              :     bool isInlineReduce
     269            0 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     270            0 :     bool isMeshTopo = topoType_ == TopoType::TOPO_TYPE_4P_MESH || topoType_ == TopoType::TOPO_TYPE_2P_MESH;
     271            0 :     bool isRingTopo = topoType_ == TopoType::TOPO_TYPE_NP_SINGLE_RING || topoType_ == TopoType::TOPO_TYPE_8P_RING;
     272              : 
     273            0 :     if (isOpbase && serverNum_ == 1 && dataSize <= HCCL_SMALL_COUNT_1_MB
     274            0 :         && (userRankSize_ == RANK_SIZE_FOUR || userRankSize_ == RANK_SIZE_EIGHT)) {
     275            0 :         algType_.algoLevel0 = AlgTypeLevel0::ALG_LEVEL0_NP_HD;
     276            0 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_HD;
     277            0 :         if (isInlineReduce && userRankSize_ == RANK_SIZE_FOUR) {
     278            0 :             algName = "AllReduceDoublingDirect";
     279            0 :         } else if (isInlineReduce && userRankSize_ == RANK_SIZE_EIGHT) {
     280            0 :             algName = "AllReduceDoubling";
     281              :         } else {
     282            0 :             algName = "AllReduceSmallCountFor910";
     283              :         }
     284            0 :     } else if (isMeshTopo) {
     285            0 :         algName = "AllReduceMeshExecutor";
     286            0 :     } else if (isRingTopo) {
     287            0 :         algName = "AllReduceRingExecutor";
     288              :     } else {
     289            0 :         algName = "AllReduceComm";
     290              :     }
     291            0 :     HCCL_INFO("[SelectAlgfor910A] AllReduce SelectAlgfor910A is algName [%s]", algName.c_str());
     292            0 :     return HCCL_SUCCESS;
     293              : }
     294              : 
     295            4 : HcclResult AllReduceOperator::SelectAlgfor910B(const OpParam& param, std::string& algName)
     296              : {
     297            4 :     HcclResult ret = HCCL_SUCCESS;
     298            4 :     u32 unitSize = SIZE_TABLE[param.DataDes.dataType];
     299              : 
     300            4 :     bool isOnlyAiv = topoMatcher_->GetIsOnlyAivConfig();
     301              :     bool isInlineReduce
     302            4 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     303            4 :     bool isRdmaReduce = IsSupportRDMAReduce(param.DataDes.dataType, param.reduceType);
     304              : 
     305            0 :     bool isMeshTopo = topoType_ == TopoType::TOPO_TYPE_NP_MESH || topoType_ == TopoType::TOPO_TYPE_4P_MESH
     306            3 :                       || topoType_ == TopoType::TOPO_TYPE_2P_MESH || topoType_ == TopoType::TOPO_TYPE_1P_MESH;
     307            3 :     bool isRingTopo = topoType_ == TopoType::TOPO_TYPE_NP_SINGLE_RING;
     308              : 
     309            3 :     u64 dataSize = param.DataDes.count * unitSize; // 单位:字节
     310              : 
     311            3 :     void* commInputPtr = nullptr;
     312            3 :     void* commOutputPtr = nullptr;
     313            3 :     u64 commInputSize = 0;
     314            3 :     u64 commOutputSize = 0;
     315              : 
     316            3 :     CHK_RET(cclBufferManager_.GetInCCLbuffer(commInputPtr, commInputSize));
     317            4 :     CHK_RET(cclBufferManager_.GetOutCCLbuffer(commOutputPtr, commOutputSize));
     318              : 
     319              :     // aiv场景单独判断逻辑,满足AIV模式打开+支持AIVReduce+非确定性场景+外层为mesh+(单机/跨机小数据/跨机中数据)时进入分支
     320            3 :     bool isOpbase = (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
     321            4 :     bool isMesh = IsAlgTypeLevel0Mesh(algType_.algoLevel0);
     322            4 :     u64 rankCountSize = dataSize / deviceNumPerAggregation_;
     323            4 :     bool isServNumPowOfTwo = (serverNum_ > 0) && ((serverNum_ & (serverNum_ - 1)) == 0);
     324              : 
     325            0 :     bool isSupportAivRdmaSmallCount = !isSingleMeshAggregation_ && !multiModuleDiffDeviceNumMode_ && isServNumPowOfTwo
     326            4 :                                       && ((rankCountSize <= HCCL_SMALL_COUNT_190_KB || isOnlyAiv));
     327              : 
     328            4 :     bool isSupportAivRdmaMidCount
     329            4 :         = !isSingleMeshAggregation_ && !multiModuleDiffDeviceNumMode_ && (dataSize <= HCCL_MID_COUNT_16_MB);
     330              : 
     331            4 :     bool isSupportAivDeter = isSingleMeshAggregation_
     332            4 :                              && (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_ENABLE)
     333            6 :                              && (dataSize <= HCCL_SMALL_COUNT_8_MB);
     334              : 
     335            2 :     bool isCCLBufferGE16M
     336            2 :         = !isOpbase || (commInputSize >= HCCL_MID_COUNT_16_MB && commOutputSize >= HCCL_MID_COUNT_16_MB);
     337              : 
     338            2 :     bool isBarrierOp = param.syncMode == SyncMode::UNLIMITED_TIMEWAITSYNCMODE; // Barrier算子不使能AIV
     339            2 :     bool isAivMode = (topoMatcher_->GetAivModeConfig() && !isBarrierOp)
     340            0 :                      && IsSupportAIVReduce(param.DataDes.dataType, param.reduceType) && isMesh && isCCLBufferGE16M
     341            0 :                      && (isSingleMeshAggregation_ || isSupportAivRdmaSmallCount || isSupportAivRdmaMidCount)
     342            1 :                      && (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_DISABLE || isSupportAivDeter);
     343            1 :     if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     344            0 :         std::string algTypeLevel1Tag;
     345            0 :         CHK_RET(AutoSelectAlgTypeLevel1(
     346              :             HcclCMDType::HCCL_CMD_ALLREDUCE, dataSize, commInputSize, algTypeLevel1Tag, isInlineReduce, isRdmaReduce,
     347              :             isAivMode));
     348            0 :         if (GetExternalInputHcclEnableEntryLog() && param.opBaseAtraceInfo != nullptr) {
     349            0 :             CHK_RET(param.opBaseAtraceInfo->SavealgtypeTraceInfo(algTypeLevel1Tag, param.tag));
     350              :         }
     351            0 :     }
     352              : 
     353              :     // AHC 算法选择逻辑
     354            1 :     if (((algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC)
     355            1 :          || (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC_BROKE))) {
     356            0 :         CHK_RET(SelectAlgforAHC(dataSize, AHCOpType::AHC_OP_TYPE_ALLREDUCE));
     357              :     }
     358              : 
     359              :     // pipeline算法task数量多,如果超出FFTS子图限制,则重定向到HD算法
     360              :     // 图模式不会重定向到HD算法
     361            2 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE
     362            1 :         && GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     363            0 :         u32 contextNum = CalcContextNumForPipeline(HcclCMDType::HCCL_CMD_ALLREDUCE);
     364            0 :         if (contextNum > HCCL_FFTS_CAPACITY) {
     365            0 :             algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_HD;
     366            0 :             HCCL_WARNING(
     367              :                 "[AllReduceOperator][SelectAlgfor910B] context num[%u] is out of capacity of FFTS+ graph[%u], "
     368              :                 "reset algorithm to HD.",
     369              :                 contextNum, HCCL_FFTS_CAPACITY);
     370              :         }
     371              :     }
     372              : 
     373            1 :     if (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_STRICT && multiModuleDiffDeviceNumMode_) {
     374              :         // 保序规约场景(多batch一致),当前不支持非对称场景
     375            0 :         HCCL_ERROR(
     376              :             "[SelectAlgfor910B] reduce order preservation only support Symmetry("
     377              :             "multiModuleDiffDeviceNumMode_[%d]).",
     378              :             multiModuleDiffDeviceNumMode_);
     379            0 :         return HCCL_E_NOT_SUPPORT;
     380              :     }
     381              : 
     382            1 :     if (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_STRICT && userRankSize_ > 2
     383            1 :         && (param.DataDes.dataType == HCCL_DATA_TYPE_FP16 || param.DataDes.dataType == HCCL_DATA_TYPE_FP32
     384            0 :             || param.DataDes.dataType == HCCL_DATA_TYPE_BFP16)) {
     385            0 :         if (param.aicpuUnfoldMode || (topoMatcher_->GetAivModeConfig() && !isBarrierOp)) {
     386              :             // AIV / AICPU场景,规约保序优先级更高
     387            0 :             HCCL_WARNING(
     388              :                 "[SelectAlgfor910B]aicpuMode[%d], AivModeConfig[%d], "
     389              :                 "the Aiv/AICPU mode does not support when the reduce order preservation is enabled.",
     390              :                 param.aicpuUnfoldMode, topoMatcher_->GetAivModeConfig());
     391              :         }
     392              :         // 只有浮点数存在多batch不一致的可能,整数天然一致
     393            0 :         algName = "AllReduceOrderPreservedExecutor";
     394            1 :     } else if (isAivMode) {
     395            0 :         if (isSupportAivDeter) {
     396            0 :             if (dataSize <= HCCL_SMALL_COUNT_8_MB) {
     397            0 :                 algName = "AllReduceAivDeterSmallExecutor";
     398              :             } else {
     399            0 :                 algName = "AllReduceAivDeterExecutor";
     400              :             }
     401            0 :             HCCL_INFO("[SelectAlgfor910B] AllReduce SelectAlgfor910B is algName [%s].", algName.c_str());
     402            0 :             return HCCL_SUCCESS;
     403              :         }
     404            0 :         bool isOpbaseBigCount = isOpbase && (dataSize >= AIV_ALL_REDUCE_BIG_SIZE);
     405            0 :         HCCL_INFO(
     406              :             "[SelectAlgfor910B] Select AivMode Alg: DataSize[%llu], RankCountSize[%llu], DeviceNumPerAgg [%u]",
     407              :             dataSize, rankCountSize, deviceNumPerAggregation_);
     408            0 :         if (isSupportAivRdmaSmallCount) {
     409            0 :             algName = "AllReduceSmallCountAivRdmaExecutor"; // 多server,满足二次幂,小数据量(单卡190K以内)
     410            0 :         } else if (isSupportAivRdmaMidCount) {
     411            0 :             algName = "AllReduceMidCountAivRdmaExecutor"; // 多server,中小数据量(总数据量16M以内)
     412            0 :         } else if (isOpbaseBigCount || !isOpbase) {
     413            0 :             algName = "AllReduceMeshAivExecutor"; // 单server,单算子AIV模式大数据 和 图模式AIV 共用一个Executor
     414              :         } else {
     415            0 :             algName = "AllReduceMeshAivSmallCountExecutor"; // 单server,单算子AIV模式小数据单独一个Executor
     416              :         }
     417              :         // 小于等于两卡场景单独判断逻辑
     418            1 :     } else if (deviceNumPerAggregation_ <= DEVICE_TWO) {
     419              :         // 动态图算子融合场景?
     420            0 :         if ((param.inputPtr == commInputPtr)
     421            0 :             && (param.outputPtr == commOutputPtr && GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)
     422            0 :             && isMeshTopo) {
     423            0 :             algName = "AllReduceMeshExecutor";
     424              :             // 两卡不存在确定性问题 server内
     425            0 :         } else if (SingleMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)) {
     426            0 :             ret = MeshTopoSelector(algName, dataSize);
     427            0 :             CHK_PRT_RET(
     428              :                 ret != HCCL_SUCCESS,
     429              :                 HCCL_ERROR("[SelectAlgfor910B] AllReduce MeshTopoSelector failed, return[%d]", ret), ret);
     430              :             // 标卡场景(只有2p)
     431            0 :         } else if (Is2U2PInfer()) {
     432            0 :             if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE && isInlineReduce) {
     433            0 :                 algName = "AllReduceMeshOneshotLoopExecutor";
     434              :             } else {
     435            0 :                 algName = "AllReduceRingExecutor";
     436              :             }
     437              :             // 多机单卡/两卡 pipeline需单独做判断(pipeline无确定性算法,并只支持单算子模式)
     438            0 :         } else if (
     439            0 :             topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_DISABLE
     440            0 :             && algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE
     441            0 :             && IsMultiMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)) {
     442            0 :             if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     443            0 :                 algName = "AllReduceMeshOpbasePipelineExecutor";
     444              :             } else {
     445            0 :                 algName = "AllReduceMeshGraphPipelineExecutor";
     446              :             }
     447              :             // 常规910B为mesh拓扑
     448            0 :         } else if (isMeshTopo) {
     449            0 :             algName = "AllReduceMeshExecutor";
     450              :             // 多机单卡topo为ring
     451            0 :         } else if (isRingTopo) {
     452            0 :             algName = "AllReduceRingExecutor";
     453              :             // 通信域打平场景
     454              :         } else {
     455            0 :             algName = "AllReduceComm";
     456              :         }
     457              :         // 多卡场景
     458              :     } else {
     459            1 :         if (isMeshTopo) {
     460            2 :             if ((param.inputPtr == commInputPtr)
     461            1 :                 && (param.outputPtr == commOutputPtr
     462            0 :                     && GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)) {
     463            0 :                 algName = "AllReduceMeshExecutor";
     464              :                 // 非确定性算法
     465            1 :             } else if (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_DISABLE) {
     466            1 :                 ret = NonDeterministicSelector(param, algName, dataSize);
     467              :                 // 确定性算法
     468              :             } else {
     469            0 :                 ret = DeterministicSelector(param, algName);
     470              :             }
     471            1 :             CHK_PRT_RET(
     472              :                 ret != HCCL_SUCCESS,
     473              :                 HCCL_ERROR("[SelectAlgfor910B] AllReduce SelectAlgfor910B failed, return[%d]", ret), ret);
     474            1 :             if (algName.empty()) {
     475            1 :                 algName = "AllReduceMeshExecutor";
     476              :             }
     477              :         } else {
     478            0 :             algName = "AllReduceComm";
     479              :         }
     480              :     }
     481              :     // 如果配置了aiv only,但是实际没有选择aiv算法,需要通过DFX打印出具体原因
     482            4 :     if (isOnlyAiv && !isAivMode) {
     483            0 :         HCCL_ERROR("The current conditions do not meet the aiv only execution criteria because:");
     484            0 :         CHK_PRT_RET(
     485              :             !IsSupportAIVReduce(param.DataDes.dataType, param.reduceType),
     486              :             HCCL_ERROR(
     487              :                 "current data type[%s] or reduceType[%s] not supported, "
     488              :                 "data type support range:[int8, int16, int32, float16, float32, bfloat16] reduce type support "
     489              :                 "range:[sum, max, min]",
     490              :                 GetDataTypeEnumStr(param.DataDes.dataType).c_str(), GetReduceOpEnumStr(param.reduceType).c_str()),
     491              :             HCCL_E_NOT_SUPPORT);
     492              : 
     493            0 :         CHK_PRT_RET(
     494              :             !isMesh, HCCL_ERROR("current algoLevel0Mesh[%d] not supported", algType_.algoLevel0), HCCL_E_NOT_SUPPORT);
     495              : 
     496            0 :         CHK_PRT_RET(
     497              :             !isCCLBufferGE16M,
     498              :             HCCL_ERROR(
     499              :                 "current isOpbase[%d] or commInputSize[%llu] or commOutputSize[%llu] not supported", isOpbase,
     500              :                 commInputSize, commOutputSize),
     501              :             HCCL_E_NOT_SUPPORT);
     502              : 
     503            0 :         CHK_PRT_RET(
     504              :             !isSingleMeshAggregation_ && multiModuleDiffDeviceNumMode_,
     505              :             HCCL_ERROR(
     506              :                 "The number of cards between servers in a multi-server setup must be consistent. "
     507              :                 "isSingleMeshAggregation_[%d] multiModuleDiffDeviceNumMode_[%d]",
     508              :                 isSingleMeshAggregation_, multiModuleDiffDeviceNumMode_),
     509              :             HCCL_E_NOT_SUPPORT);
     510              : 
     511            0 :         CHK_PRT_RET(!isServNumPowOfTwo, HCCL_ERROR("server num[%u] is pow of two.", serverNum_), HCCL_E_NOT_SUPPORT);
     512              : 
     513            0 :         CHK_PRT_RET(
     514              :             !isSupportAivRdmaMidCount, HCCL_ERROR("current data size[%llu] not support aiv rdma mid count.", dataSize),
     515              :             HCCL_E_NOT_SUPPORT);
     516              : 
     517            0 :         CHK_PRT_RET(
     518              :             !isSupportAivDeter,
     519              :             HCCL_ERROR(
     520              :                 "is not support aiv deter.isSingleMeshAggregation_[%d] isOpbase[%d] deterministic config[%u], "
     521              :                 "dataSize[%llu]",
     522              :                 isSingleMeshAggregation_, isOpbase, topoMatcher_->GetDeterministicConfig(), dataSize),
     523              :             HCCL_E_NOT_SUPPORT);
     524            0 :         return HCCL_E_NOT_SUPPORT;
     525              :     }
     526            4 :     HCCL_INFO("[SelectAlgfor910B] AllReduce SelectAlgfor910B is algName [%s].", algName.c_str());
     527            3 :     return HCCL_SUCCESS;
     528              : }
     529              : 
     530            0 : HcclResult AllReduceOperator::MeshTopoSelector(std::string& algName, u64 unitSize)
     531              : {
     532              :     // 单算子选择逻辑
     533            0 :     if (GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
     534            0 :         if (unitSize <= HCCL_SMALL_COUNT_256_KB) {
     535            0 :             algName = "AllReduceMeshSmallCountExecutor";
     536              :         } else {
     537            0 :             algName = "AllReduceMeshOpbaseLoopExecutor";
     538              :         }
     539              :         // 图模式选择逻辑
     540              :     } else {
     541            0 :         if (unitSize <= HCCL_SMALL_COUNT_GRAPH_64_KB) {
     542            0 :             algName = "AllReduceMeshSmallCountExecutor";
     543              :         } else {
     544            0 :             algName = "AllReduceMeshExecutor";
     545              :         }
     546              :     }
     547            0 :     return HCCL_SUCCESS;
     548              : }
     549              : 
     550            4 : HcclResult AllReduceOperator::NonDeterministicSelector(const OpParam& param, std::string& algName, u64 dataSize)
     551              : {
     552            4 :     const bool isOpbase = GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     553            4 :     if (isOpbase) {
     554            0 :         if (IsMultiMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)
     555            0 :             && algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE) {
     556            0 :             algName = "AllReduceMeshOpbasePipelineExecutor";
     557            0 :         } else if (SingleMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)) {
     558            0 :             if (dataSize <= HCCL_SMALL_COUNT_256_KB) {
     559            0 :                 algName = "AllReduceMeshSmallCountExecutor";
     560              :             } else {
     561            0 :                 algName = "AllReduceMeshOpbaseLoopExecutor";
     562              :             }
     563              :         }
     564            1 :     } else if (
     565            4 :         GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OPS_KERNEL_INFO_LIB
     566            2 :         && IsMultiMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)
     567            3 :         && algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE) {
     568            0 :         algName = "AllReduceMeshGraphPipelineExecutor";
     569              :     }
     570            1 :     if (!algName.empty() || !isOpbase) {
     571            1 :         return HCCL_SUCCESS;
     572              :     }
     573              :     const bool isInlineReduce
     574            0 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     575              :     // 单算子 + 数据量小于512kB
     576            0 :     if (dataSize < HCCL_SMALL_COUNT_512_KB && !isSingleMeshAggregation_ && isInlineReduce) {
     577            0 :         algName = "AllReduceMeshOpbaseSmallCountDeterministicExecutor";
     578              :     }
     579            0 :     return HCCL_SUCCESS;
     580              : }
     581              : 
     582            0 : HcclResult AllReduceOperator::DeterministicSelector(const OpParam& param, std::string& algName)
     583              : {
     584              :     // 确定性图和单算子归一流程
     585            0 :     HcclDataCountType countType = GetCountTypeForDeterAllReduce(param.DataDes.count, param.DataDes.dataType);
     586            0 :     const bool isOpbase = GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     587              :     const bool isInlineReduce
     588            0 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     589              : 
     590            0 :     if (isOpbase && algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_PIPELINE
     591            0 :         && deviceNumPerAggregation_ > DEVICE_TWO) {
     592            0 :         u64 dataSize = param.DataDes.count * SIZE_TABLE[param.DataDes.dataType];
     593            0 :         if (dataSize >= deviceNumPerAggregation_ * HCCL_MIN_SLICE_ALIGN) {
     594            0 :             algName = "AllReduceDeterPipelineExecutor";
     595            0 :             return HCCL_SUCCESS;
     596              :         }
     597              :     }
     598            0 :     if (SingleMeshInlineReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType)) {
     599            0 :         if (countType == HcclDataCountType::HCCL_COUNT_SMALL) {
     600            0 :             algName = "AllReduceMeshSmallCountExecutor";
     601            0 :         } else if (countType == HcclDataCountType::HCCL_COUNT_MEDIUM) {
     602            0 :             algName = "AllReduceMeshMidCountLoopExecutor";
     603              :         } else {
     604            0 :             algName = "AllReduceMeshOneshotLoopExecutor";
     605              :         }
     606              :     } else {
     607            0 :         u64 dataSize = param.DataDes.count * SIZE_TABLE[param.DataDes.dataType];
     608            0 :         if (isOpbase && !isSingleMeshAggregation_ && isInlineReduce) {
     609            0 :             if (dataSize <= HCCL_SMALL_COUNT_512_KB) {
     610              :                 // 单算子 + 确定性 + 数据量小于512kB
     611            0 :                 algName = "AllReduceMeshOpbaseSmallCountDeterministicExecutor";
     612              :             } else {
     613            0 :                 algName = "AllReduceMeshOpbaseMidCountDeterministicExecutor";
     614              :             }
     615              :         }
     616              :     }
     617            0 :     return HCCL_SUCCESS;
     618              : }
     619              : 
     620           16 : HcclResult AllReduceOperator::SelectAlgfor91093(const OpParam& param, std::string& algName)
     621              : {
     622           16 :     u32 unitSize = SIZE_TABLE[param.DataDes.dataType];
     623           16 :     u64 dataSize = param.DataDes.count * unitSize; // 单位:字节
     624           16 :     if (dataSize >= cclBufferManager_.GetInCCLbufferSize()) {
     625           16 :         HCCL_WARNING(
     626              :             "The current inCCLbufferSize is [%llu] bytes, change the HCCL_BUFFSIZE environment variable "
     627              :             "to be greater than the current data volume[%llu] bytes to improve the performance of the 91093 "
     628              :             "environment.",
     629              :             cclBufferManager_.GetInCCLbufferSize(), dataSize);
     630              :     }
     631              : 
     632           16 :     u64 dataSizePerRank = dataSize / deviceNumPerAggregation_;
     633           16 :     bool isOpbase = workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE;
     634           16 :     bool isOnlyAiv = topoMatcher_->GetIsOnlyAivConfig();
     635              :     // A3 AIV确定性 超节点内(单机与跨机) 支持单算子与图模式 限制单卡数据量8MB
     636           16 :     bool isBarrierOp = param.syncMode == SyncMode::UNLIMITED_TIMEWAITSYNCMODE; // Barrier算子不使能AIV
     637            0 :     bool isSupportAivDeter = (superPodNum_ == 1) && (topoMatcher_->GetAivModeConfig() && !isBarrierOp)
     638            0 :                              && IsSupportAIVReduce(param.DataDes.dataType, param.reduceType)
     639            0 :                              && ((topoMatcher_->GetDeterministicConfig() != DETERMINISTIC_DISABLE) || (serverNum_ > 1))
     640            0 :                              && ((userRankSize_ > DEVICE_EIGHT && dataSize < HCCL_SMALL_COUNT_8_MB)
     641            0 :                                  || (userRankSize_ <= DEVICE_EIGHT && dataSize <= HCCL_SMALL_COUNT_512_KB) || isOnlyAiv)
     642           16 :                              && (!retryEnable_) && userRankSize_ > 1 && !multiModuleDiffDeviceNumMode_;
     643              : 
     644           16 :     bool isAivMode = (topoMatcher_->GetAivModeConfig() && !isBarrierOp)
     645            0 :                      && IsSupportAIVReduce(param.DataDes.dataType, param.reduceType) && serverNum_ == 1
     646            0 :                      && ((isOpbase && (dataSizePerRank <= AIV_ALL_REDUCE_A3_ENTRY_SIZE || isOnlyAiv))
     647            0 :                          || (!isOpbase && (dataSizePerRank <= AIV_ALL_REDUCE_A3_GRAPH_ENTRY_SIZE || isOnlyAiv)))
     648            0 :                      && (topoMatcher_->GetDeterministicConfig() == DETERMINISTIC_DISABLE) && (!retryEnable_)
     649           16 :                      && !multiModuleDiffDeviceNumMode_;
     650              : 
     651           16 :     if (isSupportAivDeter) {
     652            0 :         algName = "AllReduceMeshAivFor91093Executor";
     653            0 :         HCCL_INFO("[SelectAlgfor91093] allreduce SelectAlgfor91093 algName [%s].", algName.c_str());
     654            0 :         return HCCL_SUCCESS;
     655              :     }
     656              : 
     657           16 :     if (IsNeedStrictMode(param)) {
     658            0 :         CHK_PRT_RET(
     659              :             !CheckStrictCondition(param),
     660              :             HCCL_ERROR("[AllReduceOperator][SelectAlgfor91093] not support DETERMINISTIC_STRICT mode."),
     661              :             HCCL_E_NOT_SUPPORT);
     662              : 
     663            0 :         algName = "AllReduceOrderPreservedFor91093Executor";
     664            0 :         HCCL_INFO("[SelectAlgfor91093] allreduce SelectAlgfor91093 algName [%s].", algName.c_str());
     665            0 :         return HCCL_SUCCESS;
     666              :     }
     667              : 
     668           16 :     if (isAivMode) {
     669            0 :         HCCL_INFO(
     670              :             "[SelectAlgfor91093] dataSize[%llu], dataSizePerRank[%llu], deviceNumPerAggregation[%u]", dataSize,
     671              :             dataSizePerRank, deviceNumPerAggregation_);
     672            0 :         if ((isOpbase && dataSize < AIV_ALL_REDUCE_BIG_SIZE)
     673            0 :             || (!isOpbase && dataSize <= AIV_A3_ALL_REDUCE_GRAPH_GUIYI_SIZE)) {
     674            0 :             algName = "AllReduceMeshAivSmallCountExecutor"; // 单server小数据
     675              :         } else {
     676            0 :             algName = "AllReduceMeshAivExecutor"; // 单server大数据
     677              :         }
     678            0 :         HCCL_INFO("[SelectAlgfor91093] AllReduce SelectAlgfor91093 is algName [%s].", algName.c_str());
     679            0 :         return HCCL_SUCCESS;
     680              :     }
     681              :     // ARS 算法选择
     682           16 :     bool isARSAlgo = multiModuleDiffDeviceNumMode_ && !multiSuperPodDiffDeviceNumMode_;
     683           16 :     if (isARSAlgo) {
     684            0 :         if (!(algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB
     685            0 :               || algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING)) {
     686            0 :             algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_NHR;
     687            0 :             HCCL_WARNING("[AllReduceOperator][SelectAlgfor91093] ARS only support NHR or RING in AlgoLevel1 "
     688              :                          "yet, default is NHR.");
     689              :         }
     690              :     }
     691              :     // AHC 算法选择逻辑
     692           16 :     if ((algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC)
     693            8 :         || (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_AHC_BROKE)) {
     694            9 :         CHK_RET(SelectAlgforAHC(dataSize, AHCOpType::AHC_OP_TYPE_ALLREDUCE));
     695              :     }
     696           16 :     void* commInputPtr = nullptr;
     697           16 :     u64 commInputSize = 0;
     698           16 :     CHK_RET(cclBufferManager_.GetInCCLbuffer(commInputPtr, commInputSize));
     699           16 :     bool cclLimit
     700           16 :         = (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)
     701           16 :           && (param.DataDes.count * SIZE_TABLE[param.DataDes.dataType] > (commInputSize / HCCL_MEMSIZE_HD_FACTOR));
     702              : 
     703              :     bool isSupportInlineReduce
     704           16 :         = IsSupportSDMAReduce(param.inputPtr, param.outputPtr, param.DataDes.dataType, param.reduceType);
     705           16 :     bool smallCountOptimSingleServer
     706           16 :         = (!retryEnable_) && (serverNum_ == 1)
     707            1 :           && ((workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE)
     708            0 :               || (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE && !param.aicpuUnfoldMode))
     709            1 :           && isSupportInlineReduce && (deviceNumPerAggregation_ > HCCL_DEVICE_NUM_TWO)
     710            1 :           && (param.DataDes.count * SIZE_TABLE[param.DataDes.dataType] <= HCCL_SMALL_COUNT_512_KB * userRankSize_)
     711           32 :           && !cclLimit;
     712            1 :     bool smallCountOptimMultiServer = (deviceNumPerAggregation_ > HCCL_DEVICE_NUM_TWO) && (serverNum_ != 1)
     713            0 :                                       && (superPodNum_ == 1)
     714           17 :                                       && (param.DataDes.count * SIZE_TABLE[param.DataDes.dataType]
     715            0 :                                           <= HCCL_SMALL_COUNT_1_MB * deviceNumPerAggregation_);
     716           16 :     bool useHostComm = !isSupportInlineReduce
     717           17 :                        && ((serverNum_ != 1 && superPodNum_ == 1 && !GetExternalInputInterHccsDisable())
     718            1 :                            || ((superPodNum_ > 1 || GetExternalInputInterHccsDisable()) && !retryEnable_
     719            0 :                                && param.DataDes.count * SIZE_TABLE[param.DataDes.dataType]
     720            0 :                                       <= HCCL_SMALL_COUNT_4_MB * deviceNumPerAggregation_));
     721           16 :     bool is2Pod2ServerTopo = (superPodNum_ == 2 && serverNum_ == 2); // 针对 A3背靠背机型
     722              :     bool smallCountOptimMultiPod
     723           16 :         = (superPodNum_ > 1 || (GetExternalInputInterHccsDisable() && serverNum_ > 1)) && !is2Pod2ServerTopo
     724           11 :           && (param.DataDes.count * unitSize <= HCCL_SMALL_COUNT_16_KB * deviceNumPerAggregation_)
     725           32 :           && !retryEnable_; // 涉及ROCE平面
     726              :     // 多超节点 的中等数据量
     727           16 :     bool midCountOptimMultiPod
     728           11 :         = (superPodNum_ > 1) && isOpbase && !multiSuperPodDiffDeviceNumMode_ && !multiModuleDiffDeviceNumMode_
     729           27 :           && (param.DataDes.count * unitSize <= HCCL_SMALL_COUNT_256_KB) && !retryEnable_; // 涉及ROCE平面
     730              : 
     731           16 :     if (multiModuleDiffDeviceNumMode_ && multiSuperPodDiffDeviceNumMode_) {
     732            0 :         algName = "AllReduceComm";
     733           16 :     } else if (multiModuleDiffDeviceNumMode_ && !multiSuperPodDiffDeviceNumMode_) {
     734            0 :         algName = "AllReduceARSFor91093Executor";
     735           16 :     } else if (midCountOptimMultiPod) {
     736            1 :         algName = "AllReduceMidCountFor91093Executor";
     737           15 :     } else if (useHostComm || smallCountOptimMultiServer || smallCountOptimMultiPod) {
     738           10 :         algName = "AllReduceComm";
     739           10 :         algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_NHR;
     740            5 :     } else if (smallCountOptimSingleServer) {
     741            0 :         algName = "AllReduceMeshSmallCountExecutor";
     742            5 :     } else if (
     743            5 :         (param.supportSymmetricMemory || param.supportZeroCopy)
     744            0 :         && (topoType_ == TopoType::TOPO_TYPE_NP_DOUBLE_RING
     745            0 :             || param.DataDes.count * unitSize > HCCL_MID_COUNT_16_MB * serverNum_)) {
     746            0 :         algName = "AllReduceRingZerocopyExecutor";
     747              :     } else {
     748            5 :         if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_HD) {
     749            0 :             algType_.algoLevel1 = AlgTypeLevel1::ALG_LEVEL1_NHR;
     750            0 :             HCCL_WARNING("[AllReduceOperator][SelectAlgfor91093] only support ring, NB and NHR in AlgoLevel1 yet, "
     751              :                          "default is algType=NHR.");
     752              :         }
     753            5 :         if (topoType_ == TopoType::TOPO_TYPE_NP_DOUBLE_RING) {
     754            4 :             algName = "AllReduceFastDoubleRingFor91093Executor";
     755            1 :         } else if (topoType_ == TopoType::TOPO_TYPE_NP_SINGLE_RING) {
     756            1 :             algName = "AllReduceRingFor91093Executor";
     757              :         } else {
     758            0 :             algName = "AllReduceComm"; // 支持91093全通信域
     759              :         }
     760              :     }
     761              :     // 如果配置了aiv only,但是实际没有选择aiv算法,需要通过DFX打印出具体原因
     762           16 :     if (isOnlyAiv && !isAivMode && !isSupportAivDeter) {
     763            0 :         HCCL_ERROR("The current conditions do not meet the aiv only execution criteria because:");
     764            0 :         CHK_PRT_RET(
     765              :             !IsSupportAIVReduce(param.DataDes.dataType, param.reduceType),
     766              :             HCCL_ERROR(
     767              :                 "current data type[%s] or reduceType[%s] not supported, "
     768              :                 "data type support range:[int8, int16, int32, float16, float32, bfloat16] reduce type support "
     769              :                 "range:[sum, max, min]",
     770              :                 GetDataTypeEnumStr(param.DataDes.dataType).c_str(), GetReduceOpEnumStr(param.reduceType).c_str()),
     771              :             HCCL_E_NOT_SUPPORT);
     772              : 
     773            0 :         CHK_PRT_RET(retryEnable_, HCCL_ERROR("retryEnable [%d] not supported", retryEnable_), HCCL_E_NOT_SUPPORT);
     774              : 
     775            0 :         CHK_PRT_RET(
     776              :             superPodNum_ != 1, HCCL_ERROR("multi superpod [%u] not supported", superPodNum_), HCCL_E_NOT_SUPPORT);
     777              : 
     778            0 :         CHK_PRT_RET(
     779              :             multiModuleDiffDeviceNumMode_,
     780              :             HCCL_ERROR("multiModuleDiffDeviceNumMode [%d] not supported", multiModuleDiffDeviceNumMode_),
     781              :             HCCL_E_NOT_SUPPORT);
     782            0 :         return HCCL_E_NOT_SUPPORT;
     783              :     }
     784           16 :     HCCL_INFO("[SelectAlgfor91093] AllReduce SelectAlgfor91093 is algName [%s].", algName.c_str());
     785           16 :     return HCCL_SUCCESS;
     786              : }
     787              : 
     788              : REGISTER_OP(HcclCMDType::HCCL_CMD_ALLREDUCE, AllReduce, AllReduceOperator);
     789              : 
     790              : } // namespace hccl
        

Generated by: LCOV version 2.0-1