LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_template/prim_alg_template - alg_template_base_v2.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 100 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 20 0

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "alg_template_base_v2.h"
      12              : #include "log.h"
      13              : 
      14              : namespace Hccl {
      15            0 : AlgTemplateBase::AlgTemplateBase(const RankId virtualRank, const u32 tempRankSize,
      16              :                                  const std::vector<std::vector<RankId>> &tempVTopo,
      17            0 :                                  const std::map<RankId, u32>            &tempVirtRankMap)
      18            0 :     : myRank_(virtualRank), tempRankSize_(tempRankSize), tempVTopo_(tempVTopo), tempVirtRankMap_(tempVirtRankMap)
      19              : {
      20            0 : }
      21              : 
      22            0 : AlgTemplateBase::~AlgTemplateBase()
      23              : {
      24            0 : }
      25              : 
      26            0 : void AlgTemplateBase::SetDmaMode(const DmaMode dmaMode)
      27              : {
      28            0 :     dmaMode_ = dmaMode;
      29            0 :     return;
      30              : }
      31              : 
      32            0 : HcclResult AlgTemplateBase::PostCopyOpbase(const UsrData &usrData, std::vector<PrimQuePtr> &tempPrimQues) const
      33              : {
      34            0 :     for (u32 i = 0; i < usrData.scratchOutSlices.size(); i++) {
      35              :         std::unique_ptr<Primitive> primLocalCopy
      36            0 :             = std::make_unique<PrimLocalCopy>(usrData.scratchOutSlices[i], usrData.usrOutSlices[i]);
      37            0 :         tempPrimQues[0]->Append(std::move(primLocalCopy));
      38            0 :     }
      39              : 
      40            0 :     return HcclResult::HCCL_SUCCESS;
      41              : }
      42              : 
      43            0 : HcclResult AlgTemplateBase::PreCopyOpbase(const UsrData &usrData, std::vector<PrimQuePtr> &tempPrimQues) const
      44              : {
      45            0 :     for (u32 i = 0; i < usrData.usrInSlices.size(); i++) {
      46              :         std::unique_ptr<Primitive> primLocalCopy
      47            0 :             = std::make_unique<PrimLocalCopy>(usrData.usrInSlices[i], usrData.scratchInSlices[i]);
      48            0 :         tempPrimQues[0]->Append(std::move(primLocalCopy));
      49            0 :     }
      50              : 
      51            0 :     return HcclResult::HCCL_SUCCESS;
      52              : }
      53              : 
      54            0 : HcclResult AlgTemplateBase::CalcSliceInfo(const AllignInfo &allignInfo, const bool forAllReduce, const u64 dataSize,
      55              :                                           RankSliceInfo &sliceInfoVec)
      56              : {
      57              :     (void)allignInfo;
      58              :     (void)forAllReduce;
      59              :     (void)dataSize;
      60              :     (void)sliceInfoVec;
      61            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of slice info calculation!");
      62            0 :     return HcclResult::HCCL_E_INTERNAL;
      63              : }
      64              : 
      65            0 : HcclResult AlgTemplateBase::CalcSliceInfo(const AllignInfo &allignInfo, const u64 dataSize, RankSliceInfo &sliceInfoVec)
      66              : {
      67              :     (void)allignInfo;
      68              :     (void)dataSize;
      69              :     (void)sliceInfoVec;
      70            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of slice info calculation!");
      71            0 :     return HcclResult::HCCL_E_INTERNAL;
      72              : }
      73              : 
      74            0 : HcclResult AlgTemplateBase::CalcRes(const bool forAllReduce, AlgTempResReq &tempResReq, u32 &requiredScratchMultiplier)
      75              : {
      76              :     (void)forAllReduce;
      77              :     (void)tempResReq;
      78              :     (void)requiredScratchMultiplier;
      79            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
      80            0 :     return HcclResult::HCCL_E_INTERNAL;
      81              : }
      82              : 
      83            0 : HcclResult AlgTemplateBase::CalcResDetour(const bool forAllReduce, const RankGraph *rankGraph,
      84              :                                           AlgTempResReq &tempResReq, u32 &requiredScratchMultiplier)
      85              : {
      86              :     (void)forAllReduce;
      87              :     (void)tempResReq;
      88              :     (void)rankGraph;
      89              :     (void)requiredScratchMultiplier;
      90            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
      91            0 :     return HcclResult::HCCL_E_INTERNAL;
      92              : }
      93              : 
      94            0 : HcclResult AlgTemplateBase::CalcResDetour(const bool forAllReduce, ConnectedLinkMgr *linkMgr, AlgTempResReq &tempResReq,
      95              :                                           u32 &requiredScratchMultiplier)
      96              : {
      97              :     (void)forAllReduce;
      98              :     (void)linkMgr;
      99              :     (void)tempResReq;
     100              :     (void)requiredScratchMultiplier;
     101            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
     102            0 :     return HcclResult::HCCL_E_INTERNAL;
     103              : }
     104              : 
     105            0 : HcclResult AlgTemplateBase::CalcRes(AlgTempResReq &tempResReq)
     106              : {
     107              :     (void)tempResReq;
     108            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
     109            0 :     return HcclResult::HCCL_E_INTERNAL;
     110              : }
     111              : 
     112            0 : HcclResult AlgTemplateBase::CalcResDetour(const RankGraph *rankGraph, AlgTempResReq &tempResReq)
     113              : {
     114              :     (void)rankGraph;
     115              :     (void)tempResReq;
     116            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
     117            0 :     return HcclResult::HCCL_E_INTERNAL;
     118              : }
     119              : 
     120            0 : HcclResult AlgTemplateBase::CalcResDetour(ConnectedLinkMgr *linkMgr, AlgTempResReq &tempResReq)
     121              : {
     122              :     (void)linkMgr;
     123              :     (void)tempResReq;
     124            0 :     HCCL_ERROR("[CollAlgFactory] Unsupported interface of resource calculation!");
     125            0 :     return HcclResult::HCCL_E_INTERNAL;
     126              : }
     127              : 
     128            0 : void AlgTemplateBase::InitReduceInfo(const ReduceOp &redOp, const DataType &dataType)
     129              : {
     130            0 :     redOp_    = redOp;
     131            0 :     dataType_ = dataType;
     132              : 
     133            0 :     return;
     134              : }
     135              : 
     136            0 : void AlgTemplateBase::SetDataType(const DataType &dataType)
     137              : {
     138            0 :     dataType_ = dataType;
     139              : 
     140            0 :     return;
     141              : }
     142              : 
     143            0 : HcclResult AlgTemplateBase::PreSync(const u32 queIdx, std::vector<PrimQuePtr> &syncPrimQues) const
     144              : {
     145            0 :     PrimQuePtr currPrimQue = syncPrimQues[queIdx];
     146            0 :     if (queIdx == 0) {
     147              :         // Semaphore Post
     148            0 :         for (u32 qidx = 1; qidx < syncPrimQues.size(); qidx++) {
     149            0 :             std::unique_ptr<Primitive> primPostTo = std::make_unique<PrimPostTo>(syncPrimQues[qidx]);
     150            0 :             CHK_PTR_NULL(primPostTo);
     151            0 :             currPrimQue->Append(std::move(primPostTo));
     152            0 :         }
     153              :     } else {
     154              :         // Semaphore Wait
     155            0 :         std::unique_ptr<Primitive> primWaitFrom = std::make_unique<PrimWaitFrom>(syncPrimQues[0]);
     156            0 :         CHK_PTR_NULL(primWaitFrom);
     157            0 :         currPrimQue->Append(std::move(primWaitFrom));
     158            0 :     }
     159              : 
     160            0 :     return HcclResult::HCCL_SUCCESS;
     161            0 : }
     162              : 
     163            0 : HcclResult AlgTemplateBase::PostSync(const u32 queIdx, std::vector<PrimQuePtr> &syncPrimQues) const
     164              : {
     165            0 :     PrimQuePtr currPrimQue = syncPrimQues[queIdx];
     166            0 :     if (queIdx == 0) {
     167              :         // Semaphore Wait
     168            0 :         if (enableCounterNotify_) {
     169            0 :             std::unique_ptr<PrimWaitGroup> primWaitGroup = std::make_unique<PrimWaitGroup>();
     170            0 :             for (u32 qidx = 1; qidx < syncPrimQues.size(); qidx++) {
     171            0 :                 primWaitGroup->Append(syncPrimQues[qidx]);
     172              :             }
     173            0 :             CHK_PTR_NULL(primWaitGroup);
     174            0 :             currPrimQue->Append(std::move(primWaitGroup));
     175            0 :         } else {
     176            0 :             for (u32 qidx = 1; qidx < syncPrimQues.size(); qidx++) {
     177            0 :                 std::unique_ptr<Primitive> primWaitFrom = std::make_unique<PrimWaitFrom>(syncPrimQues[qidx]);
     178            0 :                 CHK_PTR_NULL(primWaitFrom);
     179            0 :                 currPrimQue->Append(std::move(primWaitFrom));
     180            0 :             }
     181              :         }
     182              :     } else {
     183              :         // Semaphore Post
     184            0 :         if (enableCounterNotify_) {
     185            0 :             std::unique_ptr<Primitive> primPostTo = std::make_unique<PrimPostTo>(syncPrimQues[0], NotifyType::COUNTER);
     186            0 :             CHK_PTR_NULL(primPostTo);
     187            0 :             currPrimQue->Append(std::move(primPostTo));
     188            0 :         } else {
     189            0 :             std::unique_ptr<Primitive> primPostTo = std::make_unique<PrimPostTo>(syncPrimQues[0]);
     190            0 :             CHK_PTR_NULL(primPostTo);
     191            0 :             currPrimQue->Append(std::move(primPostTo));
     192            0 :         }
     193              :     }
     194              : 
     195            0 :     return HcclResult::HCCL_SUCCESS;
     196            0 : }
     197              : 
     198            0 : HcclResult AlgTemplateBase::PreSyncInterQueues(std::vector<PrimQuePtr> &syncPrimQues) const
     199              : {
     200            0 :     for (u32 queIdx = 0; queIdx < syncPrimQues.size(); queIdx++) {
     201            0 :         CHK_PRT_RET(PreSync(queIdx, syncPrimQues) != HcclResult::HCCL_SUCCESS,
     202              :                     HCCL_ERROR("[CollAlgFactory] Rank [%d], Que [%u], Semaphore Synchronization Failed.", myRank_,
     203              :                                syncPrimQues[queIdx]->GetId()),
     204              :                     HcclResult::HCCL_E_INTERNAL);
     205              :     }
     206              : 
     207            0 :     return HcclResult::HCCL_SUCCESS;
     208              : }
     209              : 
     210            0 : HcclResult AlgTemplateBase::PostSyncInterQueues(std::vector<PrimQuePtr> &syncPrimQues) const
     211              : {
     212            0 :     for (u32 queIdx = 0; queIdx < syncPrimQues.size(); queIdx++) {
     213            0 :         CHK_PRT_RET(PostSync(queIdx, syncPrimQues) != HcclResult::HCCL_SUCCESS,
     214              :                     HCCL_ERROR("[CollAlgFactory] Rank [%d], Que [%u], Semaphore Synchronization Failed.", myRank_,
     215              :                                syncPrimQues[queIdx]->GetId()),
     216              :                     HcclResult::HCCL_E_INTERNAL);
     217              :     }
     218              : 
     219            0 :     return HcclResult::HCCL_SUCCESS;
     220              : }
     221              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1