LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_executor/prim_alg_executor - coll_alg_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 74 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 18 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 "coll_alg_base.h"
      12              : 
      13              : namespace Hccl {
      14              : 
      15            0 : CollAlgBase::CollAlgBase()
      16              : {
      17            0 : }
      18              : 
      19            0 : CollAlgBase::~CollAlgBase()
      20              : {
      21            0 : }
      22              : 
      23            0 : void CollAlgBase::SetMyRank(RankId myRank)
      24              : {
      25            0 :     myRank_ = myRank;
      26            0 :     return;
      27              : }
      28              : 
      29            0 : void CollAlgBase::SetRankSize(u32 rankSize)
      30              : {
      31            0 :     rankSize_ = rankSize;
      32            0 :     return;
      33              : }
      34              : 
      35            0 : void CollAlgBase::SetDevType(DevType devType)
      36              : {
      37            0 :     devType_ = devType;
      38            0 :     return;
      39              : }
      40              : 
      41            0 : void CollAlgBase::SetAllignSize(u64 allignSize)
      42              : {
      43            0 :     allignSize_ = allignSize;
      44            0 :     return;
      45              : }
      46              : 
      47            0 : void CollAlgBase::EnableDataAllign(bool enableAllign)
      48              : {
      49            0 :     enableAllign_ = enableAllign;
      50            0 :     return;
      51              : }
      52              : 
      53            0 : void CollAlgBase::EnableDetour(bool enableDetour)
      54              : {
      55            0 :     enableDetour_ = enableDetour;
      56            0 :     return;
      57              : }
      58              : 
      59            0 : void CollAlgBase::SetDmaMode(const DmaMode dmaMode)
      60              : {
      61            0 :     dmaMode_ = dmaMode;
      62            0 :     return;
      63              : }
      64              : 
      65            0 : bool CollAlgBase::IsEnableCounterNotify() const
      66              : {
      67            0 :     return IsEnableCounterNotifyByDevType(myRank_, devType_);
      68              : }
      69              : 
      70            0 : HcclResult CollAlgBase::Init(const CollAlgOperator &op, const CollAlgParams &params, PrimQuePtr primQue)
      71              : {
      72              :     // init params
      73            0 :     CHK_PRT_RET(InitParams(op, params) != HcclResult::HCCL_SUCCESS,
      74              :                 HCCL_ERROR("[CollAlgFactory] Rank [%d], Fail to init params.", myRank_), HcclResult::HCCL_E_PARA);
      75              : 
      76              :     // init queMap
      77            0 :     CHK_PRT_RET(GenPrimQueMap(primQue) != HcclResult::HCCL_SUCCESS,
      78              :                 HCCL_ERROR("[CollAlgFactory] Rank [%d], Fail to init primQueMap.", myRank_), HcclResult::HCCL_E_PARA);
      79              : 
      80            0 :     return HcclResult::HCCL_SUCCESS;
      81              : }
      82              : 
      83            0 : HcclResult CollAlgBase::InitParams(const CollAlgOperator &op, const CollAlgParams &params)
      84              : {
      85            0 :     opMode_        = params.opMode;
      86            0 :     maxTmpMemSize_ = (opMode_ == OpMode::OPBASE) ? params.maxTmpMemSize : 0;
      87              : 
      88            0 :     CHK_PRT_RET((maxTmpMemSize_ == 0) && (opMode_ == OpMode::OPBASE),
      89              :                 HCCL_ERROR("[CollAlgFactory] maxTmpMemSize equals to zero for OPBASE."), HcclResult::HCCL_E_PARA);
      90              : 
      91            0 :     CHK_PRT_RET(InitDataInfo(op, dataType_, outputDataType_, dataCount_), HCCL_ERROR("[CollAlgFactory] unable to init DataInfo."),
      92              :                 HcclResult::HCCL_E_PARA);
      93              : 
      94            0 :     CHK_PRT_RET(InitOpInfo(op, opType_, redOp_, root_), HCCL_ERROR("[CollAlgFactory] unable to init OpInfo."),
      95              :                 HcclResult::HCCL_E_PARA);
      96              : 
      97            0 :     return HcclResult::HCCL_SUCCESS;
      98              : }
      99              : 
     100            0 : HcclResult CollAlgBase::GenPrimQueMap(PrimQuePtr primQue)
     101              : {
     102            0 :     CHK_PRT_RET(!primQue->IsMaster(),
     103              :                 HCCL_ERROR("[CollAlgFactory] Rank [%d], Input Primitive Queue is not a master queue.", myRank_),
     104              :                 HcclResult::HCCL_E_PARA);
     105            0 :     queId2PrimQue_.insert(std::make_pair(primQue->GetId(), primQue));
     106            0 :     return HcclResult::HCCL_SUCCESS;
     107              : }
     108              : 
     109            0 : HcclResult CollAlgBase::InitQueue(const u32 &requiredQueNum, std::vector<PrimQuePtr> &requiredQue)
     110              : {
     111            0 :     CHK_PRT_RET(!static_cast<bool>(queId2PrimQue_.count(0)),
     112              :                 HCCL_ERROR("[CollAlgFactory] Rank [%d], Invalid queId2PrimQue Map.", myRank_),
     113              :                 HcclResult::HCCL_E_INTERNAL);
     114            0 :     PrimQuePtr primQue = queId2PrimQue_[0];
     115              : 
     116            0 :     for (u32 queIdx = 0; queIdx < requiredQueNum; queIdx++) {
     117            0 :         if (!static_cast<bool>(queId2PrimQue_.count(queIdx))) {
     118            0 :             queId2PrimQue_.insert(std::make_pair(queIdx, primQue->Fork()));
     119              :         }
     120            0 :         requiredQue.push_back(queId2PrimQue_[queIdx]);
     121              :     }
     122              : 
     123            0 :     return HcclResult::HCCL_SUCCESS;
     124            0 : }
     125              : 
     126            0 : HcclResult CollAlgBase::SetLinkPrty(const std::vector<BasePortType> &linkPriority)
     127              : {
     128            0 :     CHK_PRT_RET(linkPriority.size() == 0, HCCL_ERROR("[CollAlgFactory] Invalid given link priority."),
     129              :                 HcclResult::HCCL_E_PARA);
     130            0 :     linkPriority_.assign(linkPriority.begin(), linkPriority.end());
     131              : 
     132            0 :     return HcclResult::HCCL_SUCCESS;
     133              : }
     134              : 
     135            0 : LinkReq CollAlgBase::GetSeqLinksUnion(const LinkReq &linkReq0, const LinkReq &linkReq1) const
     136              : {
     137            0 :     LinkReq retLinkReq = linkReq0;
     138            0 :     for (auto linkReqIter = linkReq1.begin(); linkReqIter != linkReq1.end(); linkReqIter++) {
     139            0 :         if (retLinkReq.find(linkReqIter->first) == retLinkReq.end()) {
     140            0 :             retLinkReq.insert(std::pair<RankId, u32>(linkReqIter->first, linkReqIter->second));
     141              :         } else {
     142            0 :             u32 tmpLinkReq                 = retLinkReq[linkReqIter->first];
     143            0 :             retLinkReq[linkReqIter->first] = std::max(tmpLinkReq, linkReqIter->second);
     144              :         }
     145              :     }
     146              : 
     147            0 :     return retLinkReq;
     148            0 : }
     149              : 
     150            0 : HcclResult CollAlgBase::AllocTempResLinks(const ResLinks &execResLinks, const LinkReq &tempLinkReq,
     151              :                                           ResLinks &tempResLinks) const
     152              : {
     153            0 :     for (auto resLinkReqIter = tempLinkReq.begin(); resLinkReqIter != tempLinkReq.end(); resLinkReqIter++) {
     154            0 :         auto execResLinkIter = execResLinks.find(resLinkReqIter->first);
     155            0 :         CHK_PRT_RET(execResLinkIter == execResLinks.end(),
     156              :                     HCCL_ERROR("[CollAlgFactory] Rank [%d], required link not in provided resLinks.", myRank_),
     157              :                     HcclResult::HCCL_E_INTERNAL);
     158            0 :         CHK_PRT_RET(execResLinkIter->second.size() < (resLinkReqIter->second),
     159              :                     HCCL_ERROR("[CollAlgFactory] Rank [%d], provided linkNum smaller than required.", myRank_),
     160              :                     HcclResult::HCCL_E_INTERNAL);
     161            0 :         std::vector<LinkData> resLinkVec(execResLinkIter->second.begin(),
     162            0 :                                          execResLinkIter->second.begin() + resLinkReqIter->second);
     163            0 :         tempResLinks.insert(std::pair<RankId, std::vector<LinkData>>(resLinkReqIter->first, resLinkVec));
     164            0 :     }
     165              : 
     166            0 :     return HcclResult::HCCL_SUCCESS;
     167              : }
     168              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1