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

Generated by: LCOV version 2.0-1