LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/communicator - calc_nb_transport_req.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 49 0
Test Date: 2026-08-04 10:52:23 Functions: 0.0 % 5 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 "calc_nb_transport_req.h"
      12              : #include "calc_ahc_template_register.h"
      13              : 
      14              : namespace hccl {
      15            0 : CalcNBTransportReq::CalcNBTransportReq(std::vector<std::vector<u32>> &subCommPlaneVector,
      16            0 :     std::vector<bool> &isBridgeVector, u32 userRank)
      17            0 :     : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank)
      18              : {
      19            0 : }
      20              : 
      21            0 : CalcNBTransportReq::~CalcNBTransportReq()
      22              : {
      23            0 : }
      24              : 
      25            0 : HcclResult CalcNBTransportReq::CalcTransportRequest(const std::string &tag, TransportMemType inputMemType,
      26              :     TransportMemType outputMemType, const CommParaInfo &commParaInfo,
      27              :     std::vector<SingleSubCommTransport> &commTransport, u32 subUserRankRoot)
      28              : {
      29              :     (void)subUserRankRoot;
      30            0 :     u32 ringSize = subCommPlaneVector_.size();
      31            0 :     commTransport.resize(ringSize);
      32              : 
      33            0 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
      34            0 :         if (commParaInfo.commPlane == COMM_LEVEL1 && !isBridgeVector_[ringIndex]) {
      35            0 :             continue; // 跳出本次循环
      36              :         }
      37              : 
      38            0 :         u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
      39            0 :         if (rank == INVALID_VALUE_RANKID) {
      40            0 :             continue;
      41              :         }
      42              : 
      43            0 :         u32 rankSize = subCommPlaneVector_[ringIndex].size();
      44            0 :         SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
      45            0 :         subCommTransport.transportRequests.resize(rankSize);
      46              :         // 只有一张卡时不需要建链
      47            0 :         if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
      48            0 :             HCCL_INFO("comm base needn't to create links, rankSize_[%u].", rankSize);
      49            0 :             return HCCL_SUCCESS;
      50              :         }
      51              : 
      52            0 :         for (u32 delta = 1; delta < rankSize; delta <<= 1) {
      53            0 :             const u32 targetRankPos = static_cast<u32>(rank + delta) % rankSize;
      54            0 :             TransportRequest &tmpTransport = subCommTransport.transportRequests[targetRankPos];
      55            0 :             tmpTransport.isValid = true;
      56            0 :             tmpTransport.localUserRank  = userRank_;
      57            0 :             tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][targetRankPos];
      58            0 :             tmpTransport.inputMemType = inputMemType;
      59            0 :             tmpTransport.outputMemType = outputMemType;
      60            0 :             HCCL_INFO("[CalcNBTransportReq][CalcTransportRequest] param_.tag[%s], ringIndex[%u], localRank[%u], "\
      61              :                 "remoteRank[%u], inputMemType[%d], outputMemType[%d]", tag.c_str(), ringIndex, userRank_,
      62              :                 tmpTransport.remoteUserRank, inputMemType, outputMemType);
      63              : 
      64            0 :             const u32 targetRankNeg = static_cast<u32>(rank + rankSize - delta) % rankSize;
      65            0 :             TransportRequest &tmpTransportNeg = subCommTransport.transportRequests[targetRankNeg];
      66            0 :             tmpTransportNeg.isValid = true;
      67            0 :             tmpTransportNeg.localUserRank  = userRank_;
      68            0 :             tmpTransportNeg.remoteUserRank = subCommPlaneVector_[ringIndex][targetRankNeg];
      69            0 :             tmpTransportNeg.inputMemType = inputMemType;
      70            0 :             tmpTransportNeg.outputMemType = outputMemType;
      71            0 :             HCCL_INFO("[CalcNBTransportReq][CalcTransportRequest] param_.tag[%s], ringIndex[%u], localRank[%u], "\
      72              :                 "remoteRank[%u], inputMemType[%d], outputMemType[%d]", tag.c_str(), ringIndex, userRank_,
      73              :                 tmpTransportNeg.remoteUserRank, inputMemType, outputMemType);
      74              :         }
      75            0 :         subCommTransport.enableUseOneDoorbell = true;
      76              :     }
      77            0 :     return HCCL_SUCCESS;
      78              : }
      79              : 
      80            0 : HcclResult CalcNBTransportReq::CalcDstRanks(const u32 rank, const std::vector<u32> commGroups,
      81              :     std::set<u32> &dstRanks)
      82              : {
      83            0 :     CHK_PRT_RET(rank >= commGroups.size(),
      84              :         HCCL_ERROR("[CalcNBTransportReq][CalcDstRanks] rank [%u] exceed commGroups Size [%u]  error", 
      85              :         rank, commGroups.size() ), HCCL_E_INTERNAL);
      86              : 
      87            0 :     for (auto i = 0; static_cast<u32>(1 << i) < commGroups.size(); ++i) {
      88              :         // 正方向第2^i个节点的rank号
      89            0 :         const u32 targetRankPos = static_cast<u32>(rank + (1 << i)) % commGroups.size();
      90            0 :         dstRanks.insert(commGroups[targetRankPos]);
      91              :  
      92              :         // 反方向第2^i个节点的rank号
      93            0 :         const u32 targetRankNeg = static_cast<u32>(rank + commGroups.size() - (1 << i)) % commGroups.size();
      94              : 
      95            0 :         HCCL_DEBUG("[CalcNBTransportReq][CalcDstRanks] local rank[%u], remote rank[%u]", commGroups[rank], commGroups[targetRankNeg]);
      96              : 
      97            0 :         dstRanks.insert(commGroups[targetRankNeg]);
      98              :     }
      99              :  
     100            0 :     return HCCL_SUCCESS;
     101              : }
     102              : 
     103              : REGISTER_AHC_COMM_CALC_FUNC(AHCTemplateType::AHC_TEMPLATE_NB, CalcNBTransportReq, CalcNBTransportReq::CalcDstRanks);
     104              : }  // namespace hccl
        

Generated by: LCOV version 2.0-1