LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_ccu_context/all_reduce - ccu_context_all_reduce_nhr1d_mem2mem.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 274 0
Test Date: 2026-07-28 12:11:00 Functions: 0.0 % 17 0

            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 "ccu_context_all_reduce_nhr1d_mem2mem.h"
      12              : 
      13              : namespace Hccl {
      14              : 
      15              : constexpr uint16_t RANK_NUM_PER_CKE = 16; // 本rank给远端置位时应当写的CKE,16个对端一个CKE
      16              : constexpr uint16_t OUTPUT_XN_ID     = 1;
      17              : constexpr uint16_t TOKEN_XN_ID      = 2;
      18              : constexpr uint16_t CKE_IDX_0        = 0;    // 后同步
      19              : constexpr uint16_t CKE_IDX_1        = 1;    // 前同步addr
      20              : constexpr uint16_t CKE_IDX_2        = 2;    // 前同步token
      21              : constexpr uint16_t CKE_IDX_3        = 3;    // NHR step同步信号0,用于RS前同步,AG后同步
      22              : constexpr uint16_t CKE_IDX_4        = 4;    // NHR step同步信号1,用于RS后同步
      23              : constexpr uint16_t FST_AXIS_ID      = 0;
      24              : constexpr uint16_t SEC_AXIS_ID      = 1;
      25              : 
      26            0 : CcuContextAllReduceNHR1D::CcuContextAllReduceNHR1D(const CcuCtxArg &arg, const std::vector<CcuTransport *> &transports,
      27            0 :                                                    const CcuTransportGroup &group)
      28            0 :     : CcuContextAlgBase(arg, transports, group)
      29              : {
      30            0 :     const CcuCtxArgAllReduceNHR1D *ctxArg = dynamic_cast<const CcuCtxArgAllReduceNHR1D *>(&arg);
      31            0 :     rankId_                               = ctxArg->rankId_;
      32            0 :     axisId_                               = ctxArg->axisId_;
      33            0 :     axisSize_                             = ctxArg->axisSize_;
      34            0 :     dimSize_                              = ctxArg->dimSize_[0];
      35            0 :     stepInfoVector_                       = ctxArg->stepInfoVector_;
      36            0 :     indexMap_                             = ctxArg->indexMap_;
      37            0 :     localSize_                            = indexMap_.size();
      38            0 :     myRankIdx_                            = indexMap_.size();
      39            0 :     dataType_                             = ctxArg->op_.dataType;
      40            0 :     reduceOp_                             = ctxArg->op_.reduceOp;
      41            0 :     signalNum_ = (dimSize_ + RANK_NUM_PER_CKE - 1) / RANK_NUM_PER_CKE; // 每个CKE有16个bit
      42            0 :     HCCL_INFO("[CcuContextAllReduceNHR1D] CtxArg: rankId_[%u], axisId_[%u], axisSize_[%u], dimSize_[%u], localSize_[%u], "
      43              :               "signalNum_[%u], dataType[%s], reduceOp[%s]",
      44              :               rankId_, axisId_, axisSize_, dimSize_, localSize_, signalNum_, dataType_.Describe().c_str(),
      45              :               reduceOp_.Describe().c_str());
      46            0 : }
      47              : 
      48            0 : void CcuContextAllReduceNHR1D::LoadArgs()
      49              : {
      50            0 :     Load(input_);
      51            0 :     Load(output_[myRankIdx_]);
      52            0 :     Load(token_[myRankIdx_]);
      53            0 :     Load(isInputOutputEqual_);
      54            0 :     Load(die0Size_);
      55            0 :     Load(die1Size_);
      56            0 :     Load(die0SliceSize_);
      57            0 :     Load(die1SliceSize_);
      58            0 :     Load(die0LastSliceSize_);
      59            0 :     Load(die1LastSliceSize_);
      60            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] LoadArgs run finished");
      61            0 : }
      62              : 
      63            0 : void CcuContextAllReduceNHR1D::InitResources()
      64              : {
      65            0 :     isInputOutputEqual_ = CreateVariable();
      66            0 :     die0SliceSize_      = CreateVariable();
      67            0 :     die1SliceSize_      = CreateVariable();
      68            0 :     die0LastSliceSize_  = CreateVariable();
      69            0 :     die1LastSliceSize_  = CreateVariable();
      70            0 :     die0Size_           = CreateVariable();
      71            0 :     die1Size_           = CreateVariable();
      72            0 :     localSignal_        = CreateMaskSignal();
      73              : 
      74            0 :     input_ = CreateVariable();
      75            0 :     for (uint32_t transportIdx = 0; transportIdx < localSize_; transportIdx++) {
      76            0 :         HCCL_DEBUG("[CcuContextAllReduceNHR1D] MyRank[%u], TransportId[%u]", rankId_, transportIdx);
      77            0 :         CHK_PRT_RET(transports[transportIdx] == nullptr,
      78              :                     HCCL_ERROR("[CcuContextAllReduceNHR1D] Algorithm transport ptr is null"), );
      79            0 :         output_.push_back(
      80            0 :             CreateVariable((*transports[transportIdx]), OUTPUT_XN_ID)); // 获取transport中id=1的Var来传递output
      81            0 :         token_.push_back(CreateVariable((*transports[transportIdx]), TOKEN_XN_ID));
      82              :     }
      83            0 :     output_.push_back(CreateVariable());
      84            0 :     token_.push_back(CreateVariable());
      85              :     
      86            0 :     srcMem_ = CreateMemory();
      87            0 :     dstMem_ = CreateMemory();
      88            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] InitResources finished");
      89              : }
      90              : 
      91            0 : void CcuContextAllReduceNHR1D::PreSync()
      92              : {
      93            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] PreSync start");
      94            0 :     uint16_t selfBit      = 1 << (rankId_ % RANK_NUM_PER_CKE);
      95            0 :     uint16_t selfSignalId = rankId_ / RANK_NUM_PER_CKE;
      96            0 :     std::vector<uint16_t> waitBitVector(signalNum_, 0);
      97            0 :     for (auto t : transports) {
      98            0 :         WriteVariableWithSignal(*t, output_[localSize_], OUTPUT_XN_ID, selfSignalId + signalNum_ * CKE_IDX_1, selfBit);
      99            0 :         WriteVariableWithSignal(*t, token_[localSize_], TOKEN_XN_ID, selfSignalId + signalNum_ * CKE_IDX_2, selfBit);
     100              :     }
     101            0 :     for (auto &pair : indexMap_) {
     102            0 :         uint16_t pairBit            = 1 << (pair.first % RANK_NUM_PER_CKE);
     103            0 :         uint16_t pairSignalId       = pair.first / RANK_NUM_PER_CKE;
     104            0 :         waitBitVector[pairSignalId] = waitBitVector[pairSignalId] | pairBit;
     105              :     }
     106            0 :     for (uint16_t sId = 0; sId < waitBitVector.size(); sId++) {
     107            0 :         GroupWait(*transportGroup, sId + signalNum_ * CKE_IDX_1, waitBitVector[sId]);
     108            0 :         GroupWait(*transportGroup, sId + signalNum_ * CKE_IDX_2, waitBitVector[sId]);
     109              :     }
     110            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] PreSync end");
     111            0 : }
     112              : 
     113            0 : void CcuContextAllReduceNHR1D::PostSync()
     114              : {
     115            0 :     uint16_t selfSignalId = rankId_ / RANK_NUM_PER_CKE;
     116            0 :     uint16_t selfBit      = 1 << (rankId_ % RANK_NUM_PER_CKE);
     117            0 :     std::vector<uint16_t> waitBitVector(signalNum_, 0);
     118            0 :     for (auto &t : transports) {
     119            0 :         RemotePost(*t, selfSignalId + signalNum_ * CKE_IDX_0, selfBit);
     120              :     }
     121            0 :     for (auto &pair : indexMap_) {
     122            0 :         uint16_t pairSignalId       = pair.first / RANK_NUM_PER_CKE;
     123            0 :         uint16_t pairBit            = 1 << (pair.first % RANK_NUM_PER_CKE);
     124            0 :         waitBitVector[pairSignalId] = waitBitVector[pairSignalId] | pairBit;
     125              :     }
     126            0 :     for (uint32_t sId = 0; sId < signalNum_; sId++) {
     127            0 :         GroupWait(*transportGroup, sId + signalNum_ * CKE_IDX_0, waitBitVector[sId]);
     128              :     }
     129            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] PostSync run finished");
     130            0 : }
     131              : 
     132            0 : void CcuContextAllReduceNHR1D::AxisSync(uint32_t signalIndex)
     133              : {
     134            0 :     const uint32_t DIE_NUM = 2;
     135            0 :     if (signalIndex > 1) {
     136            0 :         THROW<InvalidParamsException>(
     137            0 :             StringFormat("[CcuContextAllReduceNHR1D] Unexpected SignalInex[%u]", signalIndex));
     138              :     }
     139            0 :     LocalCtxPost(anotherAxisSignal_, 1 << (axisId_ + signalIndex * DIE_NUM));
     140            0 :     LocalWait(localAxisSignal_, 1 << (1 - axisId_ + signalIndex * DIE_NUM));
     141            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] AxisSync run finished");
     142            0 :     return;
     143              : }
     144              : 
     145            0 : void CcuContextAllReduceNHR1D::DoReduceScatterNHR()
     146              : {
     147            0 :     const uint32_t NHR_NUM = 2;
     148            0 :     for (u64 i = 0; i < stepInfoVector_.size() / NHR_NUM; i++) {
     149            0 :         const NHRStepInfo &nhrStepInfo = stepInfoVector_[i];
     150            0 :         DoReduceScatterNHRSingleStep(nhrStepInfo);
     151              :     }
     152            0 : }
     153              : 
     154            0 : void CcuContextAllReduceNHR1D::DoReduceScatterNHRSingleStep(const NHRStepInfo &nhrStepInfo)
     155              : {
     156            0 :     u32 sendSliceIdx = 0;
     157            0 :     u32 &fromRankIdx = indexMap_[nhrStepInfo.fromRank];
     158            0 :     u32 &toRankIdx = indexMap_[nhrStepInfo.toRank];
     159            0 :     const std::vector<u32> &sendSliceIdxList = nhrStepInfo.txSliceIdxs;
     160            0 :     srcMem_.token = token_[myRankIdx_];
     161            0 :     dstMem_.token = token_[toRankIdx];
     162            0 :     CcuTransport *sendTransport = transports[toRankIdx];
     163            0 :     CcuTransport *recvTransport = transports[fromRankIdx];
     164              : 
     165            0 :     uint16_t selfSignalId = rankId_ / RANK_NUM_PER_CKE;
     166            0 :     uint16_t selfBit      = 1 << (rankId_ % RANK_NUM_PER_CKE);
     167            0 :     uint16_t sendSignalId = nhrStepInfo.toRank / RANK_NUM_PER_CKE;
     168            0 :     uint16_t sendBit      = 1 << (nhrStepInfo.toRank % RANK_NUM_PER_CKE);
     169            0 :     if (nhrStepInfo.step != 0) {
     170              :         // 通知fromRank,可以写入
     171            0 :         RemotePost(*recvTransport, selfSignalId + signalNum_ * CKE_IDX_3, selfBit, true);
     172              : 
     173              :         // 等待toRank通知其可以写入
     174            0 :         RemoteWait(*sendTransport, sendSignalId + signalNum_ * CKE_IDX_3, sendBit);
     175              :     }
     176              : 
     177            0 :     for (u32 i = 0; i < sendSliceIdxList.size(); i++) {
     178            0 :         sendSliceIdx = sendSliceIdxList[i];
     179            0 :         if (i != 0) {
     180            0 :             if (i % RANK_NUM_PER_CKE == 0) {
     181            0 :                 LocalWait(localSignal_, (1 << RANK_NUM_PER_CKE) - 1);
     182              :             }
     183              :         }
     184            0 :         if (nhrStepInfo.step == 0) {
     185              :             // 只有第0步的源数据从input中取
     186            0 :             HCCL_INFO("[CcuContextAllReduceNHR1D] nhrStepInfo 0.");
     187            0 :             srcMem_.addr = input_;
     188            0 :             srcMem_.addr += sliceOffset_[sendSliceIdx];
     189              :         } else {
     190            0 :             srcMem_.addr = output_[myRankIdx_];
     191            0 :             srcMem_.addr += sliceOffset_[sendSliceIdx];
     192              :         }
     193            0 :         dstMem_.addr = output_[toRankIdx];
     194            0 :         dstMem_.addr += sliceOffset_[sendSliceIdx];
     195            0 :         DoWriteReduceSlice(nhrStepInfo.toRank, srcMem_, dstMem_, sendSliceIdx, i % RANK_NUM_PER_CKE);
     196              :     }
     197            0 :     LocalWait(localSignal_, (1 << (sendSliceIdxList.size() % RANK_NUM_PER_CKE)) - 1);
     198              : 
     199              :     // 通知toRank数据写入完毕
     200            0 :     RemotePost(*sendTransport, selfSignalId + signalNum_ * CKE_IDX_4, selfBit, true);
     201              :     // 等待fromRank通知数据写入完毕
     202            0 :     uint16_t recvBit      = 1 << (nhrStepInfo.fromRank % RANK_NUM_PER_CKE);
     203            0 :     uint16_t recvSignalId = nhrStepInfo.fromRank / RANK_NUM_PER_CKE;
     204            0 :     RemoteWait(*recvTransport, recvSignalId + signalNum_ * CKE_IDX_4, recvBit);
     205            0 :     HCCL_DEBUG("[DoReduceScatterNHRSingleStep] rank %u step %u, toRank=%u, fromRank=%u, nSlice=%lu",
     206              :                 rankId_, nhrStepInfo.step, nhrStepInfo.toRank, nhrStepInfo.fromRank, sendSliceIdxList.size());
     207            0 : }
     208              : 
     209            0 : void CcuContextAllReduceNHR1D::DoWriteReduceSlice(const u32 &toRank, CcuRep::Memory &src, CcuRep::Memory &dst, 
     210              :                                                   const u32 &sendSliceIdx, u32 signalIndex)
     211              : {
     212              :     bool          islastSlice;
     213              :     // 添加 die1 偏移
     214            0 :     if (axisId_ == 1) {
     215            0 :         dst.addr += die0Size_;
     216            0 :         src.addr += die0Size_;
     217              :     }
     218            0 :     CcuTransport *sendTransport = transports[indexMap_[toRank]];
     219            0 :     islastSlice = (sendSliceIdx + 1 == dimSize_);
     220              :     
     221              :     // allreduce切片的最后一块slice,大小可能不一致
     222            0 :     const CcuRep::Variable &sliceSize = axisId_ == 0? (islastSlice? die0LastSliceSize_ : die0SliceSize_)
     223              :                                                     : (islastSlice? die1LastSliceSize_ : die1SliceSize_);
     224            0 :     CCU_IF(sliceSize != 0)
     225              :     {
     226            0 :         WriteReduce(*sendTransport, dst, src, sliceSize, dataType_, reduceOp_, localSignal_, 1 << signalIndex);
     227            0 :     }
     228            0 :     CCU_IF(sliceSize == 0)
     229              :     {
     230            0 :         LocalPost(localSignal_, 1 << signalIndex);
     231            0 :     }
     232            0 : }
     233              : 
     234            0 : void CcuContextAllReduceNHR1D::DoAllGatherNHR()
     235              : {
     236            0 :     const uint32_t NHR_NUM = 2;
     237            0 :     for (u64 i = stepInfoVector_.size() / NHR_NUM; i < stepInfoVector_.size(); i++) {
     238            0 :         const NHRStepInfo &nhrStepInfo = stepInfoVector_[i];
     239            0 :         DoAllGatherNHRSingleStep(nhrStepInfo);
     240              :     }
     241            0 : }
     242              : 
     243            0 : void CcuContextAllReduceNHR1D::DoAllGatherNHRSingleStep(const NHRStepInfo &nhrStepInfo)
     244              : {
     245            0 :     u32  sendSliceIdx = 0;
     246            0 :     u32& toRankIdx = indexMap_[nhrStepInfo.toRank];
     247            0 :     u32& fromRankIdx = indexMap_[nhrStepInfo.fromRank];
     248            0 :     CcuTransport           *sendTransport = transports[toRankIdx];
     249            0 :     CcuTransport           *recvTransport = transports[fromRankIdx];
     250            0 :     const std::vector<u32> &sendSliceIdxList  = nhrStepInfo.txSliceIdxs;
     251            0 :     srcMem_.token                         = token_[myRankIdx_];
     252            0 :     dstMem_.token                         = token_[toRankIdx];
     253              :     
     254            0 :     uint16_t selfSignalId = rankId_ / RANK_NUM_PER_CKE;
     255            0 :     uint16_t selfBit      = 1 << (rankId_ % RANK_NUM_PER_CKE);
     256              : 
     257            0 :     for (u32 i = 0; i < sendSliceIdxList.size(); i++) {
     258            0 :         sendSliceIdx = sendSliceIdxList[i];
     259              : 
     260            0 :         if (i != 0) {
     261            0 :             if (i % RANK_NUM_PER_CKE == 0) {
     262            0 :                 LocalWait(localSignal_, (1 << RANK_NUM_PER_CKE) - 1);
     263              :             }
     264              :         }
     265              : 
     266            0 :         srcMem_.addr = output_[myRankIdx_];
     267            0 :         dstMem_.addr = output_[toRankIdx];
     268            0 :         dstMem_.addr += sliceOffset_[sendSliceIdx];
     269            0 :         srcMem_.addr += sliceOffset_[sendSliceIdx];
     270            0 :         DoSendRecvSlice(nhrStepInfo.toRank, srcMem_, dstMem_, sendSliceIdx, i % RANK_NUM_PER_CKE);
     271              :     }
     272            0 :     LocalWait(localSignal_, (1 << (sendSliceIdxList.size() % RANK_NUM_PER_CKE)) - 1);
     273              : 
     274            0 :     if (nhrStepInfo.step + 1 != stepInfoVector_.size()) {   // 最后一步不需要同步
     275              :         // 通知toRank,写入完毕
     276            0 :         RemotePost(*sendTransport, selfSignalId + signalNum_ * CKE_IDX_3, selfBit, true);
     277              :         // 等待fromRank通知写入完毕
     278            0 :         uint16_t recvBit      = 1 << (nhrStepInfo.fromRank % RANK_NUM_PER_CKE);
     279            0 :         uint16_t recvSignalId = nhrStepInfo.fromRank / RANK_NUM_PER_CKE;
     280            0 :         RemoteWait(*recvTransport, recvSignalId + signalNum_ * CKE_IDX_3, recvBit);
     281              :     }
     282              : 
     283            0 :     HCCL_DEBUG("[DoAllGatherNHRSingleStep] rank %u step %u, toRank=%u, fromRank=%u, nSlice=%lu",
     284              :                 rankId_, nhrStepInfo.step, nhrStepInfo.toRank, nhrStepInfo.fromRank, sendSliceIdxList.size());
     285            0 : }
     286              : 
     287            0 : void CcuContextAllReduceNHR1D::DoSendRecvSlice(const u32 &toRank, CcuRep::Memory &src, CcuRep::Memory &dst,
     288              :                                                const u32 &sendSliceIdx, u32 signalIndex)
     289              : {
     290              :     bool          islastSlice;
     291            0 :     CcuTransport *sendTransport = transports[indexMap_[toRank]];
     292            0 :     islastSlice = (sendSliceIdx + 1 == dimSize_);
     293              :     // 添加 die1 偏移
     294            0 :     if (axisId_ == 1) {
     295            0 :         dst.addr += die0Size_;
     296            0 :         src.addr += die0Size_;
     297              :     }
     298            0 :     const CcuRep::Variable &sliceSize = axisId_ == 0? (islastSlice? die0LastSliceSize_ : die0SliceSize_)
     299              :                                                     : (islastSlice? die1LastSliceSize_ : die1SliceSize_);
     300            0 :     CCU_IF(sliceSize != 0)
     301              :     {
     302            0 :         Write(*sendTransport, dst, src, sliceSize, localSignal_, 1 << signalIndex);
     303            0 :     }
     304            0 :     CCU_IF(sliceSize == 0)
     305              :     {
     306            0 :         LocalPost(localSignal_, 1 << signalIndex);
     307            0 :     }
     308            0 : }
     309              : 
     310            0 : void CcuContextAllReduceNHR1D::LocalCopySlices()
     311              : {
     312            0 :     u32              nonTxSliceIdx    = 0;
     313            0 :     CcuRep::Variable tmpSliceOffset   = CreateVariable();
     314            0 :     tmpSliceOffset                    = 0;
     315              : 
     316            0 :     for (u64 i = 0; i < dimSize_; i++) {
     317            0 :         sliceOffset_.push_back(CreateVariable());
     318            0 :         sliceOffset_[i] = tmpSliceOffset;
     319            0 :         tmpSliceOffset += axisId_ == 0? die0SliceSize_: die1SliceSize_;
     320              :     }
     321              :     
     322              :     // 当input == output时,不需要拷贝
     323            0 :     CCU_IF(isInputOutputEqual_ == 0)
     324              :     {
     325              :         // 将step0中不需要写的slice,拷贝到本rank的output中
     326            0 :         const NHRStepInfo &nhrStepInfo = stepInfoVector_[0];
     327            0 :         const std::vector<u32> &nonTxSliceIdxList = GetNonTxSliceIdxs(nhrStepInfo.txSliceIdxs);
     328            0 :         for (u32 i = 0; i < nonTxSliceIdxList.size(); i++) {
     329            0 :             nonTxSliceIdx = nonTxSliceIdxList[i];
     330              : 
     331            0 :             if (i != 0) {
     332            0 :                 if (i % RANK_NUM_PER_CKE == 0) {
     333            0 :                     LocalWait(localSignal_, (1 << RANK_NUM_PER_CKE) - 1);
     334              :                 }
     335              :             }
     336              : 
     337            0 :             srcMem_.addr  = input_;
     338            0 :             dstMem_.addr  = output_[myRankIdx_];
     339            0 :             srcMem_.addr += sliceOffset_[nonTxSliceIdx];
     340            0 :             dstMem_.addr += sliceOffset_[nonTxSliceIdx];
     341            0 :             srcMem_.token = token_[myRankIdx_];
     342            0 :             dstMem_.token = token_[myRankIdx_];
     343            0 :             DoLocalCopySlice(srcMem_, dstMem_, nonTxSliceIdx, i);
     344              :         }
     345            0 :         LocalWait(localSignal_, (1 << (nonTxSliceIdxList.size() % RANK_NUM_PER_CKE)) - 1);
     346            0 :     } 
     347            0 : }
     348              : 
     349            0 : std::vector<u32> CcuContextAllReduceNHR1D::GetNonTxSliceIdxs(const std::vector<u32> &txSliceIdxs) const
     350              : {
     351            0 :     std::vector<bool> isTx(dimSize_, false);
     352            0 :     for (u32 idx : txSliceIdxs) {
     353            0 :         if (idx < dimSize_) {
     354            0 :             isTx[idx] = true;
     355              :         }
     356              :     }
     357              : 
     358            0 :     std::vector<u32> nonTxSliceIdxs;
     359            0 :     for (u32 idx = 0; idx < dimSize_; ++idx) {
     360            0 :         if (!isTx[idx]) {
     361            0 :             nonTxSliceIdxs.push_back(idx);
     362              :         }
     363              :     }
     364              : 
     365            0 :     return nonTxSliceIdxs;
     366            0 : }
     367              : 
     368            0 : void CcuContextAllReduceNHR1D::DoLocalCopySlice(CcuRep::Memory &src, CcuRep::Memory &dst,
     369              :                                                 const u32 &copySliceIdx, u32 signalIndex)
     370              : {
     371              :     bool islastSlice;
     372              :     // 添加 die1 偏移
     373            0 :     if (axisId_ == 1) {
     374            0 :         src.addr += die0Size_;
     375            0 :         dst.addr += die0Size_;
     376              :     }
     377              : 
     378            0 :     islastSlice = (copySliceIdx + 1 == dimSize_);
     379            0 :     const CcuRep::Variable &sliceSize = axisId_ == 0? (islastSlice? die0LastSliceSize_ : die0SliceSize_)
     380              :                                                     : (islastSlice? die1LastSliceSize_ : die1SliceSize_);
     381            0 :     CCU_IF(sliceSize == 0)
     382              :     {
     383            0 :         LocalPost(localSignal_, 1 << signalIndex);
     384            0 :     }
     385              : 
     386            0 :     CCU_IF(sliceSize != 0)
     387              :     {
     388            0 :         LocalCopy(dst, src, sliceSize, localSignal_, 1 << signalIndex);
     389            0 :     }
     390            0 : }
     391              : 
     392            0 : void CcuContextAllReduceNHR1D::Algorithm()
     393              : {
     394            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] AllReduceNHR1D run");
     395              : 
     396            0 :     InitResources();
     397            0 :     LoadArgs();
     398            0 :     LocalCopySlices();
     399            0 :     PreSync();
     400            0 :     DoReduceScatterNHR();
     401            0 :     DoAllGatherNHR();
     402            0 :     PostSync();
     403              : 
     404            0 :     HCCL_DEBUG("[CcuContextAllReduceNHR1D] AllReduceNHR1D end");
     405            0 :     return;
     406              : }
     407              : 
     408            0 : std::vector<uint64_t> CcuContextAllReduceNHR1D::GeneArgs(const CcuTaskArg &arg)
     409              : {
     410            0 :     const CcuTaskArgAllReduceNHR1D *taskArg = dynamic_cast<const CcuTaskArgAllReduceNHR1D *>(&arg);
     411            0 :     if (taskArg == nullptr) {
     412            0 :         THROW<NullPtrException>(StringFormat("CcuContextAllReduceNHR1D::taskArg ptr is null"));
     413              :     }
     414              :     // input&output&buffer地址
     415            0 :     uint64_t inputAddr          = taskArg->inputAddr_;
     416            0 :     uint64_t outputAddr         = taskArg->outputAddr_;
     417            0 :     uint64_t token              = taskArg->token_;
     418            0 :     uint64_t isInputOutputEqual = taskArg->isInputOutputEqual_;
     419            0 :     uint64_t die0Size           = taskArg->die0Size_;
     420            0 :     uint64_t die1Size           = taskArg->die1Size_;
     421            0 :     uint64_t die0SliceSize      = taskArg->die0SliceSize_;
     422            0 :     uint64_t die1SliceSize      = taskArg->die1SliceSize_;
     423            0 :     uint64_t die0LastSliceSize  = taskArg->die0LastSliceSize_;
     424            0 :     uint64_t die1LastSliceSize  = taskArg->die1LastSliceSize_;
     425              : 
     426            0 :     HCCL_INFO("[CcuContextAllReduceNHR1D] TaskArgs: inputAddr[%llu], outputAddr[%llu], "
     427              :               "die0Size[%llu], die1Size[%llu], die0SliceSize[%llu], die1SliceSize[%llu],"
     428              :               "die0LastSliceSize[%llu], die1LastSliceSize[%llu]",
     429              :               inputAddr, outputAddr, die0Size, die1Size, die0SliceSize, die1SliceSize,
     430              :               die0LastSliceSize, die1LastSliceSize);
     431              : 
     432              :     return {inputAddr,          outputAddr,         token,
     433              :             isInputOutputEqual, die0Size,           die1Size,
     434              :             die0SliceSize,      die1SliceSize,      die0LastSliceSize,
     435            0 :             die1LastSliceSize};
     436              : }
     437              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1