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 % 102 0
Test Date: 2026-08-18 17:47:01 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(
      16              :     const RankId virtualRank, const u32 tempRankSize, const std::vector<std::vector<RankId>>& tempVTopo,
      17            0 :     const std::map<RankId, u32>& tempVirtRankMap)
      18            0 :     : myRank_(virtualRank),
      19            0 :       tempRankSize_(tempRankSize),
      20            0 :       tempVTopo_(tempVTopo),
      21            0 :       tempVirtRankMap_(tempVirtRankMap)
      22            0 : {}
      23              : 
      24            0 : AlgTemplateBase::~AlgTemplateBase() {}
      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(
      55              :     const AllignInfo& allignInfo, const bool forAllReduce, const u64 dataSize, 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(
      84              :     const bool forAllReduce, const RankGraph* rankGraph, 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(
      95              :     const bool forAllReduce, ConnectedLinkMgr* linkMgr, AlgTempResReq& tempResReq, 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(
     202              :             PreSync(queIdx, syncPrimQues) != HcclResult::HCCL_SUCCESS,
     203              :             HCCL_ERROR(
     204              :                 "[CollAlgFactory] Rank [%d], Que [%u], Semaphore Synchronization Failed.", myRank_,
     205              :                 syncPrimQues[queIdx]->GetId()),
     206              :             HcclResult::HCCL_E_INTERNAL);
     207              :     }
     208              : 
     209            0 :     return HcclResult::HCCL_SUCCESS;
     210              : }
     211              : 
     212            0 : HcclResult AlgTemplateBase::PostSyncInterQueues(std::vector<PrimQuePtr>& syncPrimQues) const
     213              : {
     214            0 :     for (u32 queIdx = 0; queIdx < syncPrimQues.size(); queIdx++) {
     215            0 :         CHK_PRT_RET(
     216              :             PostSync(queIdx, syncPrimQues) != HcclResult::HCCL_SUCCESS,
     217              :             HCCL_ERROR(
     218              :                 "[CollAlgFactory] Rank [%d], Que [%u], Semaphore Synchronization Failed.", myRank_,
     219              :                 syncPrimQues[queIdx]->GetId()),
     220              :             HcclResult::HCCL_E_INTERNAL);
     221              :     }
     222              : 
     223            0 :     return HcclResult::HCCL_SUCCESS;
     224              : }
     225              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1