LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/alg_template/temp_all_reduce - all_reduce_local_reduce.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 20.3 % 251 51
Test Date: 2026-08-18 17:47:01 Functions: 35.7 % 14 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 <cmath>
      12              : #include "alg_template_register.h"
      13              : #include "all_reduce_local_reduce.h"
      14              : 
      15              : namespace hccl {
      16            2 : AllReduceLocalReduce::AllReduceLocalReduce(const HcclDispatcher dispatcher) : AlgTemplateBase(dispatcher) {}
      17              : 
      18            4 : AllReduceLocalReduce::~AllReduceLocalReduce() {}
      19              : 
      20            2 : HcclResult AllReduceLocalReduce::Prepare(
      21              :     u64 reduceAttrBitMap, std::vector<Stream>& meshStreams, std::vector<std::shared_ptr<LocalNotify>>& meshSignal,
      22              :     std::vector<std::shared_ptr<LocalNotify>>& meshSignalAux, u32 interRank, u32 interRankSize, u32 userRank,
      23              :     HcomCollOpInfo* opInfo)
      24              : {
      25            2 :     reduceAttr_ = reduceAttrBitMap;
      26            2 :     localRank_ = interRank;
      27            2 :     localRankSize_ = interRankSize;
      28            2 :     userRank_ = userRank;
      29            2 :     meshStreams_ = meshStreams;
      30            2 :     meshSignal_ = &meshSignal;
      31            2 :     meshSignalAux_ = &meshSignalAux;
      32            2 :     opInfo_ = opInfo;
      33            2 :     return HCCL_SUCCESS;
      34              : }
      35            0 : HcclResult AllReduceLocalReduce::MainRecordSub()
      36              : {
      37            0 :     for (u32 signalIndex = 0; signalIndex < meshSignalAux_->size(); signalIndex++) {
      38            0 :         CHK_RET(LocalNotify::Post(stream_, dispatcher_, (*meshSignalAux_)[signalIndex], profilerInput_.stage));
      39              :     }
      40            0 :     return HCCL_SUCCESS;
      41              : }
      42              : 
      43            0 : HcclResult AllReduceLocalReduce::SubWaitMain()
      44              : {
      45            0 :     for (u32 streamIndex = 0; streamIndex < meshSignalAux_->size(); streamIndex++) {
      46            0 :         CHK_RET(LocalNotify::Wait(
      47              :             meshStreams_[streamIndex], dispatcher_, (*meshSignalAux_)[streamIndex], profilerInput_.stage));
      48              :     }
      49            0 :     return HCCL_SUCCESS;
      50              : }
      51              : 
      52            0 : HcclResult AllReduceLocalReduce::MainWaitSub()
      53              : {
      54            0 :     for (u32 signalIndex = 0; signalIndex < meshSignal_->size(); signalIndex++) {
      55            0 :         CHK_RET(LocalNotify::Wait(stream_, dispatcher_, (*meshSignal_)[signalIndex], profilerInput_.stage));
      56              :     }
      57            0 :     return HCCL_SUCCESS;
      58              : }
      59              : 
      60            0 : HcclResult AllReduceLocalReduce::SubRecordMain()
      61              : {
      62            0 :     for (u32 streamIndex = 0; streamIndex < meshSignal_->size(); streamIndex++) {
      63            0 :         CHK_RET(LocalNotify::Post(
      64              :             meshStreams_[streamIndex], dispatcher_, (*meshSignal_)[streamIndex], profilerInput_.stage));
      65              :     }
      66            0 :     return HCCL_SUCCESS;
      67              : }
      68              : 
      69              : // 将数据均分,最小单位是128
      70            1 : HcclResult AllReduceLocalReduce::PrepareSlice(
      71              :     u64 dataCount, u32 unitSize, u32 sliceNum, std::vector<Slice>& dataSlice, std::vector<Slice>& startSlice)
      72              : {
      73            1 :     Slice temp;
      74            1 :     Slice startTemp;
      75            1 :     u64 totalSize = dataCount * unitSize;
      76            1 :     dataSlice.clear();
      77            1 :     dataSlice.reserve(sliceNum);
      78            1 :     if (sliceNum == 0) {
      79            0 :         HCCL_ERROR("[Prepare][SliceData]data slice prepare, sliceNum is 0");
      80            0 :         return HCCL_E_PARA;
      81              :     }
      82            1 :     u64 sizePerSliceOri = (totalSize + sliceNum - 1) / sliceNum; /* 1是为了向上取整 */
      83            1 :     u64 sizeLimit = 0;
      84            1 :     if (outputMem_.ptr() == opInfo_->outputAddr) {
      85            1 :         sizeLimit = outputMem_.size();
      86              :     } else {
      87            0 :         sizeLimit = totalSize;
      88              :     }
      89              : 
      90            1 :     u64 sizePerSlice = RoundUpWithDivisor(sizePerSliceOri, HCCL_MIN_SLICE_ALIGN_910B); // 512B对齐
      91            1 :     if (sizePerSlice * (localRankSize_ - 1) > sizeLimit) {
      92            1 :         sizePerSlice = RoundUpWithDivisor(sizePerSliceOri, HCCL_MIN_SLICE_ALIGN_ONCHIP);
      93              :     }
      94            1 :     if (sizePerSlice * (localRankSize_ - 1) > sizeLimit) {
      95            1 :         sizePerSlice = RoundUpWithDivisor(sizePerSliceOri, unitSize);
      96              :     }
      97            1 :     u64 residueSize = totalSize;
      98            1 :     u32 i = 0;
      99            7 :     while (residueSize > 0) {
     100            6 :         u64 sliceSize = sizePerSlice < residueSize ? sizePerSlice : residueSize;
     101            6 :         temp.size = sliceSize;
     102            6 :         temp.offset = totalSize - residueSize;
     103            6 :         i++;
     104            6 :         if (sliceSize <= 0) {
     105            0 :             HCCL_ERROR("[Prepare][SliceData]data_slices_prepare sliceSize[%llu]", sliceSize);
     106            0 :             return HCCL_E_PARA;
     107              :         }
     108            6 :         residueSize -= sliceSize;
     109            6 :         dataSlice.push_back(temp);
     110            6 :         if (i != sliceNum) {
     111            6 :             startTemp.size = sizePerSlice;
     112            6 :             startTemp.offset = 0;
     113            6 :             startSlice.push_back(startTemp);
     114              :         } else {
     115            0 :             startTemp.size = sizePerSlice;
     116            0 :             startTemp.offset = sizePerSlice;
     117            0 :             startSlice.push_back(startTemp);
     118              :         }
     119              :     }
     120            3 :     while (i < sliceNum) {
     121            2 :         temp.size = 0;
     122            2 :         temp.offset = totalSize;
     123            2 :         i++;
     124            2 :         dataSlice.push_back(temp);
     125            2 :         startTemp.size = 0;
     126            2 :         startTemp.offset = 0;
     127            2 :         startSlice.push_back(startTemp);
     128              :     }
     129            1 :     return HCCL_SUCCESS;
     130              : }
     131              : 
     132            0 : HcclResult AllReduceLocalReduce::PrepareAllreduceSliceData()
     133              : {
     134            0 :     return PrepareSlice(count_, DataUnitSize(dataType_), localRankSize_, slices_, startOffset);
     135              : }
     136              : 
     137              : // ringallreduce算法的函数入口
     138            0 : HcclResult AllReduceLocalReduce::RunAsync(const u32 rank, const u32 rankSize, const std::vector<LINK>& links)
     139              : {
     140            0 :     HcclResult ret = HCCL_SUCCESS;
     141            0 :     CHK_SMART_PTR_NULL(dispatcher_);
     142            0 :     CHK_PTR_NULL(stream_.ptr());
     143            0 :     HCCL_INFO(
     144              :         "AllReduceLocalReduce run: rank[%u] ranksize[%u] inputMem[%p] outputMem[%p] count[%llu]", rank, rankSize,
     145              :         inputMem_.ptr(), outputMem_.ptr(), count_);
     146              : 
     147            0 :     if (links.size() < rankSize) {
     148            0 :         HCCL_ERROR(
     149              :             "[AllReduceLocalReduce][RunAsync]rank[%u] linksize[%llu] is less than rankSize[%u]", rank, links.size(),
     150              :             rankSize);
     151            0 :         return HCCL_E_INTERNAL;
     152              :     }
     153              : 
     154              :     // 如果ranksize为1, inline reduce和普通跨片reduce操作一致,从input->output
     155            0 :     if (rankSize == 1) {
     156            0 :         if (opInfo_->inputAddr != opInfo_->outputAddr) {
     157            0 :             DeviceMem userMemIn = DeviceMem::create(opInfo_->inputAddr, count_ * DataUnitSize(dataType_));
     158            0 :             DeviceMem userMemOut = DeviceMem::create(opInfo_->outputAddr, count_ * DataUnitSize(dataType_));
     159            0 :             ret = HcclD2DMemcpyAsync(dispatcher_, userMemOut, userMemIn, stream_);
     160            0 :             CHK_PRT_RET(
     161              :                 ret != HCCL_SUCCESS, HCCL_ERROR("[AllReduceLocalReuce][RunAsync]rank[%u] memcpy async failed", rank),
     162              :                 ret);
     163            0 :         }
     164            0 :         return ret;
     165              :     }
     166              : 
     167            0 :     ret = PrepareAllreduceSliceData();
     168            0 :     CHK_PRT_RET(
     169              :         ret != HCCL_SUCCESS,
     170              :         HCCL_ERROR("[AllReduceLocalReuce][RunAsync]rank[%u] count[%llu] failed in PrepareSliceData step", rank, count_),
     171              :         ret);
     172              : 
     173            0 :     ret = RunReduceScatter(rank, rankSize, links);
     174            0 :     CHK_PRT_RET(
     175              :         ret != HCCL_SUCCESS,
     176              :         HCCL_ERROR("[AllReduceLocalReuce][RunAsync]rank[%u] count[%llu] failed in reducescater step", rank, count_),
     177              :         ret);
     178              : 
     179            0 :     ret = RunAllGather(rank, rankSize, links);
     180            0 :     CHK_PRT_RET(
     181              :         ret != HCCL_SUCCESS,
     182              :         HCCL_ERROR("[AllReduceLocalReuce][RunAsync]rank[%u] count[%llu] failed in AllGather step", rank, count_), ret);
     183              : 
     184            0 :     HCCL_INFO("AllReduceLocalReduce finished: rank[%u] ranksize[%u]", rank, rankSize);
     185            0 :     return HCCL_SUCCESS;
     186              : }
     187              : 
     188            0 : HcclResult AllReduceLocalReduce::RunReduceScatter(u32 rank, u32 rankSize, const std::vector<LINK>& links)
     189              : {
     190            0 :     HCCL_INFO(
     191              :         "ReduceScatterMeshLocalReduce run: rank[%u] totalrank[%u] inputMem[%p] outputMem[%p] count[%llu]", rank,
     192              :         rankSize, inputMem_.ptr(), outputMem_.ptr(), count_);
     193              : 
     194              :     // 数据准备
     195            0 :     u32 unitSize = DataUnitSize(dataType_);
     196            0 :     DeviceMem userMemIn = DeviceMem::create(opInfo_->inputAddr, count_ * unitSize);
     197            0 :     DeviceMem commMemOut = DeviceMem::create(outputMem_.ptr(), outputMem_.size());
     198              : 
     199            0 :     DeviceMem src;
     200            0 :     DeviceMem dst;
     201              : 
     202            0 :     src = DeviceMem::create(static_cast<char*>(opInfo_->inputAddr) + slices_[rank].offset, slices_[rank].size);
     203            0 :     dst = commMemOut.range(slices_[rank].offset, slices_[rank].size);
     204            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dst, src, stream_));
     205              : 
     206            0 :     DeviceMem emptySrc = userMemIn.range(0, 0);
     207            0 :     DeviceMem emptyDst = commMemOut.range(0, 0);
     208              : 
     209            0 :     CHK_RET(MainRecordSub());
     210            0 :     CHK_RET(SubWaitMain());
     211              : 
     212            0 :     for (u32 round = 1; round < rankSize; round++) {
     213            0 :         u32 dstRank = (round + rank) % rankSize;
     214            0 :         Stream& subStream = (round == rankSize - 1) ? stream_ : meshStreams_[round - 1];
     215              : 
     216            0 :         CHK_RET(links[dstRank]->TxAck(subStream));
     217            0 :         CHK_RET(links[dstRank]->RxAck(subStream));
     218              :     }
     219            0 :     HCCL_DEBUG("[ReduceScatterMeshLocalReduce] D2DMemcpy start");
     220            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     221              : 
     222            0 :     CHK_RET(SubRecordMain());
     223            0 :     CHK_RET(MainWaitSub());
     224              : 
     225            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     226              : 
     227            0 :     CHK_RET(MainRecordSub());
     228            0 :     CHK_RET(SubWaitMain());
     229              : 
     230            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     231              : 
     232            0 :     for (u32 round = 1; round < rankSize; round++) {
     233            0 :         Stream& subStream = (round == rankSize - 1) ? stream_ : meshStreams_[round - 1];
     234            0 :         void* remMemPtr = nullptr;
     235            0 :         u32 dstRank = (rank + round) % rankSize;
     236            0 :         u32 dstSlice = (dstRank + round) % (rankSize - 1);
     237            0 :         if (dstRank == (rankSize - 1)) {
     238            0 :             dstSlice = (dstSlice + rankSize - 1 - 1) % (rankSize - 1);
     239              :         }
     240            0 :         if (round == (rankSize - 1)) {
     241            0 :             CHK_RET(links[dstRank]->GetRemoteMem(UserMemType::OUTPUT_MEM, &remMemPtr));
     242              : 
     243            0 :             dstSlice = (dstRank == (rankSize - 1)) ? (dstRank - 1) : dstRank;
     244            0 :             dst = DeviceMem::create(
     245            0 :                 static_cast<char*>(remMemPtr) + startOffset[dstRank].offset + dstSlice * startOffset[dstRank].size,
     246            0 :                 slices_[dstRank].size);
     247            0 :             src = userMemIn.range(slices_[dstRank].offset, slices_[dstRank].size);
     248              : 
     249            0 :             HCCL_INFO(
     250              :                 "AllReducelocalreduce reduce dst offset1 %llu offset2 %llu size %llu, rank %u, dstrank %u",
     251              :                 startOffset[dstRank].offset, dstSlice * startOffset[dstRank].size, slices_[dstRank].size, rank,
     252              :                 dstRank);
     253              : 
     254            0 :             HCCL_INFO(
     255              :                 "AllReducelocalreduce reduce src offset %llu size %llu, rank %u, dstrank %u", slices_[dstRank].offset,
     256              :                 slices_[dstRank].size, rank, dstRank);
     257              : 
     258            0 :             CHK_RET(HcclReduceAsync(
     259              :                 dispatcher_, static_cast<void*>(src.ptr()), slices_[dstRank].size / unitSize, dataType_, reductionOp_,
     260              :                 subStream, static_cast<void*>(dst.ptr()), links[dstRank]->GetRemoteRank(),
     261              :                 links[dstRank]->GetLinkType(), INLINE_REDUCE_BIT));
     262              :         } else {
     263            0 :             CHK_RET(links[dstRank]->GetRemoteMem(UserMemType::OUTPUT_MEM, &remMemPtr));
     264              : 
     265            0 :             dst = DeviceMem::create(
     266            0 :                 static_cast<char*>(remMemPtr) + startOffset[dstRank].offset + dstSlice * startOffset[dstRank].size,
     267            0 :                 slices_[dstRank].size);
     268            0 :             src = userMemIn.range(slices_[dstRank].offset, slices_[dstRank].size);
     269              : 
     270            0 :             HCCL_INFO(
     271              :                 "AllReducelocalreduce memcpy dst offset1 %llu offset2 %llu size %llu, rank %u, dstrank %u",
     272              :                 startOffset[dstRank].offset, dstSlice * startOffset[dstRank].size, slices_[dstRank].size, rank,
     273              :                 dstRank);
     274              : 
     275            0 :             HCCL_INFO(
     276              :                 "AllReducelocalreduce memcpy src offset %llu size %llu, rank %u, dstrank %u", slices_[dstRank].offset,
     277              :                 slices_[dstRank].size, rank, dstRank);
     278              : 
     279            0 :             CHK_RET(HcclD2DMemcpyAsync(
     280              :                 dispatcher_, dst, src, subStream, links[dstRank]->GetRemoteRank(), links[dstRank]->GetLinkType()));
     281              :         }
     282              : 
     283            0 :         CHK_RET(links[dstRank]->TxDataSignal(subStream));
     284            0 :         CHK_RET(links[dstRank]->RxDataSignal(subStream));
     285              :     }
     286              : 
     287            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     288              : 
     289            0 :     CHK_RET(SubRecordMain());
     290            0 :     CHK_RET(MainWaitSub());
     291              : 
     292            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     293              : 
     294            0 :     HcclResult ret = HCCL_SUCCESS;
     295            0 :     ret = RunLocalReduce(rank, rankSize);
     296              : 
     297            0 :     CHK_PRT_RET(ret != HCCL_SUCCESS, HCCL_ERROR("[AllReduclocalReduce]rank[%u] ReduceScatter failed", rank), ret);
     298            0 :     return HCCL_SUCCESS;
     299            0 : }
     300              : 
     301            0 : HcclResult AllReduceLocalReduce::RunLocalReduce(u32 rank, u32 rankSize)
     302              : {
     303            0 :     DeviceMem commMemOut = DeviceMem::create(outputMem_.ptr(), outputMem_.size());
     304            0 :     u32 power = static_cast<u32>(log2(rankSize - 1));
     305            0 :     u32 rankPower = static_cast<u32>(pow(2, power));
     306            0 :     u32 unitSize = SIZE_TABLE[dataType_];
     307            0 :     u64 align = startOffset[rank].size;
     308            0 :     u64 totalSize = slices_[rank].size;
     309            0 :     DeviceMem src;
     310            0 :     DeviceMem dst;
     311            0 :     for (u32 i = 0u; i < rankSize - rankPower - 1; ++i) {
     312            0 :         u64 size = totalSize;
     313            0 :         if (rank < rankPower) {
     314            0 :             src = commMemOut.range(startOffset[rank].offset + (rankPower + i) * align, size);
     315            0 :             dst = commMemOut.range(startOffset[rank].offset + i * align, size);
     316            0 :             HCCL_INFO(
     317              :                 "[RunLocalReduce]LocalReduce rank[%u] src[%llu], dst[%llu] size[%llu]", rank,
     318              :                 startOffset[rank].offset + (rankPower + i) * align, startOffset[rank].offset + i * align, size);
     319              :         } else {
     320            0 :             dst = commMemOut.range(startOffset[rank].offset + (rankPower + i) * align, size);
     321            0 :             src = commMemOut.range(startOffset[rank].offset + i * align, size);
     322            0 :             HCCL_INFO(
     323              :                 "[RunLocalReduce]LocalReduce rank[%u] src[%llu], dst[%llu] size[%llu]", rank,
     324              :                 startOffset[rank].offset + i * align, startOffset[rank].offset + (rankPower + i) * align, size);
     325              :         }
     326            0 :         CHK_RET(HcclReduceAsync(
     327              :             dispatcher_, static_cast<void*>(src.ptr()), size / unitSize, dataType_, reductionOp_, stream_,
     328              :             static_cast<void*>(dst.ptr()), INVALID_VALUE_RANKID, LinkType::LINK_ONCHIP, INLINE_REDUCE_BIT));
     329              :     }
     330            0 :     u32 center = rank < rankPower ? rank : (rank - rankPower + 1);
     331            0 :     center = std::min(center, rankPower - 1);
     332            0 :     u64 offset = rank < rankPower ? 0 : ((rankSize - rankPower - 1) * align);
     333            0 :     offset += startOffset[rank].offset;
     334            0 :     for (u32 round = 0; round < power; round++) {
     335            0 :         u32 slices_num = static_cast<u32>(rankPower / pow(2, round + 1));
     336            0 :         u64 size = totalSize;
     337            0 :         if (center < slices_num) {
     338            0 :             for (auto i = 0u; i < slices_num; ++i) {
     339            0 :                 src = commMemOut.range(offset + (slices_num + i) * align, size);
     340            0 :                 dst = commMemOut.range(offset + i * align, size);
     341            0 :                 HCCL_INFO(
     342              :                     "[RunLocalReduce]LocalReduce rank[%u] src[%llu], dst[%llu] size[%llu]", rank,
     343              :                     offset + (slices_num + i) * align, offset + i * align, size);
     344            0 :                 CHK_RET(HcclReduceAsync(
     345              :                     dispatcher_, static_cast<void*>(src.ptr()), src.size() / unitSize, dataType_, reductionOp_, stream_,
     346              :                     static_cast<void*>(dst.ptr()), INVALID_VALUE_RANKID, LinkType::LINK_ONCHIP, INLINE_REDUCE_BIT));
     347              :             }
     348              :         } else {
     349            0 :             for (auto i = 0u; i < slices_num; ++i) {
     350            0 :                 dst = commMemOut.range(offset + (slices_num + i) * align, size);
     351            0 :                 src = commMemOut.range(offset + i * align, size);
     352            0 :                 HCCL_INFO(
     353              :                     "[RunLocalReduce]LocalReduce rank[%u] src[%llu], dst[%llu] size[%llu]", rank, offset + i * align,
     354              :                     offset + (slices_num + i) * align, size);
     355            0 :                 CHK_RET(HcclReduceAsync(
     356              :                     dispatcher_, static_cast<void*>(src.ptr()), src.size() / unitSize, dataType_, reductionOp_, stream_,
     357              :                     static_cast<void*>(dst.ptr()), INVALID_VALUE_RANKID, LinkType::LINK_ONCHIP, INLINE_REDUCE_BIT));
     358              :             }
     359            0 :             offset = offset + slices_num * align;
     360            0 :             center -= slices_num;
     361              :         }
     362              :     }
     363            0 :     return HCCL_SUCCESS;
     364            0 : }
     365              : 
     366            0 : HcclResult AllReduceLocalReduce::RunAllGather(u32 rank, u32 rankSize, const std::vector<LINK>& links)
     367              : {
     368            0 :     HCCL_INFO(
     369              :         "AllGatherMesh run: rank[%u] totalrank[%u] inputMem[%p] outputMem[%p] count[%llu]", rank, rankSize,
     370              :         inputMem_.ptr(), outputMem_.ptr(), count_);
     371            0 :     u32 unitSize = DataUnitSize(dataType_);
     372            0 :     DeviceMem userMemOut = DeviceMem::create(opInfo_->outputAddr, count_ * unitSize);
     373            0 :     DeviceMem commMemOut = DeviceMem::create(outputMem_.ptr(), outputMem_.size());
     374              : 
     375            0 :     DeviceMem src;
     376            0 :     DeviceMem dst;
     377              : 
     378            0 :     DeviceMem emptySrc = commMemOut.range(0, 0);
     379            0 :     DeviceMem emptyDst = userMemOut.range(0, 0);
     380              : 
     381            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     382              : 
     383            0 :     CHK_RET(MainRecordSub());
     384            0 :     CHK_RET(SubWaitMain());
     385              : 
     386            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     387              : 
     388            0 :     for (u32 round = 1; round < rankSize; round++) {
     389            0 :         u32 dstRank = BackwardRank(rank, rankSize, round);
     390            0 :         Stream& subStream = (round == rankSize - 1) ? stream_ : meshStreams_[round - 1];
     391            0 :         CHK_RET(links[dstRank]->TxAck(subStream));
     392            0 :         CHK_RET(links[dstRank]->RxAck(subStream));
     393              :     }
     394              : 
     395            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     396              : 
     397            0 :     CHK_RET(SubRecordMain());
     398            0 :     CHK_RET(MainWaitSub());
     399              : 
     400            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     401              : 
     402            0 :     CHK_RET(MainRecordSub());
     403            0 :     CHK_RET(SubWaitMain());
     404              : 
     405            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     406              : 
     407            0 :     if (userMemOut.ptr() != commMemOut.ptr()) {
     408            0 :         src = commMemOut.range(slices_[rank].offset, slices_[rank].size);
     409            0 :         dst = userMemOut.range(slices_[rank].offset, slices_[rank].size);
     410            0 :         CHK_RET(HcclD2DMemcpyAsync(dispatcher_, dst, src, meshStreams_[meshStreams_.size() - 1]));
     411              :     }
     412              : 
     413            0 :     for (u32 round = 1; round < rankSize; round++) {
     414            0 :         u32 dstRank = BackwardRank(rank, rankSize, round);
     415            0 :         Stream& subStream = (round == rankSize - 1) ? stream_ : meshStreams_[round - 1];
     416            0 :         void* remMemPtr = nullptr;
     417            0 :         CHK_RET(links[dstRank]->GetRemoteMem(UserMemType::OUTPUT_MEM, &remMemPtr));
     418              : 
     419            0 :         src = DeviceMem::create(static_cast<char*>(remMemPtr) + dstRank * slices_[0].size, slices_[dstRank].size);
     420            0 :         dst = userMemOut.range(slices_[dstRank].offset, slices_[dstRank].size);
     421              : 
     422            0 :         CHK_RET(HcclD2DMemcpyAsync(
     423              :             dispatcher_, dst, src, subStream, links[dstRank]->GetRemoteRank(), links[dstRank]->GetLinkType()));
     424            0 :         CHK_RET(links[dstRank]->TxDataSignal(subStream));
     425            0 :         CHK_RET(links[dstRank]->RxDataSignal(subStream));
     426              :     }
     427              : 
     428            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     429              : 
     430            0 :     CHK_RET(SubRecordMain());
     431            0 :     CHK_RET(MainWaitSub());
     432              : 
     433            0 :     CHK_RET(HcclD2DMemcpyAsync(dispatcher_, emptyDst, emptySrc, stream_));
     434              : 
     435            0 :     HCCL_INFO("AllGatherMesh finished: rank[%u]", rank);
     436            0 :     return HCCL_SUCCESS;
     437            0 : }
     438              : REGISTER_TEMPLATE(TemplateType::TEMPLATE_ALL_REDUCE_LOCAL_REDUCE, AllReduceLocalReduce);
     439              : } // namespace hccl
        

Generated by: LCOV version 2.0-1