LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_gather_v - coll_all_gather_v_mesh_opbase_pipeline_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 97 0
Test Date: 2026-07-28 12:11:00 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_v_mesh_opbase_pipeline_executor.h"
      12              : 
      13              : namespace hccl {
      14            0 : CollAllGatherVMeshOpbasePipelineExecutor::CollAllGatherVMeshOpbasePipelineExecutor(const HcclDispatcher dispatcher,
      15            0 :     std::unique_ptr<TopoMatcher> &topoMatcher)
      16            0 :     : CollAllGatherVExecutor(dispatcher, topoMatcher)
      17              : {
      18            0 :     DMAReduceFlag_ = true;
      19            0 : }
      20              : 
      21            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcStreamNum(u32& streamNum)
      22              : {
      23            0 :     u32 totalStreamNum = topoAttr_.deviceNumPerAggregation + 1U;
      24            0 :     streamNum = totalStreamNum - 1U;
      25            0 :     HCCL_INFO("[CollAllGatherVMeshOpbasePipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]",
      26              :         tag_.c_str(), streamNum);
      27            0 :     return HCCL_SUCCESS;
      28              : }
      29              : 
      30            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcCurCountsAndCurDispls(const u64 maxTotalCount,
      31              :     std::vector<u64> &countsLeft, std::vector<u64> &displs, std::vector<u64> &curCounts, std::vector<u64> &curDispls,
      32              :     bool &finished)
      33              : {
      34            0 :     finished = true;
      35              : 
      36            0 :     curCounts.resize(countsLeft.size(), 0);
      37            0 :     curDispls.resize(displs.size(), 0);
      38              : 
      39              :     // 先设置本轮的displacements,等于入参displs
      40            0 :     std::copy(displs.begin(), displs.end(), curDispls.begin());
      41              : 
      42              :     // 分配好每个rank的counts
      43            0 :     for (auto i = 0U; i < countsLeft.size(); ++i) {
      44            0 :         const auto curCount = countsLeft[i] < maxTotalCount ? countsLeft[i] : maxTotalCount;
      45            0 :         curCounts[i] = curCount;
      46            0 :         countsLeft[i] -= curCount;
      47            0 :         displs[i] += curCount;
      48              : 
      49            0 :         if(countsLeft[i] != 0) {
      50            0 :             finished = false;
      51              :         }
      52              :     }
      53              : 
      54            0 :     return HCCL_SUCCESS;
      55              : }
      56              : 
      57            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      58              : {
      59            0 :     TransportMemType inputType = TransportMemType::RESERVED;
      60            0 :     TransportMemType outputType = TransportMemType::RESERVED;
      61            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      62            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      63            0 :     CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
      64            0 :     return HCCL_SUCCESS;
      65              : }
      66              : 
      67            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcTransportMemType(TransportMemType &inputType,
      68              :     TransportMemType &outputType)
      69              : {
      70            0 :     inputType = TransportMemType::CCL_INPUT;
      71            0 :     outputType = TransportMemType::CCL_OUTPUT;
      72            0 :     HCCL_INFO("[CollAllGatherVMeshOpbasePipelineExecutor][CalcTransportMemType]" \
      73              :         "tag[%s] inputType[%d], outputType[%d]",
      74              :         tag_.c_str(), inputType, outputType);
      75            0 :     return HCCL_SUCCESS;
      76              : }
      77              : 
      78            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcLevel0CommInfo(TransportMemType inputType,
      79              :     TransportMemType outputType,
      80              :     std::vector<LevelNSubCommTransport>& opTransport)
      81              : {
      82            0 :     CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      83            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
      84            0 :     return HCCL_SUCCESS;
      85            0 : }
      86              : 
      87              : // PipeLine模式下使用Ring算法
      88            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::CalcLevel1CommInfo(TransportMemType inputType,
      89              :     TransportMemType outputType,
      90              :     std::vector<LevelNSubCommTransport>& opTransport)
      91              : {
      92            0 :     CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
      93            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
      94            0 :     return HCCL_SUCCESS;
      95            0 : }
      96              : 
      97            0 : u64 CollAllGatherVMeshOpbasePipelineExecutor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
      98              : {
      99            0 :     u64 maxCountPerLoop = (cclBuffSize - HCCL_MIN_SLICE_ALIGN_910B) / HCCL_MIN_SLICE_ALIGN
     100            0 :         * HCCL_MIN_SLICE_ALIGN / unitSize;
     101            0 :     return maxCountPerLoop;
     102              : }
     103              : 
     104            0 : bool CollAllGatherVMeshOpbasePipelineExecutor::IsHugeData(const u64 curSize)
     105              : {
     106            0 :     bool hugeData = curSize > RDMA_SEND_MAX_SIZE || curSize > SDMA_SEND_MAX_SIZE;
     107            0 :     return hugeData;
     108              : }
     109              : 
     110            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::KernelRun(const OpParam &param, ExecMem &execMem)
     111              : {
     112            0 :     HCCL_CONFIG_INFO(HCCL_ALG,
     113              :         "[CollAllGatherVMeshOpbasePipelineExecutor][KernelRun]AllGatherVMeshOpbasePipelineExecutor begins.");
     114              : 
     115              :     // step 1 先获取 comm level0 \ comm level1 的value
     116            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     117            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     118            0 :     u32 commIndex = level0CommInfo.localRank;
     119            0 :     CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
     120            0 :     SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
     121              : 
     122              :     // allgatherv 计算slice,数据分成ranksize份,每份的起始偏移和大小
     123            0 :     u32 perDataSize = SIZE_TABLE[param.VDataDes.dataType];
     124            0 :     std::vector<Slice> outputSlices;
     125            0 :     const auto counts = static_cast<u64*>(param.VDataDes.counts);
     126            0 :     const auto displs = static_cast<u64*>(param.VDataDes.displs);
     127            0 :     for (u32 rank = 0; rank < topoAttr_.userRankSize; ++rank) {
     128            0 :         Slice userslice;
     129            0 :         userslice.offset = displs[rank] * perDataSize;
     130            0 :         userslice.size = counts[rank] * perDataSize;
     131            0 :         outputSlices.emplace_back(std::move(userslice));
     132              :     }
     133              : 
     134              :     // DMA消减场景,打包opInfo
     135            0 :     HcomCollOpInfo opInfo = {
     136            0 :         "", execMem.inputPtr, execMem.outputPtr, 0, param.VDataDes.dataType, 0, HCCL_REDUCE_RESERVED
     137            0 :     };
     138              : 
     139            0 :     std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     140            0 :                 TemplateType::TEMPLATE_ALL_GATHER_V_PIPELINE, dispatcher_);
     141            0 :     CHK_SMART_PTR_NULL(tempAlg);
     142            0 :     Stream stream = param.stream;
     143            0 :     CHK_RET(tempAlg->Prepare(&opInfo, topoAttr_.userRank, execMem.count, execMem.inputMem, execMem.outputMem,
     144              :         level0CommInfo, level1CommInfo, stream,
     145              :         algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux, outputSlices));
     146            0 :     CHK_RET(tempAlg->RunAsync());
     147            0 :     return HCCL_SUCCESS;
     148            0 : }
     149              : 
     150            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::Getlevel1CommRank(SubCommInfo& level1CommInfo)
     151              : {
     152            0 :     if (CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1) != HCCL_SUCCESS) {
     153            0 :         return HCCL_E_UNAVAIL;
     154              :     }
     155            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     156            0 :     u32 ringNum = (topoType_ == TopoType::TOPO_TYPE_8P_RING) ? LEVEL0_PLANE_NUM_IN_8PRING :
     157              :         LEVEL0_PLANE_NUM_IN_NPRING_SINGLE;
     158            0 :     u32 commIndex = (ringNum == LEVEL0_PLANE_NUM_IN_8PRING) ? topoAttr_.devicePhyId : level0CommInfo.localRank;
     159              : 
     160            0 :     if (CheckCommSize(COMM_LEVEL1, commIndex + 1) != HCCL_SUCCESS) {
     161            0 :         return HCCL_E_UNAVAIL;
     162              :     }
     163            0 :     level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
     164              : 
     165            0 :     return HCCL_SUCCESS;
     166            0 : }
     167              : 
     168            0 : HcclResult CollAllGatherVMeshOpbasePipelineExecutor::SelectTempAlg(std::unique_ptr<AlgTemplateBase> &level1TempAlg, u32 level1RankSize)
     169              : {
     170            0 :     if (level1RankSize > 1) {
     171            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     172            0 :                 TemplateType::TEMPLATE_ALL_GATHER_V_PIPELINE, dispatcher_);
     173            0 :         CHK_SMART_PTR_NULL(level1TempAlg);
     174            0 :         return HCCL_SUCCESS;
     175              :     }
     176            0 :     return HCCL_E_UNAVAIL;
     177              : }
     178              : REGISTER_EXEC("AllGatherVMeshOpbasePipelineExecutor", AllGatherVOpbasePipeline, CollAllGatherVMeshOpbasePipelineExecutor);
     179              : 
     180              : } // namespace hccl
        

Generated by: LCOV version 2.0-1