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