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 "instruction.h"
12 : #include "types.h"
13 : #include "inttypes.h"
14 :
15 : namespace Hccl {
16 48 : string InsLocalCopy::Describe() const
17 : {
18 : return StringFormat(
19 48 : "InsLocalCopy[srcSlice=%s, dstSlice=%s]", srcSlice_.Describe().c_str(), dstSlice_.Describe().c_str());
20 : }
21 13 : const DataSlice& InsLocalCopy::GetSrcSlice() const { return srcSlice_; }
22 6 : const DataSlice& InsLocalCopy::GetDstSlice() const { return dstSlice_; }
23 :
24 0 : string InsLocalCopyExtend::Describe() const
25 : {
26 : return StringFormat(
27 0 : "InsLocalCopyExtend[srcBuffer=%s, dstBuffer=%s]", srcBuffer_.Describe().c_str(), dstBuffer_.Describe().c_str());
28 : }
29 5 : const DataBuffer& InsLocalCopyExtend::GetSrcBuffer() const { return srcBuffer_; }
30 1 : const DataBuffer& InsLocalCopyExtend::GetDstBuffer() const { return dstBuffer_; }
31 :
32 4 : string InsLocalReduce::Describe() const
33 : {
34 : return StringFormat(
35 8 : "InsLocalReduce[dataType=%s, reduceOp=%s, srcSlice=%s, dstSlice=%s]", dataType_.Describe().c_str(),
36 12 : reduceOp_.Describe().c_str(), srcSlice_.Describe().c_str(), dstSlice_.Describe().c_str());
37 : }
38 16 : const DataSlice& InsLocalReduce::GetSrcSlice() const { return srcSlice_; }
39 9 : const DataSlice& InsLocalReduce::GetDstSlice() const { return dstSlice_; }
40 9 : const DataType InsLocalReduce::GetDataType() const { return dataType_; }
41 6 : const ReduceOp InsLocalReduce::GetReduceOp() const { return reduceOp_; }
42 :
43 8 : string InsLocalPostTo::Describe() const
44 : {
45 : return StringFormat(
46 8 : "InsLocalPostTo[notifyType=%s, postQid=%u, waitQid=%u, topicId=%u]", notifyType_.Describe().c_str(), postQid_,
47 16 : waitQid_, topicId_);
48 : }
49 :
50 38 : void InsLocalPostTo::SetPostQid(QId qid)
51 : {
52 38 : if (waitQid_ == qid) {
53 1 : THROW<InvalidParamsException>("post Qid is equal to wait Qid");
54 : }
55 37 : postQid_ = qid;
56 37 : }
57 :
58 9 : QId InsLocalPostTo::GetPostQid() const { return postQid_; }
59 14 : QId InsLocalPostTo::GetWaitQid() const { return waitQid_; }
60 12 : u32 InsLocalPostTo::GetTopicId() const { return topicId_; }
61 13 : NotifyType InsLocalPostTo::GetNotifyType() const { return notifyType_; }
62 :
63 8 : string InsLocalWaitFrom::Describe() const
64 : {
65 8 : return StringFormat("InsLocalWaitFrom[waitQid=%u, postQid=%u, topicId=%u]", waitQid_, postQid_, topicId_);
66 : }
67 :
68 38 : void InsLocalWaitFrom::SetWaitQid(QId qid)
69 : {
70 38 : if (postQid_ == qid) {
71 1 : THROW<InvalidParamsException>("post Qid is equal to wait Qid");
72 : }
73 37 : waitQid_ = qid;
74 37 : }
75 :
76 14 : QId InsLocalWaitFrom::GetPostQid() const { return postQid_; }
77 9 : QId InsLocalWaitFrom::GetWaitQid() const { return waitQid_; }
78 12 : u32 InsLocalWaitFrom::GetTopicId() const { return topicId_; }
79 12 : NotifyType InsLocalWaitFrom::GetNotifyType() const { return notifyType_; }
80 :
81 : using Iterator = BaseConstIterator<vector, QId>;
82 6 : void InsLocalWaitGroup::Append(QId postQid) { postQids_.push_back(postQid); }
83 5 : string InsLocalWaitGroup::Describe() const
84 : {
85 5 : std::string postQidsStr;
86 12 : for (u32 idx = 0; idx < postQids_.size(); idx++) {
87 7 : postQidsStr += StringFormat("%u, ", postQids_[idx]);
88 : }
89 5 : if (!postQidsStr.empty()) {
90 4 : u32 redundantLen = 2;
91 4 : postQidsStr = postQidsStr.substr(0, postQidsStr.size() - redundantLen);
92 : }
93 :
94 : return StringFormat(
95 5 : "InsLocalWaitGroup[waitQid=%u, topicId=%u, postQidNum=%zu, postQids=postQidList[%s]]", waitQid_, topicId_,
96 10 : postQids_.size(), postQidsStr.c_str());
97 5 : }
98 7 : QId InsLocalWaitGroup::GetWaitQid() const { return waitQid_; }
99 7 : u32 InsLocalWaitGroup::GetTopicId() const { return topicId_; }
100 3 : void InsLocalWaitGroup::SetWaitQid(QId qId)
101 : {
102 4 : for (auto iter = Iter(); iter.HasNext(); ++iter) {
103 2 : if (*iter == qId) {
104 1 : THROW<InvalidParamsException>("One of post Qids is equal to wait Qid");
105 : }
106 : }
107 :
108 2 : waitQid_ = qId;
109 2 : }
110 :
111 4 : void InsLocalBcastPost::Append(QId waitQid) { waitQids_.push_back(waitQid); }
112 3 : string InsLocalBcastPost::Describe() const
113 : {
114 3 : std::string waitQidsStr;
115 9 : for (u32 idx = 0; idx < waitQids_.size(); idx++) {
116 6 : waitQidsStr += StringFormat("%u, ", waitQids_[idx]);
117 : }
118 3 : if (!waitQidsStr.empty()) {
119 3 : u32 redundantLen = 2;
120 3 : waitQidsStr = waitQidsStr.substr(0, waitQidsStr.size() - redundantLen);
121 : }
122 :
123 : return StringFormat(
124 3 : "InsLocalBcastPost[postQid=%d, topicId=%d, waitQidNum=%u, waitQids=waitQidList[%s]]", postQid_, topicId_,
125 6 : waitQids_.size(), waitQidsStr.c_str());
126 3 : }
127 6 : QId InsLocalBcastPost::GetPostQid() const { return postQid_; }
128 6 : u32 InsLocalBcastPost::GetTopicId() const { return topicId_; }
129 1 : void InsLocalBcastPost::SetPostQid(QId qId)
130 : {
131 1 : for (auto iter = Iter(); iter.HasNext(); ++iter) {
132 0 : if (*iter == qId) {
133 0 : THROW<InvalidParamsException>("One of post Qids is equal to wait Qid");
134 : }
135 : }
136 :
137 1 : postQid_ = qId;
138 1 : }
139 :
140 4 : string InsPostReady::Describe() const
141 : {
142 4 : return StringFormat("InsPostReady:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
143 : }
144 3 : RankId InsPostReady::GetRemoteRank() const { return remoteRank_; }
145 11 : const LinkData* InsPostReady::GetLink() const { return &link_; }
146 :
147 5 : string InsWaitReady::Describe() const
148 : {
149 5 : return StringFormat("InsWaitReady:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
150 : }
151 4 : RankId InsWaitReady::GetRemoteRank() const { return remoteRank_; }
152 16 : const LinkData* InsWaitReady::GetLink() const { return &link_; }
153 :
154 4 : string InsPostFin::Describe() const
155 : {
156 4 : return StringFormat("InsPostFin:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
157 : }
158 3 : RankId InsPostFin::GetRemoteRank() const { return remoteRank_; }
159 11 : const LinkData* InsPostFin::GetLink() const { return &link_; }
160 :
161 4 : string InsWaitFin::Describe() const
162 : {
163 4 : return StringFormat("InsWaitFin:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
164 : }
165 3 : RankId InsWaitFin::GetRemoteRank() const { return remoteRank_; }
166 11 : const LinkData* InsWaitFin::GetLink() const { return &link_; }
167 :
168 2 : string InsWaitGroupFin::Describe() const
169 : {
170 2 : string linksStr;
171 4 : for (auto iter = links_.begin(); iter != links_.end(); ++iter) {
172 2 : linksStr += iter->Describe();
173 : }
174 2 : if (!linksStr.empty()) {
175 2 : u32 redundantLen = 2;
176 2 : linksStr = linksStr.substr(0, linksStr.size() - redundantLen);
177 : }
178 4 : return StringFormat("InsWaitGroupFin[topicId=%u, value=0x%x, links=%s]", topicId_, value_, linksStr.c_str());
179 2 : }
180 2 : u32 InsWaitGroupFin::GetTopicId() const { return topicId_; }
181 2 : void InsWaitGroupFin::Append(LinkData link) { links_.push_back(link); }
182 :
183 3 : u32 InsWaitGroupFin::GetValue() const { return value_; }
184 :
185 3 : string InsPostFinAck::Describe() const
186 : {
187 3 : return StringFormat("InsPostFinAck[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
188 : }
189 2 : RankId InsPostFinAck::GetRemoteRank() const { return remoteRank_; }
190 8 : const LinkData* InsPostFinAck::GetLink() const { return &link_; }
191 :
192 3 : string InsWaitFinAck::Describe() const
193 : {
194 3 : return StringFormat("InsWaitFinAck[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
195 : }
196 2 : RankId InsWaitFinAck::GetRemoteRank() const { return remoteRank_; }
197 8 : const LinkData* InsWaitFinAck::GetLink() const { return &link_; }
198 :
199 5 : string InsRead::Describe() const
200 : {
201 : return StringFormat(
202 10 : "InsRead[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s]", remoteRank_, link_.Describe().c_str(),
203 15 : localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
204 : }
205 :
206 2 : RankId InsRead::GetRemoteRank() const { return remoteRank_; }
207 16 : const LinkData* InsRead::GetLink() const { return &link_; }
208 25 : const DataSlice& InsRead::GetLocalSlice() const { return localSlice_; }
209 20 : const DataSlice& InsRead::GetRemoteSlice() const { return remoteSlice_; }
210 :
211 2 : string InsReadReduce::Describe() const
212 : {
213 : return StringFormat(
214 2 : "InsReadReduce[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
215 8 : link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
216 10 : localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
217 : }
218 :
219 1 : string InsReadExtend::Describe() const
220 : {
221 : return StringFormat(
222 2 : "InsReadExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_, link_.Describe().c_str(),
223 3 : localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
224 : }
225 :
226 1 : RankId InsReadExtend::GetRemoteRank() const { return remoteRank_; }
227 1 : const LinkData* InsReadExtend::GetLink() const { return &link_; }
228 1 : const DataBuffer& InsReadExtend::GetLocalBuffer() const { return localBuffer_; }
229 1 : const DataBuffer& InsReadExtend::GetRemoteBuffer() const { return remoteBuffer_; }
230 :
231 1 : RankId InsReadReduce::GetRemoteRank() const { return remoteRank_; }
232 10 : const LinkData* InsReadReduce::GetLink() const { return &link_; }
233 19 : const DataSlice& InsReadReduce::GetLocalSlice() const { return localSlice_; }
234 17 : const DataSlice& InsReadReduce::GetRemoteSlice() const { return remoteSlice_; }
235 5 : const DataType InsReadReduce::GetDataType() const { return dataType_; }
236 5 : const ReduceOp InsReadReduce::GetReduceOp() const { return reduceOp_; }
237 :
238 1 : string InsBatchRead::Describe() const
239 : {
240 : return StringFormat(
241 2 : "InsBatchRead[remoteRank=%d, link=%s, readInsVec size=%zu]", remoteRank, link.Describe().c_str(),
242 3 : readInsVec.size());
243 : }
244 :
245 1 : RankId InsBatchRead::GetRemoteRank() const { return remoteRank; }
246 :
247 13 : const LinkData* InsBatchRead::GetLink() const { return &link; }
248 :
249 9 : void InsBatchRead::PushReadIns(unique_ptr<Instruction> readIns)
250 : {
251 9 : if (readIns->GetType() != InstructionType::READ && readIns->GetType() != InstructionType::READ_REDUCE) {
252 1 : THROW<NotSupportException>(StringFormat(
253 : "[InsBatchRead][%s] only support read and readReduce instruction type, "
254 : "but get instruction type[%s]",
255 3 : __func__, readIns->GetType().Describe().c_str()));
256 : }
257 :
258 8 : readInsVec.push_back(std::move(readIns));
259 8 : }
260 :
261 1 : string InsReadReduceExtend::Describe() const
262 : {
263 : return StringFormat(
264 : "InsReadReduceExtend[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s]",
265 4 : remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
266 5 : localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
267 : }
268 :
269 1 : RankId InsReadReduceExtend::GetRemoteRank() const { return remoteRank_; }
270 1 : const LinkData* InsReadReduceExtend::GetLink() const { return &link_; }
271 1 : const DataBuffer& InsReadReduceExtend::GetLocalBuffer() const { return localBuffer_; }
272 1 : const DataBuffer& InsReadReduceExtend::GetRemoteBuffer() const { return remoteBuffer_; }
273 1 : const DataType InsReadReduceExtend::GetDataType() const { return dataType_; }
274 1 : const ReduceOp InsReadReduceExtend::GetReduceOp() const { return reduceOp_; }
275 :
276 3 : string InsWrite::Describe() const
277 : {
278 : return StringFormat(
279 6 : "InsWrite[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s]", remoteRank_, link_.Describe().c_str(),
280 9 : localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
281 : }
282 :
283 1 : RankId InsWrite::GetRemoteRank() const { return remoteRank_; }
284 14 : const LinkData* InsWrite::GetLink() const { return &link_; }
285 23 : const DataSlice& InsWrite::GetLocalSlice() const { return localSlice_; }
286 21 : const DataSlice& InsWrite::GetRemoteSlice() const { return remoteSlice_; }
287 :
288 0 : string InsWriteExtend::Describe() const
289 : {
290 : return StringFormat(
291 0 : "InsWriteExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_,
292 0 : link_.Describe().c_str(), localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
293 : }
294 :
295 1 : RankId InsWriteExtend::GetRemoteRank() const { return remoteRank_; }
296 2 : const LinkData* InsWriteExtend::GetLink() const { return &link_; }
297 2 : const DataBuffer& InsWriteExtend::GetLocalBuffer() const { return localBuffer_; }
298 1 : const DataBuffer& InsWriteExtend::GetRemoteBuffer() const { return remoteBuffer_; }
299 :
300 2 : string InsWriteReduce::Describe() const
301 : {
302 : return StringFormat(
303 2 : "InsWriteReduce[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
304 8 : link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
305 10 : localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
306 : }
307 :
308 1 : RankId InsWriteReduce::GetRemoteRank() const { return remoteRank_; }
309 7 : const LinkData* InsWriteReduce::GetLink() const { return &link_; }
310 19 : const DataSlice& InsWriteReduce::GetLocalSlice() const { return localSlice_; }
311 17 : const DataSlice& InsWriteReduce::GetRemoteSlice() const { return remoteSlice_; }
312 4 : const DataType InsWriteReduce::GetDataType() const { return dataType_; }
313 4 : const ReduceOp InsWriteReduce::GetReduceOp() const { return reduceOp_; }
314 :
315 1 : string InsBatchWrite::Describe() const
316 : {
317 : return StringFormat(
318 2 : "InsBatchWrite[remoteRank=%d, link=%s, writeInsVec size=%zu]", remoteRank, link.Describe().c_str(),
319 3 : writeInsVec.size());
320 : }
321 :
322 2 : RankId InsBatchWrite::GetRemoteRank() const { return remoteRank; }
323 :
324 14 : const LinkData* InsBatchWrite::GetLink() const { return &link; }
325 :
326 9 : void InsBatchWrite::PushWriteIns(unique_ptr<Instruction> writeIns)
327 : {
328 9 : if (writeIns->GetType() != InstructionType::WRITE && writeIns->GetType() != InstructionType::WRITE_REDUCE) {
329 1 : THROW<NotSupportException>(StringFormat(
330 : "[InsBatchWrite][%s] only support Write and WriteReduce instruction "
331 : "type, but get instruction type[%s]",
332 3 : __func__, writeIns->GetType().Describe().c_str()));
333 : }
334 :
335 8 : writeInsVec.push_back(std::move(writeIns));
336 8 : }
337 :
338 1 : string InsWriteReduceExtend::Describe() const
339 : {
340 : return StringFormat(
341 : "InsWriteReduceExtend[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s]",
342 4 : remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
343 5 : localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
344 : }
345 :
346 1 : RankId InsWriteReduceExtend::GetRemoteRank() const { return remoteRank_; }
347 1 : const LinkData* InsWriteReduceExtend::GetLink() const { return &link_; }
348 1 : const DataBuffer& InsWriteReduceExtend::GetLocalBuffer() const { return localBuffer_; }
349 1 : const DataBuffer& InsWriteReduceExtend::GetRemoteBuffer() const { return remoteBuffer_; }
350 1 : const DataType InsWriteReduceExtend::GetDataType() const { return dataType_; }
351 1 : const ReduceOp InsWriteReduceExtend::GetReduceOp() const { return reduceOp_; }
352 :
353 2 : string InsWriteWithFin::Describe() const
354 : {
355 : return StringFormat(
356 2 : "InsWriteWithFin[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s, bitValue=0x%x]", remoteRank_,
357 2 : link_.Describe().c_str(), localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str(), bitValue_);
358 : }
359 :
360 1 : RankId InsWriteWithFin::GetRemoteRank() const { return remoteRank_; }
361 17 : const LinkData* InsWriteWithFin::GetLink() const { return &link_; }
362 14 : const DataSlice& InsWriteWithFin::GetLocalSlice() const { return localSlice_; }
363 12 : const DataSlice& InsWriteWithFin::GetRemoteSlice() const { return remoteSlice_; }
364 :
365 0 : string InsWriteWithFinExtend::Describe() const
366 : {
367 : return StringFormat(
368 0 : "InsWriteWithFinExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s, bitValue=0x%x]", remoteRank_,
369 0 : link_.Describe().c_str(), localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str(), bitValue_);
370 : }
371 :
372 1 : RankId InsWriteWithFinExtend::GetRemoteRank() const { return remoteRank_; }
373 4 : const LinkData* InsWriteWithFinExtend::GetLink() const { return &link_; }
374 2 : const DataBuffer& InsWriteWithFinExtend::GetLocalBuffer() const { return localBuffer_; }
375 2 : const DataBuffer& InsWriteWithFinExtend::GetRemoteBuffer() const { return remoteBuffer_; }
376 :
377 2 : string InsWriteReduceWithFin::Describe() const
378 : {
379 : return StringFormat(
380 : "InsWriteReduceWithFin[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s, "
381 : "bitValue=0x%u]",
382 8 : remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
383 10 : localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str(), bitValue_);
384 : }
385 :
386 1 : RankId InsWriteReduceWithFin::GetRemoteRank() const { return remoteRank_; }
387 17 : const LinkData* InsWriteReduceWithFin::GetLink() const { return &link_; }
388 14 : const DataSlice& InsWriteReduceWithFin::GetLocalSlice() const { return localSlice_; }
389 12 : const DataSlice& InsWriteReduceWithFin::GetRemoteSlice() const { return remoteSlice_; }
390 6 : const DataType InsWriteReduceWithFin::GetDataType() const { return dataType_; }
391 6 : const ReduceOp InsWriteReduceWithFin::GetReduceOp() const { return reduceOp_; }
392 :
393 1 : string InsWriteReduceWithFinExtend::Describe() const
394 : {
395 : return StringFormat(
396 : "InsWriteReduceWithFin[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s, "
397 : "bitValue=0x%u]",
398 4 : remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
399 5 : localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str(), bitValue_);
400 : }
401 :
402 1 : RankId InsWriteReduceWithFinExtend::GetRemoteRank() const { return remoteRank_; }
403 1 : const LinkData* InsWriteReduceWithFinExtend::GetLink() const { return &link_; }
404 1 : const DataBuffer& InsWriteReduceWithFinExtend::GetLocalBuffer() const { return localBuffer_; }
405 1 : const DataBuffer& InsWriteReduceWithFinExtend::GetRemoteBuffer() const { return remoteBuffer_; }
406 1 : const DataType InsWriteReduceWithFinExtend::GetDataType() const { return dataType_; }
407 1 : const ReduceOp InsWriteReduceWithFinExtend::GetReduceOp() const { return reduceOp_; }
408 0 : const NotifyType& InsWriteReduceWithFinExtend::GetNotifyType() const { return notifyType_; }
409 0 : const u32& InsWriteReduceWithFinExtend::GetTopicId() const { return topicId_; }
410 0 : const u32& InsWriteReduceWithFinExtend::GetBitValue() const { return bitValue_; }
411 :
412 622 : const InstructionType Instruction::GetType() const { return type_; }
413 :
414 6 : const NotifyType& InsWriteWithFin::GetNotifyType() const { return notifyType_; }
415 :
416 3 : const u32& InsWriteWithFin::GetTopicId() const { return topicId_; }
417 :
418 3 : const u32& InsWriteWithFin::GetBitValue() const { return bitValue_; }
419 :
420 6 : const NotifyType& InsWriteReduceWithFin::GetNotifyType() const { return notifyType_; }
421 3 : const u32& InsWriteReduceWithFin::GetTopicId() const { return topicId_; }
422 :
423 3 : const u32& InsWriteReduceWithFin::GetBitValue() const { return bitValue_; }
424 :
425 1 : string InsBatchOneSidedRead::Describe() const
426 : {
427 1 : return StringFormat("InsBatchOneSidedRead[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
428 : }
429 :
430 1 : RankId InsBatchOneSidedRead::GetRemoteRank() const { return remoteRank_; }
431 1 : const LinkData* InsBatchOneSidedRead::GetLink() const { return &link_; }
432 :
433 1 : const vector<RmaBufSliceLite>& InsBatchOneSidedRead::GetLocalSlice() const { return localSlice_; }
434 :
435 1 : const vector<RmtRmaBufSliceLite>& InsBatchOneSidedRead::GetRemoteSlice() const { return remoteSlice_; }
436 :
437 1 : string InsBatchOneSidedWrite::Describe() const
438 : {
439 1 : return StringFormat("InsBatchOneSidedWrite[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
440 : }
441 :
442 1 : RankId InsBatchOneSidedWrite::GetRemoteRank() const { return remoteRank_; }
443 1 : const LinkData* InsBatchOneSidedWrite::GetLink() const { return &link_; }
444 1 : const vector<RmaBufSliceLite>& InsBatchOneSidedWrite::GetLocalSlice() const { return localSlice_; }
445 :
446 1 : const vector<RmtRmaBufSliceLite>& InsBatchOneSidedWrite::GetRemoteSlice() const { return remoteSlice_; }
447 :
448 1 : string InsStreamSync::Describe() const { return StringFormat("InsStreamSync"); }
449 :
450 2 : string InsAicpuReduce::Describe() const
451 : {
452 : return StringFormat(
453 4 : "InsAicpuReduce[dataType=%s, reduceOp=%s, srcSlice=%s, dstSlice=%s]", dataType_.Describe().c_str(),
454 6 : reduceOp_.Describe().c_str(), srcSlice_.Describe().c_str(), dstSlice_.Describe().c_str());
455 : }
456 9 : const DataSlice& InsAicpuReduce::GetSrcSlice() const { return srcSlice_; }
457 6 : const DataSlice& InsAicpuReduce::GetDstSlice() const { return dstSlice_; }
458 3 : const DataType InsAicpuReduce::GetDataType() const { return dataType_; }
459 3 : const ReduceOp InsAicpuReduce::GetReduceOp() const { return reduceOp_; }
460 :
461 : template <typename T>
462 4 : void InsAicpuReduce::AicpuReduceTemplate(T* dst, u64 dstSize, T* src, u64 srcSize, ReduceOp reduceOp)
463 : {
464 4 : if (dst == nullptr || src == nullptr) {
465 0 : THROW<NullPtrException>(StringFormat("nsAicpuReduce::AicpuReduceTemplate dst or src is nullptr"));
466 : }
467 4 : if (dstSize != srcSize) {
468 0 : string msg = StringFormat("srcSize[" PRIu64 "] should be equal to dstSize[" PRIu64 "]", srcSize, dstSize);
469 0 : THROW<InternalException>(msg);
470 0 : }
471 4 : u64 count = dstSize / u64(sizeof(T));
472 8 : for (u64 i = 0; i < count; ++i) {
473 4 : T dstData = *(dst + i);
474 4 : T srcData = *(src + i);
475 4 : switch (reduceOp) {
476 1 : case ReduceOp::SUM:
477 1 : *(dst + i) = srcData + dstData;
478 1 : break;
479 1 : case ReduceOp::PROD:
480 1 : *(dst + i) = srcData * dstData;
481 1 : break;
482 1 : case ReduceOp::MAX:
483 1 : *(dst + i) = std::max(srcData, dstData);
484 1 : break;
485 1 : case ReduceOp::MIN:
486 1 : *(dst + i) = std::min(srcData, dstData);
487 1 : break;
488 0 : default:
489 0 : string msg = StringFormat("ReduceOp[%d] not support", int(reduceOp));
490 0 : THROW<NotSupportException>(msg);
491 : break;
492 0 : }
493 : }
494 4 : }
495 :
496 4 : void InsAicpuReduce::RunAicpuReduce(
497 : void* dst, u64 dstSize, void* src, u64 srcSize, DataType dataType, ReduceOp reduceOp)
498 : {
499 4 : switch (dataType) {
500 2 : case DataType::INT64:
501 2 : AicpuReduceTemplate<int64_t>((int64_t*)(dst), dstSize, (int64_t*)(src), srcSize, reduceOp);
502 2 : break;
503 1 : case DataType::UINT64:
504 1 : AicpuReduceTemplate<uint64_t>((uint64_t*)(dst), dstSize, (uint64_t*)(src), srcSize, reduceOp);
505 1 : break;
506 1 : case DataType::FP64:
507 1 : AicpuReduceTemplate<double>((double*)(dst), dstSize, (double*)(src), srcSize, reduceOp);
508 1 : break;
509 0 : default:
510 0 : string msg = StringFormat("DataType[%d] not support", int(dataType));
511 0 : THROW<NotSupportException>(msg);
512 : break;
513 : }
514 4 : }
515 :
516 6 : string InsPreStreamSync::Describe() const { return StringFormat("InsPreStreamSync"); }
517 : } // namespace Hccl
|