LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_executor/ins_alg_executor - ins_coll_alg_base.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 34.3 % 105 36
Test Date: 2026-08-04 10:52:23 Functions: 43.5 % 23 10

            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 "log.h"
      12              : 
      13              : #include "ins_coll_alg_base.h"
      14              : 
      15              : namespace Hccl {
      16              : 
      17            1 : InsCollAlgBase::InsCollAlgBase()
      18              : {
      19            1 : }
      20              : 
      21            1 : InsCollAlgBase::~InsCollAlgBase()
      22              : {
      23            1 : }
      24              : 
      25            1 : void InsCollAlgBase::SetMyRank(RankId myRank)
      26              : {
      27            1 :     myRank_ = myRank;
      28            1 :     return;
      29              : }
      30              : 
      31            1 : void InsCollAlgBase::SetRankSize(u32 rankSize)
      32              : {
      33            1 :     rankSize_ = rankSize;
      34            1 :     return;
      35              : }
      36              : 
      37            1 : void InsCollAlgBase::SetDevType(DevType devType)
      38              : {
      39            1 :     devType_ = devType;
      40            1 :     return;
      41              : }
      42              : 
      43            0 : void InsCollAlgBase::SetSendRecvRemoteRank(RankId sendRecvRemoteRank)
      44              : {
      45            0 :     sendRecvRemoteRank_ = sendRecvRemoteRank;
      46            0 :     return;
      47              : }
      48              : 
      49            0 : void InsCollAlgBase::SetOp(const CollAlgOperator &op)
      50              : {
      51            0 :     op_ = op;
      52            0 :     return;
      53              : }
      54              : 
      55            0 : void InsCollAlgBase::SetAllignSize(u64 allignSize)
      56              : {
      57            0 :     allignSize_ = allignSize;
      58            0 :     return;
      59              : }
      60              : 
      61            1 : void InsCollAlgBase::EnableDataAllign(bool enableAllign)
      62              : {
      63            1 :     enableAllign_ = enableAllign;
      64            1 :     return;
      65              : }
      66              : 
      67            1 : void InsCollAlgBase::EnableDetour(bool enableDetour)
      68              : {
      69            1 :     enableDetour_ = enableDetour;
      70            1 :     return;
      71              : }
      72              : 
      73            0 : void InsCollAlgBase::SetDmaMode(const DmaMode dmaMode)
      74              : {
      75            0 :     dmaMode_ = dmaMode;
      76            0 :     return;
      77              : }
      78              : 
      79            0 : void InsCollAlgBase::SetRmaDataBufferMgr(const RmtDataBufferMgr *rmaDataBufferMgr)
      80              : {
      81              :     (void)rmaDataBufferMgr;
      82            0 :     return;
      83              : }
      84              : 
      85            0 : bool InsCollAlgBase::IsEnableCounterNotify() const
      86              : {
      87            0 :     HCCL_DEBUG("[InsCollAlgBase][%s] start.", __func__);
      88            0 :     return true;
      89              : }
      90              : 
      91            1 : HcclResult InsCollAlgBase::Init(const CollAlgOperator &op, const CollAlgParams &params, InsQuePtr insQue)
      92              : {
      93              :     // init params
      94            1 :     CHK_PRT_RET(InitParams(op, params) != HcclResult::HCCL_SUCCESS,
      95              :         HCCL_ERROR("[InsCollAlgFactory] Rank [%d], Fail to init params.", myRank_), HcclResult::HCCL_E_PARA);
      96              : 
      97              :     // init queMap
      98            1 :     CHK_PRT_RET(GenInsQueMap(insQue) != HcclResult::HCCL_SUCCESS,
      99              :         HCCL_ERROR("[InsCollAlgFactory] Rank [%d], Fail to init insQueMap.", myRank_), HcclResult::HCCL_E_PARA);
     100              : 
     101            1 :     return HcclResult::HCCL_SUCCESS;
     102              : }
     103              : 
     104            0 : HcclResult InsCollAlgBase::InitParams(const CollAlgOperator &op, const CollAlgParams &params)
     105              : {
     106            0 :     op_ = op;
     107            0 :     opMode_ = params.opMode;
     108            0 :     maxTmpMemSize_ = params.maxTmpMemSize;
     109              : 
     110            0 :     CHK_PRT_RET((maxTmpMemSize_ == 0) && (opMode_ == OpMode::OPBASE),
     111              :         HCCL_ERROR("[InsCollAlgFactory] maxTmpMemSize equals to zero for OPBASE."), HcclResult::HCCL_E_PARA);
     112              : 
     113            0 :     CHK_PRT_RET(InitDataInfo(op, dataType_, outputDataType_, dataCount_),
     114              :         HCCL_ERROR("[InsCollAlgFactory] unable to init DataInfo."), HcclResult::HCCL_E_PARA);
     115            0 :     dataTypeSize_ = DataTypeSizeGet(dataType_);
     116            0 :     dataSize_ = dataCount_ * dataTypeSize_;
     117              : 
     118            0 :     CHK_PRT_RET(InitOpInfo(op, opType_, redOp_, root_), HCCL_ERROR("[InsCollAlgFactory] unable to init OpInfo."),
     119              :         HcclResult::HCCL_E_PARA);
     120              : 
     121            0 :     return HcclResult::HCCL_SUCCESS;
     122              : }
     123              : 
     124            1 : HcclResult InsCollAlgBase::GenInsQueMap(InsQuePtr insQue)
     125              : {
     126            1 :     if (insQue == nullptr) {
     127            0 :         HCCL_ERROR("[InsCollAlgBase] insQue is nullptr.");
     128            0 :         return HcclResult::HCCL_E_PTR;
     129              :     }
     130            1 :     CHK_PRT_RET(!insQue->IsMaster(),
     131              :         HCCL_ERROR("[InsCollAlgFactory] Rank [%d], Input Primitive Queue is not a master queue.", myRank_),
     132              :         HcclResult::HCCL_E_PARA);
     133            1 :     queId2InsQue_.insert(std::make_pair(insQue->GetId(), insQue));
     134            1 :     return HcclResult::HCCL_SUCCESS;
     135              : }
     136              : 
     137            1 : HcclResult InsCollAlgBase::InitQueue(const u32 &requiredQueNum, std::vector<InsQuePtr> &requiredQue)
     138              : {
     139            1 :     CHK_PRT_RET(!static_cast<bool>(queId2InsQue_.count(0)),
     140              :         HCCL_ERROR("[InsCollAlgFactory] Rank [%d], Invalid queId2InsQue Map.", myRank_), HcclResult::HCCL_E_INTERNAL);
     141            1 :     InsQuePtr insQue = queId2InsQue_[0];
     142              : 
     143            2 :     for (u32 queIdx = 0; queIdx < requiredQueNum; queIdx++) {
     144            1 :         if (!static_cast<bool>(queId2InsQue_.count(queIdx))) {
     145            0 :             queId2InsQue_.insert(std::make_pair(queIdx, insQue->Fork()));
     146              :         }
     147            1 :         requiredQue.push_back(queId2InsQue_[queIdx]);
     148              :     }
     149              : 
     150            1 :     return HcclResult::HCCL_SUCCESS;
     151            1 : }
     152              : 
     153            0 : HcclResult InsCollAlgBase::SetLinkPrty(const std::vector<BasePortType> &linkPriority)
     154              : {
     155            0 :     CHK_PRT_RET(linkPriority.size() == 0, HCCL_ERROR("[InsCollAlgFactory] Invalid given link priority."),
     156              :         HcclResult::HCCL_E_PARA);
     157            0 :     linkPriority_.assign(linkPriority.begin(), linkPriority.end());
     158              : 
     159            0 :     return HcclResult::HCCL_SUCCESS;
     160              : }
     161              : 
     162            0 : HcclResult InsCollAlgBase::CalcParallelNotifyReq(
     163              :     const u32 primQueueNum, const u32 IntraqueNum, std::vector<std::tuple<QId, QId, u32>> &queueNotifys) const
     164              : {
     165            0 :     u32 slaveNum = primQueueNum - 1;
     166            0 :     std::vector<std::tuple<QId, QId, u32>> notifyRequests;
     167              : 
     168            0 :     notifyRequests.reserve(slaveNum);  // 每个从流需要1个
     169            0 :     for (QId q = 1; q < primQueueNum; q++) {
     170            0 :         notifyRequests.emplace_back(std::make_tuple(0, q, 0));
     171            0 :         notifyRequests.emplace_back(std::make_tuple(q, 0, 0));
     172              :     }
     173            0 :     for (QId q = IntraqueNum; q < primQueueNum; q++) {
     174            0 :         if (IntraqueNum == q) {
     175            0 :             continue;
     176              :         }
     177            0 :         notifyRequests.emplace_back(std::make_tuple(IntraqueNum, q, 0));
     178            0 :         notifyRequests.emplace_back(std::make_tuple(q, IntraqueNum, 0));
     179              :     }
     180            0 :     queueNotifys = notifyRequests;
     181            0 :     return HcclResult::HCCL_SUCCESS;
     182            0 : }
     183              : 
     184            0 : HcclResult InsCollAlgBase::CalcLocalRankSize(const RankId myRank,
     185              :                                              const std::vector<std::vector<RankId>> &virtRanks, 
     186              :                                              u32 &rankSizeLevel0, u32 &rankSizeLevel1) const
     187              : {
     188            0 :     constexpr uint64_t virtRanks_2 = 2;
     189            0 :     CHK_PRT_RET(virtRanks.size() < virtRanks_2,
     190              :         HCCL_ERROR("[CalcLocalRankSize] virtRanks level num is smaller than 2."),
     191              :         HcclResult::HCCL_E_INTERNAL);
     192              : 
     193            0 :     rankSizeLevel0 = virtRanks.at(0).size();
     194            0 :     rankSizeLevel1 = virtRanks.at(1).size();
     195              : 
     196            0 :     HCCL_INFO("[CalcLocalRankSize] localRankSize: myRank[%d] rankSizeLevel0_[%u] rankSizeLevel1_[%u]",
     197              :         myRank,
     198              :         rankSizeLevel0,
     199              :         rankSizeLevel1);
     200            0 :     return HcclResult::HCCL_SUCCESS;
     201              : };
     202              : 
     203            0 : LinkReq InsCollAlgBase::GetSeqLinksUnion(const LinkReq &linkReq0, const LinkReq &linkReq1) const
     204              : {
     205            0 :     LinkReq retLinkReq = linkReq0;
     206            0 :     for (auto linkReqIter = linkReq1.begin(); linkReqIter != linkReq1.end(); linkReqIter++) {
     207            0 :         if (retLinkReq.find(linkReqIter->first) == retLinkReq.end()) {
     208            0 :             retLinkReq.insert(std::pair<RankId, u32>(linkReqIter->first, linkReqIter->second));
     209              :         } else {
     210            0 :             u32 tmpLinkReq = retLinkReq[linkReqIter->first];
     211            0 :             retLinkReq[linkReqIter->first] = std::max(tmpLinkReq, linkReqIter->second);
     212              :         }
     213              :     }
     214            0 :     return retLinkReq;
     215            0 : }
     216              : 
     217            0 : HcclResult InsCollAlgBase::CalNumBlocks(u32 &numBlocks, u64 dataSize, u32 numBlocksLimit)
     218              : {
     219            0 :     numBlocks = 0;
     220              :     (void)dataSize;
     221              :     (void)numBlocksLimit;
     222            0 :     HCCL_INFO("[InsCollAlgFactory] current executor doesn't support controlling num of aiv cores.");
     223            0 :     return HcclResult::HCCL_SUCCESS;
     224              : }
     225              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1