LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_gather_v - coll_all_gather_v_mesh_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 218 0
Test Date: 2026-08-25 19:18:03 Functions: 0.0 % 17 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_v_mesh_executor.h"
      12              : 
      13              : #include <algorithm>
      14              : #include <numeric>
      15              : 
      16              : namespace hccl {
      17            0 : CollAllGatherVMeshExecutor::CollAllGatherVMeshExecutor(
      18            0 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      19            0 :     : CollAllGatherVExecutor(dispatcher, topoMatcher)
      20              : {
      21            0 :     DMAReduceFlag_ = (topoAttr_.moduleNum <= 1);
      22            0 : }
      23              : 
      24            0 : HcclResult CollAllGatherVMeshExecutor::CalcStreamNum(u32& streamNum)
      25              : {
      26            0 :     u32 totalStreamNum = 0;
      27            0 :     if (topoAttr_.moduleNum > 1) {
      28            0 :         totalStreamNum = topoAttr_.deviceNumPerAggregation > 1U ? topoAttr_.deviceNumPerAggregation - 1U : 1U;
      29              :     } else {
      30            0 :         totalStreamNum = topoAttr_.deviceNumPerAggregation;
      31              :     }
      32            0 :     streamNum = totalStreamNum - 1U;
      33            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
      34            0 :     return HCCL_SUCCESS;
      35              : }
      36              : 
      37            0 : HcclResult CollAllGatherVMeshExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      38              : {
      39            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      40            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      41            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      42            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      43            0 :     if (topoAttr_.moduleNum > 1) {
      44            0 :         CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
      45              :     }
      46              : 
      47            0 :     return HCCL_SUCCESS;
      48              : }
      49              : 
      50              : HcclResult
      51            0 : CollAllGatherVMeshExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType) const
      52              : {
      53            0 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      54            0 :         inputType = TransportMemType::CCL_INPUT;
      55            0 :         outputType = TransportMemType::CCL_OUTPUT;
      56              :     } else {
      57            0 :         inputType = TransportMemType::PARAM_INPUT;
      58            0 :         outputType = TransportMemType::PARAM_OUTPUT;
      59              :     }
      60            0 :     HCCL_INFO(
      61              :         "[CollAllGatherVMeshExecutor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]", tag_.c_str(),
      62              :         inputType, outputType);
      63            0 :     return HCCL_SUCCESS;
      64              : }
      65              : 
      66            0 : HcclResult CollAllGatherVMeshExecutor::CalcLevel0CommInfo(
      67              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      68              : {
      69            0 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      70            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      71            0 :     return HCCL_SUCCESS;
      72            0 : }
      73              : 
      74            0 : HcclResult CollAllGatherVMeshExecutor::CalcLevel1CommInfo(
      75              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      76              : {
      77            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][CalcLevel1CommInfo]tag[%s] start", tag_.c_str());
      78            0 :     CommParaInfo commParaLevel1(COMM_LEVEL1, CommType::COMM_TAG_MAX);
      79            0 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING
      80            0 :         || (topoAttr_.isDiffDeviceModule && topoAttr_.serverNum == 1)) {
      81            0 :         commParaLevel1.commType = CommType::COMM_TAG_RING_INNER;
      82            0 :         HCCL_INFO("[CollAllGatherVMeshExecutor][CalcLevel1CommInfo]tag[%s] Calc RingCommInfo", tag_.c_str());
      83            0 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
      84            0 :         commParaLevel1.commType = CommType::COMM_TAG_NONUNIFORM_BRUCK;
      85            0 :         HCCL_INFO("[CollAllGatherVMeshExecutor][CalcLevel1CommInfo]tag[%s] Calc NBCommInfo", tag_.c_str());
      86              :     } else {
      87            0 :         commParaLevel1.commType = CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING;
      88            0 :         HCCL_INFO("[CollAllGatherVMeshExecutor][CalcLevel1CommInfo]tag[%s] Calc NHRCommInfo", tag_.c_str());
      89              :     }
      90            0 :     commParaLevel1.forceRdma = false;
      91            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel1, opTransport[commParaLevel1.commPlane], inputType, outputType));
      92              : 
      93            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][COMM_LEVEL1]tag[%s] Calc CommInfo Finish", tag_.c_str());
      94              : 
      95            0 :     return HCCL_SUCCESS;
      96            0 : }
      97              : 
      98            0 : u64 CollAllGatherVMeshExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
      99              : {
     100              :     u64 maxCountPerLoop;
     101            0 :     if (topoAttr_.moduleNum > 1) {
     102            0 :         maxCountPerLoop = cclBuffSize / HCCL_MIN_SLICE_ALIGN * HCCL_MIN_SLICE_ALIGN / unitSize;
     103              :     } else {
     104              :         maxCountPerLoop
     105            0 :             = (cclBuffSize - HCCL_MIN_SLICE_ALIGN_910B) / HCCL_MIN_SLICE_ALIGN * HCCL_MIN_SLICE_ALIGN / unitSize;
     106              :     }
     107              : 
     108            0 :     return maxCountPerLoop;
     109              : }
     110              : 
     111            0 : bool CollAllGatherVMeshExecutor::IsHugeData(const u64 curSize)
     112              : {
     113            0 :     bool hugeData = curSize * topoAttr_.userRankSize > RDMA_SEND_MAX_SIZE || curSize > SDMA_SEND_MAX_SIZE;
     114            0 :     return hugeData;
     115              : }
     116              : 
     117            0 : HcclResult CollAllGatherVMeshExecutor::RunLevel0(
     118              :     const OpParam& param, ExecMem& execMem, SubCommInfo& level0CommInfo, const SubCommInfo& level1CommInfo)
     119              : {
     120            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherVMeshExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
     121            0 :     u32 perDataSize = SIZE_TABLE[param.VDataDes.dataType];
     122            0 :     const auto counts = static_cast<u64*>(param.VDataDes.counts);
     123            0 :     u32 serverIndex = level1CommInfo.localRank;
     124            0 :     u32 rankBaseOffset = serverIndex * level0CommInfo.localRankSize;
     125            0 :     u64 countBaseOffset = std::accumulate(counts, counts + rankBaseOffset, 0ULL);
     126              :     // level0的rank 0在整个通信域中的偏移
     127            0 :     u64 baseOffset = countBaseOffset * perDataSize;
     128              :     // allgatherv 计算slice,数据分成ranksize份,每份的起始偏移和大小
     129            0 :     std::vector<Slice> outputSlices;
     130            0 :     u64 outputMemSize = 0;
     131            0 :     for (u32 rank = rankBaseOffset; rank < rankBaseOffset + level0CommInfo.localRankSize; ++rank) {
     132            0 :         Slice userslice;
     133            0 :         userslice.offset = outputMemSize;
     134            0 :         userslice.size = counts[rank] * perDataSize;
     135            0 :         outputSlices.emplace_back(std::move(userslice));
     136            0 :         outputMemSize += userslice.size;
     137              :     }
     138              : 
     139            0 :     u64 inputMemSize = outputSlices[level0CommInfo.localRank].size;
     140            0 :     u64 level0Offset = outputSlices[level0CommInfo.localRank].offset;
     141            0 :     DeviceMem srcMem = execMem.inputMem.range(0, inputMemSize);
     142            0 :     DeviceMem dstMem = execMem.outputMem.range(baseOffset + level0Offset, inputMemSize);
     143            0 :     CHK_SMART_PTR_NULL(dstMem);
     144            0 :     Stream stream = param.stream;
     145              :     // 将数据从input内存拷贝到output内存的对应位置
     146            0 :     HcclResult ret = HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, stream);
     147            0 :     CHK_PRT_RET(
     148              :         ret != HCCL_SUCCESS,
     149              :         HCCL_ERROR(
     150              :             "[CollAllGatherVMeshExecutor][KernelRun]all gatherV mesh memcpy Failed, Offset[%llu], Size[%llu].",
     151              :             level0Offset, inputMemSize),
     152              :         ret);
     153              : 
     154            0 :     CHK_RET(ActiveSlaveStreams(param.stream));
     155              : 
     156              :     //  抽取当前用于多环all gather 的output内存数据
     157            0 :     DeviceMem currentOutputMem = execMem.outputMem.range(baseOffset, outputMemSize);
     158            0 :     CHK_SMART_PTR_NULL(currentOutputMem);
     159              : 
     160              :     std::unique_ptr<AlgTemplateBase> level0TempAlg
     161            0 :         = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_MESH_ATOMIC, dispatcher_);
     162            0 :     CHK_SMART_PTR_NULL(level0TempAlg);
     163            0 :     CHK_RET(level0TempAlg->Prepare(
     164              :         algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux, topoAttr_.userRank, nullptr,
     165              :         level0CommInfo.localRank, level0CommInfo.localRankSize));
     166            0 :     CHK_RET(level0TempAlg->Prepare(
     167              :         currentOutputMem, currentOutputMem, execMem.inputMem, execMem.count, param.VDataDes.dataType, param.stream,
     168              :         HCCL_REDUCE_RESERVED, LEVEL0_BRIDGE_RANK_ID, outputSlices, baseOffset));
     169            0 :     u32 rankSize = level0CommInfo.localRankSize;
     170            0 :     CHK_RET(level0TempAlg->RegisterProfiler(
     171              :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank, PROF_STAGE_1, HCCL_EXEC_STEP_NOT_SET,
     172              :         param.stream));
     173            0 :     CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
     174            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][RunLevel0] level 0 for A2 run success");
     175            0 :     return HCCL_SUCCESS;
     176            0 : }
     177              : 
     178            0 : HcclResult CollAllGatherVMeshExecutor::RunLevel1(
     179              :     const OpParam& param, ExecMem& execMem, const SubCommInfo& level0CommInfo, SubCommInfo& level1CommInfo) const
     180              : {
     181            0 :     std::unique_ptr<AlgTemplateBase> level1TempAlg;
     182            0 :     if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_RING
     183            0 :         || (topoAttr_.isDiffDeviceModule && topoAttr_.serverNum == 1)) {
     184              :         // 1-单server-SDMA
     185              :         level1TempAlg
     186            0 :             = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_RING, dispatcher_);
     187            0 :         HCCL_INFO("allgatherv mesh: using ring algo inter-server.");
     188            0 :     } else if (algType_.algoLevel1 == AlgTypeLevel1::ALG_LEVEL1_NB) {
     189              :         level1TempAlg
     190            0 :             = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_NB, dispatcher_);
     191            0 :         HCCL_INFO("allgatherv mesh: using nonuniform-bruck algo inter-server.");
     192              :     } else {
     193              :         // 使用nhr作为兜底算法
     194              :         level1TempAlg
     195            0 :             = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_NHR, dispatcher_);
     196            0 :         level1TempAlg->CloseBarrier();
     197            0 :         HCCL_INFO("allgatherv mesh: using nhr algo inter-server.");
     198              :     }
     199            0 :     CHK_SMART_PTR_NULL(level1TempAlg);
     200              : 
     201            0 :     u32 perDataSize = SIZE_TABLE[param.VDataDes.dataType];
     202            0 :     const auto counts = static_cast<u64*>(param.VDataDes.counts);
     203              :     // allgatherv 计算slice,数据分成level1 ranksize份,每份的起始偏移和大小
     204            0 :     std::vector<Slice> outputSlices;
     205            0 :     u64 outputMemSize = 0;
     206            0 :     for (u32 rankLevel1 = 0; rankLevel1 < level1CommInfo.localRankSize; ++rankLevel1) {
     207            0 :         Slice userslice;
     208              :         // 计算偏移值
     209            0 :         u64 countLevel0 = std::accumulate(
     210            0 :             counts + rankLevel1 * level0CommInfo.localRankSize,
     211            0 :             counts + (rankLevel1 + 1) * level0CommInfo.localRankSize, 0ULL);
     212            0 :         userslice.offset = outputMemSize;
     213            0 :         userslice.size = countLevel0 * perDataSize;
     214            0 :         outputSlices.emplace_back(std::move(userslice));
     215            0 :         outputMemSize += userslice.size;
     216              :     }
     217              : 
     218              :     //  此处虽然带入inputMem作为scratch mem, 但inputMem 不能被使用
     219            0 :     CHK_RET(level1TempAlg->Prepare(
     220              :         execMem.outputMem, execMem.outputMem, execMem.inputMem,
     221              :         outputSlices[level1CommInfo.localRank].size / perDataSize, param.VDataDes.dataType, param.stream,
     222              :         HcclReduceOp::HCCL_REDUCE_RESERVED, INVALID_VALUE_RANKID, outputSlices, 0));
     223              : 
     224            0 :     u32 rankSize = level1CommInfo.localRankSize;
     225            0 :     CHK_RET(level1TempAlg->RegisterProfiler(
     226              :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level1CommInfo.localRank, PROF_STAGE_2, HCCL_EXEC_STEP_NOT_SET,
     227              :         param.stream));
     228              : 
     229            0 :     CHK_RET(RunTemplate(level1TempAlg, level1CommInfo));
     230            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][RunLevel1] level 1 for A2 run success");
     231              : 
     232            0 :     return HCCL_SUCCESS;
     233            0 : }
     234              : 
     235            0 : HcclResult CollAllGatherVMeshExecutor::RunSingleMesh(const OpParam& param, ExecMem& execMem)
     236              : {
     237            0 :     HcclDataType dataType = HCCL_DATA_TYPE_RESERVED;
     238            0 :     dataType = param.VDataDes.dataType;
     239            0 :     const u32 unitSize = SIZE_TABLE[dataType];
     240              : 
     241            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     242            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     243            0 :     u32 rankSize = level0CommInfo.localRankSize;
     244              : 
     245              :     // DMA消减后仅使用ccl out通信,ccl out根据实际使用大小重新申请内存空间
     246            0 :     u64 inputMemSize = execMem.inputMem.size();
     247            0 :     u64 baseOffset = 0;
     248            0 :     DeviceMem curOutputMem = execMem.outputMem.range(baseOffset, inputMemSize);
     249            0 :     CHK_SMART_PTR_NULL(curOutputMem);
     250              : 
     251              :     // allgatherv 计算slice,数据分成ranksize份,每份的起始偏移和大小
     252            0 :     std::vector<Slice> outputSlices;
     253            0 :     const auto counts = static_cast<u64*>(param.VDataDes.counts);
     254            0 :     const auto displs = static_cast<u64*>(param.VDataDes.displs);
     255            0 :     for (u32 rank = 0; rank < rankSize; ++rank) {
     256            0 :         Slice userslice;
     257            0 :         userslice.offset = displs[rank] * unitSize;
     258            0 :         userslice.size = counts[rank] * unitSize;
     259            0 :         outputSlices.emplace_back(std::move(userslice));
     260              :     }
     261              : 
     262              :     // DMA消减场景,打包opInfo
     263            0 :     HcomCollOpInfo opInfo
     264            0 :         = {"", execMem.inputPtr, execMem.outputPtr, execMem.count, dataType, param.root, param.reduceType, 0};
     265              : 
     266              :     std::unique_ptr<AlgTemplateBase> tempAlg
     267            0 :         = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_GATHER_MESH_DIRECT, dispatcher_);
     268            0 :     CHK_SMART_PTR_NULL(tempAlg);
     269            0 :     CHK_RET(tempAlg->Prepare(
     270              :         algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux, topoAttr_.userRank, &opInfo,
     271              :         level0CommInfo.localRank, level0CommInfo.localRankSize));
     272              : 
     273            0 :     CHK_RET(tempAlg->Prepare(
     274              :         curOutputMem, curOutputMem, execMem.inputMem, execMem.count, dataType, param.stream, HCCL_REDUCE_RESERVED,
     275              :         LEVEL0_BRIDGE_RANK_ID, outputSlices, baseOffset));
     276              : 
     277            0 :     CHK_RET(tempAlg->RegisterProfiler(
     278              :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank, PROF_STAGE_0, HCCL_EXEC_STEP_NOT_SET,
     279              :         param.stream));
     280              : 
     281            0 :     CHK_RET(RunTemplate(tempAlg, level0CommInfo));
     282              : 
     283            0 :     HCCL_INFO("[CollAllGatherVMeshExecutor][RunSingleMesh] single mesh for A2 run success");
     284            0 :     return HCCL_SUCCESS;
     285            0 : }
     286              : 
     287            0 : HcclResult CollAllGatherVMeshExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
     288              : {
     289            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollAllGatherVMeshExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
     290            0 :     if (topoAttr_.moduleNum > 1) {
     291              :         // 获取子通信域信息
     292            0 :         CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     293            0 :         SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     294            0 :         CHK_RET(CheckCommSize(COMM_LEVEL1, level0CommInfo.localRank + 1));
     295            0 :         SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, level0CommInfo.localRank);
     296              : 
     297            0 :         CHK_RET(RunLevel0(param, execMem, level0CommInfo, level1CommInfo));
     298            0 :         CHK_RET(RunLevel1(param, execMem, level0CommInfo, level1CommInfo));
     299            0 :     } else {
     300            0 :         CHK_RET(RunSingleMesh(param, execMem));
     301              :     }
     302              : 
     303            0 :     return HCCL_SUCCESS;
     304              : }
     305              : 
     306            0 : HcclResult CollAllGatherVMeshExecutor::CalcCurCountsAndCurDisplsMultiModule(
     307              :     const u64 maxTotalCount, std::vector<u64>& countsLeft, std::vector<u64>& displs, std::vector<u64>& curCounts,
     308              :     std::vector<u64>& curDispls, bool& finished) const
     309              : {
     310            0 :     curCounts = std::vector<u64>(countsLeft.size(), 0);
     311            0 :     curDispls = std::vector<u64>(displs.size(), 0);
     312            0 :     auto allocatableCount = maxTotalCount;
     313              : 
     314            0 :     HCCL_DEBUG("CalcCurCountsAndCurDisplsMultiModule begin");
     315              :     // 先设置本轮的displacements,等于入参displs
     316            0 :     std::copy(displs.begin(), displs.end(), curDispls.begin());
     317              : 
     318              :     // 分配本轮的counts,如果CCLbuffer空间还没完全利用,则再进行分配
     319            0 :     while (allocatableCount > 0) {
     320              :         // 计算现在还有几个rank还有数据需要去通信(countsLeft不为0)
     321            0 :         const auto nonZeroCount = std::count_if(countsLeft.begin(), countsLeft.end(), [](const u64 count) {
     322            0 :             return count != 0;
     323              :         });
     324            0 :         if (nonZeroCount == 0) {
     325            0 :             finished = true;
     326            0 :             HCCL_INFO("[%s] Calc CurCountsAndCurDispls for multiModule finish", __func__);
     327            0 :             return HCCL_SUCCESS;
     328              :         }
     329              :         // 计算每个rank可以分到多少count
     330            0 :         const auto perRankCount = allocatableCount / nonZeroCount;
     331            0 :         if (perRankCount == 0) {
     332            0 :             break;
     333              :         }
     334            0 :         HCCL_DEBUG("[%s] Calc CurCountsAndCurDispls for perRankCount finish", __func__);
     335            0 :         for (auto i = 0U; i < countsLeft.size(); ++i) {
     336            0 :             const auto curCount = countsLeft[i] < perRankCount ? countsLeft[i] : perRankCount;
     337            0 :             allocatableCount -= curCount;
     338            0 :             curCounts[i] += curCount;
     339            0 :             countsLeft[i] -= curCount;
     340            0 :             displs[i] += curCount;
     341              :         }
     342              :     }
     343              :     // 特殊情况下,allocatableCount 刚好使用完毕时,不仅如此while循环,导致RunLoop额外循环一次
     344            0 :     const auto nonZeroCount = std::count_if(countsLeft.begin(), countsLeft.end(), [](const u64 count) {
     345            0 :         return count != 0;
     346              :     });
     347            0 :     if (nonZeroCount == 0) {
     348            0 :         finished = true;
     349              :     }
     350            0 :     HCCL_INFO("[%s] Calc CurCountsAndCurDispls for multiModule finish.", __func__);
     351            0 :     return HCCL_SUCCESS;
     352              : }
     353              : 
     354            0 : HcclResult CollAllGatherVMeshExecutor::CalcCurCountsAndCurDisplsSingleModule(
     355              :     const u64 maxTotalCount, std::vector<u64>& countsLeft, std::vector<u64>& displs, std::vector<u64>& curCounts,
     356              :     std::vector<u64>& curDispls, bool& finished) const
     357              : {
     358            0 :     finished = true;
     359              : 
     360            0 :     curCounts.resize(countsLeft.size(), 0);
     361            0 :     curDispls.resize(displs.size(), 0);
     362              : 
     363              :     // 先设置本轮的displacements,等于入参displs
     364            0 :     std::copy(displs.begin(), displs.end(), curDispls.begin());
     365              : 
     366              :     // 分配好每个rank的counts
     367            0 :     for (auto i = 0U; i < countsLeft.size(); ++i) {
     368            0 :         const auto curCount = countsLeft[i] < maxTotalCount ? countsLeft[i] : maxTotalCount;
     369            0 :         curCounts[i] = curCount;
     370            0 :         countsLeft[i] -= curCount;
     371            0 :         displs[i] += curCount;
     372              : 
     373            0 :         if (countsLeft[i] != 0) {
     374            0 :             finished = false;
     375              :         }
     376              :     }
     377              : 
     378            0 :     return HCCL_SUCCESS;
     379              : }
     380              : 
     381            0 : HcclResult CollAllGatherVMeshExecutor::CalcCurCountsAndCurDispls(
     382              :     const u64 maxTotalCount, std::vector<u64>& countsLeft, std::vector<u64>& displs, std::vector<u64>& curCounts,
     383              :     std::vector<u64>& curDispls, bool& finished)
     384              : {
     385            0 :     if (topoAttr_.moduleNum > 1) {
     386            0 :         CHK_RET(
     387              :             CalcCurCountsAndCurDisplsMultiModule(maxTotalCount, countsLeft, displs, curCounts, curDispls, finished));
     388              :     } else {
     389            0 :         CHK_RET(
     390              :             CalcCurCountsAndCurDisplsSingleModule(maxTotalCount, countsLeft, displs, curCounts, curDispls, finished));
     391              :     }
     392            0 :     return HCCL_SUCCESS;
     393              : }
     394              : 
     395              : REGISTER_EXEC("AllGatherVMeshExecutor", AllGatherVMesh, CollAllGatherVMeshExecutor);
     396              : } // namespace hccl
        

Generated by: LCOV version 2.0-1