LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_reduce - coll_all_reduce_mesh_mid_count_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 95.0 % 60 57
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 8 8

            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_reduce_mesh_mid_count_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            1 : CollAllReduceMeshMidCountExecutor::CollAllReduceMeshMidCountExecutor(
      16            1 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher>& topoMatcher)
      17            1 :     : CollAllReduceExecutor(dispatcher, topoMatcher)
      18              : {
      19            1 :     CCLMemSlice_ = false;
      20            1 :     DMAReduceFlag_ = true;
      21            1 : }
      22              : 
      23            1 : HcclResult CollAllReduceMeshMidCountExecutor::CalcStreamNum(u32& streamNum)
      24              : {
      25            1 :     u32 totalStreamNum = INVALID_UINT;
      26            1 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      27            1 :         totalStreamNum = topoAttr_.deviceNumPerAggregation;
      28              :     } else {
      29            0 :         totalStreamNum = topoAttr_.deviceNumPerAggregation - 1U;
      30              :     }
      31            1 :     streamNum = totalStreamNum - 1U;
      32            1 :     HCCL_INFO("[CollAllReduceMeshMidCountExecutor][CalcStreamNum] tag[%s] streamNum[%u]", tag_.c_str(), streamNum);
      33            1 :     return HCCL_SUCCESS;
      34              : }
      35              : 
      36            1 : HcclResult CollAllReduceMeshMidCountExecutor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      37              : {
      38            1 :     TransportMemType inputType = TransportMemType::RESERVED;
      39            1 :     TransportMemType outputType = TransportMemType::RESERVED;
      40            1 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      41            1 :     CHK_RET(CalcLevel0CommInfo(inputType, outputType, opTransport));
      42            1 :     return HCCL_SUCCESS;
      43              : }
      44              : 
      45              : HcclResult
      46            1 : CollAllReduceMeshMidCountExecutor::CalcTransportMemType(TransportMemType& inputType, TransportMemType& outputType)
      47              : {
      48            1 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      49            1 :         inputType = TransportMemType::CCL_INPUT;
      50            1 :         outputType = TransportMemType::CCL_OUTPUT;
      51              :     } else {
      52            0 :         inputType = TransportMemType::PARAM_INPUT; // userInput
      53            0 :         outputType = TransportMemType::PARAM_OUTPUT;
      54              :     }
      55            1 :     HCCL_INFO(
      56              :         "[CollAllReduceMeshMidCountExecutor][CalcTransportMemType]tag[%s] inputType[%d], outputType[%d].", tag_.c_str(),
      57              :         inputType, outputType);
      58            1 :     return HCCL_SUCCESS;
      59              : }
      60              : 
      61            1 : HcclResult CollAllReduceMeshMidCountExecutor::CalcLevel0CommInfo(
      62              :     TransportMemType inputType, TransportMemType outputType, std::vector<LevelNSubCommTransport>& opTransport)
      63              : {
      64            1 :     CommParaInfo commParaLevel0(COMM_LEVEL0, CommType::COMM_TAG_MESH);
      65            1 :     commParaLevel0.meshSinglePlane = true;
      66            1 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel0, opTransport[COMM_LEVEL0], inputType, outputType));
      67            1 :     return HCCL_SUCCESS;
      68            1 : }
      69              : 
      70            1 : bool CollAllReduceMeshMidCountExecutor::IsHugeData(const u64 curSize)
      71              : {
      72              :     // 只有server内通信,多QP哈希散列下不刷新子图
      73            1 :     bool hugeData = curSize > SDMA_SEND_MAX_SIZE;
      74            1 :     return hugeData;
      75              : }
      76              : 
      77            1 : bool CollAllReduceMeshMidCountExecutor::IsSmallData(const u64 totalSize, [[maybe_unused]] const u64 curSize)
      78              : {
      79            1 :     bool smallData = totalSize <= HCCL_SMALL_COUNT_128_KB;
      80            1 :     return smallData;
      81              : }
      82              : 
      83            1 : HcclResult CollAllReduceMeshMidCountExecutor::KernelRun(const OpParam& param, ExecMem& execMem)
      84              : {
      85            1 :     HCCL_CONFIG_INFO(
      86              :         HCCL_ALG, "[CollAllReduceMeshMidCountExecutor][KernelRun] userRank[%u] starts.", topoAttr_.userRank);
      87            1 :     std::vector<Slice> dataSegsSlice; // 数据分成ranksize份,每份的起始偏移和大小
      88              : 
      89            1 :     CHK_RET(CheckCommSize(COMM_LEVEL0, COMM_INDEX_0 + 1));
      90            1 :     SubCommInfo level0CommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      91              : 
      92            1 :     CHK_RET(ActiveSlaveStreams(param.stream));
      93              : 
      94            1 :     u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, param.DataDes.dataType, param.reduceType);
      95            1 :     HcomCollOpInfo opInfo
      96            1 :         = {"", execMem.inputPtr, execMem.outputPtr, execMem.count, param.DataDes.dataType, param.root, param.reduceType,
      97            1 :            0};
      98              : 
      99            1 :     std::unique_ptr<AlgTemplateBase> level0TempAlg;
     100              :     level0TempAlg
     101            1 :         = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_LOCAL_REDUCE, dispatcher_);
     102            1 :     CHK_SMART_PTR_NULL(level0TempAlg);
     103            1 :     CHK_RET(level0TempAlg->Prepare(
     104              :         reduceAttr, algResResp_->slaveStreams, algResResp_->notifiesMain, algResResp_->notifiesAux,
     105              :         level0CommInfo.localRank, level0CommInfo.localRankSize, topoAttr_.userRank, &opInfo));
     106              : 
     107            3 :     CHK_RET(level0TempAlg->Prepare(
     108              :         execMem.outputMem, execMem.outputMem, execMem.outputMem, execMem.count, param.DataDes.dataType, param.stream,
     109              :         param.reduceType, LEVEL0_BRIDGE_RANK_ID, dataSegsSlice, 0));
     110            1 :     CHK_RET(level0TempAlg->RegisterProfiler(
     111              :         (level0CommInfo.localRankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0CommInfo.localRank, PROF_STAGE_2,
     112              :         HCCL_EXEC_STEP_NOT_SET, param.stream));
     113            1 :     CHK_RET(RunTemplate(level0TempAlg, level0CommInfo));
     114            1 :     HCCL_INFO("AllReduce mid count run success.");
     115              : 
     116            1 :     return HCCL_SUCCESS;
     117            1 : }
     118              : 
     119              : REGISTER_EXEC("AllReduceMeshMidCountLoopExecutor", AllReduceMeshMidCount, CollAllReduceMeshMidCountExecutor);
     120              : 
     121              : } // namespace hccl
        

Generated by: LCOV version 2.0-1