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

Generated by: LCOV version 2.0-1