LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_reduce_scatter - coll_reduce_scatter_mesh_opbase_pipeline_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 117 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_reduce_scatter_mesh_opbase_pipeline_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            0 : CollReduceScatterMeshOpbasePipelineExecutor::CollReduceScatterMeshOpbasePipelineExecutor(
      16            0 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17            0 :     : CollReduceScatterExecutor(dispatcher, topoMatcher)
      18              : {
      19            0 :     DMAReduceFlag_ = true;
      20            0 : }
      21              : 
      22            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::RunLoop(OpParam& param, AlgResourceResponse& algRes)
      23              : {
      24            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[CollReduceScatterMeshOpbasePipelineExecutor][RunLoop] begins.");
      25              : 
      26            0 :     u32 unitSize = SIZE_TABLE[param.DataDes.dataType];
      27            0 :     ReduceType reduceType
      28            0 :         = ((param.reduceType != HCCL_REDUCE_PROD) && (param.DataDes.dataType != HCCL_DATA_TYPE_INT64)) ?
      29              :               ReduceType::INLINE_REDUCE :
      30              :               ReduceType::TBE_REDUCE;
      31              : 
      32            0 :     u8* curInputPtr = static_cast<u8*>(param.inputPtr);
      33            0 :     u8* curOutputPtr = static_cast<u8*>(param.outputPtr);
      34            0 :     CHK_PTR_NULL(curInputPtr);
      35            0 :     CHK_PTR_NULL(curOutputPtr);
      36              : 
      37            0 :     u64 maxCountPerLoop = CalcLoopMaxCount(unitSize);
      38            0 :     HCCL_DEBUG(
      39              :         "[CollReduceScatterMeshOpbasePipelineExecutor][RunLoop]tag[%s], userRankSize is [%u], maxCountPerLoop "
      40              :         "is [%llu].",
      41              :         param.tag.c_str(), topoAttr_.userRankSize, maxCountPerLoop);
      42              : 
      43              :     // 先获取 comm level0 \ comm level1 的value
      44            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
      45            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      46            0 :     u32 commIndex = level0CommInfo.localRank;
      47              : 
      48            0 :     CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
      49            0 :     SubCommInfo level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
      50              : 
      51            0 :     DeviceMem userInMem = DeviceMem::create(param.inputPtr, param.DataDes.count * unitSize);
      52            0 :     u64 reduceAttr = GetReduceAttr(
      53            0 :         userInMem, const_cast<DeviceMem&>(algRes.cclInputMem), param.DataDes.dataType,
      54              :         param.reduceType); // scratchMem用的cclin
      55            0 :     u64 bufferSize = algRes.cclInputMem.size();
      56              : 
      57            0 :     auto originalAlgTypeLevel1 = static_cast<u32>(algType_.algoLevel1);
      58              : 
      59            0 :     for (u64 countLeft = param.DataDes.count, curCount = 0, curOffset = 0, curSize = 0; countLeft > 0;
      60            0 :          countLeft -= curCount) {
      61            0 :         curInputPtr += curSize;
      62            0 :         curOutputPtr += curSize;
      63              : 
      64            0 :         curCount = (countLeft > maxCountPerLoop) ? maxCountPerLoop : countLeft;
      65            0 :         curSize = curCount * unitSize;
      66              : 
      67            0 :         HCCL_CONFIG_DEBUG(
      68              :             HCCL_ALG,
      69              :             "[CollReduceScatterMeshOpbasePipelineExecutor][RunLoop]tag[%s], curOffset[%llu],"
      70              :             "curInputPtr[%p], curOutputPtr[%p], curCount[%llu], dataType[%d].",
      71              :             param.tag.c_str(), curOffset, curInputPtr, curOutputPtr, curCount, param.DataDes.dataType);
      72              : 
      73            0 :         bool hugeData = IsHugeData(curSize);
      74            0 :         u8 deterministic = topoMatcher_->GetExternalInputHcclDeterministic();
      75            0 :         auto meta = HcclOpMetaInfo::GetOneForReduceScatter(
      76              :             originalAlgTypeLevel1, param.DataDes.dataType, reduceType, hugeData, false, CopyPattern::BCOPY, false,
      77              :             deterministic, false);
      78            0 :         CHK_RET(InitTask(dispatcher_, const_cast<Stream&>(param.stream), meta.isEnableCache, meta.GetCacheKey()));
      79              : 
      80            0 :         ExecMem execMem;
      81            0 :         execMem.count = curCount;
      82            0 :         execMem.inputMem = algRes.cclInputMem;
      83            0 :         execMem.outputMem = algRes.cclOutputMem;
      84            0 :         execMem.scratchMem = algRes.scratchMem;
      85              :         // 使用当前Loop偏移到的地址作为当前的inputPtr和outputPtr
      86            0 :         execMem.inputPtr = curInputPtr;
      87            0 :         execMem.outputPtr = curOutputPtr;
      88              : 
      89            0 :         std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
      90            0 :             TemplateType::TEMPLATE_REDUCESCATTER_PIPELINE, dispatcher_);
      91            0 :         CHK_SMART_PTR_NULL(tempAlg);
      92              : 
      93            0 :         HcomCollOpInfo opInfo = {"",
      94            0 :                                  execMem.inputPtr,
      95            0 :                                  execMem.outputPtr,
      96            0 :                                  param.DataDes.count,
      97            0 :                                  param.DataDes.dataType,
      98            0 :                                  param.root,
      99            0 :                                  param.reduceType,
     100            0 :                                  0};
     101              : 
     102            0 :         CHK_RET(tempAlg->Prepare(
     103              :             &opInfo, execMem.inputMem, curCount, bufferSize, curOffset, level0CommInfo, level1CommInfo,
     104              :             const_cast<Stream&>(param.stream), algResResp_->slaveStreams, algResResp_->notifiesMain,
     105              :             algResResp_->notifiesAux, reduceAttr));
     106            0 :         CHK_RET(tempAlg->RunAsync());
     107              : 
     108            0 :         CHK_RET(LaunchTask(dispatcher_, const_cast<Stream&>(param.stream)));
     109              : 
     110            0 :         curOffset += curSize;
     111            0 :     }
     112              : 
     113            0 :     return HCCL_SUCCESS;
     114            0 : }
     115              : 
     116            0 : void CollReduceScatterMeshOpbasePipelineExecutor::ParseParam(const OpParam& param)
     117              : {
     118            0 :     tag_ = param.tag;
     119            0 :     aicpuUnfoldMode_ = param.aicpuUnfoldMode;
     120            0 : }
     121              : 
     122            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::CalcStreamNum(u32& streamNum)
     123              : {
     124            0 :     u32 totalStreamNum = topoAttr_.deviceNumPerAggregation + 1U;
     125            0 :     streamNum = totalStreamNum - 1U;
     126            0 :     HCCL_INFO(
     127              :         "[CollReduceScatterMeshOpbasePipelineExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
     128            0 :     return HCCL_SUCCESS;
     129              : }
     130              : 
     131            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
     132              : {
     133            0 :     TransportMemType inputType = TransportMemType::RESERVED;
     134            0 :     TransportMemType outputType = TransportMemType::RESERVED;
     135            0 :     CHK_RET(CalcTransportMemType(inputType, outputType));
     136            0 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
     137            0 :     CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
     138            0 :     return HCCL_SUCCESS;
     139              : }
     140              : 
     141            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::CalcLevel0CommInfo(
     142              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
     143              : {
     144            0 :     CommParaInfo commParaInfo(COMM_LEVEL0, CommType::COMM_TAG_MESH);
     145            0 :     commParaInfo.meshSinglePlane = true;
     146            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL0], inputType, outputType));
     147            0 :     return HCCL_SUCCESS;
     148            0 : }
     149              : 
     150              : // PipeLine模式下使用Ring算法
     151            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::CalcLevel1CommInfo(
     152              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
     153              : {
     154            0 :     CommParaInfo commParaInfo(COMM_LEVEL1, CommType::COMM_TAG_RING_INNER);
     155            0 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaInfo, opTransport[COMM_LEVEL1], inputType, outputType));
     156            0 :     return HCCL_SUCCESS;
     157            0 : }
     158              : 
     159            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::CalcTransportMemType(
     160              :     TransportMemType& inputType, TransportMemType& outputType)
     161              : {
     162            0 :     inputType = TransportMemType::CCL_INPUT;
     163            0 :     outputType = TransportMemType::CCL_OUTPUT;
     164            0 :     HCCL_INFO(
     165              :         "[CollReduceScatterMeshOpbasePipelineExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
     166              :         " outputType[%d]",
     167              :         tag_.c_str(), inputType, outputType);
     168            0 :     return HCCL_SUCCESS;
     169              : }
     170              : 
     171            0 : u64 CollReduceScatterMeshOpbasePipelineExecutor::CalcLoopMaxCount(const u32 unitSize)
     172              : {
     173              :     // 中转内存单次最多能够接受的output count,放开ranksize限制
     174            0 :     u64 maxCountPerLoop = ((inCCLbufferSize_ / (HCCL_MIN_SLICE_ALIGN_910B * PIPELINE_DEPTH)) * HCCL_MIN_SLICE_ALIGN_910B
     175            0 :                            - HCCL_MIN_SLICE_ALIGN_910B)
     176            0 :                           / unitSize;
     177            0 :     HCCL_INFO("[CollReduceScatterMeshOpbasePipelineExecutor][CalcLoopMaxCount] maxCountPerLoop[%llu]", maxCountPerLoop);
     178            0 :     return maxCountPerLoop;
     179              : }
     180              : 
     181            0 : bool CollReduceScatterMeshOpbasePipelineExecutor::IsHugeData(const u64 curSize, [[maybe_unused]] OpParam* param)
     182              : {
     183            0 :     bool hugeData = curSize > RDMA_SEND_MAX_SIZE || curSize > SDMA_SEND_MAX_SIZE;
     184            0 :     return hugeData;
     185              : }
     186              : 
     187            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::Getlevel1CommRank(SubCommInfo& level1CommInfo)
     188              : {
     189            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
     190            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     191              : 
     192            0 :     u32 commIndex = level0CommInfo.localRank; // 找到rank所在的节点间平面
     193            0 :     CHK_RET(CheckCommSize(COMM_LEVEL1, commIndex + 1));
     194              : 
     195            0 :     level1CommInfo = GetSubCommInfo(COMM_LEVEL1, commIndex);
     196            0 :     return HCCL_SUCCESS;
     197            0 : }
     198              : 
     199            0 : HcclResult CollReduceScatterMeshOpbasePipelineExecutor::SelectTempAlg(
     200              :     std::unique_ptr<AlgTemplateBase>& level1TempAlg, u32 level1RankSize)
     201              : {
     202            0 :     if (level1RankSize > 1) {
     203            0 :         level1TempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     204            0 :             TemplateType::TEMPLATE_REDUCESCATTER_PIPELINE, dispatcher_);
     205            0 :         CHK_SMART_PTR_NULL(level1TempAlg);
     206              :     }
     207            0 :     return HCCL_SUCCESS;
     208              : }
     209              : 
     210              : REGISTER_EXEC(
     211              :     "ReduceScatterMeshOpbasePipelineExecutor", ReduceScatterMeshOpbasePipeline,
     212              :     CollReduceScatterMeshOpbasePipelineExecutor);
     213              : 
     214              : } // namespace hccl
        

Generated by: LCOV version 2.0-1