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

Generated by: LCOV version 2.0-1