LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_reduce - coll_all_reduce_comm_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 77.6 % 85 66
Test Date: 2026-08-18 17:47:01 Functions: 71.4 % 7 5

            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 "coll_all_reduce_comm_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15           22 : CollAllReduceCommExecutor::CollAllReduceCommExecutor(
      16           22 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17           22 :     : CollAllReduceExecutor(dispatcher, topoMatcher)
      18              : {
      19           22 :     desc_.deterministic = 1;
      20           22 :     DMAReduceFlag_ = false;
      21           22 : }
      22              : 
      23           22 : HcclResult CollAllReduceCommExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      24              : {
      25           22 :     TransportMemType inputType = TransportMemType::RESERVED;
      26           22 :     TransportMemType outputType = TransportMemType::RESERVED;
      27           22 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      28           22 :     CHK_RET(CalcCombinedCommInfo(inputType, outputType, opTransport));
      29           22 :     return HCCL_SUCCESS;
      30              : }
      31              : 
      32           22 : HcclResult CollAllReduceCommExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
      33              : {
      34           22 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      35            1 :         inputType = TransportMemType::CCL_INPUT;
      36            1 :         outputType = TransportMemType::CCL_OUTPUT;
      37              :     } else {
      38           21 :         inputType = TransportMemType::PARAM_INPUT;
      39           21 :         outputType = TransportMemType::PARAM_OUTPUT;
      40              :     }
      41           22 :     HCCL_INFO(
      42              :         "[CollAllReduceCommExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(),
      43              :         inputType, outputType);
      44           22 :     return HCCL_SUCCESS;
      45              : }
      46              : 
      47           22 : HcclResult CollAllReduceCommExecutor::CalcCombinedCommInfo(
      48              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      49              : {
      50           22 :     CommPlane commPlane = COMM_COMBINE;
      51           22 :     if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
      52           10 :         commPlane = COMM_COMBINE_ORDER;
      53              :     }
      54              : 
      55           22 :     CommParaInfo commParaInfo(commPlane, CommType::COMM_TAG_MAX);
      56           22 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
      57           11 :         commParaInfo.commType = CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING;
      58           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
      59            0 :         commParaInfo.commType = CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING_V1;
      60           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
      61            0 :         commParaInfo.commType = CommType::COMM_TAG_NONUNIFORM_BRUCK;
      62              :     } else {
      63           11 :         commParaInfo.commType = CommType::COMM_TAG_RING_INNER;
      64              :     }
      65           22 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[commPlane], inputType, outputType));
      66              : 
      67           22 :     return HCCL_SUCCESS;
      68           22 : }
      69              : 
      70            0 : bool CollAllReduceCommExecutor::IsHugeData(const u64 curSize)
      71              : {
      72            0 :     bool hugeData = curSize / topoAttr_.deviceNumPerAggregation / HCCL_INTERNODE_MAX_DATA_RATE > RDMA_SEND_MAX_SIZE
      73            0 :                     || curSize > SDMA_SEND_MAX_SIZE;
      74            0 :     return hugeData;
      75              : }
      76              : 
      77            0 : bool CollAllReduceCommExecutor::IsSmallData([[maybe_unused]] const u64 totalSize, const u64 curSize)
      78              : {
      79            0 :     bool smallData = IsAllReduceSmallData(curSize);
      80            0 :     return smallData;
      81              : }
      82              : 
      83           21 : HcclResult CollAllReduceCommExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
      84              : {
      85           21 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] userRank[%u] starts.", __func__, topoAttr_.userRank);
      86           21 :     CommPlane commPlane = COMM_COMBINE;
      87           21 :     if (topoAttr_.deviceType == DevType::DEV_TYPE_910_93) {
      88            9 :         commPlane = COMM_COMBINE_ORDER;
      89              :     }
      90              : 
      91           21 :     CHK_RET(CheckCommSize(commPlane, 1));
      92           21 :     SubCommInfo combinedCommInfo = GetSubCommInfo(commPlane, 0);
      93              : 
      94           21 :     u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, param.DataDes.dataType, param.reduceType);
      95              : 
      96           21 :     std::unique_ptr<AlgTemplateBase> tempAlg;
      97           21 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
      98           10 :         u64 curSize = execMem.count * SIZE_TABLE[param.DataDes.dataType]; // 单位 byte
      99           10 :         if (curSize <= NHR_ALLREDUCE_SMALL_SIZE) {
     100           20 :             tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     101           10 :                 TemplateType::TEMPLATE_ALL_REDUCE_NHR_ONESHOT, dispatcher_);
     102           10 :             HCCL_CONFIG_INFO(
     103              :                 HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_ONESHOT in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     104              :         } else {
     105              :             tempAlg
     106            0 :                 = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR, dispatcher_);
     107            0 :             HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     108              :         }
     109           10 :         HCCL_INFO("AllReduce comm: using nhr algo inter-server.");
     110           10 :         CHK_SMART_PTR_NULL(tempAlg);
     111           10 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     112           10 :         if (topoAttr_.deviceType != DevType::DEV_TYPE_910_93 || algoAttr_.isSupportAtomicWrite) {
     113            1 :             tempAlg->CloseBarrier();
     114              :         }
     115           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
     116            0 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR_V1, dispatcher_);
     117            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_V1 in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     118            0 :         CHK_SMART_PTR_NULL(tempAlg);
     119            0 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     120           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
     121            0 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NB, dispatcher_);
     122            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NB in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     123            0 :         CHK_SMART_PTR_NULL(tempAlg);
     124            0 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     125              :     } else {
     126           11 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_RING, dispatcher_);
     127           11 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_RING in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     128           11 :         CHK_SMART_PTR_NULL(tempAlg);
     129           11 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     130              :     }
     131           21 :     CHK_SMART_PTR_NULL(tempAlg);
     132              : 
     133           21 :     u32 rankSize = combinedCommInfo.localRankSize;
     134          105 :     CHK_RET(tempAlg->Prepare(
     135              :         execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count, param.DataDes.dataType, param.stream,
     136              :         param.reduceType, LEVEL0_BRIDGE_RANK_ID, std::vector<Slice>(0), 0));
     137              : 
     138           21 :     CHK_RET(tempAlg->RegisterProfiler(
     139              :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + combinedCommInfo.localRank, PROF_STAGE_0,
     140              :         HCCL_EXEC_STEP_NOT_SET, param.stream));
     141              : 
     142           21 :     CHK_RET(RunTemplate(tempAlg, combinedCommInfo));
     143           21 :     return HCCL_SUCCESS;
     144           21 : }
     145              : 
     146              : REGISTER_EXEC("AllReduceComm", AllReduceComm, CollAllReduceCommExecutor);
     147              : 
     148              : } // namespace hccl
        

Generated by: LCOV version 2.0-1