LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_ccu_context/reduce - ccu_context_reduce_mesh1d_two_shot_mem2mem.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 273 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 13 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_reduce_mesh1d_two_shot_mem2mem.h"
      12              : #include "ccu_instruction_reduce_mesh1d_two_shot_mem2mem.h"
      13              : #include "ccu_assist.h"
      14              : namespace Hccl {
      15              : constexpr int INPUT_XN_ID   = 0;
      16              : constexpr int OUTPUT_XN_ID  = 1;
      17              : constexpr int SCRATCH_XN_ID = 2;
      18              : constexpr int TOKEN_XN_ID   = 3;
      19              : constexpr int CKE_IDX_0     = 0;
      20              : constexpr int CKE_IDX_1     = 1;
      21              : constexpr int CKE_IDX_2     = 2;
      22              : constexpr int CKE_IDX_3     = 3;
      23              : 
      24              : using CurrentCtxArg  = CcuCtxArgReduceMeshTwoShotMem2Mem1D;
      25              : using CurrentTaskArg = CcuTaskArgReduceMeshTwoShotMem2Mem1D;
      26              : 
      27            0 : CcuContextReduceMeshTwoShotMem2Mem1D::CcuContextReduceMeshTwoShotMem2Mem1D(
      28            0 :     const CcuCtxArg &arg, const std::vector<CcuTransport *> &transports, const CcuTransportGroup &group)
      29            0 :     : CcuContext(arg, transports, group)
      30              : {
      31            0 :     HCCL_DEBUG("[CcuContextReduceMeshTwoShotMem2Mem1D] Enter Constructor.");
      32            0 :     const CurrentCtxArg *ctxArg = dynamic_cast<const CurrentCtxArg *>(&arg);
      33            0 :     if (ctxArg == nullptr) {
      34            0 :         THROW<NullPtrException>(StringFormat("CcuContextReduceMeshTwoShotMem2Mem1D::ctxArg ptr is null"));
      35              :     }
      36            0 :     rankId_         = ctxArg->rankId_;
      37            0 :     rootId_         = ctxArg->rootId_;
      38            0 :     rankSize_       = ctxArg->dimSize_[0];
      39            0 :     dataType_       = ctxArg->op_.dataType;
      40            0 :     outputDataType_ = ctxArg->op_.outputDataType;
      41            0 :     if (outputDataType_ == DataType::INVALID) {
      42            0 :         outputDataType_ = dataType_;
      43            0 :         HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] outputDataType is [INVALID], set outputDataType to[%s]",
      44              :                   outputDataType_.Describe().c_str());
      45              :     }
      46            0 :     CHK_PRT_THROW(
      47              :         ctxArg->dimSize_[0] == 0,
      48              :         HCCL_ERROR("[CcuContextReduceMeshTwoShotMem2Mem1D] ctxArg->dimSize_[0] is zero"),
      49              :         InvalidParamsException, "ctxArg->dimSize_[0] is invalid");
      50            0 :     if (ctxArg->dimSize_.size() > 0) {
      51            0 :         rankSize_ = ctxArg->dimSize_[0];
      52              :     }
      53            0 :     reduceOp_ = ctxArg->op_.reduceOp;
      54            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] Init, CtxArgs are rankId[%u], rankSize_[%llu], dataType[%s], "
      55              :               "outputDataType[%s], reduceOp[%s]",
      56              :               rankId_, rankSize_, dataType_.Describe().c_str(), outputDataType_.Describe().c_str(),
      57              :               reduceOp_.Describe().c_str());
      58            0 : }
      59              : 
      60            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::InitResource()
      61              : {
      62            0 :     if (transports.size() == 0) {
      63            0 :         THROW<NullPtrException>(StringFormat("CcuContextReduceMeshTwoShotMem2Mem1D transports is empty"));
      64              :     }
      65            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D]transports.size: [%zu]", transports.size());
      66            0 :     uint16_t transportIdx = 0;
      67              :     // 按照rank号从小到大遍历transports,遇到本rank就填充本地资源,否则依次取远端资源,要求给框架返回的Link同样是按顺序排列的
      68            0 :     for (uint64_t peerId = 0; peerId < rankSize_; peerId++) {
      69            0 :         if (peerId == rankId_) {
      70            0 :             input_.push_back(CreateVariable());
      71            0 :             output_.push_back(CreateVariable());
      72            0 :             scratch_.push_back(CreateVariable());
      73            0 :             token_.push_back(CreateVariable());
      74              :         } else {
      75            0 :             HCCL_DEBUG("[CcuContextReduceMeshTwoShotMem2Mem1D] MyRank[%u], PeerId[%llu], TransportId[%u]",
      76              :                        rankId_, peerId, transportIdx);
      77            0 :             CHK_PRT_THROW(
      78              :                 transports[transportIdx] == nullptr,
      79              :                 HCCL_ERROR("[CcuContextReduceMeshTwoShotMem2Mem1D] [InitResource] transports[%u] is nullptr",
      80              :                            transportIdx),
      81              :                 NullPtrException, "transport is null");
      82            0 :             input_.push_back(CreateVariable((*transports[transportIdx]), INPUT_XN_ID));
      83            0 :             output_.push_back(CreateVariable((*transports[transportIdx]), OUTPUT_XN_ID));
      84            0 :             scratch_.push_back(CreateVariable((*transports[transportIdx]), SCRATCH_XN_ID));
      85            0 :             token_.push_back(CreateVariable((*transports[transportIdx]), TOKEN_XN_ID));
      86            0 :             transportIdx++;
      87              :         }
      88              :     }
      89            0 :     normalSliceSize_              = CreateVariable();
      90            0 :     lastSliceSize_                = CreateVariable();
      91            0 :     mySliceSize_                  = CreateVariable();
      92              :     
      93            0 :     isInputOutputEqual_           = CreateVariable();
      94            0 :     locMask_                      = CreateMaskSignal();
      95            0 :     srcMem_                       = CreateMemory();
      96            0 :     dstMem_                       = CreateMemory();
      97              : 
      98            0 :     reduceScatterSrc_.reserve(rankSize_);
      99            0 :     reduceScatterDst_.reserve(rankSize_);
     100            0 :     gatherSrc_.reserve(rankSize_);
     101            0 :     gatherDst_.reserve(rankSize_);
     102              : 
     103            0 :     sliceOffset_.reserve(rankSize_);
     104            0 :     len_.reserve(rankSize_);
     105            0 :     for (uint32_t rankIdx = 0; rankIdx < rankSize_; rankIdx++) {
     106            0 :         reduceScatterSrc_.push_back(CreateMemory());
     107            0 :         reduceScatterDst_.push_back(CreateMemory());
     108            0 :         gatherSrc_.push_back(CreateMemory());
     109            0 :         gatherDst_.push_back(CreateMemory());
     110              : 
     111            0 :         sliceOffset_.push_back(CreateVariable());
     112            0 :         len_.push_back(CreateVariable());
     113              :     }
     114              : 
     115            0 :     sliceSize_ = CreateVariable();
     116            0 :     selfBit_   = 1 << rankId_;
     117            0 :     allBit_    = ((1 << rankSize_) - 1) & (~(1 << rankId_)); // rankId_位为0,其他位都为1
     118            0 :     localGoSize_ = CreateGroupOpSize();
     119            0 :     return;
     120              : }
     121              : 
     122            0 : std::string CcuContextReduceMeshTwoShotMem2Mem1D::GetLoopBlockTag(std::string loopType, int32_t index)
     123              : {
     124            0 :     return loopType + LOOP_BLOCK_TAG + std::to_string(index);
     125              : }
     126              :  
     127            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::CreateReduceLoop(uint32_t size, DataType dataType, DataType outputDataType,
     128              :     ReduceOp opType)
     129              : {
     130            0 :     constexpr uint32_t LOOP_NUM = 16;
     131            0 :     AllocGoResource(LOOP_NUM);
     132              : 
     133            0 :     std::string loopType = CcuRep::GetReduceTypeStr(dataType, opType);
     134            0 :     if (registeredLoop.find(loopType) != registeredLoop.end()) {
     135            0 :         return;
     136              :     }
     137              : 
     138            0 :     uint32_t expansionNum = CcuRep::GetReduceExpansionNum(opType, dataType, outputDataType);
     139            0 :     uint32_t usedBufNum   = size > expansionNum ? size : expansionNum;
     140              : 
     141            0 :     for (int32_t index = 0; index < 2; index++) { // 需要实例化2个Loop
     142            0 :         CcuRep::Memory dst = CreateMemory();
     143            0 :         CcuRep::Memory src = CreateMemory();
     144            0 :         std::vector<CcuRep::Memory> scratch;
     145            0 :         for (uint32_t i = 0; i < size; i++) {
     146            0 :             scratch.emplace_back(CreateMemory());
     147              :         }
     148            0 :         CcuRep::Variable            len = CreateVariable();
     149            0 :         CcuRep::Variable            lenForExpansion = CreateVariable();
     150            0 :         CcuRep::LoopBlock           lb(this, GetLoopBlockTag(loopType, index));
     151            0 :         lb(dst, src, scratch, len, lenForExpansion);
     152              : 
     153            0 :         std::vector<CcuRep::CcuBuffer> bufs = {moRes.ccuBuffer.begin() + index * moConfig.msInterleave,
     154            0 :                                                moRes.ccuBuffer.begin() + index * moConfig.msInterleave + usedBufNum};
     155            0 :         CcuRep::MaskSignal             sem  = moRes.maskSignal[index];
     156              : 
     157            0 :         for (uint32_t i = 0; i < size; i++) {
     158            0 :             if (i == rankId_) {
     159            0 :                 LocalCopy(bufs[i], src, len, sem, 1 << i);
     160              :             } else {
     161            0 :                 LocalCopy(bufs[i], scratch[i], len, sem, 1 << i);
     162              :             }
     163              :         }
     164            0 :         LocalWait(sem, (1 << size) - 1);
     165              : 
     166            0 :         if (size > 1) {
     167            0 :             LocalReduce(bufs, size, dataType, outputDataType, opType, sem, len);
     168            0 :             LocalWait(sem);
     169              :         }
     170              : 
     171            0 :         LocalCopy(dst, bufs[0], lenForExpansion, sem);
     172            0 :         LocalWait(sem);
     173            0 :     }
     174              : 
     175            0 :     registeredLoop.insert(loopType);
     176            0 : }
     177              : 
     178            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::ReduceLoopGroup(CcuRep::Memory outDstOrg, CcuRep::Memory srcOrg,
     179              :     std::vector<CcuRep::Memory> &scratchOrg, GroupOpSize goSize, DataType dataType, DataType outputDataType,
     180              :     ReduceOp opType)
     181              : {
     182            0 :     const uint32_t size = scratchOrg.size();
     183              : 
     184            0 :     CcuRep::Memory dst = CreateMemory();
     185            0 :     dst = outDstOrg;
     186              : 
     187            0 :     CcuRep::Memory src = CreateMemory();
     188            0 :     src = srcOrg;
     189              : 
     190            0 :     std::vector<CcuRep::Memory> scratch;
     191            0 :     for (uint32_t idx = 0; idx < size; idx++) {
     192            0 :         scratch.push_back(CreateMemory());
     193            0 :         scratch[idx] = scratchOrg[idx];
     194              :     }
     195              : 
     196            0 :     CreateReduceLoop(size, dataType, outputDataType, opType);
     197              : 
     198            0 :     std::string loopType = CcuRep::GetReduceTypeStr(dataType, opType);
     199            0 :     uint32_t         expansionNum = CcuRep::GetReduceExpansionNum(opType, dataType, outputDataType);
     200            0 :     CcuRep::Variable sliceSizeExpansion = CreateVariable();
     201              : 
     202            0 :     if (expansionNum != 1) {
     203            0 :         CcuRep::Variable tmp = CreateVariable();
     204            0 :         tmp = CcuRep::GetExpansionParam(expansionNum);
     205            0 :         dst.token += tmp;
     206            0 :     }
     207              : 
     208              :     // m部分
     209            0 :     CCU_IF(goSize.loopParam != 0)                   // goSize1
     210              :     {
     211            0 :         CcuRep::Variable loopParam = CreateVariable();
     212            0 :         loopParam = CcuRep::GetLoopParam(0, moConfig.memSlice * moConfig.loopCount, 0);
     213            0 :         loopParam += goSize.loopParam;
     214              : 
     215            0 :         CcuRep::Variable sliceSize = CreateVariable();
     216            0 :         sliceSize          = moConfig.memSlice;
     217            0 :         sliceSizeExpansion = moConfig.memSlice * expansionNum;
     218              : 
     219            0 :         auto lc = Loop(GetLoopBlockTag(loopType, 0))(dst, src, scratch, sliceSize, sliceSizeExpansion);
     220              : 
     221            0 :         CcuRep::Variable paraCfg = CreateVariable();
     222            0 :         paraCfg = CcuRep::GetParallelParam(moConfig.loopCount - 1, 0, 1);
     223            0 :         CcuRep::Variable offsetCfg = CreateVariable();
     224            0 :         offsetCfg = CcuRep::GetOffsetParam(moConfig.memSlice, moConfig.msInterleave, 1);
     225              : 
     226            0 :         LoopGroup({lc}, {loopParam}, paraCfg, offsetCfg);
     227            0 :     }
     228              : 
     229            0 :     CCU_IF(goSize.parallelParam != 0)               // goSize2
     230              :     {
     231              :         // p部分,加m的偏移
     232            0 :         for (uint32_t i = 0; i < size; i++) {
     233            0 :             scratch[i].addr += goSize.addrOffset;
     234              :         }
     235            0 :         src.addr += goSize.addrOffset;              // goSize0
     236            0 :         for (uint32_t i = 0; i < expansionNum; i++) {
     237            0 :             dst.addr += goSize.addrOffset;
     238              :         }
     239              : 
     240            0 :         sliceSizeExpansion = 0;
     241            0 :         for (uint32_t i = 0; i < expansionNum; i++) {
     242            0 :             sliceSizeExpansion += goSize.residual;  // goSize3
     243              :         }
     244              : 
     245            0 :         auto lc0 = Loop(GetLoopBlockTag(loopType, 0))(dst, src, scratch, goSize.residual, sliceSizeExpansion);
     246              : 
     247              :         // n部分,再加p的偏移
     248            0 :         for (uint32_t i = 0; i < size; i++) {
     249            0 :             scratch[i].addr += goSize.residual;
     250              :         }
     251            0 :         src.addr += goSize.residual;
     252            0 :         for (uint32_t i = 0; i < expansionNum; i++) {
     253            0 :             dst.addr += goSize.residual;
     254              :         }
     255              : 
     256            0 :         CcuRep::Variable sliceSize = CreateVariable();
     257            0 :         sliceSize          = moConfig.memSlice;
     258            0 :         sliceSizeExpansion = moConfig.memSlice * expansionNum;
     259              : 
     260            0 :         auto lc1 = Loop(GetLoopBlockTag(loopType, 1))(dst, src, scratch, sliceSize, sliceSizeExpansion);
     261              : 
     262            0 :         CcuRep::Variable loopCfg0 = CreateVariable();
     263            0 :         loopCfg0 = CcuRep::GetLoopParam(0, 0, 1);
     264            0 :         CcuRep::Variable loopCfg1 = CreateVariable();
     265            0 :         loopCfg1 = CcuRep::GetLoopParam(0, 0, 1);
     266            0 :         CcuRep::Variable offsetCfg = CreateVariable();
     267            0 :         offsetCfg = CcuRep::GetOffsetParam(moConfig.memSlice, moConfig.msInterleave, 1);
     268              : 
     269            0 :         LoopGroup({lc0, lc1}, {loopCfg0, loopCfg1}, goSize.parallelParam, offsetCfg);
     270            0 :     }
     271            0 : }
     272              : 
     273            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::LoadArgs()
     274              : {
     275            0 :     Load(input_[rankId_]);
     276            0 :     Load(output_[rankId_]);
     277            0 :     Load(token_[rankId_]);
     278            0 :     Load(scratch_[rankId_]);
     279            0 :     Load(normalSliceSize_);
     280            0 :     Load(lastSliceSize_);
     281            0 :     Load(mySliceSize_);
     282            0 :     Load(localGoSize_);
     283            0 :     return;
     284              : }
     285              : 
     286            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::PreSync()
     287              : {
     288              :     // 互换内存信息
     289            0 :     for (auto t : transports) {
     290            0 :         HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] ReduceMeshTwoShotMem2Mem1D LocalPost begin");
     291              :         // 交换起始地址
     292            0 :         WriteVariableWithSignal(*t, input_[rankId_], INPUT_XN_ID, CKE_IDX_1, selfBit_);
     293            0 :         WriteVariableWithSignal(*t, output_[rankId_], OUTPUT_XN_ID, CKE_IDX_2, selfBit_);
     294            0 :         WriteVariableWithSignal(*t, token_[rankId_], TOKEN_XN_ID, CKE_IDX_3, selfBit_);
     295              :     }
     296            0 :     GroupWait(*transportGroup, CKE_IDX_1, allBit_);
     297            0 :     GroupWait(*transportGroup, CKE_IDX_2, allBit_);
     298            0 :     GroupWait(*transportGroup, CKE_IDX_3, allBit_);
     299            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] ReduceMeshTwoShotMem2Mem1D wait all end");
     300            0 :     return;
     301              : }
     302              : 
     303            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::PostSync()
     304              : {
     305            0 :     for (auto &t : transports) {
     306            0 :         RemotePost(*t, CKE_IDX_0, selfBit_);
     307              :     }
     308            0 :     GroupWait(*transportGroup, CKE_IDX_0, allBit_);
     309            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] ReduceMeshTwoShotMem2Mem1D AllReduce groupwait end");
     310            0 : }
     311              : 
     312            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::ReduceRmtToLoc(const std::vector<CcuRep::Variable> &srcAddr,
     313              :                                                                 const CcuRep::Variable              &dstAddr)
     314              : {
     315            0 :     CHK_PRT_THROW(
     316              :         srcAddr.size() != transports.size() + 1,
     317              :         HCCL_ERROR("[ReduceRmtToLoc] srcAddr.size[%zu] != transports size[%zu] +1", srcAddr.size(), transports.size()),
     318              :         InvalidParamsException, "Invalid srcAddr size");
     319              : 
     320            0 :     dstMem_.addr = dstAddr;
     321            0 :     dstMem_.addr += sliceOffset_[rankId_];
     322            0 :     dstMem_.token = token_[rankId_];
     323              : 
     324            0 :     CcuRep::Variable scratchOffset = CreateVariable();
     325            0 :     scratchOffset                  = 0;
     326            0 :     for (uint32_t rankIdx = 0; rankIdx < rankSize_; rankIdx++) {
     327            0 :         reduceScatterSrc_[rankIdx].addr = srcAddr[rankIdx];
     328            0 :         reduceScatterSrc_[rankIdx].addr += sliceOffset_[rankId_];
     329            0 :         reduceScatterSrc_[rankIdx].token = token_[rankIdx];
     330              : 
     331            0 :         reduceScatterDst_[rankIdx].addr = scratch_[rankId_];
     332            0 :         reduceScatterDst_[rankIdx].addr += scratchOffset;
     333            0 :         scratchOffset += normalSliceSize_;
     334            0 :         reduceScatterDst_[rankIdx].token = token_[rankId_];
     335              :     }
     336              : 
     337            0 :     uint32_t transportId = 0;
     338            0 :     for (uint32_t rankIdx = 0; rankIdx < rankSize_; rankIdx++) {
     339            0 :         if (rankIdx == rankId_) {
     340            0 :             LocalPost(locMask_, 1 << rankIdx);
     341              :         } else {
     342            0 :             Read(*transports[transportId], reduceScatterDst_[rankIdx], reduceScatterSrc_[rankIdx], sliceSize_, locMask_,
     343            0 :                  1 << rankIdx);
     344            0 :             transportId++;
     345              :         }
     346              :     }
     347            0 :     LocalWait(locMask_, (1 << rankSize_) - 1);
     348            0 :     ReduceLoopGroup(dstMem_, reduceScatterSrc_[rankId_], reduceScatterDst_,  localGoSize_, dataType_, outputDataType_, reduceOp_);
     349            0 : }
     350              : 
     351            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::BcastLocToRmt(const CcuRep::Variable              &srcAddr,
     352              :                                                         const std::vector<CcuRep::Variable> &dstAddr)
     353              : {
     354            0 :     CHK_PRT_THROW(
     355              :         dstAddr.size() != transports.size() + 1,
     356              :         HCCL_ERROR("[ReduceRmtToLoc] srcAddr.size[%zu] != transports size[%zu] + 1", dstAddr.size(), transports.size()),
     357              :         InvalidParamsException, "Invalid srcAddr size");
     358            0 :     gatherSrc_[rankId_].addr = srcAddr;
     359            0 :     gatherSrc_[rankId_].addr += sliceOffset_[rankId_];
     360            0 :     gatherSrc_[rankId_].token = token_[rankId_];
     361            0 :     uint32_t transportIdx = 0;
     362            0 :     for (uint32_t rmtId = 0; rmtId < dstAddr.size(); rmtId++) {
     363            0 :         if (rmtId == rankId_) {
     364            0 :             continue;
     365              :         }
     366            0 :         gatherDst_[rankId_].addr = dstAddr[rmtId];
     367            0 :         gatherDst_[rankId_].addr += sliceOffset_[rankId_];
     368            0 :         gatherDst_[rankId_].token = token_[rmtId];
     369            0 :         Write(*transports[transportIdx], gatherDst_[rankId_], gatherSrc_[rankId_], len_[rankId_], locMask_, 1 << rmtId);
     370            0 :         transportIdx++;
     371              :     }
     372            0 :     LocalWait(locMask_, allBit_);
     373            0 : }
     374              : 
     375            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::DoRepeatReduceTwoShot()
     376              : {
     377            0 :     if (rankId_ != rankSize_ - 1) {
     378            0 :         sliceSize_ = normalSliceSize_;
     379              :     } else {
     380            0 :         sliceSize_ = lastSliceSize_;
     381              :     }
     382            0 :     sliceOffset_[0] = 0;
     383            0 :     for (uint32_t rankIdx = 1; rankIdx < rankSize_; rankIdx++) {
     384            0 :         sliceOffset_[rankIdx] = sliceOffset_[rankIdx-1] + normalSliceSize_;
     385              :     }
     386            0 :     for (uint32_t rankIdx = 0; rankIdx < rankSize_-1; rankIdx++) {
     387            0 :         len_[rankIdx] = normalSliceSize_;
     388              :     }
     389            0 :     len_[rankSize_-1] = lastSliceSize_;
     390            0 :     ReduceRmtToLoc(input_, output_[rankId_]);//从对端input搬到自己的scratch,做完规约后再放到自己的output
     391            0 :     BcastLocToRmt(output_[rankId_], output_);
     392            0 : }
     393              : 
     394            0 : void CcuContextReduceMeshTwoShotMem2Mem1D::Algorithm()
     395              : {
     396            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] ReduceMeshTwoShotMem2Mem1D run");
     397            0 :     InitResource();
     398            0 :     LoadArgs();
     399            0 :     PreSync();
     400              : 
     401            0 :     CCU_IF(mySliceSize_ != 0)
     402              :     {
     403            0 :         DoRepeatReduceTwoShot();
     404            0 :     }
     405            0 :     PostSync();
     406            0 :     HCCL_INFO("[CcuContextReduceMeshTwoShotMem2Mem1D] ReduceMeshTwoShotMem2Mem1D end");
     407            0 :     return;
     408              : }
     409              : 
     410            0 : std::vector<uint64_t> CcuContextReduceMeshTwoShotMem2Mem1D::GeneArgs(const CcuTaskArg &arg)
     411              : {
     412            0 :     const CurrentTaskArg *taskArg = dynamic_cast<const CurrentTaskArg *>(&arg);
     413              :     // 空指针校验
     414            0 :     if (taskArg == nullptr) {
     415            0 :         THROW<NullPtrException>(StringFormat("CcuContextReduceMeshTwoShotMem2Mem1D::taskArg ptr is null"));
     416              :     }
     417            0 :     uint64_t inputAddr                    = taskArg->inputAddr_;
     418            0 :     uint64_t outputAddr                   = taskArg->outputAddr_;
     419            0 :     uint64_t tokenInfo                    = taskArg->token_;
     420            0 :     uint64_t scratchAddr                  = taskArg->scratchAddr_;
     421            0 :     uint64_t normalSliceSize              = taskArg->normalSliceSize_;
     422            0 :     uint64_t lastSliceSize                = taskArg->lastSliceSize_;
     423            0 :     uint64_t mySliceSize                  = taskArg->mySliceSize_;
     424              : 
     425              :     std::vector<uint64_t> taskArgs = {
     426              :         inputAddr,
     427              :         outputAddr,
     428              :         tokenInfo,
     429              :         scratchAddr,
     430              :         normalSliceSize,
     431              :         lastSliceSize,
     432              :         mySliceSize,
     433            0 :     };
     434              : 
     435            0 :     auto normalGoSize = CalGoSize(normalSliceSize);
     436            0 :     auto lastGoSize = CalGoSize(lastSliceSize);
     437              : 
     438            0 :     if (rankId_ != rankSize_ - 1 ) {
     439            0 :         taskArgs.insert(taskArgs.end(), normalGoSize.begin(), normalGoSize.end());
     440              :     } else {
     441            0 :         taskArgs.insert(taskArgs.end(), lastGoSize.begin(), lastGoSize.end());
     442              :     }
     443              : 
     444            0 :     HCCL_INFO("[CcuContextAllReduce1DMesh] TaskArgs: inputAddr[%llu], outputAddr[%llu], scratchAddr[%llu], "
     445              :               " normalSliceSize[%llu], lastSliceSize[%llu], mySliceSize[%llu]",
     446              :               inputAddr, outputAddr, scratchAddr, normalSliceSize, lastSliceSize, mySliceSize);
     447            0 :     return taskArgs;
     448            0 : }
     449              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1