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: 78.3 % 83 65
Test Date: 2026-08-04 10:52:23 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(const HcclDispatcher dispatcher,
      16           22 :                                                      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("[CollAllReduceCommExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
      42              :         tag_.c_str(), inputType, outputType);
      43           22 :     return HCCL_SUCCESS;
      44              : }
      45              : 
      46           22 : HcclResult CollAllReduceCommExecutor::CalcCombinedCommInfo(TransportMemType inputType,
      47              :     TransportMemType outputType,
      48              :     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              :         curSize > SDMA_SEND_MAX_SIZE;
      74            0 :     return hugeData;
      75              : }
      76              : 
      77            0 : bool CollAllReduceCommExecutor::IsSmallData(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           10 :             tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR_ONESHOT, dispatcher_);
     101           10 :             HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_ONESHOT in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     102              :         } else {
     103            0 :             tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR, dispatcher_);
     104            0 :             HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     105              :         }
     106           10 :         HCCL_INFO("AllReduce comm: using nhr algo inter-server.");
     107           10 :         CHK_SMART_PTR_NULL(tempAlg);
     108           10 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     109           10 :         if (topoAttr_.deviceType != DevType::DEV_TYPE_910_93 || algoAttr_.isSupportAtomicWrite) {
     110            1 :             tempAlg->CloseBarrier();
     111              :         }
     112           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
     113            0 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR_V1, dispatcher_);
     114            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_V1 in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     115            0 :         CHK_SMART_PTR_NULL(tempAlg);
     116            0 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     117           11 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
     118            0 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NB, dispatcher_);
     119            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NB in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     120            0 :         CHK_SMART_PTR_NULL(tempAlg);
     121            0 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     122              :     } else {
     123           11 :         tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_RING, dispatcher_);
     124           11 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_RING in COMM_COMBINE/COMM_COMBINE_ORDER", __func__);
     125           11 :         CHK_SMART_PTR_NULL(tempAlg);
     126           11 :         CHK_RET(tempAlg->Prepare(reduceAttr));
     127              :     }
     128           21 :     CHK_SMART_PTR_NULL(tempAlg);
     129              : 
     130           21 :     u32 rankSize = combinedCommInfo.localRankSize;
     131          105 :     CHK_RET(tempAlg->Prepare(execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count,
     132              :         param.DataDes.dataType, param.stream, param.reduceType,
     133              :         LEVEL0_BRIDGE_RANK_ID, std::vector<Slice>(0), 0));
     134              : 
     135           21 :     CHK_RET(tempAlg->RegisterProfiler(
     136              :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) +
     137              :         combinedCommInfo.localRank, PROF_STAGE_0, HCCL_EXEC_STEP_NOT_SET, param.stream));
     138              : 
     139           21 :     CHK_RET(RunTemplate(tempAlg, combinedCommInfo));
     140           21 :     return HCCL_SUCCESS;
     141           21 : }
     142              : 
     143              : REGISTER_EXEC("AllReduceComm", AllReduceComm, CollAllReduceCommExecutor);
     144              : 
     145              : } // namespace hccl
        

Generated by: LCOV version 2.0-1