LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/ins_alg_template - ins_temp_broadcast_mesh_2D_two_shot.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 250 0
Test Date: 2026-08-18 17:47:01 Functions: 0.0 % 14 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 "log.h"
      12              : 
      13              : #include "alg_data_trans_wrapper.h"
      14              : #include "ins_alg_template/ins_temp_broadcast_mesh_2D_two_shot.h"
      15              : 
      16              : namespace Hccl {
      17              : 
      18            0 : InsTempBroadcastMesh2DTwoShot::InsTempBroadcastMesh2DTwoShot(
      19              :     const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
      20            0 :     const std::map<RankId, u32>& tempVirtRankMap)
      21              :     : InsAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap),
      22            0 :       sizeX_(static_cast<u32>(tempVTopo[0].size())),
      23            0 :       sizeY_(static_cast<u32>(tempVTopo[1].size()))
      24              : {
      25            0 :     std::tie(curX_, curY_) = GetRankPos(myRank_);
      26            0 : }
      27              : 
      28            0 : InsTempBroadcastMesh2DTwoShot::~InsTempBroadcastMesh2DTwoShot() {}
      29              : 
      30            0 : HcclResult InsTempBroadcastMesh2DTwoShot::CalcRes(AlgTempResReq& tempResReq)
      31              : {
      32            0 :     tempResReq.queNum = sizeX_ - 1 + sizeY_ - 1 > 0 ? sizeX_ - 1 + sizeY_ - 1 : 1;
      33            0 :     tempResReq.streamNum = tempResReq.queNum;
      34            0 :     tempResReq.queNotifys = CreateMasterSlaveQueNotifiesRequest(tempResReq.queNum);
      35            0 :     QId centerQ = 0;
      36            0 :     tempResReq.localWaitGroupCntNotify.emplace_back(centerQ, 0);
      37            0 :     tempResReq.localBcastPostCntNotify.emplace_back(centerQ, 0);
      38            0 :     CHK_RET(CalcResLinksMesh2D(myRank_, tempVTopo_, linkNumBtwPeers_, tempResReq));
      39            0 :     HCCL_INFO(
      40              :         "[InsTempBroadcastMesh2DTwoShot]CalcRes: queNum[%u], myRank[%d], tempRankSize[%u]", tempResReq.queNum, myRank_,
      41              :         tempRankSize_);
      42            0 :     return HcclResult::HCCL_SUCCESS;
      43              : }
      44            0 : u32 InsTempBroadcastMesh2DTwoShot::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
      45              : {
      46              :     (void)inBuffType;
      47              :     (void)outBuffType;
      48            0 :     if (op_.opMode == OpMode::OPBASE) {
      49            0 :         return 1;
      50              :     } else {
      51            0 :         return 0;
      52              :     }
      53              : }
      54              : 
      55            0 : HcclResult InsTempBroadcastMesh2DTwoShot::RunScatter(
      56              :     const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, u64 baseOffset, u64 dataSize, u32 root,
      57              :     bool isRootX)
      58              : {
      59            0 :     if (dataSize == 0) {
      60            0 :         return HcclResult::HCCL_SUCCESS;
      61              :     }
      62              :     u32 rootX, rootY;
      63            0 :     u64 rankStride = isRootX ? dataSize / sizeX_ / dataTypeSize_ * dataTypeSize_ :
      64            0 :                                dataSize / sizeY_ / dataTypeSize_ * dataTypeSize_;
      65            0 :     std::tie(rootX, rootY) = GetRankPos(root);
      66            0 :     if (root == u32(myRank_)) {
      67            0 :         if (isRootX) {
      68              :             // x轴(板内)SendRecvInfo
      69            0 :             for (u32 i = 0, index = 0; i < sizeX_; i++) {
      70            0 :                 if (i == rootY)
      71            0 :                     continue;
      72            0 :                 u64 dataOffset = baseOffset + i * rankStride;
      73            0 :                 u64 curSize = i == sizeX_ - 1 ? dataSize - rankStride * i : rankStride;
      74            0 :                 u32 peerRank = rootX * sizeX_ + i;
      75            0 :                 const LinkData& linkSend = tempLinks.at(peerRank)[0];
      76            0 :                 u64 dataOffsetAll = opMode_ == OpMode::OFFLOAD ? inputOffset_ + dataOffset : dataOffset;
      77            0 :                 BufferType srcDstBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
      78            0 :                 std::vector<DataSlice> srcSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
      79            0 :                 std::vector<DataSlice> dstSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
      80            0 :                 SlicesList txSlicesList(srcSlices, dstSlices);
      81            0 :                 DataInfo sendData(linkSend, txSlicesList);
      82            0 :                 CHK_PRT_RET(
      83              :                     Send(sendData, tempInsQues[index], 0, true, DmaMode::GET),
      84              :                     HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchSend failed"), HcclResult::HCCL_E_INTERNAL);
      85            0 :                 index++;
      86            0 :             }
      87              :         } else {
      88              :             // y轴(板间)SendRecvInfo
      89            0 :             for (u32 i = 0, index = 0; i < sizeY_; i++) {
      90            0 :                 if (i == rootX)
      91            0 :                     continue;
      92            0 :                 u64 dataOffset = baseOffset + i * rankStride;
      93            0 :                 u64 curSize = i == sizeY_ - 1 ? dataSize - rankStride * i : rankStride;
      94            0 :                 u32 peerRank = i * sizeX_ + rootY;
      95            0 :                 const LinkData& linkSend = tempLinks.at(peerRank)[0];
      96            0 :                 u64 dataOffsetAll = opMode_ == OpMode::OFFLOAD ? inputOffset_ + dataOffset : dataOffset;
      97            0 :                 BufferType srcDstBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
      98            0 :                 std::vector<DataSlice> srcSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
      99            0 :                 std::vector<DataSlice> dstSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
     100            0 :                 SlicesList txSlicesList(srcSlices, dstSlices);
     101            0 :                 DataInfo sendData(linkSend, txSlicesList);
     102            0 :                 CHK_PRT_RET(
     103              :                     Send(sendData, tempInsQues[sizeX_ - 1 + index], 0, true, DmaMode::GET),
     104              :                     HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchSend failed"), HcclResult::HCCL_E_INTERNAL);
     105            0 :                 index++;
     106            0 :             }
     107              :         }
     108            0 :     } else if (curX_ == rootX && isRootX) {
     109            0 :         u64 dataOffset = baseOffset + curY_ * rankStride;
     110            0 :         u64 curSize = curY_ == sizeX_ - 1 ? dataSize - rankStride * curY_ : rankStride;
     111            0 :         const LinkData& linkRecv = tempLinks.at(root)[0];
     112            0 :         u64 dataOffsetAll = opMode_ == OpMode::OFFLOAD ? inputOffset_ + dataOffset : dataOffset;
     113            0 :         BufferType srcDstBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
     114            0 :         std::vector<DataSlice> srcSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
     115            0 :         std::vector<DataSlice> dstSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
     116            0 :         SlicesList rxSlicesList(srcSlices, dstSlices);
     117            0 :         DataInfo recvData(linkRecv, rxSlicesList);
     118            0 :         u32 index = curY_ > rootY ? curY_ - 1 : curY_;
     119            0 :         CHK_PRT_RET(
     120              :             Recv(recvData, tempInsQues[index], 0, true, DmaMode::GET),
     121              :             HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchRecv failed"), HcclResult::HCCL_E_INTERNAL);
     122            0 :     } else if (curY_ == rootY && !isRootX) {
     123            0 :         u64 dataOffset = baseOffset + curX_ * rankStride;
     124            0 :         u64 curSize = curX_ == sizeY_ - 1 ? dataSize - rankStride * curX_ : rankStride;
     125            0 :         const LinkData& linkRecv = tempLinks.at(root)[0];
     126            0 :         u64 dataOffsetAll = opMode_ == OpMode::OFFLOAD ? inputOffset_ + dataOffset : dataOffset;
     127            0 :         BufferType srcDstBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
     128            0 :         std::vector<DataSlice> srcSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
     129            0 :         std::vector<DataSlice> dstSlices = {DataSlice(srcDstBufferType, dataOffsetAll, curSize)};
     130            0 :         SlicesList rxSlicesList(srcSlices, dstSlices);
     131            0 :         DataInfo recvData(linkRecv, rxSlicesList);
     132            0 :         u32 index = curX_ > rootX ? curX_ - 1 : curX_;
     133            0 :         CHK_PRT_RET(
     134              :             Recv(recvData, tempInsQues[sizeX_ - 1 + index], 0, true, DmaMode::GET),
     135              :             HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchRecv failed"), HcclResult::HCCL_E_INTERNAL);
     136            0 :     }
     137            0 :     return HcclResult::HCCL_SUCCESS;
     138              : }
     139              : 
     140            0 : HcclResult InsTempBroadcastMesh2DTwoShot::RunAllgather(
     141              :     const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues, u64 baseOffset, u64 dataSize, bool isX, bool isDma)
     142              : {
     143            0 :     if (dataSize == 0) {
     144            0 :         return HcclResult::HCCL_SUCCESS;
     145              :     }
     146            0 :     u64 rankStride
     147            0 :         = isX ? dataSize / sizeX_ / dataTypeSize_ * dataTypeSize_ : dataSize / sizeY_ / dataTypeSize_ * dataTypeSize_;
     148              : 
     149            0 :     if (isX) {
     150            0 :         for (u32 i = 0, index = 0; i < sizeX_; i++) {
     151            0 :             if (i == curY_)
     152            0 :                 continue;
     153              :             // send to peer rank
     154            0 :             u64 sendOffset = baseOffset + curY_ * rankStride;
     155            0 :             u64 sendSize = curY_ == sizeX_ - 1 ? dataSize - rankStride * curY_ : rankStride;
     156            0 :             u32 peerRank = curX_ * sizeX_ + i;
     157              :             // recv from peer rank
     158            0 :             u64 recvOffset = baseOffset + i * rankStride;
     159            0 :             u64 recvSize = i == sizeX_ - 1 ? dataSize - rankStride * i : rankStride;
     160            0 :             const LinkData& linkSendRecv = tempLinks.at(peerRank)[0];
     161            0 :             u64 sendOffsetSrc = opMode_ == OpMode::OFFLOAD ? inputOffset_ + sendOffset : sendOffset;
     162            0 :             u64 sendOffsetDst = opMode_ == OpMode::OFFLOAD || isDma ? inputOffset_ + sendOffset : sendOffset;
     163            0 :             u64 recvOffsetSrc = opMode_ == OpMode::OFFLOAD ? inputOffset_ + recvOffset : recvOffset;
     164            0 :             u64 recvOffsetDst = opMode_ == OpMode::OFFLOAD || isDma ? inputOffset_ + recvOffset : recvOffset;
     165            0 :             BufferType srcBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
     166            0 :             BufferType dstBufferType = opMode_ == OpMode::OFFLOAD || isDma ? BufferType::INPUT : BufferType::SCRATCH;
     167            0 :             std::vector<DataSlice> txSrcSlices = {DataSlice(srcBufferType, sendOffsetSrc, sendSize)};
     168            0 :             std::vector<DataSlice> txDstSlices = {DataSlice(dstBufferType, sendOffsetDst, sendSize)};
     169            0 :             std::vector<DataSlice> rxSrcSlices = {DataSlice(srcBufferType, recvOffsetSrc, recvSize)};
     170            0 :             std::vector<DataSlice> rxDstSlices = {DataSlice(dstBufferType, recvOffsetDst, recvSize)};
     171            0 :             TxRxSlicesList sendRecvSlicesList({txSrcSlices, txDstSlices}, {rxSrcSlices, rxDstSlices});
     172            0 :             TxRxLinks sendRecvLinks(linkSendRecv, linkSendRecv);
     173            0 :             SendRecvInfo sendRecvInfo(sendRecvLinks, sendRecvSlicesList);
     174            0 :             CHK_PRT_RET(
     175              :                 SendRecv(sendRecvInfo, tempInsQues[index], 0, true, DmaMode::GET),
     176              :                 HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchSendRecv failed"), HcclResult::HCCL_E_INTERNAL);
     177            0 :             index++;
     178            0 :         }
     179              :     } else {
     180            0 :         for (u32 i = 0, index = 0; i < sizeY_; i++) {
     181            0 :             if (i == curX_)
     182            0 :                 continue;
     183              :             // send to peer rank
     184            0 :             u64 sendOffset = baseOffset + curX_ * rankStride;
     185            0 :             u64 sendSize = curX_ == sizeY_ - 1 ? dataSize - rankStride * curX_ : rankStride;
     186            0 :             u32 peerRank = i * sizeX_ + curY_;
     187              :             // recv from peer rank
     188            0 :             u64 recvOffset = baseOffset + i * rankStride;
     189            0 :             u64 recvSize = i == sizeY_ - 1 ? dataSize - rankStride * i : rankStride;
     190            0 :             const LinkData& linkSendRecv = tempLinks.at(peerRank)[0];
     191            0 :             u64 sendOffsetSrc = opMode_ == OpMode::OFFLOAD ? inputOffset_ + sendOffset : sendOffset;
     192            0 :             u64 sendOffsetDst = opMode_ == OpMode::OFFLOAD || isDma ? inputOffset_ + sendOffset : sendOffset;
     193            0 :             u64 recvOffsetSrc = opMode_ == OpMode::OFFLOAD ? inputOffset_ + recvOffset : recvOffset;
     194            0 :             u64 recvOffsetDst = opMode_ == OpMode::OFFLOAD || isDma ? inputOffset_ + recvOffset : recvOffset;
     195            0 :             BufferType srcBufferType = opMode_ == OpMode::OFFLOAD ? BufferType::INPUT : BufferType::SCRATCH;
     196            0 :             BufferType dstBufferType = opMode_ == OpMode::OFFLOAD || isDma ? BufferType::INPUT : BufferType::SCRATCH;
     197            0 :             std::vector<DataSlice> txSrcSlices = {DataSlice(srcBufferType, sendOffsetSrc, sendSize)};
     198            0 :             std::vector<DataSlice> txDstSlices = {DataSlice(dstBufferType, sendOffsetDst, sendSize)};
     199            0 :             std::vector<DataSlice> rxSrcSlices = {DataSlice(srcBufferType, recvOffsetSrc, recvSize)};
     200            0 :             std::vector<DataSlice> rxDstSlices = {DataSlice(dstBufferType, recvOffsetDst, recvSize)};
     201            0 :             TxRxSlicesList sendRecvSlicesList({txSrcSlices, txDstSlices}, {rxSrcSlices, rxDstSlices});
     202            0 :             TxRxLinks sendRecvLinks(linkSendRecv, linkSendRecv);
     203            0 :             SendRecvInfo sendRecvInfo(sendRecvLinks, sendRecvSlicesList);
     204            0 :             CHK_PRT_RET(
     205              :                 SendRecv(sendRecvInfo, tempInsQues[sizeX_ - 1 + index], 0, true, DmaMode::GET),
     206              :                 HCCL_ERROR("[InsTempBroadcastMesh2DTwoShot] BatchSendRecv failed"), HcclResult::HCCL_E_INTERNAL);
     207            0 :             index++;
     208            0 :         }
     209              :     }
     210            0 :     return HcclResult::HCCL_SUCCESS;
     211              : }
     212              : 
     213            0 : HcclResult InsTempBroadcastMesh2DTwoShot::Run1RootScatterXY(
     214              :     u64 dataSize, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues)
     215              : {
     216            0 :     u64 perRank = dataSize / (sizeX_ + sizeY_) / dataTypeSize_ * dataTypeSize_;
     217              :     u32 rootX, rootY;
     218            0 :     std::tie(rootX, rootY) = GetRankPos(root_);
     219            0 :     u64 step14DataSizeX = perRank * sizeX_;
     220            0 :     u64 step14DataSizeY = dataSize - step14DataSizeX;
     221            0 :     u64 step14OffsetX = 0;
     222            0 :     u64 step14OffsetY = step14DataSizeX;
     223            0 :     CHK_RET(PreSyncInterQueues(tempInsQues));
     224            0 :     CHK_RET(RunScatter(tempLinks, tempInsQues, step14OffsetX, step14DataSizeX, root_, true));
     225            0 :     CHK_RET(RunScatter(tempLinks, tempInsQues, step14OffsetY, step14DataSizeY, root_, false));
     226            0 :     CHK_RET(PostSyncInterQueues(tempInsQues));
     227            0 :     return HcclResult::HCCL_SUCCESS;
     228              : }
     229              : 
     230            0 : HcclResult InsTempBroadcastMesh2DTwoShot::RunNRootScatterYX(
     231              :     u64 dataSize, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues)
     232              : {
     233            0 :     u64 perRank = dataSize / (sizeX_ + sizeY_) / dataTypeSize_ * dataTypeSize_;
     234              :     u32 rootX, rootY;
     235            0 :     std::tie(rootX, rootY) = GetRankPos(root_);
     236            0 :     u64 step23DataSizeX = perRank * sizeX_;
     237            0 :     u64 step23BaseOffsetY = perRank * sizeX_;
     238            0 :     u64 step23DataSizeY = dataSize - perRank * sizeX_;
     239            0 :     u64 step23PerRankY = step23DataSizeY / sizeY_ / dataTypeSize_ * dataTypeSize_;
     240            0 :     CHK_RET(PreSyncInterQueues(tempInsQues));
     241              :     // n root scatter
     242            0 :     for (u32 i = 0; i < sizeX_; i++) {
     243            0 :         u64 dataOffset = i * perRank;
     244            0 :         u64 curSize = i == sizeX_ - 1 ? step23DataSizeX - perRank * i : perRank;
     245            0 :         u32 curRank = rootX * sizeX_ + i;
     246            0 :         CHK_RET(RunScatter(tempLinks, tempInsQues, dataOffset, curSize, curRank, false));
     247              :     }
     248              : 
     249            0 :     for (u32 i = 0; i < sizeY_; i++) {
     250            0 :         u64 dataOffset = step23BaseOffsetY + i * step23PerRankY;
     251            0 :         u64 curSize = i == sizeY_ - 1 ? step23DataSizeY - step23PerRankY * i : step23PerRankY;
     252            0 :         u64 curRank = i * sizeX_ + rootY;
     253            0 :         CHK_RET(RunScatter(tempLinks, tempInsQues, dataOffset, curSize, curRank, true));
     254              :     }
     255            0 :     CHK_RET(PostSyncInterQueues(tempInsQues));
     256            0 :     return HcclResult::HCCL_SUCCESS;
     257              : }
     258              : 
     259            0 : HcclResult InsTempBroadcastMesh2DTwoShot::RunAllgatherYX(
     260              :     u64 dataSize, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues)
     261              : {
     262            0 :     u64 perRank = dataSize / (sizeX_ + sizeY_) / dataTypeSize_ * dataTypeSize_;
     263              :     u32 rootX, rootY;
     264            0 :     std::tie(rootX, rootY) = GetRankPos(root_);
     265            0 :     u64 step23DataSizeX = perRank * sizeX_;
     266            0 :     u64 step23BaseOffsetY = perRank * sizeX_;
     267            0 :     u64 step23DataSizeY = dataSize - perRank * sizeX_;
     268            0 :     u64 step23PerRankY = step23DataSizeY / sizeY_ / dataTypeSize_ * dataTypeSize_;
     269              :     // allgather yx轴
     270            0 :     CHK_RET(PreSyncInterQueues(tempInsQues));
     271            0 :     u64 dataOffsetY = curY_ * perRank;
     272            0 :     u64 curSizeY = curY_ == sizeX_ - 1 ? step23DataSizeX - perRank * curY_ : perRank;
     273            0 :     CHK_RET(RunAllgather(tempLinks, tempInsQues, dataOffsetY, curSizeY, false, false));
     274              : 
     275            0 :     u64 dataOffsetX = step23BaseOffsetY + curX_ * step23PerRankY;
     276            0 :     u64 curSizeX = curX_ == sizeY_ - 1 ? step23DataSizeY - step23PerRankY * curX_ : step23PerRankY;
     277            0 :     CHK_RET(RunAllgather(tempLinks, tempInsQues, dataOffsetX, curSizeX, true, false));
     278              : 
     279            0 :     CHK_RET(PostSyncInterQueues(tempInsQues));
     280            0 :     return HcclResult::HCCL_SUCCESS;
     281              : }
     282              : 
     283            0 : HcclResult InsTempBroadcastMesh2DTwoShot::RunAllgatherXY(
     284              :     u64 dataSize, const ResLinks& tempLinks, std::vector<InsQuePtr>& tempInsQues)
     285              : {
     286            0 :     u64 perRank = dataSize / (sizeX_ + sizeY_) / dataTypeSize_ * dataTypeSize_;
     287              :     u32 rootX, rootY;
     288            0 :     std::tie(rootX, rootY) = GetRankPos(root_);
     289            0 :     u64 step14DataSizeX = perRank * sizeX_;
     290            0 :     u64 step14DataSizeY = dataSize - step14DataSizeX;
     291            0 :     u64 step14OffsetX = 0;
     292            0 :     u64 step14OffsetY = step14DataSizeX;
     293              :     // allgather xy轴
     294            0 :     CHK_RET(PreSyncInterQueues(tempInsQues));
     295            0 :     CHK_RET(RunAllgather(tempLinks, tempInsQues, step14OffsetX, step14DataSizeX, true, true));
     296            0 :     CHK_RET(RunAllgather(tempLinks, tempInsQues, step14OffsetY, step14DataSizeY, false, true));
     297            0 :     CHK_RET(PostSyncInterQueues(tempInsQues));
     298            0 :     return HcclResult::HCCL_SUCCESS;
     299              : }
     300              : 
     301            0 : HcclResult InsTempBroadcastMesh2DTwoShot::PreCopy(
     302              :     const TemplateDataParams& templateDataParams, std::vector<InsQuePtr>& tempInsQues)
     303              : {
     304            0 :     if (opMode_ == OpMode::OFFLOAD || u32(myRank_) != root_) {
     305            0 :         return HcclResult::HCCL_SUCCESS;
     306              :     }
     307            0 :     std::vector<DataSlice> scratchSlices = {DataSlice(BufferType::SCRATCH, 0, templateDataParams.sliceSize)};
     308              :     std::vector<DataSlice> inputSlices
     309            0 :         = {DataSlice(BufferType::INPUT, templateDataParams.buffInfo.inBuffBaseOff, templateDataParams.sliceSize)};
     310            0 :     CHK_RET(LocalCopySlices(tempInsQues[0], inputSlices, scratchSlices));
     311            0 :     return HcclResult::HCCL_SUCCESS;
     312            0 : }
     313              : 
     314            0 : HcclResult InsTempBroadcastMesh2DTwoShot::PostCopy(
     315              :     const TemplateDataParams& templateDataParams, std::vector<InsQuePtr>& tempInsQues)
     316              : {
     317            0 :     if (opMode_ == OpMode::OFFLOAD) {
     318            0 :         return HcclResult::HCCL_SUCCESS;
     319              :     }
     320            0 :     u64 perRank = templateDataParams.sliceSize / (sizeX_ + sizeY_) / dataTypeSize_ * dataTypeSize_;
     321            0 :     u64 scratchDataSizeX = perRank * sizeX_;
     322            0 :     u64 scratchDataSizeY = templateDataParams.sliceSize - scratchDataSizeX;
     323            0 :     u64 scratchOffsetX = 0;
     324            0 :     u64 scratchOffsetY = scratchDataSizeX;
     325              :     // x轴当前卡
     326            0 :     u64 curRankDataOffsetX = scratchOffsetX + perRank * curY_;
     327            0 :     u64 curRankDataSizeX = perRank;
     328            0 :     u64 perRankY = scratchDataSizeY / sizeY_ / dataTypeSize_ * dataTypeSize_;
     329            0 :     u64 curRankDataOffsetY = scratchOffsetY + perRankY * curX_;
     330            0 :     u64 curRankDataSizeY = curX_ == sizeY_ - 1 ? scratchDataSizeY - curX_ * perRankY : perRankY;
     331              : 
     332              :     std::vector<DataSlice> scratchSlices
     333            0 :         = {DataSlice(BufferType::SCRATCH, curRankDataOffsetX, curRankDataSizeX),
     334            0 :            DataSlice(BufferType::SCRATCH, curRankDataOffsetY, curRankDataSizeY)};
     335              :     std::vector<DataSlice> inputSlices = {
     336            0 :         DataSlice(BufferType::INPUT, templateDataParams.buffInfo.inBuffBaseOff + curRankDataOffsetX, curRankDataSizeX),
     337            0 :         DataSlice(BufferType::INPUT, templateDataParams.buffInfo.inBuffBaseOff + curRankDataOffsetY, curRankDataSizeY)};
     338            0 :     CHK_RET(LocalCopySlices(tempInsQues[0], scratchSlices, inputSlices));
     339              : 
     340            0 :     return HcclResult::HCCL_SUCCESS;
     341            0 : }
     342              : 
     343            0 : HcclResult InsTempBroadcastMesh2DTwoShot::GenExtIns(
     344              :     const TempFuncs& tempFuncs, const TemplateDataParams& templateDataParams, const ResLinks& tempLinks,
     345              :     std::vector<InsQuePtr>& tempInsQues)
     346              : {
     347            0 :     HCCL_INFO("[InsTempBroadcastMesh2DTwoShot][GenExtIns] Broadcast2DMesh start: rank[%d] end", myRank_);
     348            0 :     opMode_ = tempFuncs.opMode;
     349            0 :     dataTypeSize_ = DataTypeSizeGet(dataType_);
     350            0 :     inputOffset_ = templateDataParams.buffInfo.inBuffBaseOff;
     351            0 :     if (sizeX_ == 1 && sizeY_ == 1) {
     352            0 :         HCCL_INFO("[InsTempBroadcastMesh2DTwoShot][GenExtIns] Broadcast2DMesh finished: rank[%d] end", myRank_);
     353            0 :         return HcclResult::HCCL_SUCCESS;
     354              :     }
     355            0 :     queNum_ = sizeX_ - 1 + sizeY_ - 1;
     356            0 :     CHK_PRT_RET(
     357              :         queNum_ != tempInsQues.size(),
     358              :         HCCL_ERROR("[CollAlgFactory] [InsTempBroadcastMesh2DTwoShot] Rank [%d], requiredQue Error.", myRank_),
     359              :         HcclResult::HCCL_E_INTERNAL);
     360              : 
     361            0 :     CHK_RET(PreCopy(templateDataParams, tempInsQues));
     362              : 
     363            0 :     CHK_RET(Run1RootScatterXY(templateDataParams.sliceSize, tempLinks, tempInsQues));
     364            0 :     CHK_RET(RunNRootScatterYX(templateDataParams.sliceSize, tempLinks, tempInsQues));
     365            0 :     CHK_RET(RunAllgatherYX(templateDataParams.sliceSize, tempLinks, tempInsQues));
     366            0 :     CHK_RET(RunAllgatherXY(templateDataParams.sliceSize, tempLinks, tempInsQues));
     367              : 
     368            0 :     CHK_RET(PostCopy(templateDataParams, tempInsQues));
     369              : 
     370            0 :     HCCL_INFO("[InsTempBroadcastMesh2DTwoShot][GenExtIns] Broadcast2DMesh finished: rank[%d] end", myRank_);
     371            0 :     return HcclResult::HCCL_SUCCESS;
     372              : }
     373              : 
     374              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1