LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_gather - coll_all_gather_mesh_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 141 0
Test Date: 2026-07-28 12:11:00 Functions: 0.0 % 9 0

            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_gather_mesh_executor.h"
      12              : 
      13              : namespace hccl {
      14            0 : CollAllGatherMeshExecutor::CollAllGatherMeshExecutor(const HcclDispatcher dispatcher,
      15            0 :     std::unique_ptr<TopoMatcher> &topoMatcher)
      16            0 :     : CollAllGatherExecutor(dispatcher, topoMatcher)
      17              : {
      18            0 :     DMAReduceFlag_ = false;
      19            0 : }
      20              : 
      21            0 : HcclResult CollAllGatherMeshExecutor::CalcStreamNum(u32& streamNum)
      22              : {
      23            0 :     u32 totalStreamNum = topoAttr_.deviceNumPerAggregation > 1U ? topoAttr_.deviceNumPerAggregation - 1U : 1U;
      24            0 :     streamNum = totalStreamNum - 1U;
      25            0 :     HCCL_INFO("[CollAllGatherMeshExecutor][CalcStreamNum] tag[%s] streamNum[%u].",
      26              :         tag_.c_str(), streamNum);
      27            0 :     return HCCL_SUCCESS;
      28              : }
      29              : 
      30            0 : HcclResult CollAllGatherMeshExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      31              : {
      32            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      33            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      34            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      35            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      36            0 :     CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
      37            0 :     return HCCL_SUCCESS;
      38              : }
      39              : 
      40            0 : HcclResult CollAllGatherMeshExecutor::CalcTransportMemType(TransportMemType &inputType, TransportMemType &outputType)
      41              : {
      42            0 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      43            0 :         inputType = TransportMemType::CCL_INPUT;
      44            0 :         outputType = TransportMemType::CCL_OUTPUT;
      45              :     } else {
      46            0 :         inputType = TransportMemType::PARAM_INPUT;
      47            0 :         outputType = TransportMemType::PARAM_OUTPUT;
      48              :     }
      49            0 :     HCCL_INFO("[CollAllGatherMeshExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d].",
      50              :         tag_.c_str(), inputType, outputType);
      51            0 :     return HCCL_SUCCESS;
      52              : }
      53              : 
      54            0 : HcclResult CollAllGatherMeshExecutor::CalcLevel0CommInfo(TransportMemType inputType, TransportMemType outputType,
      55              :     std::vector<LevelNSubCommTransport>& opTransport)
      56              : {
      57            0 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      58            0 :     commParaLevel0.meshSinglePlane = (topoAttr_.deviceType == DevType::DEV_TYPE_910B) &&
      59            0 :         topoMatcher_->GetExternalInputHcclDeterministic() == DETERMINISTIC_DISABLE &&
      60            0 :         (workflowMode_ != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE);
      61            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      62            0 :     return HCCL_SUCCESS;
      63            0 : }
      64              : 
      65            0 : u64 CollAllGatherMeshExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
      66              : {
      67            0 :     u64 maxCountPerLoop = cclBuffSize / topoAttr_.userRankSize / HCCL_MIN_SLICE_ALIGN
      68            0 :         * HCCL_MIN_SLICE_ALIGN / unitSize;
      69            0 :     return maxCountPerLoop;
      70              : }
      71              : 
      72            0 : HcclResult CollAllGatherMeshExecutor::KernelRun(const OpParam &param, ExecMem &execMem)
      73              : {
      74            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherMeshExecutor][KernelRun]AllGather mesh start");
      75            0 :     u32 perDataSize = SIZE_TABLE[param.DataDes.dataType];
      76              : 
      77              :     // 获取子通信域信息
      78            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
      79            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      80            0 :     u32 level0RankSize = level0CommInfo.localRankSize;
      81            0 :     u32 commIndex = level0CommInfo.localRank;
      82            0 :     CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
      83            0 :     SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
      84            0 :     u32 serverIndex = level1CommInfo.localRank;
      85              : 
      86            0 :     HCCL_DEBUG("[CollAllGatherMeshExecutor][KernelRun]serverIndex is %u, commIndex is %u", serverIndex, commIndex);
      87            0 :     u64 inputMemSize = execMem.inputMem.size();
      88            0 :     u64 baseOffset = serverIndex * inputMemSize * level0RankSize;
      89            0 :     u64 level0Offset = commIndex * inputMemSize;
      90            0 :     DeviceMem dstMem = execMem.outputMem.range(baseOffset + level0Offset, inputMemSize);
      91            0 :     CHK_SMART_PTR_NULL(dstMem);
      92              :     //  第一步,将数据从input内存拷贝到output内存的对应位置
      93            0 :     HcclResult ret = HcclD2DMemcpyAsync(dispatcher_, dstMem, execMem.inputMem, const_cast<Stream&>(param.stream));
      94            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      95              :         HCCL_ERROR("[CollAllGatherMeshExecutor][KernelRun]AllGather 4PmeshHD memcpy Failed, Offset[%llu], Size[%llu].",
      96              :         baseOffset + level0Offset, inputMemSize), ret);
      97              : 
      98              :     // 第二步,各个AI Server 内 multi stream mesh AllGather
      99            0 :     std::vector<Slice> dataSegsSlice;                 // 数据分成ranksize份,每份的起始偏移和大小
     100            0 :     std::vector<std::vector<Slice>> multiStreamSlice; // 每个stream使用的数据基于用户buffer的偏移
     101            0 :     u32 sliceNum = level0RankSize;
     102            0 :     CHK_RET(PrepareAllgatherSlice(sliceNum, inputMemSize, dataSegsSlice));
     103              : 
     104              :     // mesh算法stream数量为server内rank数减1
     105            0 :     CHK_RET(AlgTemplateBase::PrepareSliceMeshStreams(dataSegsSlice, sliceNum - 1, multiStreamSlice));
     106              : 
     107            0 :     CHK_RET(ActiveSlaveStreams(param.stream));
     108              : 
     109              :     //  抽取当前用于多环AllGather 的output内存数据
     110            0 :     DeviceMem currentOutputMem = execMem.outputMem.range(baseOffset, inputMemSize * level0RankSize);
     111            0 :     CHK_SMART_PTR_NULL(currentOutputMem);
     112              : 
     113            0 :     std::unique_ptr<AlgTemplateBase> level0TempAlg;
     114            0 :     if (topoAttr_.deviceType == DevType::DEV_TYPE_910B) {
     115            0 :         level0TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_MESH_ATOMIC,
     116            0 :                                                                        dispatcher_);
     117              :     } else {
     118            0 :         level0TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_MESH,
     119            0 :                                                                        dispatcher_);
     120              :     }
     121            0 :     CHK_SMART_PTR_NULL(level0TempAlg);
     122            0 :     CHK_RET(level0TempAlg->Prepare(algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux,
     123              :         topoAttr_.userRank, nullptr, commIndex, level0RankSize));
     124            0 :     CHK_RET(level0TempAlg->Prepare(currentOutputMem, currentOutputMem, execMem.inputMem,
     125              :         execMem.count * level0RankSize, param.DataDes.dataType, param.stream, HCCL_REDUCE_RESERVED,
     126              :         LEVEL0_BRIDGE_RANK_ID, dataSegsSlice, baseOffset));
     127            0 :     u32 rankSize = level0RankSize;
     128            0 :     CHK_RET(level0TempAlg->RegisterProfiler((rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + commIndex,
     129              :         PROF_STAGE_1, HCCL_EXEC_STEP_NOT_SET, param.stream));
     130            0 :     CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
     131            0 :     HCCL_INFO("AllGather mesh HD level0 run success");
     132              : 
     133              :     //  第三步, AI server 间 recursive halving doubling AllGather
     134            0 :     u64 hdSize = inputMemSize * level0RankSize;
     135            0 :     u64 hdCount = hdSize / perDataSize;
     136              : 
     137            0 :     std::unique_ptr<AlgTemplateBase> level1TempAlg;
     138            0 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING || (topoAttr_.isDiffDeviceModule && topoAttr_.serverNum == 1)) {
     139              :         // 1-单server-SDMA
     140            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     141            0 :                 TemplateType::TEMPLATE_ALL_GATHER_RING, dispatcher_);
     142            0 :         HCCL_INFO("AllGather mesh: using ring algo inter-server.");
     143            0 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
     144            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     145            0 :                 TemplateType::TEMPLATE_ALL_GATHER_NHR, dispatcher_);
     146            0 :         HCCL_INFO("AllGather mesh: using nhr algo inter-server.");
     147            0 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
     148            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     149            0 :                 TemplateType::TEMPLATE_ALL_GATHER_NHRV1, dispatcher_);
     150            0 :         HCCL_INFO("AllGather mesh: using nhr_v1 algo inter-server.");
     151            0 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
     152            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     153            0 :                 TemplateType::TEMPLATE_ALL_GATHER_NB, dispatcher_);
     154            0 :         HCCL_INFO("AllGather mesh: using nonuniform-bruck algo inter-server.");
     155              :     } else {
     156            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     157            0 :                 TemplateType::TEMPLATE_ALL_GATHER_RECURSIVE_HALVING_DOUBLING, dispatcher_);
     158            0 :         HCCL_INFO("AllGather mesh: using halving-doubling algo inter-server.");
     159              :     }
     160            0 :     CHK_SMART_PTR_NULL(level1TempAlg);
     161              : 
     162              :     //  此处虽然带入inputMem作为scratch mem, 但inputMem 不能被使用
     163            0 :     CHK_RET(level1TempAlg->Prepare(execMem.outputMem, execMem.outputMem, execMem.inputMem, hdCount,
     164              :         param.DataDes.dataType, param.stream, HcclReduceOp::HCCL_REDUCE_RESERVED, INVALID_VALUE_RANKID,
     165              :         std::vector<Slice>(COMM_INDEX_0), 0));
     166              : 
     167            0 :     rankSize = level1CommInfo.localRankSize;
     168            0 :     CHK_RET(level1TempAlg->RegisterProfiler((rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + serverIndex,
     169              :         PROF_STAGE_2, HCCL_EXEC_STEP_NOT_SET, param.stream));
     170              : 
     171            0 :     CHK_RET(RunTemplate(level1TempAlg, level1CommInfo));
     172            0 :     HCCL_INFO("AllGather mesh HD level1 run success");
     173            0 :     return HCCL_SUCCESS;
     174            0 : }
     175            0 : HcclResult CollAllGatherMeshExecutor::Getlevel1CommRank(SubCommInfo& level1CommInfo)
     176              : {
     177            0 :     if (CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1) != HCCL_SUCCESS) {
     178            0 :         return HCCL_E_UNAVAIL;
     179              :     }
     180            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     181            0 :     u32 ringNum = (topoType_ == TopoType::TOPO_TYPE_8P_RING) ? LEVEL0_PLANE_NUM_IN_8PRING :
     182              :         LEVEL0_PLANE_NUM_IN_NPRING_SINGLE;
     183            0 :     u32 commIndex = (ringNum == LEVEL0_PLANE_NUM_IN_8PRING) ? topoAttr_.devicePhyId : level0CommInfo.localRank;
     184              : 
     185            0 :     if (CheckCommSize(COMM_LEVEL1, commIndex + 1) != HCCL_SUCCESS) {
     186            0 :         return HCCL_E_UNAVAIL;
     187              :     }
     188            0 :     level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
     189              : 
     190            0 :     return HCCL_SUCCESS;
     191            0 : }
     192              : 
     193            0 : HcclResult CollAllGatherMeshExecutor::SelectTempAlg(std::unique_ptr<AlgTemplateBase> &level1TempAlg, u32 level1RankSize)
     194              : {
     195            0 :     if (level1RankSize > 1) {
     196            0 :         if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING || (topoAttr_.isDiffDeviceModule && topoAttr_.serverNum == 1)) {
     197              :             // 1-单server-SDMA
     198            0 :             level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     199            0 :                     TemplateType::TEMPLATE_ALL_GATHER_RING, dispatcher_);
     200            0 :             HCCL_INFO("AllGather mesh: using ring algo inter-server.");
     201            0 :         } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR) {
     202            0 :             level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     203            0 :                     TemplateType::TEMPLATE_ALL_GATHER_NHR, dispatcher_);
     204            0 :             HCCL_INFO("AllGather mesh: using nhr algo inter-server.");
     205            0 :         } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NHR_V1) {
     206            0 :             level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     207            0 :                     TemplateType::TEMPLATE_ALL_GATHER_NHRV1, dispatcher_);
     208            0 :             HCCL_INFO("AllGather mesh: using nhr_v1 algo inter-server.");
     209            0 :         } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
     210            0 :             level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     211            0 :                     TemplateType::TEMPLATE_ALL_GATHER_NB, dispatcher_);
     212            0 :             HCCL_INFO("AllGather mesh: using nonuniform-bruck algo inter-server.");
     213              :         } else {
     214            0 :             level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     215            0 :                     TemplateType::TEMPLATE_ALL_GATHER_RECURSIVE_HALVING_DOUBLING, dispatcher_);
     216            0 :             HCCL_INFO("AllGather mesh: using halving-doubling algo inter-server.");
     217              :         }
     218            0 :         CHK_SMART_PTR_NULL(level1TempAlg);
     219            0 :         return HCCL_SUCCESS;
     220              :     }
     221            0 :     return HCCL_E_UNAVAIL;
     222              : }
     223              : REGISTER_EXEC("AllGatherMeshExecutor", AllGatherMesh, CollAllGatherMeshExecutor);
     224              : } // namespace hccl
        

Generated by: LCOV version 2.0-1