LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_reduce - coll_all_reduce_mid_count_for_910_93_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 35.9 % 92 33
Test Date: 2026-07-28 12:11:00 Functions: 85.7 % 7 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_all_reduce_mid_count_for_910_93_executor.h"
      12              : 
      13              : namespace hccl {
      14            1 : CollAllReduceMidCountFor91093Executor::CollAllReduceMidCountFor91093Executor(const HcclDispatcher dispatcher,
      15            1 :                                                                    std::unique_ptr<TopoMatcher> &topoMatcher)
      16            1 :     : CollAllReduceExecutor(dispatcher, topoMatcher)
      17              : {
      18            1 :     DMAReduceFlag_ = true;
      19            0 :     desc_.level1SupportedAlgos = {
      20              :         AlgTypeLevel1::ALG_LEVEL1_NHR,
      21            1 :     };
      22            0 :     desc_.level2SupportedAlgos = {
      23              :         AlgTypeLevel2::ALG_LEVEL2_NHR,
      24            1 :     };
      25            1 : }
      26              : 
      27            1 : HcclResult CollAllReduceMidCountFor91093Executor::CalcCommInfo(std::vector<LevelNSubCommTransport>& opTransport)
      28              : {
      29            1 :     TransportMemType inputType = TransportMemType::RESERVED;
      30            1 :     TransportMemType outputType = TransportMemType::RESERVED;
      31            1 :     CHK_RET(CalcTransportMemType(inputType, outputType));
      32            1 :     CHK_RET(CalcLevel1CommInfo(inputType, outputType, opTransport));
      33            1 :     CHK_RET(CalcLevel2CommInfo(inputType, outputType, opTransport));
      34            1 :     return HCCL_SUCCESS;
      35              : }
      36              : 
      37            1 : HcclResult CollAllReduceMidCountFor91093Executor::CalcTransportMemType(TransportMemType &inputType,
      38              :     TransportMemType &outputType) const
      39              : {
      40            1 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      41            1 :         inputType = TransportMemType::CCL_INPUT;
      42            1 :         outputType = TransportMemType::CCL_OUTPUT;
      43              :     } else {
      44            0 :         HCCL_ERROR("AllReduceMidCountFor91093Executor do not support offload mode");
      45            0 :         return HCCL_E_UNAVAIL;
      46              :     }
      47            1 :     HCCL_INFO("[CollAllReduceMidCountFor91093Executor][CalcTransportMemType] tag[%s] inputType[%d], outputType[%d]",
      48              :         tag_.c_str(), inputType, outputType);
      49            1 :     return HCCL_SUCCESS;
      50              : }
      51              : 
      52            1 : HcclResult CollAllReduceMidCountFor91093Executor::CalcLevel1CommInfo(TransportMemType inputType,
      53              :     TransportMemType outputType,
      54              :     std::vector<LevelNSubCommTransport>& opTransport)
      55              : {
      56            1 :     CommParaInfo commParaCombineL1(COMM_COMBINE_L1, CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING);
      57            1 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaCombineL1, opTransport[COMM_COMBINE_L1], inputType, outputType));
      58            1 :     return HCCL_SUCCESS;
      59            1 : }
      60              : 
      61            1 : HcclResult CollAllReduceMidCountFor91093Executor::CalcLevel2CommInfo(TransportMemType inputType, TransportMemType outputType,
      62              :     std::vector<LevelNSubCommTransport>& opTransport)
      63              : {
      64            1 :     CommParaInfo commParaLevel2(COMM_LEVEL2, CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING);
      65            1 :     CHK_RET(CalcCommPlaneInfo(tag_, commParaLevel2, opTransport[COMM_LEVEL2], inputType, outputType));
      66            1 :     return HCCL_SUCCESS;
      67            1 : }
      68              : 
      69            1 : u64 CollAllReduceMidCountFor91093Executor::CalcLoopMaxCount(const u64 cclBuffSize, const u32 unitSize)
      70              : {
      71            1 :     u64 maxCountPerLoop = cclBuffSize / HCCL_MIN_SLICE_ALIGN_910_93 / unitSize * HCCL_MIN_SLICE_ALIGN_910_93;
      72            1 :     return maxCountPerLoop;
      73              : }
      74              : 
      75            0 : HcclResult CollAllReduceMidCountFor91093Executor::KernelRun(const OpParam &param, ExecMem &execMem)
      76              : {
      77            0 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] The MidCountFor91093Executor starts, topoType_[%u]", __func__, topoType_);
      78              : 
      79            0 :     u32 unitSize = 0;
      80            0 :     CHK_RET(SalGetDataTypeSize(param.GetDataType(), unitSize));
      81              :     
      82              :     // 获取 level1 打平级通信域
      83            0 :     CHK_RET(CheckCommSize(COMM_COMBINE_L1, COMM_INDEX_0 + 1));
      84            0 :     SubCommInfo level1CommInfo = GetSubCommInfo(COMM_COMBINE_L1, COMM_INDEX_0);
      85              : 
      86              :     // 获取 level2 级通信域
      87            0 :     CHK_RET(CheckCommSize(COMM_LEVEL2, COMM_INDEX_0 + 1));
      88            0 :     SubCommInfo level2CommInfo = GetSubCommInfo(COMM_LEVEL2, COMM_INDEX_0);
      89              :     
      90            0 :     const u32 level1RankSize = level1CommInfo.localRankSize;
      91            0 :     const u32 level2RankSize = level2CommInfo.localRankSize;
      92            0 :     u64 inputMemSize = execMem.count * unitSize;
      93            0 :     const u32 SINGLERANK = 1;
      94              : 
      95            0 :     if (DMAReduceFlag_) {
      96            0 :         DeviceMem srcMem = DeviceMem::create(static_cast<u8 *>(execMem.inputPtr), inputMemSize);
      97            0 :         DeviceMem dstMem = execMem.inputMem.range(0, inputMemSize);
      98            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
      99            0 :         HCCL_DEBUG("copy from user in to ccl in.");
     100            0 :     }
     101              : 
     102            0 :     u64 reduceAttr = GetReduceAttr(execMem.inputMem, execMem.outputMem, param.DataDes.dataType, param.reduceType);
     103              : 
     104              :     //step1:  run nhr ont shot in level1
     105            0 :     if (level1RankSize > SINGLERANK) {
     106            0 :         std::unique_ptr<AlgTemplateBase> level1tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR_ONESHOT, dispatcher_);
     107            0 :         CHK_SMART_PTR_NULL(level1tempAlg);
     108            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_ONESHOT in COMM_COMBINE_L1/COMM_LEVEL2", __func__);
     109            0 :         HCCL_INFO("AllReduce mid count: using nhr algo intra-server.");
     110              :         
     111            0 :         CHK_RET(level1tempAlg->Prepare(reduceAttr));
     112            0 :         level1tempAlg->CloseBarrier();
     113              : 
     114            0 :         CHK_RET(level1tempAlg->Prepare(execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count,
     115              :             param.DataDes.dataType, param.stream, param.reduceType,
     116              :             LEVEL0_BRIDGE_RANK_ID, std::vector<Slice>(0), 0));
     117              : 
     118            0 :         CHK_RET(level1tempAlg->RegisterProfiler(
     119              :             (level1RankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) +
     120              :             level1CommInfo.localRank, PROF_STAGE_0, HCCL_EXEC_STEP_NOT_SET, param.stream));
     121              : 
     122            0 :         CHK_RET(RunTemplate(level1tempAlg, level1CommInfo));
     123            0 :     } 
     124              : 
     125              :     // 数据回拷
     126            0 :     if(level1RankSize > SINGLERANK && level2RankSize > SINGLERANK) {
     127            0 :         DeviceMem srcMem = execMem.outputMem.range(0, inputMemSize);
     128            0 :         DeviceMem dstMem = execMem.inputMem.range(0, inputMemSize);
     129            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));  
     130            0 :     }
     131              :     
     132              :     //step2:  run nhr ont shot in level2
     133            0 :     if (level2RankSize > SINGLERANK) {
     134            0 :         std::unique_ptr<AlgTemplateBase> level2tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(TemplateType::TEMPLATE_ALL_REDUCE_NHR_ONESHOT, dispatcher_);
     135            0 :         CHK_SMART_PTR_NULL(level2tempAlg);
     136            0 :         HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALL_REDUCE_NHR_ONESHOT in COMM_COMBINE_L1/COMM_LEVEL2", __func__);
     137            0 :         HCCL_INFO("AllReduce mid count: using nhr algo intra-server.");
     138              :         
     139            0 :         CHK_RET(level2tempAlg->Prepare(reduceAttr));
     140            0 :         level2tempAlg->CloseBarrier();
     141              : 
     142            0 :         CHK_RET(level2tempAlg->Prepare(execMem.inputMem, execMem.outputMem, execMem.outputMem, execMem.count,
     143              :             param.DataDes.dataType, param.stream, param.reduceType, LEVEL0_BRIDGE_RANK_ID, std::vector<Slice>(0), 0));
     144              : 
     145            0 :         CHK_RET(level2tempAlg->RegisterProfiler(
     146              :             (level2RankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) +
     147              :             level2CommInfo.localRank, PROF_STAGE_1, HCCL_EXEC_STEP_NOT_SET, param.stream));
     148              : 
     149            0 :         CHK_RET(RunTemplate(level2tempAlg, level2CommInfo));
     150            0 :     }
     151              : 
     152            0 :     if (DMAReduceFlag_) {
     153            0 :         DeviceMem srcMem = execMem.outputMem.range(0, inputMemSize);
     154            0 :         DeviceMem dstMem = DeviceMem::create(static_cast<u8 *>(execMem.outputPtr), inputMemSize);
     155            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dstMem, srcMem, const_cast<Stream&>(param.stream)));
     156            0 :         HCCL_DEBUG("copy from ccl out to user out.");
     157            0 :     }
     158              : 
     159            0 :     HCCL_INFO("AllReduce mid count run success");
     160            0 :     return HCCL_SUCCESS;
     161            0 : }
     162              : 
     163              : REGISTER_EXEC("AllReduceMidCountFor91093Executor", AllReduceMidCountFor91093, CollAllReduceMidCountFor91093Executor);
     164              : } // namespace hccl
        

Generated by: LCOV version 2.0-1