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_mesh1D_oneshot.h"
15 :
16 : namespace Hccl {
17 0 : InsTempBroadcastMesh1DOneShot::InsTempBroadcastMesh1DOneShot(const RankId virtualRank, const u32 tempRankSize,
18 : const std::vector<std::vector<RankId>> &tempVTopo,
19 0 : const std::map<RankId, u32> &tempVirtRankMap)
20 0 : : InsAlgTemplateBase(virtualRank, tempRankSize, tempVTopo, tempVirtRankMap)
21 : {
22 0 : }
23 :
24 0 : InsTempBroadcastMesh1DOneShot::~InsTempBroadcastMesh1DOneShot()
25 : {
26 0 : }
27 :
28 0 : HcclResult InsTempBroadcastMesh1DOneShot::CalcRes(AlgTempResReq &tempResReq)
29 : {
30 0 : tempResReq.queNum = tempVTopo_[0].size() - 1 > 0 ? tempVTopo_[0].size() - 1 : 1;
31 0 : tempResReq.streamNum = tempResReq.queNum;
32 0 : tempResReq.queNotifys = CreateMasterSlaveQueNotifiesRequest(tempResReq.queNum);
33 0 : QId centerQ = 0;
34 0 : tempResReq.localWaitGroupCntNotify.emplace_back(centerQ, 0);
35 0 : tempResReq.localBcastPostCntNotify.emplace_back(centerQ, 0);
36 0 : CHK_RET(CalcResLinksMesh(myRank_, tempRankSize_, tempVTopo_, linkNumBtwPeers_, tempResReq));
37 0 : HCCL_DEBUG("[InsTempBroadcastMesh1DOneShot]CalcRes: queNum[%u], myRank[%d], tempRankSize[%u]", tempResReq.queNum, myRank_, tempRankSize_);
38 0 : return HcclResult::HCCL_SUCCESS;
39 : }
40 :
41 0 : u32 InsTempBroadcastMesh1DOneShot::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
42 : {
43 : (void) inBuffType;
44 : (void) outBuffType;
45 0 : if (op_.opMode == OpMode::OPBASE) {
46 0 : return 1;
47 : } else {
48 0 : return 0;
49 : }
50 : }
51 :
52 0 : HcclResult InsTempBroadcastMesh1DOneShot::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams,
53 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
54 : {
55 0 : if (tempVTopo_[0].size() == 1) {
56 0 : return HcclResult::HCCL_SUCCESS;
57 : }
58 :
59 0 : HCCL_INFO("[InsTempBroadcastMesh1DOneShot][Run] Broadcast1DMesh start: rank[%d] end", myRank_);
60 0 : opMode_ = tempFuncs.opMode;
61 0 : queNum_ = tempVTopo_[0].size() - 1;
62 0 : CHK_PRT_RET(queNum_ != tempInsQues.size(),
63 : HCCL_ERROR("[CollAlgFactory] [InsTempBroadcastMesh1DOneShot] Rank [%d], requiredQue Error.", myRank_),
64 : HcclResult::HCCL_E_INTERNAL);
65 0 : UsrData usrData;
66 0 : usrData.usrInSlices.emplace_back(BufferType::INPUT, templateDataParams.buffInfo.inBuffBaseOff, templateDataParams.sliceSize);
67 0 : usrData.scratchInSlices.emplace_back(BufferType::SCRATCH, 0, templateDataParams.sliceSize);
68 0 : usrData.scratchOutSlices.emplace_back(BufferType::SCRATCH, 0, templateDataParams.sliceSize);
69 0 : usrData.usrOutSlices.emplace_back(BufferType::INPUT, templateDataParams.buffInfo.inBuffBaseOff, templateDataParams.sliceSize);
70 0 : if (root_ == u32(myRank_)) {
71 0 : CHK_RET(PreSyncInterQueues(tempInsQues));
72 0 : for (u32 i = 0; i < tempVTopo_[0].size() - 1; i++) {
73 0 : u32 neighborRank = (myRank_ + 1 + i) % tempVTopo_[0].size();
74 0 : const LinkData &linkSend = tempLinks.at(neighborRank)[0];
75 0 : std::vector<DataSlice> txSlices;
76 0 : if (opMode_ == OpMode::OPBASE) {
77 0 : txSlices = usrData.scratchOutSlices;
78 : } else {
79 0 : txSlices = usrData.usrInSlices;
80 : }
81 0 : SlicesList txSlicesList(usrData.usrInSlices, txSlices);
82 0 : DataInfo sendData(linkSend, txSlicesList);
83 0 : CHK_PRT_RET(Send(sendData, tempInsQues[i], 0, true, DmaMode::PUT), HCCL_ERROR("[InsTempBroadcastMesh1DOneShot] BatchSend failed"),
84 : HcclResult::HCCL_E_INTERNAL);
85 0 : }
86 0 : CHK_RET(PostSyncInterQueues(tempInsQues));
87 : } else {
88 0 : const LinkData &linkRecv = tempLinks.at(root_)[0];
89 0 : std::vector<DataSlice> rxSlices;
90 0 : if (opMode_ == OpMode::OPBASE) {
91 0 : rxSlices = usrData.scratchOutSlices;
92 : } else {
93 0 : rxSlices = usrData.usrInSlices;
94 : }
95 0 : SlicesList rxSlicesList(usrData.usrInSlices, rxSlices);
96 0 : DataInfo recvData(linkRecv, rxSlicesList);
97 0 : CHK_PRT_RET(Recv(recvData, tempInsQues[0], 0, true, DmaMode::PUT), HCCL_ERROR("[InsTempBroadcastMesh1DOneShot] BatchRecv failed"),
98 : HcclResult::HCCL_E_INTERNAL);
99 0 : if (opMode_ == OpMode::OPBASE) {
100 0 : LocalCopySlices(tempInsQues[0], usrData.scratchOutSlices, usrData.usrInSlices);
101 : }
102 0 : }
103 0 : HCCL_INFO("[InsTempBroadcastMesh1DOneShot][Run] Broadcast1DMesh finished: rank[%d] end", myRank_);
104 :
105 0 : return HcclResult::HCCL_SUCCESS;
106 0 : }
107 :
108 : } // namespace Hccl
|