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

Generated by: LCOV version 2.0-1