LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_reduce_scatter - coll_reduce_scatter_mesh_dma_elimination.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 48.5 % 68 33
Test Date: 2026-07-28 12:11:00 Functions: 60.0 % 10 6

            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_dma_elimination.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            8 : CollReduceScatterMeshDmaEliminationExecutor::CollReduceScatterMeshDmaEliminationExecutor(
      16              :     const HcclDispatcher dispatcher,
      17            8 :     std::unique_ptr<TopoMatcher> &topoMatcher)
      18            8 :     : CollReduceScatterExecutor(dispatcher, topoMatcher)
      19              : {
      20            8 :     DMAReduceFlag_ = true;
      21            8 :     CCLMemSlice_ = false;
      22            8 : }
      23              : 
      24            8 : void CollReduceScatterMeshDmaEliminationExecutor::ParseParam(const OpParam& param)
      25              : {
      26            8 :     tag_ = param.tag;
      27            8 :     aicpuUnfoldMode_ = param.aicpuUnfoldMode;
      28            8 : }
      29              : 
      30            8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcStreamNum(u32& streamNum)
      31              : {
      32            8 :     u32 totalStreamNum = topoAttr_.deviceNumPerAggregation;
      33            8 :     streamNum = totalStreamNum - 1U;
      34            8 :     HCCL_INFO("[CollReduceScatterMeshDmaEliminationExecutor][CalcStreamNum] tag[%s] streamNum[%u]",
      35              :         tag_.c_str(), streamNum);
      36            8 :     return HCCL_SUCCESS;
      37              : }
      38              : 
      39            8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcCommInfo(
      40              :     std::vector<LevelNSubCommTransport>& opTransport)
      41              : {
      42            8 :     TransportMemType inputType = TransportMemType::RESERVED;
      43            8 :     TransportMemType outputType = TransportMemType::RESERVED;
      44            8 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      45            8 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      46            8 :     return HCCL_SUCCESS;
      47              : }
      48              : 
      49            8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcTransportMemType(TransportMemType &inputType,
      50              :     TransportMemType &outputType)
      51              : {
      52            8 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      53            8 :         inputType = TransportMemType::CCL_INPUT;
      54            8 :         outputType = TransportMemType::CCL_OUTPUT;
      55              :     } else {
      56            0 :         inputType = TransportMemType::PARAM_INPUT;
      57            0 :         outputType = TransportMemType::PARAM_OUTPUT;
      58              :     }
      59            8 :     HCCL_INFO("[CollReduceScatterMeshDmaEliminationExecutor][CalcTransportMemType] tag[%s] inputType[%d],"
      60              :         " outputType[%d]", tag_.c_str(), inputType, outputType);
      61            8 :     return HCCL_SUCCESS;
      62              : }
      63              : 
      64            8 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::CalcLevel0CommInfo(TransportMemType inputType,
      65              :     TransportMemType outputType,
      66              :     std::vector<LevelNSubCommTransport>& opTransport)
      67              : {
      68            8 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      69            8 :     commParaLevel0.meshSinglePlane = true;
      70            8 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      71            8 :     return HCCL_SUCCESS;
      72            8 : }
      73              : 
      74            0 : u64 CollReduceScatterMeshDmaEliminationExecutor::CalcLoopMaxCount(const u32 unitSize)
      75              : {
      76              :     // 中转内存单次最多能够接受的output count,放开ranksize限制
      77            0 :     u64 maxCountPerLoop = inCCLbufferSize_ / unitSize;
      78            0 :     return maxCountPerLoop;
      79              : }
      80              : 
      81            0 : bool CollReduceScatterMeshDmaEliminationExecutor::IsHugeData(const u64 curSize, OpParam *param)
      82              : {
      83              :     // 只有server内通信,多QP哈希散列下不刷新子图
      84            0 :     bool hugeData = curSize > SDMA_SEND_MAX_SIZE;
      85            0 :     return hugeData;
      86              : }
      87              : 
      88            0 : bool CollReduceScatterMeshDmaEliminationExecutor::IsSmallData(const u64 totalSize, const u64 curSize)
      89              : {
      90            0 :     bool smallData = totalSize <= HCCL_SMALL_COUNT_32_KB;
      91            0 :     return smallData;
      92              : }
      93              : 
      94            0 : HcclResult CollReduceScatterMeshDmaEliminationExecutor::KernelRun(const OpParam &param, ExecMem &execMem)
      95              : {
      96            0 :     HCCL_CONFIG_INFO(HCCL_ALG,
      97              :         "[CollReduceScatterMeshDmaEliminationExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
      98            0 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
      99            0 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
     100              : 
     101            0 :     u32 commIndex = level0CommInfo.localRank; // 找到rank所在的节点间平面
     102              : 
     103              :     /* *******************节点内reducescatter ******************************************/
     104            0 :     CHK_RET(ActiveSlaveStreams(param.stream));
     105              : 
     106            0 :     u32 sliceNum = level0CommInfo.localRankSize;
     107              :     // 根据数据量算每个环上数据的偏移和大小,把做完hd的slice均分成RankSize份
     108            0 :     std::vector<Slice> dataSegsSlice;
     109              : 
     110            0 :     HCCL_DEBUG("inputMem.size()=%llu, level0CommInfo.localRankSize=%u, commIndex=%u",
     111              :         execMem.inputMem.size(), level0CommInfo.localRankSize, commIndex);
     112              : 
     113            0 :     HcomCollOpInfo *opInfoPtr = nullptr;
     114            0 :     HcomCollOpInfo opInfo = {"", execMem.inputPtr, execMem.outputPtr, param.DataDes.count, param.DataDes.dataType,
     115            0 :         param.root, param.reduceType};
     116            0 :     if (DMAReduceFlag_) {
     117            0 :         opInfoPtr = &opInfo;
     118              :     }
     119              : 
     120            0 :     if (topoMatcher_->GetExternalInputHcclDeterministic() == DETERMINISTIC_DISABLE &&
     121            0 :         (param.DataDes.dataType != HCCL_DATA_TYPE_INT64) &&
     122            0 :         (topoAttr_.deviceType == DevType::DEV_TYPE_910B && param.reduceType != HCCL_REDUCE_PROD)) {
     123            0 :         CHK_RET(MultiStreamReduceScatterMeshAtomic(param.tag, execMem.inputMem, execMem.scratchMem,
     124              :             execMem.count, param.DataDes.dataType, param.reduceType, dataSegsSlice, const_cast<Stream&>(param.stream),
     125              :             COMM_LEVEL0, 0, opInfoPtr));
     126              :     } else {
     127            0 :         std::vector<std::vector<Slice> > multiStreamSlice; // 每个stream使用的数据基于用户buffer的偏移
     128              :         // mesh算法stream数量为rank数减1
     129            0 :         CHK_RET(AlgTemplateBase::PrepareSliceMeshStreams(dataSegsSlice, sliceNum - 1, multiStreamSlice));
     130            0 :         CHK_RET(MultiStreamReduceScatterMesh(param.tag, execMem.inputMem, execMem.scratchMem,
     131              :             execMem.count, param.DataDes.dataType, param.reduceType, multiStreamSlice, param.stream, COMM_LEVEL0, 0));
     132            0 :     }
     133              : 
     134            0 :     return HCCL_SUCCESS;
     135            0 : }
     136              : 
     137              : REGISTER_EXEC("ReduceScatterMeshDmaEliminationExecutor",
     138              :     ReduceScatterMeshDmaElimination, CollReduceScatterMeshDmaEliminationExecutor);
     139              : }
        

Generated by: LCOV version 2.0-1