LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/instruction - instruction.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.6 % 438 410
Test Date: 2026-07-28 12:11:00 Functions: 96.4 % 166 160

            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           96 :     return StringFormat("InsLocalCopy[srcSlice=%s, dstSlice=%s]", srcSlice_.Describe().c_str(),
      19          144 :                         dstSlice_.Describe().c_str());
      20              : }
      21           13 : const DataSlice &InsLocalCopy::GetSrcSlice() const
      22              : {
      23           13 :     return srcSlice_;
      24              : }
      25            6 : const DataSlice &InsLocalCopy::GetDstSlice() const
      26              : {
      27            6 :     return dstSlice_;
      28              : }
      29              : 
      30            0 : string InsLocalCopyExtend::Describe() const
      31              : {
      32            0 :     return StringFormat("InsLocalCopyExtend[srcBuffer=%s, dstBuffer=%s]", srcBuffer_.Describe().c_str(),
      33            0 :                         dstBuffer_.Describe().c_str());
      34              : }
      35            5 : const DataBuffer &InsLocalCopyExtend::GetSrcBuffer() const
      36              : {
      37            5 :     return srcBuffer_;
      38              : }
      39            1 : const DataBuffer &InsLocalCopyExtend::GetDstBuffer() const
      40              : {
      41            1 :     return dstBuffer_;
      42              : }
      43              : 
      44            3 : string InsLocalReduce::Describe() const
      45              : {
      46              :     return StringFormat("InsLocalReduce[dataType=%s, reduceOp=%s, srcSlice=%s, dstSlice=%s]",
      47           12 :                         dataType_.Describe().c_str(), reduceOp_.Describe().c_str(), srcSlice_.Describe().c_str(),
      48           15 :                         dstSlice_.Describe().c_str());
      49              : }
      50           14 : const DataSlice &InsLocalReduce::GetSrcSlice() const
      51              : {
      52           14 :     return srcSlice_;
      53              : }
      54            8 : const DataSlice &InsLocalReduce::GetDstSlice() const
      55              : {
      56            8 :     return dstSlice_;
      57              : }
      58            8 : const DataType InsLocalReduce::GetDataType() const
      59              : {
      60            8 :     return dataType_;
      61              : }
      62            6 : const ReduceOp InsLocalReduce::GetReduceOp() const
      63              : {
      64            6 :     return reduceOp_;
      65              : }
      66              : 
      67            8 : string InsLocalPostTo::Describe() const
      68              : {
      69              :     return StringFormat("InsLocalPostTo[notifyType=%s, postQid=%u, waitQid=%u, topicId=%u]",
      70            8 :                         notifyType_.Describe().c_str(), postQid_, waitQid_, topicId_);
      71              : }
      72              : 
      73           38 : void InsLocalPostTo::SetPostQid(QId qid)
      74              : {
      75           38 :     if (waitQid_ == qid) {
      76            1 :         THROW<InvalidParamsException>("post Qid is equal to wait Qid");
      77              :     }
      78           37 :     postQid_ = qid;
      79           37 : }
      80              : 
      81            9 : QId InsLocalPostTo::GetPostQid() const
      82              : {
      83            9 :     return postQid_;
      84              : }
      85           14 : QId InsLocalPostTo::GetWaitQid() const
      86              : {
      87           14 :     return waitQid_;
      88              : }
      89           12 : u32 InsLocalPostTo::GetTopicId() const
      90              : {
      91           12 :     return topicId_;
      92              : }
      93           13 : NotifyType InsLocalPostTo::GetNotifyType() const
      94              : {
      95           13 :     return notifyType_;
      96              : }
      97              : 
      98            8 : string InsLocalWaitFrom::Describe() const
      99              : {
     100            8 :     return StringFormat("InsLocalWaitFrom[waitQid=%u, postQid=%u, topicId=%u]", waitQid_, postQid_, topicId_);
     101              : }
     102              : 
     103           38 : void InsLocalWaitFrom::SetWaitQid(QId qid)
     104              : {
     105           38 :     if (postQid_ == qid) {
     106            1 :         THROW<InvalidParamsException>("post Qid is equal to wait Qid");
     107              :     }
     108           37 :     waitQid_ = qid;
     109           37 : }
     110              : 
     111           14 : QId InsLocalWaitFrom::GetPostQid() const
     112              : {
     113           14 :     return postQid_;
     114              : }
     115            9 : QId InsLocalWaitFrom::GetWaitQid() const
     116              : {
     117            9 :     return waitQid_;
     118              : }
     119           12 : u32 InsLocalWaitFrom::GetTopicId() const
     120              : {
     121           12 :     return topicId_;
     122              : }
     123           12 : NotifyType InsLocalWaitFrom::GetNotifyType() const
     124              : {
     125           12 :     return notifyType_;
     126              : }
     127              : 
     128              : using Iterator = BaseConstIterator<vector, QId>;
     129            6 : void InsLocalWaitGroup::Append(QId postQid)
     130              : {
     131            6 :     postQids_.push_back(postQid);
     132            6 : }
     133            5 : string InsLocalWaitGroup::Describe() const
     134              : {
     135            5 :     std::string postQidsStr;
     136           12 :     for (u32 idx = 0; idx < postQids_.size(); idx++) {
     137            7 :         postQidsStr += StringFormat("%u, ", postQids_[idx]);
     138              :     }
     139            5 :     if (!postQidsStr.empty()) {
     140            4 :         u32 redundantLen = 2;
     141            4 :         postQidsStr      = postQidsStr.substr(0, postQidsStr.size() - redundantLen);
     142              :     }
     143              : 
     144            5 :     return StringFormat("InsLocalWaitGroup[waitQid=%u, topicId=%u, postQidNum=%zu, postQids=postQidList[%s]]", waitQid_,
     145           10 :                         topicId_, postQids_.size(), postQidsStr.c_str());
     146            5 : }
     147            7 : QId InsLocalWaitGroup::GetWaitQid() const
     148              : {
     149            7 :     return waitQid_;
     150              : }
     151            7 : u32 InsLocalWaitGroup::GetTopicId() const
     152              : {
     153            7 :     return topicId_;
     154              : }
     155            3 : void InsLocalWaitGroup::SetWaitQid(QId qId)
     156              : {
     157            4 :     for (auto iter = Iter(); iter.HasNext(); ++iter) {
     158            2 :         if (*iter == qId) {
     159            1 :             THROW<InvalidParamsException>("One of post Qids is equal to wait Qid");
     160              :         }
     161              :     }
     162              : 
     163            2 :     waitQid_ = qId;
     164            2 : }
     165              : 
     166            4 : void InsLocalBcastPost::Append(QId waitQid)
     167              : {
     168            4 :     waitQids_.push_back(waitQid);
     169            4 : }
     170            3 : string InsLocalBcastPost::Describe() const
     171              : {
     172            3 :     std::string waitQidsStr;
     173            9 :     for (u32 idx = 0; idx < waitQids_.size(); idx++) {
     174            6 :         waitQidsStr += StringFormat("%u, ", waitQids_[idx]);
     175              :     }
     176            3 :     if (!waitQidsStr.empty()) {
     177            3 :         u32 redundantLen = 2;
     178            3 :         waitQidsStr      = waitQidsStr.substr(0, waitQidsStr.size() - redundantLen);
     179              :     }
     180              : 
     181            3 :     return StringFormat("InsLocalBcastPost[postQid=%d, topicId=%d, waitQidNum=%u, waitQids=waitQidList[%s]]", postQid_,
     182            6 :                         topicId_, waitQids_.size(), waitQidsStr.c_str());
     183            3 : }
     184            6 : QId InsLocalBcastPost::GetPostQid() const
     185              : {
     186            6 :     return postQid_;
     187              : }
     188            6 : u32 InsLocalBcastPost::GetTopicId() const
     189              : {
     190            6 :     return topicId_;
     191              : }
     192            1 : void InsLocalBcastPost::SetPostQid(QId qId)
     193              : {
     194            1 :     for (auto iter = Iter(); iter.HasNext(); ++iter) {
     195            0 :         if (*iter == qId) {
     196            0 :             THROW<InvalidParamsException>("One of post Qids is equal to wait Qid");
     197              :         }
     198              :     }
     199              : 
     200            1 :     postQid_ = qId;
     201            1 : }
     202              : 
     203            4 : string InsPostReady::Describe() const
     204              : {
     205            4 :     return StringFormat("InsPostReady:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
     206              : }
     207            3 : RankId InsPostReady::GetRemoteRank() const
     208              : {
     209            3 :     return remoteRank_;
     210              : }
     211           11 : const LinkData *InsPostReady::GetLink() const
     212              : {
     213           11 :     return &link_;
     214              : }
     215              : 
     216            5 : string InsWaitReady::Describe() const
     217              : {
     218            5 :     return StringFormat("InsWaitReady:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
     219              : }
     220            4 : RankId InsWaitReady::GetRemoteRank() const
     221              : {
     222            4 :     return remoteRank_;
     223              : }
     224           16 : const LinkData *InsWaitReady::GetLink() const
     225              : {
     226           16 :     return &link_;
     227              : }
     228              : 
     229            4 : string InsPostFin::Describe() const
     230              : {
     231            4 :     return StringFormat("InsPostFin:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
     232              : }
     233            3 : RankId InsPostFin::GetRemoteRank() const
     234              : {
     235            3 :     return remoteRank_;
     236              : }
     237           11 : const LinkData *InsPostFin::GetLink() const
     238              : {
     239           11 :     return &link_;
     240              : }
     241              : 
     242            4 : string InsWaitFin::Describe() const
     243              : {
     244            4 :     return StringFormat("InsWaitFin:remoteRank=%d, link=%s", remoteRank_, link_.Describe().c_str());
     245              : }
     246            3 : RankId InsWaitFin::GetRemoteRank() const
     247              : {
     248            3 :     return remoteRank_;
     249              : }
     250           11 : const LinkData *InsWaitFin::GetLink() const
     251              : {
     252           11 :     return &link_;
     253              : }
     254              : 
     255            2 : string InsWaitGroupFin::Describe() const
     256              : {
     257            2 :     string linksStr;
     258            4 :     for (auto iter = links_.begin(); iter != links_.end(); ++iter) {
     259            2 :         linksStr += iter->Describe();
     260              :     }
     261            2 :     if (!linksStr.empty()) {
     262            2 :         u32 redundantLen = 2;
     263            2 :         linksStr = linksStr.substr(0, linksStr.size() - redundantLen);
     264              :     }
     265            4 :     return StringFormat("InsWaitGroupFin[topicId=%u, value=0x%x, links=%s]", topicId_, value_, linksStr.c_str());
     266            2 : }
     267            2 : u32 InsWaitGroupFin::GetTopicId() const
     268              : {
     269            2 :     return topicId_;
     270              : }
     271            2 : void InsWaitGroupFin::Append(LinkData link)
     272              : {
     273            2 :     links_.push_back(link);
     274            2 : }
     275              : 
     276            3 : u32 InsWaitGroupFin::GetValue() const
     277              : {
     278            3 :     return value_;
     279              : }
     280              : 
     281            3 : string InsPostFinAck::Describe() const
     282              : {
     283            3 :     return StringFormat("InsPostFinAck[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
     284              : }
     285            2 : RankId InsPostFinAck::GetRemoteRank() const
     286              : {
     287            2 :     return remoteRank_;
     288              : }
     289            8 : const LinkData *InsPostFinAck::GetLink() const
     290              : {
     291            8 :     return &link_;
     292              : }
     293              : 
     294            3 : string InsWaitFinAck::Describe() const
     295              : {
     296            3 :     return StringFormat("InsWaitFinAck[remoteRank=%d, link=%s]", remoteRank_, link_.Describe().c_str());
     297              : }
     298            2 : RankId InsWaitFinAck::GetRemoteRank() const
     299              : {
     300            2 :     return remoteRank_;
     301              : }
     302            8 : const LinkData *InsWaitFinAck::GetLink() const
     303              : {
     304            8 :     return &link_;
     305              : }
     306              : 
     307            5 : string InsRead::Describe() const
     308              : {
     309            5 :     return StringFormat("InsRead[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
     310            5 :                         link_.Describe().c_str(), localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
     311              : }
     312              : 
     313            2 : RankId InsRead::GetRemoteRank() const
     314              : {
     315            2 :     return remoteRank_;
     316              : }
     317           16 : const LinkData *InsRead::GetLink() const
     318              : {
     319           16 :     return &link_;
     320              : }
     321           24 : const DataSlice &InsRead::GetLocalSlice() const
     322              : {
     323           24 :     return localSlice_;
     324              : }
     325           19 : const DataSlice &InsRead::GetRemoteSlice() const
     326              : {
     327           19 :     return remoteSlice_;
     328              : }
     329              : 
     330            2 : string InsReadReduce::Describe() const
     331              : {
     332              :     return StringFormat(
     333            2 :         "InsReadReduce[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
     334            8 :         link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     335           10 :         localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
     336              : }
     337              : 
     338            1 : string InsReadExtend::Describe() const
     339              : {
     340            1 :     return StringFormat("InsReadExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_,
     341            1 :                         link_.Describe().c_str(), localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
     342              : }
     343              :  
     344            1 : RankId InsReadExtend::GetRemoteRank() const
     345              : {
     346            1 :     return remoteRank_;
     347              : }
     348            1 : const LinkData *InsReadExtend::GetLink() const
     349              : {
     350            1 :     return &link_;
     351              : }
     352            1 : const DataBuffer &InsReadExtend::GetLocalBuffer() const
     353              : {
     354            1 :     return localBuffer_;
     355              : }
     356            1 : const DataBuffer &InsReadExtend::GetRemoteBuffer() const
     357              : {
     358            1 :     return remoteBuffer_;
     359              : }
     360              : 
     361            1 : RankId InsReadReduce::GetRemoteRank() const
     362              : {
     363            1 :     return remoteRank_;
     364              : }
     365           10 : const LinkData *InsReadReduce::GetLink() const
     366              : {
     367           10 :     return &link_;
     368              : }
     369           18 : const DataSlice &InsReadReduce::GetLocalSlice() const
     370              : {
     371           18 :     return localSlice_;
     372              : }
     373           16 : const DataSlice &InsReadReduce::GetRemoteSlice() const
     374              : {
     375           16 :     return remoteSlice_;
     376              : }
     377            5 : const DataType InsReadReduce::GetDataType() const
     378              : {
     379            5 :     return dataType_;
     380              : }
     381            5 : const ReduceOp InsReadReduce::GetReduceOp() const
     382              : {
     383            5 :     return reduceOp_;
     384              : }
     385              : 
     386            1 : string InsBatchRead::Describe() const
     387              : {
     388              :     return StringFormat("InsBatchRead[remoteRank=%d, link=%s, readInsVec size=%zu]",
     389            2 :                         remoteRank, link.Describe().c_str(), readInsVec.size());
     390              : }
     391              : 
     392            1 : RankId InsBatchRead::GetRemoteRank() const
     393              : {
     394            1 :     return remoteRank;
     395              : }
     396              : 
     397           13 : const LinkData *InsBatchRead::GetLink() const
     398              : {
     399           13 :     return &link;
     400              : }
     401              : 
     402            9 : void InsBatchRead::PushReadIns(unique_ptr<Instruction> readIns)
     403              : {
     404            9 :     if (readIns->GetType() != InstructionType::READ && readIns->GetType() != InstructionType::READ_REDUCE) {
     405            1 :         THROW<NotSupportException>(StringFormat("[InsBatchRead][%s] only support read and readReduce instruction type, "
     406            3 :         "but get instruction type[%s]", __func__, readIns->GetType().Describe().c_str()));
     407              :     }
     408              : 
     409            8 :     readInsVec.push_back(std::move(readIns));
     410            8 : }
     411              : 
     412            1 : string InsReadReduceExtend::Describe() const
     413              : {
     414              :     return StringFormat(
     415            1 :         "InsReadReduceExtend[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_,
     416            4 :         link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     417            5 :         localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
     418              : }
     419              :  
     420            1 : RankId InsReadReduceExtend::GetRemoteRank() const
     421              : {
     422            1 :     return remoteRank_;
     423              : }
     424            1 : const LinkData *InsReadReduceExtend::GetLink() const
     425              : {
     426            1 :     return &link_;
     427              : }
     428            1 : const DataBuffer &InsReadReduceExtend::GetLocalBuffer() const
     429              : {
     430            1 :     return localBuffer_;
     431              : }
     432            1 : const DataBuffer &InsReadReduceExtend::GetRemoteBuffer() const
     433              : {
     434            1 :     return remoteBuffer_;
     435              : }
     436            1 : const DataType InsReadReduceExtend::GetDataType() const
     437              : {
     438            1 :     return dataType_;
     439              : }
     440            1 : const ReduceOp InsReadReduceExtend::GetReduceOp() const
     441              : {
     442            1 :     return reduceOp_;
     443              : }
     444              : 
     445            3 : string InsWrite::Describe() const
     446              : {
     447            3 :     return StringFormat("InsWrite[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
     448            3 :                         link_.Describe().c_str(), localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
     449              : }
     450              : 
     451            1 : RankId InsWrite::GetRemoteRank() const
     452              : {
     453            1 :     return remoteRank_;
     454              : }
     455           14 : const LinkData *InsWrite::GetLink() const
     456              : {
     457           14 :     return &link_;
     458              : }
     459           22 : const DataSlice &InsWrite::GetLocalSlice() const
     460              : {
     461           22 :     return localSlice_;
     462              : }
     463           20 : const DataSlice &InsWrite::GetRemoteSlice() const
     464              : {
     465           20 :     return remoteSlice_;
     466              : }
     467              : 
     468            0 : string InsWriteExtend::Describe() const
     469              : {
     470            0 :     return StringFormat("InsWriteExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_,
     471            0 :                         link_.Describe().c_str(), localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
     472              : }
     473              :  
     474            1 : RankId InsWriteExtend::GetRemoteRank() const
     475              : {
     476            1 :     return remoteRank_;
     477              : }
     478            2 : const LinkData *InsWriteExtend::GetLink() const
     479              : {
     480            2 :     return &link_;
     481              : }
     482            2 : const DataBuffer &InsWriteExtend::GetLocalBuffer() const
     483              : {
     484            2 :     return localBuffer_;
     485              : }
     486            1 : const DataBuffer &InsWriteExtend::GetRemoteBuffer() const
     487              : {
     488            1 :     return remoteBuffer_;
     489              : }
     490              : 
     491            2 : string InsWriteReduce::Describe() const
     492              : {
     493              :     return StringFormat(
     494            2 :         "InsWriteReduce[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s]", remoteRank_,
     495            8 :         link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     496           10 :         localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str());
     497              : }
     498              : 
     499            1 : RankId InsWriteReduce::GetRemoteRank() const
     500              : {
     501            1 :     return remoteRank_;
     502              : }
     503            7 : const LinkData *InsWriteReduce::GetLink() const
     504              : {
     505            7 :     return &link_;
     506              : }
     507           18 : const DataSlice &InsWriteReduce::GetLocalSlice() const
     508              : {
     509           18 :     return localSlice_;
     510              : }
     511           16 : const DataSlice &InsWriteReduce::GetRemoteSlice() const
     512              : {
     513           16 :     return remoteSlice_;
     514              : }
     515            4 : const DataType InsWriteReduce::GetDataType() const
     516              : {
     517            4 :     return dataType_;
     518              : }
     519            4 : const ReduceOp InsWriteReduce::GetReduceOp() const
     520              : {
     521            4 :     return reduceOp_;
     522              : }
     523              : 
     524            1 : string InsBatchWrite::Describe() const
     525              : {
     526              :     return StringFormat("InsBatchWrite[remoteRank=%d, link=%s, writeInsVec size=%zu]",
     527            2 :                         remoteRank, link.Describe().c_str(), writeInsVec.size());
     528              : }
     529              : 
     530            2 : RankId InsBatchWrite::GetRemoteRank() const
     531              : {
     532            2 :     return remoteRank;
     533              : }
     534              : 
     535           14 : const LinkData *InsBatchWrite::GetLink() const
     536              : {
     537           14 :     return &link;
     538              : }
     539              : 
     540            9 : void InsBatchWrite::PushWriteIns(unique_ptr<Instruction> writeIns)
     541              : {
     542            9 :     if (writeIns->GetType() != InstructionType::WRITE && writeIns->GetType() != InstructionType::WRITE_REDUCE) {
     543            1 :         THROW<NotSupportException>(StringFormat("[InsBatchWrite][%s] only support Write and WriteReduce instruction "
     544            3 :         "type, but get instruction type[%s]", __func__, writeIns->GetType().Describe().c_str()));
     545              :     }
     546              : 
     547            8 :     writeInsVec.push_back(std::move(writeIns));
     548            8 : }
     549              : 
     550            1 : string InsWriteReduceExtend::Describe() const
     551              : {
     552              :     return StringFormat(
     553            1 :         "InsWriteReduceExtend[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s]", remoteRank_,
     554            4 :         link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     555            5 :         localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str());
     556              : }
     557              : 
     558            1 : RankId InsWriteReduceExtend::GetRemoteRank() const
     559              : {
     560            1 :     return remoteRank_;
     561              : }
     562            1 : const LinkData *InsWriteReduceExtend::GetLink() const
     563              : {
     564            1 :     return &link_;
     565              : }
     566            1 : const DataBuffer &InsWriteReduceExtend::GetLocalBuffer() const
     567              : {
     568            1 :     return localBuffer_;
     569              : }
     570            1 : const DataBuffer &InsWriteReduceExtend::GetRemoteBuffer() const
     571              : {
     572            1 :     return remoteBuffer_;
     573              : }
     574            1 : const DataType InsWriteReduceExtend::GetDataType() const
     575              : {
     576            1 :     return dataType_;
     577              : }
     578            1 : const ReduceOp InsWriteReduceExtend::GetReduceOp() const
     579              : {
     580            1 :     return reduceOp_;
     581              : }
     582              : 
     583            2 : string InsWriteWithFin::Describe() const
     584              : {
     585              :     return StringFormat("InsWriteWithFin[remoteRank=%d, link=%s, localSlice=%s, remoteSlice=%s, bitValue=0x%x]",
     586            6 :                         remoteRank_, link_.Describe().c_str(), localSlice_.Describe().c_str(),
     587            8 :                         remoteSlice_.Describe().c_str(), bitValue_);
     588              : }
     589              : 
     590            1 : RankId InsWriteWithFin::GetRemoteRank() const
     591              : {
     592            1 :     return remoteRank_;
     593              : }
     594           17 : const LinkData *InsWriteWithFin::GetLink() const
     595              : {
     596           17 :     return &link_;
     597              : }
     598           14 : const DataSlice &InsWriteWithFin::GetLocalSlice() const
     599              : {
     600           14 :     return localSlice_;
     601              : }
     602           12 : const DataSlice &InsWriteWithFin::GetRemoteSlice() const
     603              : {
     604           12 :     return remoteSlice_;
     605              : }
     606              : 
     607            0 : string InsWriteWithFinExtend::Describe() const
     608              : {
     609              :     return StringFormat("InsWriteWithFinExtend[remoteRank=%d, link=%s, localBuffer=%s, remoteBuffer=%s, bitValue=0x%x]",
     610            0 :                         remoteRank_, link_.Describe().c_str(), localBuffer_.Describe().c_str(),
     611            0 :                         remoteBuffer_.Describe().c_str(), bitValue_);
     612              : }
     613              : 
     614            1 : RankId InsWriteWithFinExtend::GetRemoteRank() const
     615              : {
     616            1 :     return remoteRank_;
     617              : }
     618            4 : const LinkData *InsWriteWithFinExtend::GetLink() const
     619              : {
     620            4 :     return &link_;
     621              : }
     622            2 : const DataBuffer &InsWriteWithFinExtend::GetLocalBuffer() const
     623              : {
     624            2 :     return localBuffer_;
     625              : }
     626            2 : const DataBuffer &InsWriteWithFinExtend::GetRemoteBuffer() const
     627              : {
     628            2 :     return remoteBuffer_;
     629              : }
     630              : 
     631            2 : string InsWriteReduceWithFin::Describe() const
     632              : {
     633              :     return StringFormat(
     634              :         "InsWriteReduceWithFin[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localSlice=%s, remoteSlice=%s, bitValue=0x%u]",
     635            8 :         remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     636           10 :         localSlice_.Describe().c_str(), remoteSlice_.Describe().c_str(), bitValue_);
     637              : }
     638              : 
     639            1 : RankId InsWriteReduceWithFin::GetRemoteRank() const
     640              : {
     641            1 :     return remoteRank_;
     642              : }
     643           17 : const LinkData *InsWriteReduceWithFin::GetLink() const
     644              : {
     645           17 :     return &link_;
     646              : }
     647           14 : const DataSlice &InsWriteReduceWithFin::GetLocalSlice() const
     648              : {
     649           14 :     return localSlice_;
     650              : }
     651           12 : const DataSlice &InsWriteReduceWithFin::GetRemoteSlice() const
     652              : {
     653           12 :     return remoteSlice_;
     654              : }
     655            6 : const DataType InsWriteReduceWithFin::GetDataType() const
     656              : {
     657            6 :     return dataType_;
     658              : }
     659            6 : const ReduceOp InsWriteReduceWithFin::GetReduceOp() const
     660              : {
     661            6 :     return reduceOp_;
     662              : }
     663              : 
     664            1 : string InsWriteReduceWithFinExtend::Describe() const
     665              : {
     666              :     return StringFormat(
     667              :         "InsWriteReduceWithFin[remoteRank=%d, link=%s, dataType=%s, reduceOp=%s, localBuffer=%s, remoteBuffer=%s, bitValue=0x%u]",
     668            4 :         remoteRank_, link_.Describe().c_str(), dataType_.Describe().c_str(), reduceOp_.Describe().c_str(),
     669            5 :         localBuffer_.Describe().c_str(), remoteBuffer_.Describe().c_str(), bitValue_);
     670              : }
     671              : 
     672            1 : RankId InsWriteReduceWithFinExtend::GetRemoteRank() const
     673              : {
     674            1 :     return remoteRank_;
     675              : }
     676            1 : const LinkData *InsWriteReduceWithFinExtend::GetLink() const
     677              : {
     678            1 :     return &link_;
     679              : }
     680            1 : const DataBuffer &InsWriteReduceWithFinExtend::GetLocalBuffer() const
     681              : {
     682            1 :     return localBuffer_;
     683              : }
     684            1 : const DataBuffer &InsWriteReduceWithFinExtend::GetRemoteBuffer() const
     685              : {
     686            1 :     return remoteBuffer_;
     687              : }
     688            1 : const DataType InsWriteReduceWithFinExtend::GetDataType() const
     689              : {
     690            1 :     return dataType_;
     691              : }
     692            1 : const ReduceOp InsWriteReduceWithFinExtend::GetReduceOp() const
     693              : {
     694            1 :     return reduceOp_;
     695              : }
     696            0 : const NotifyType &InsWriteReduceWithFinExtend::GetNotifyType() const
     697              : {
     698            0 :     return notifyType_;
     699              : }
     700            0 : const u32 &InsWriteReduceWithFinExtend::GetTopicId() const
     701              : {
     702            0 :     return topicId_;
     703              : }
     704            0 : const u32 &InsWriteReduceWithFinExtend::GetBitValue() const
     705              : {
     706            0 :     return bitValue_;
     707              : }
     708              : 
     709          622 : const InstructionType Instruction::GetType() const
     710              : {
     711          622 :     return type_;
     712              : }
     713              : 
     714            6 : const NotifyType &InsWriteWithFin::GetNotifyType() const
     715              : {
     716            6 :     return notifyType_;
     717              : }
     718              :  
     719            3 : const u32 &InsWriteWithFin::GetTopicId() const
     720              : {
     721            3 :     return topicId_;
     722              : }
     723              : 
     724            3 : const u32 &InsWriteWithFin::GetBitValue() const
     725              : {
     726            3 :     return bitValue_;
     727              : }
     728              : 
     729            6 : const NotifyType &InsWriteReduceWithFin::GetNotifyType() const
     730              : {
     731            6 :     return notifyType_;
     732              : }
     733            3 : const u32 &InsWriteReduceWithFin::GetTopicId() const
     734              : {
     735            3 :     return topicId_;
     736              : }
     737              : 
     738            3 : const u32 &InsWriteReduceWithFin::GetBitValue() const
     739              : {
     740            3 :     return bitValue_;
     741              : }
     742              : 
     743            1 : string InsBatchOneSidedRead::Describe() const
     744              : {
     745            1 :     return StringFormat("InsBatchOneSidedRead[remoteRank=%d, link=%s]", remoteRank_,
     746            1 :                         link_.Describe().c_str());
     747              : }
     748              : 
     749            1 : RankId InsBatchOneSidedRead::GetRemoteRank() const
     750              : {
     751            1 :     return remoteRank_;
     752              : }
     753            1 : const LinkData *InsBatchOneSidedRead::GetLink() const
     754              : {
     755            1 :     return &link_;
     756              : }
     757              : 
     758            1 : const vector<RmaBufSliceLite> &InsBatchOneSidedRead::GetLocalSlice() const
     759              : {
     760            1 :     return localSlice_;
     761              : }
     762              : 
     763            1 : const vector<RmtRmaBufSliceLite> &InsBatchOneSidedRead::GetRemoteSlice() const
     764              : {
     765            1 :     return remoteSlice_;
     766              : }
     767              : 
     768            1 : string InsBatchOneSidedWrite::Describe() const
     769              : {
     770            1 :     return StringFormat("InsBatchOneSidedWrite[remoteRank=%d, link=%s]", remoteRank_,
     771            1 :                         link_.Describe().c_str());
     772              : }
     773              : 
     774            1 : RankId InsBatchOneSidedWrite::GetRemoteRank() const
     775              : {
     776            1 :     return remoteRank_;
     777              : }
     778            1 : const LinkData *InsBatchOneSidedWrite::GetLink() const
     779              : {
     780            1 :     return &link_;
     781              : }
     782            1 : const vector<RmaBufSliceLite> &InsBatchOneSidedWrite::GetLocalSlice() const
     783              : {
     784            1 :     return localSlice_;
     785              : }
     786              : 
     787            1 : const vector<RmtRmaBufSliceLite> &InsBatchOneSidedWrite::GetRemoteSlice() const
     788              : {
     789            1 :     return remoteSlice_;
     790              : }
     791              : 
     792            1 : string InsStreamSync::Describe() const
     793              : {
     794            1 :     return StringFormat("InsStreamSync");
     795              : }
     796              : 
     797            2 : string InsAicpuReduce::Describe() const
     798              : {
     799              :     return StringFormat("InsAicpuReduce[dataType=%s, reduceOp=%s, srcSlice=%s, dstSlice=%s]",
     800            8 :                         dataType_.Describe().c_str(), reduceOp_.Describe().c_str(), srcSlice_.Describe().c_str(),
     801           10 :                         dstSlice_.Describe().c_str());
     802              : }
     803            9 : const DataSlice &InsAicpuReduce::GetSrcSlice() const
     804              : {
     805            9 :     return srcSlice_;
     806              : }
     807            6 : const DataSlice &InsAicpuReduce::GetDstSlice() const
     808              : {
     809            6 :     return dstSlice_;
     810              : }
     811            3 : const DataType InsAicpuReduce::GetDataType() const
     812              : {
     813            3 :     return dataType_;
     814              : }
     815            3 : const ReduceOp InsAicpuReduce::GetReduceOp() const
     816              : {
     817            3 :     return reduceOp_;
     818              : }
     819              : 
     820              : template <typename T>
     821            4 : void InsAicpuReduce::AicpuReduceTemplate(T* dst, u64 dstSize, T* src, u64 srcSize, ReduceOp reduceOp)
     822              : {
     823            4 :     if (dst == nullptr || src == nullptr) {
     824            0 :         THROW<NullPtrException>(StringFormat("nsAicpuReduce::AicpuReduceTemplate dst or src is nullptr"));
     825              :     }
     826            4 :     if (dstSize != srcSize) {
     827            0 :         string msg = StringFormat("srcSize[" PRIu64 "] should be equal to dstSize[" PRIu64 "]",
     828              :                 srcSize, dstSize);
     829            0 :         THROW<InternalException>(msg);
     830            0 :     }
     831            4 :     u64 count = dstSize / u64(sizeof(T));
     832            8 :     for (u64 i = 0; i < count; ++i) {
     833            4 :         T dstData = *(dst + i);
     834            4 :         T srcData = *(src + i);
     835            4 :         switch (reduceOp) {
     836            1 :             case ReduceOp::SUM:
     837            1 :                 *(dst + i) = srcData + dstData;
     838            1 :                 break;
     839            1 :             case ReduceOp::PROD:
     840            1 :                 *(dst + i) = srcData * dstData;
     841            1 :                 break;
     842            1 :             case ReduceOp::MAX:
     843            1 :                 *(dst + i) = std::max(srcData, dstData);
     844            1 :                 break;
     845            1 :             case ReduceOp::MIN:
     846            1 :                 *(dst + i) = std::min(srcData, dstData);
     847            1 :                 break;
     848            0 :             default:
     849            0 :                 string msg = StringFormat("ReduceOp[%d] not support", int(reduceOp));
     850            0 :                 THROW<NotSupportException>(msg);
     851              :                 break;   
     852            0 :         }
     853              :     }
     854            4 : }
     855              : 
     856            4 : void InsAicpuReduce::RunAicpuReduce(void* dst, u64 dstSize, void* src, u64 srcSize, DataType dataType, ReduceOp reduceOp)
     857              : {
     858            4 :     switch (dataType) {
     859            2 :         case DataType::INT64:
     860            2 :             AicpuReduceTemplate<int64_t>((int64_t*)(dst), dstSize, (int64_t*)(src), srcSize, reduceOp);
     861            2 :             break;
     862            1 :         case DataType::UINT64:
     863            1 :             AicpuReduceTemplate<uint64_t>((uint64_t*)(dst), dstSize, (uint64_t*)(src), srcSize, reduceOp);
     864            1 :             break;
     865            1 :         case DataType::FP64:
     866            1 :             AicpuReduceTemplate<double>((double*)(dst), dstSize, (double*)(src), srcSize, reduceOp);
     867            1 :             break;
     868            0 :         default:
     869            0 :             string msg = StringFormat("DataType[%d] not support", int(dataType));
     870            0 :             THROW<NotSupportException>(msg);
     871              :             break; 
     872              :     }
     873            4 : }
     874              : 
     875            6 : string InsPreStreamSync::Describe() const
     876              : {
     877            6 :     return StringFormat("InsPreStreamSync");
     878              : }
     879              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1