LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl/coll_executor/coll_all_reduce - coll_all_reduce_fast_double_ring_for_910_93_executor.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.7 % 77 76
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 5 5

            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_fast_double_ring_for_910_93_executor.h"
      12              : 
      13              : namespace hccl {
      14              : 
      15            4 : CollAllReduceFastDoubleRingFor91093Executor::CollAllReduceFastDoubleRingFor91093Executor(
      16            4 :     const HcclDispatcher dispatcher, std::unique_ptr<TopoMatcher> &topoMatcher)
      17            4 :     : CollAllReduceRingFor91093Executor(dispatcher, topoMatcher)
      18              : {
      19            4 :     if (workflowMode_ == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      20            4 :         DMAReduceFlag_ = true;
      21              :     } else {
      22            0 :         DMAReduceFlag_ = false;
      23              :     }
      24            4 : }
      25              : 
      26           16 : HcclResult CollAllReduceFastDoubleRingFor91093Executor::DoubleRingReduceScatter(const std::string &tag,
      27              :     DeviceMem inputMem, DeviceMem outputMem, const u64 count, const HcclDataType dataType,
      28              :     const HcclReduceOp reductionOp, const std::vector<std::vector<Slice>> multRingsSliceZero, Stream stream,
      29              :     s32 profStage, const u64 baseOffset, const HcomCollOpInfo *opInfo,
      30              :     const std::vector<std::vector<Slice>> multRingsUserMemSlice, const bool disableDMAReduce)
      31              : {
      32              :     (void)tag;
      33           16 :     HCCL_CONFIG_INFO(HCCL_ALG,
      34              :         "[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingReduceScatter] DoubleRingReduceScatter starts");
      35           16 :     HcclResult ret = HCCL_SUCCESS;
      36           16 :     u32 ringNum = multRingsSliceZero.size();
      37           16 :     CHK_RET(CheckCommSize(COMM_LEVEL0, ringNum));
      38              :     // 拿到ring环映射关系
      39           16 :     SubCommInfo level0ZeroCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      40           16 :     auto nicList = topoAttr_.nicList;
      41              :     std::vector<std::vector<u32>> multiRingsOrder =
      42           16 :         GetRingsOrderByTopoType(level0ZeroCommInfo.localRankSize, topoType_, nicList);
      43           16 :     u64 reduceAttr = GetReduceAttr(inputMem, outputMem, dataType, reductionOp);
      44           16 :     SubCommInfo level0RingCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      45              :     // 生成两个ring上的userMemIn_上对应的slices
      46           16 :     std::vector<std::vector<Slice>> userMemInputSlicesOfDoubleRing;
      47           16 :     CHK_RET(CollectMultiRingsUserMemSlices(ringNum, dataType, opInfo, multRingsSliceZero,
      48              :         multiRingsOrder, multRingsUserMemSlice, userMemInputSlicesOfDoubleRing));
      49              :     // 生成两个ring上的rankOrder
      50           16 :     std::vector<std::vector<u32>> rankOrders;
      51           16 :     CHK_RET(CollectMultiRingsRankOrder(ringNum, multiRingsOrder, rankOrders));
      52              :     // 初始化executor
      53           16 :     std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
      54           16 :         TemplateType::TEMPLATE_REDUCESCATTER_DB_RING_SLC, dispatcher_);
      55           16 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_REDUCESCATTER_DB_RING_SLC in COMM_LEVEL0", __func__);
      56           16 :     CHK_SMART_PTR_NULL(tempAlg);
      57           16 :     ret = tempAlg->Prepare(inputMem, inputMem, outputMem, count, dataType, stream,
      58              :         multRingsSliceZero, reductionOp, LEVEL0_BRIDGE_RANK_ID, baseOffset, disableDMAReduce, 
      59           16 :         reduceAttr, opInfo, topoAttr_.userRank, algResResp_->slaveStreams, algResResp_->notifiesMain,
      60           16 :         algResResp_->notifiesAux, rankOrders, userMemInputSlicesOfDoubleRing);
      61           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      62              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring "
      63              :                    "ReduceScatter failed,return[%d]", ret), ret);
      64           16 :     u32 ringIndexOp = COMM_INDEX_0;
      65           16 :     u32 rankSize = level0RingCommInfo.localRankSize;
      66           16 :     ret = tempAlg->RegisterProfiler(((ringIndexOp + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID) +
      67           16 :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0RingCommInfo.localRank, profStage,
      68              :         HCCL_EXEC_STEP_NOT_SET, stream);
      69           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      70              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring "
      71              :                    "ReduceScatter failed,return[%d]", ret), ret);
      72              :     // 空拷贝用于后续操作附着
      73           16 :     CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
      74           16 :     ret = RunTemplate(tempAlg, level0RingCommInfo);
      75           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
      76              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingReduceScatter] Double ring "
      77              :                    "ReduceScatter failed,return[%d]", ret), ret);
      78              : 
      79           16 :     CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
      80           16 :     return HCCL_SUCCESS;
      81           16 : }
      82              : 
      83           16 : HcclResult CollAllReduceFastDoubleRingFor91093Executor::DoubleRingAllGather(
      84              :     const std::string &tag, DeviceMem inputMem, DeviceMem outputMem,
      85              :     const u64 count, const HcclDataType dataType, const std::vector<std::vector<Slice> > multRingsSliceZero,
      86              :     Stream stream, s32 profStage, const u64 baseOffset, const HcomCollOpInfo *opInfo,
      87              :     const std::vector<std::vector<Slice>> multRingsUserMemSlice)
      88              : {
      89              :     (void)tag;
      90           16 :     HCCL_CONFIG_INFO(HCCL_ALG,
      91              :         "[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingAllGather] DoubleRingAllGather starts");
      92           16 :     HcclResult ret = HCCL_SUCCESS;
      93           16 :     u32 ringNum = multRingsSliceZero.size();
      94           16 :     CHK_RET(CheckCommSize(COMM_LEVEL0, ringNum));
      95              :     // 拿到ring环映射关系
      96           16 :     SubCommInfo level0ZeroCommInfo = GetSubCommInfo(COMM_LEVEL0, COMM_INDEX_0);
      97           16 :     auto nicList = topoAttr_.nicList;
      98              :     std::vector<std::vector<u32>> multiRingsOrder =
      99           16 :         GetRingsOrderByTopoType(level0ZeroCommInfo.localRankSize, topoType_, nicList);
     100              :     // 生成两个ring上的userMemOut_上对应的slices
     101           16 :     std::vector<std::vector<Slice>> userMemOutputSlicesOfDoubleRing;
     102           16 :     CHK_RET(CollectMultiRingsUserMemSlices(ringNum, dataType, opInfo, multRingsSliceZero,
     103              :         multiRingsOrder, multRingsUserMemSlice, userMemOutputSlicesOfDoubleRing));
     104              :     // 生成两个ring上的rankOrder
     105           16 :     std::vector<std::vector<u32>> rankOrders;
     106           16 :     CHK_RET(CollectMultiRingsRankOrder(ringNum, multiRingsOrder, rankOrders));
     107              :     // 初始化executor
     108           16 :     std::unique_ptr<AlgTemplateBase> tempAlg = AlgTemplateRegistry::Instance().GetAlgTemplate(
     109           16 :         TemplateType::TEMPLATE_ALIGNED_ALL_GATHER_DOUBLE_RING, dispatcher_);
     110           16 :     HCCL_CONFIG_INFO(HCCL_ALG, "[%s] Run TEMPLATE_ALIGNED_ALL_GATHER_DOUBLE_RING in COMM_LEVEL0", __func__);
     111           16 :     CHK_SMART_PTR_NULL(tempAlg);
     112           16 :     CHK_RET(tempAlg->Prepare(const_cast<HcomCollOpInfo*>(opInfo), topoAttr_.userRank, algResResp_->slaveStreams,
     113              :         algResResp_->notifiesMain, algResResp_->notifiesAux, rankOrders, userMemOutputSlicesOfDoubleRing));
     114              : 
     115           16 :     ret = tempAlg->Prepare(outputMem, outputMem, inputMem, count, dataType, stream, multRingsSliceZero,
     116              :         HCCL_REDUCE_RESERVED, LEVEL0_BRIDGE_RANK_ID, baseOffset);
     117           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     118              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingAllGather]Double ring "
     119              :         "AllGather failed, return[%d]", ret), ret);
     120           16 :     u32 ringIndexOp = COMM_INDEX_0;
     121           16 :     u32 rankSize = level0ZeroCommInfo.localRankSize;
     122           16 :     ret = tempAlg->RegisterProfiler(
     123           16 :         ((ringIndexOp + 1) << PROF_RINGINDEX_OFFSET_OF_PLANEID) +
     124           16 :         (rankSize << PROF_RANKSIZE_OFFSET_OF_PLANEID) + level0ZeroCommInfo.localRank,
     125              :         profStage, HCCL_EXEC_STEP_NOT_SET, stream);
     126           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     127              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingAllGather]Double ring "
     128              :         "AllGather failed, return[%d]", ret), ret);
     129              : 
     130              :     // 空拷贝用于后续操作附着
     131           16 :     CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
     132           16 :     ret = RunTemplate(tempAlg, level0ZeroCommInfo);
     133           16 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     134              :         HCCL_ERROR("[CollAllReduceFastDoubleRingFor91093Executor][DoubleRingAllGather] Double ring "
     135              :                    "AllGather failed,return[%d]", ret), ret);
     136              :     // 添加空task,保证执行时不乱序
     137           16 :     CHK_RET(AlgTemplateBase::ExecEmptyTask(inputMem, outputMem, stream, dispatcher_));
     138           16 :     return HCCL_SUCCESS;
     139           16 : }
     140              : 
     141           16 : HcclResult CollAllReduceFastDoubleRingFor91093Executor::RunIntraSeverReduceScatter(
     142              :     const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
     143              :     const u64 count, const HcclDataType &dataType, const HcclReduceOp &reductionOp,
     144              :     const std::vector<std::vector<Slice>> &multRingsSliceZero, const Stream &stream, s32 profStage,
     145              :     const u64 baseOffset, const HcomCollOpInfo *opInfo,
     146              :     const std::vector<std::vector<Slice>> &multRingsUserMemSlice, const bool disableDMAReduce)
     147              : {
     148           16 :     CHK_RET(DoubleRingReduceScatter(tag, inputMem, outputMem, count, dataType, reductionOp,
     149              :         multRingsSliceZero, stream, profStage, baseOffset, opInfo, multRingsUserMemSlice, disableDMAReduce));
     150           16 :     return HCCL_SUCCESS;
     151              : }
     152              : 
     153           16 : HcclResult CollAllReduceFastDoubleRingFor91093Executor::RunIntraSeverAllGather(
     154              :     const std::string &tag, DeviceMem &inputMem, DeviceMem &outputMem,
     155              :     const u64 count, const HcclDataType &dataType, const std::vector<std::vector<Slice>> &multRingsSliceZero,
     156              :     const Stream &stream, s32 profStage, const u64 baseOffset, const HcomCollOpInfo *opInfo,
     157              :     const std::vector<std::vector<Slice>> &multRingsUserMemSlice)
     158              : {
     159           16 :     CHK_RET(DoubleRingAllGather(tag, inputMem, outputMem, count, dataType,
     160              :         multRingsSliceZero, stream, profStage, baseOffset, opInfo, multRingsUserMemSlice));
     161           16 :     return HCCL_SUCCESS;
     162              : }
     163              : 
     164              : REGISTER_EXEC("AllReduceFastDoubleRingFor91093Executor", AllReduceFastDoubleRingFor91093,
     165              :     CollAllReduceFastDoubleRingFor91093Executor);
     166              : 
     167              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1