LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_gather - coll_all_gather_mid_count_for_910_93_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 146 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 12 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_mid_count_for_910_93_executor.h"
      12              : 
      13              : namespace hccl {
      14            0 : CollAllGatherMidCountFor91093Executor::CollAllGatherMidCountFor91093Executor(
      15            0 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      16            0 :     : CollAllGatherExecutor(dispatcher, topoMatcher)
      17              : {
      18            0 :     DMAReduceFlag_ = true;
      19            0 :     desc_.level1SupportedAlgos = {
      20              :         AlgTypeLevel1::ALG_LEVEL1_NHR,
      21            0 :     };
      22            0 :     desc_.level2SupportedAlgos = {
      23              :         AlgTypeLevel2::ALG_LEVEL2_NHR,
      24            0 :     };
      25            0 : }
      26              : 
      27            0 : HcclResult CollAllGatherMidCountFor91093Executor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      28              : {
      29            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      30            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      31            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      32            0 :     CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
      33            0 :     CHK_RET(CalcLevel2CommInfo(inputType, outputType, opTransport));
      34            0 :     return HCCL_SUCCESS;
      35              : }
      36              : 
      37            0 : HcclResult CollAllGatherMidCountFor91093Executor::CalcTransportMemType(
      38              :     TransportMemType& inputType, TransportMemType& outputType) const
      39              : {
      40            0 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      41            0 :         inputType = TransportMemType::CCL_INPUT;
      42            0 :         outputType = TransportMemType::CCL_OUTPUT;
      43              :     } else {
      44            0 :         HCCL_ERROR("AllGatherMidCountFor91093Executor do not support offload mode");
      45            0 :         return HCCL_E_UNAVAIL;
      46              :     }
      47            0 :     HCCL_INFO(
      48              :         "[CollAllGatherMidCountFor91093Executor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
      49              :         tag_.c_str(), inputType, outputType);
      50            0 :     return HCCL_SUCCESS;
      51              : }
      52              : 
      53            0 : HcclResult CollAllGatherMidCountFor91093Executor::CalcLevel1CommInfo(
      54              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      55              : {
      56            0 :     CommParaInfo commParaCombineL1(COMM_COMBINE_L1, CommType::COMM_TAG_WHOLE_NHR);
      57            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaCombineL1, opTransport[COMM_COMBINE_L1], inputType, outputType));
      58            0 :     return HCCL_SUCCESS;
      59            0 : }
      60              : 
      61            0 : HcclResult CollAllGatherMidCountFor91093Executor::CalcLevel2CommInfo(
      62              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      63              : {
      64            0 :     CommParaInfo commParaLevel2(COMM_LEVEL2, CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING);
      65            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel2, opTransport[COMM_LEVEL2], inputType, outputType));
      66            0 :     return HCCL_SUCCESS;
      67            0 : }
      68              : 
      69            0 : u64 CollAllGatherMidCountFor91093Executor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
      70              : {
      71            0 :     u64 maxCountPerLoop
      72            0 :         = cclBuffSize / topoAttr_.userRankSize / HCCL_MIN_SLICE_ALIGN_910_93 / unitSize * HCCL_MIN_SLICE_ALIGN_910_93;
      73            0 :     if (cclBuffSize != 0 && maxCountPerLoop == 0) {
      74            0 :         maxCountPerLoop = cclBuffSize / topoAttr_.userRankSize / unitSize;
      75            0 :         HCCL_INFO(
      76              :             "[CollAllGatherMidCountFor91093Executor][CalcLoopMaxCount]"
      77              :             "using default maxCountPerLoop[%llu] as CCLBuffSize / unitSize",
      78              :             maxCountPerLoop);
      79              :     }
      80            0 :     if (maxCountPerLoop == 0) {
      81            0 :         HCCL_ERROR("[CollAllGatherMidCountFor91093Executor][CalcLoopMaxCount] cclbuffer size is too small");
      82              :     }
      83            0 :     return maxCountPerLoop;
      84              : }
      85              : 
      86            0 : u64 CollAllGatherMidCountFor91093Executor::CalcDstMemOffset(const OpParam& param, u64 inputMemSize) const
      87              : {
      88              :     (void)param;
      89            0 :     return topoAttr_.userRank * inputMemSize;
      90              : }
      91              : 
      92            0 : HcclResult CollAllGatherMidCountFor91093Executor::PrepareL2DataSlices(
      93              :     const OpParam& param, const SubCommInfo& level1CommInfo, const SubCommInfo& level2CommInfo, u64 inputMemSize,
      94              :     std::vector<Slice>& dataSlices) const
      95              : {
      96              :     (void)param;
      97            0 :     const u32 level1RankSize = level1CommInfo.localRankSize;
      98            0 :     const u32 level1RankIndex = level1CommInfo.localRank;
      99            0 :     const u32 level2RankSize = level2CommInfo.localRankSize;
     100              : 
     101            0 :     std::vector<Slice> level2DataSlices;
     102            0 :     for (u32 i = 0; i < level2RankSize; i++) {
     103            0 :         Slice sliceTemp;
     104            0 :         sliceTemp.size = inputMemSize;
     105            0 :         sliceTemp.offset = inputMemSize * (i * level1RankSize + level1RankIndex);
     106            0 :         level2DataSlices.push_back(sliceTemp);
     107              :     }
     108              : 
     109            0 :     dataSlices = std::move(level2DataSlices);
     110            0 :     return HCCL_SUCCESS;
     111            0 : }
     112              : 
     113            0 : HcclResult CollAllGatherMidCountFor91093Executor::RunLevel2ByNHR(
     114              :     const OpParam& param, ExecMem& execMem, SubCommInfo& level1CommInfo, SubCommInfo& level2CommInfo) const
     115              : {
     116            0 :     const u32 level2RankSize = level2CommInfo.localRankSize;
     117            0 :     const u32 multiSuperPodMode = 1;
     118            0 :     if (level2RankSize > multiSuperPodMode) {
     119            0 :         u32 unitSize = 0;
     120            0 :         const HcclDataType dataType = param.GetDataType();
     121            0 :         CHK_RET(SalGetDataTypeSize(dataType, unitSize));
     122            0 :         u64 inputMemSize = execMem.count * unitSize;
     123              : 
     124              :         std::unique_ptr<AlgTemplateBase> level2AGExecutor
     125            0 :             = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_NHR, dispatcher_);
     126            0 :         CHK_SMART_PTR_NULL(level2AGExecutor);
     127              : 
     128            0 :         std::vector<Slice> dataSlices;
     129            0 :         CHK_RET(PrepareL2DataSlices(param, level1CommInfo, level2CommInfo, inputMemSize, dataSlices));
     130            0 :         CHK_RET(level2AGExecutor->Prepare(
     131              :             execMem.outputMem, execMem.outputMem, execMem.inputMem, execMem.count, param.GetDataType(), param.stream,
     132              :             HCCL_REDUCE_RESERVED, INVALID_VALUE_RANKID, dataSlices, 0));
     133              : 
     134            0 :         CHK_RET(level2AGExecutor->RegisterProfiler(
     135              :             (level2RankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level2CommInfo.localRank, PROF_STAGE_0,
     136              :             HCCL_EXEC_STEP_NOT_SET, param.stream));
     137              : 
     138            0 :         CHK_RET(RunTemplate(level2AGExecutor, level2CommInfo));
     139            0 :     }
     140            0 :     HCCL_INFO("MidCountAllGather run success in level2");
     141            0 :     return HCCL_SUCCESS;
     142              : }
     143              : 
     144            0 : HcclResult CollAllGatherMidCountFor91093Executor::PrepareL1DataSlices(
     145              :     const OpParam& param, const SubCommInfo& level1CommInfo, const SubCommInfo& level2CommInfo, u64 inputMemSize,
     146              :     u32 moduleId, std::vector<Slice>& dataSlices) const
     147              : {
     148              :     (void)level2CommInfo;
     149            0 :     u32 unitSize = 0;
     150            0 :     CHK_RET(SalGetDataTypeSize(param.GetDataType(), unitSize));
     151            0 :     const u32 level1RankSize = level1CommInfo.localRankSize;
     152            0 :     std::vector<Slice> level1DataSlices;
     153            0 :     for (u32 i = 0; i < level1RankSize; i++) {
     154            0 :         Slice sliceTemp;
     155            0 :         sliceTemp.size = inputMemSize;
     156            0 :         sliceTemp.offset = inputMemSize * (level1RankSize * moduleId + i);
     157            0 :         level1DataSlices.push_back(sliceTemp);
     158              :     }
     159            0 :     dataSlices = std::move(level1DataSlices);
     160            0 :     return HCCL_SUCCESS;
     161            0 : }
     162              : 
     163            0 : HcclResult CollAllGatherMidCountFor91093Executor::RunLevel1ByNHR(
     164              :     const OpParam& param, ExecMem& execMem, SubCommInfo& level1CommInfo, SubCommInfo& level2CommInfo)
     165              : {
     166            0 :     const u32 level1RankSize = level1CommInfo.localRankSize;
     167            0 :     const u32 level2RankSize = level2CommInfo.localRankSize;
     168            0 :     const u32 multiRankMode = 1;
     169            0 :     if (level1RankSize <= multiRankMode) {
     170            0 :         return HCCL_SUCCESS;
     171              :     }
     172              : 
     173            0 :     u32 unitSize = 0;
     174            0 :     const HcclDataType dataType = param.GetDataType();
     175            0 :     CHK_RET(SalGetDataTypeSize(dataType, unitSize));
     176            0 :     u64 inputMemSize = execMem.count * unitSize;
     177              : 
     178            0 :     for (u32 moduleId = 0; moduleId < level2RankSize; moduleId++) {
     179            0 :         std::vector<Slice> dataSlices;
     180            0 :         CHK_RET(PrepareL1DataSlices(param, level1CommInfo, level2CommInfo, inputMemSize, moduleId, dataSlices));
     181              : 
     182              :         // 计算slice, 不同超节点相同slice
     183              :         std::unique_ptr<AlgTemplateBase> level1AGExecutor
     184            0 :             = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_NHR, dispatcher_);
     185            0 :         CHK_SMART_PTR_NULL(level1AGExecutor);
     186              : 
     187            0 :         CHK_RET(level1AGExecutor->Prepare(
     188              :             execMem.outputMem, execMem.outputMem, execMem.inputMem, execMem.count, param.DataDes.dataType, param.stream,
     189              :             HCCL_REDUCE_RESERVED, INVALID_VALUE_RANKID, dataSlices, 0));
     190              : 
     191            0 :         CHK_RET(level1AGExecutor->RegisterProfiler(
     192              :             (level1RankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level2CommInfo.localRank, PROF_STAGE_1,
     193              :             HCCL_EXEC_STEP_NOT_SET, param.stream));
     194              : 
     195            0 :         CHK_RET(RunTemplate(level1AGExecutor, level1CommInfo));
     196            0 :     }
     197            0 :     HCCL_INFO("MidCountAllGather run success in level1");
     198            0 :     return HCCL_SUCCESS;
     199              : }
     200              : 
     201            0 : HcclResult CollAllGatherMidCountFor91093Executor::KernelRun(const OpParam& param, ExecMem& execMem)
     202              : {
     203            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] The MidCountFor91093Executor starts", __func__);
     204              : 
     205            0 :     SubCommInfo level1CommInfo;
     206            0 :     SubCommInfo level2CommInfo;
     207            0 :     CHK_RET(CheckCommSize(COMM_COMBINE_L1, COMM_INDEX_0 + 1));
     208            0 :     CHK_RET(CheckCommSize(COMM_LEVEL2, COMM_INDEX_0 + 1));
     209            0 :     level1CommInfo = GetSubCommInfo(COMM_COMBINE_L1, COMM_INDEX_0);
     210            0 :     level2CommInfo = GetSubCommInfo(COMM_LEVEL2, COMM_INDEX_0);
     211              : 
     212            0 :     u32 unitSize = 0;
     213            0 :     const HcclDataType dataType = param.GetDataType();
     214            0 :     CHK_RET(SalGetDataTypeSize(dataType, unitSize));
     215              : 
     216            0 :     u64 inputMemSize = execMem.count * unitSize;
     217            0 :     const u32 SINGLE_RANK_FLAG = 1;
     218              : 
     219            0 :     if (topoAttr_.userRankSize == SINGLE_RANK_FLAG) {
     220            0 :         DeviceMem srcMem = DeviceMem::create(static_cast<u8*>(execMem.inputPtr), inputMemSize);
     221            0 :         DeviceMem dstMem = DeviceMem::create(static_cast<u8*>(execMem.outputPtr), inputMemSize);
     222            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
     223            0 :         return HCCL_SUCCESS;
     224            0 :     }
     225              : 
     226              :     // 先做server间算法,带有消减拷贝场景数据需要从user input取,拷贝到ccl output上
     227            0 :     if (DMAReduceFlag_) {
     228            0 :         u64 dstMemOffset = CalcDstMemOffset(param, inputMemSize);
     229            0 :         DeviceMem srcMem = DeviceMem::create(static_cast<u8*>(execMem.inputPtr), inputMemSize);
     230            0 :         DeviceMem dstMem = execMem.outputMem.range(dstMemOffset, inputMemSize);
     231            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
     232            0 :     }
     233              : 
     234            0 :     CHK_RET(RunLevel2ByNHR(param, execMem, level1CommInfo, level2CommInfo));
     235            0 :     CHK_RET(RunLevel1ByNHR(param, execMem, level1CommInfo, level2CommInfo));
     236              : 
     237            0 :     if (DMAReduceFlag_) {
     238            0 :         for (u32 i = 0; i < topoAttr_.userRankSize; i++) {
     239              :             DeviceMem srcMem
     240            0 :                 = DeviceMem::create(static_cast<u8*>(execMem.outputMem.ptr()) + inputMemSize * i, inputMemSize);
     241              :             DeviceMem dstMem = DeviceMem::create(
     242            0 :                 static_cast<u8*>(execMem.outputPtr) + param.DataDes.count * unitSize * i, inputMemSize);
     243            0 :             CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
     244            0 :         }
     245              :     }
     246            0 :     HCCL_INFO("MidCountAllGather run success.");
     247            0 :     return HCCL_SUCCESS;
     248            0 : }
     249              : REGISTER_EXEC("AllGatherMidCountFor91093Executor", AllGatherMidCountFor91093, CollAllGatherMidCountFor91093Executor);
     250              : } // namespace hccl
        

Generated by: LCOV version 2.0-1