LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/communicator - calc_ring_transport_req.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 80.0 % 45 36
Test Date: 2026-08-18 17:47:01 Functions: 80.0 % 5 4

            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_ring_transport_req.h"
      12              : #include "calc_ahc_template_register.h"
      13              : 
      14              : constexpr u32 HCCL_RANK_OFFSET = 1;
      15              : 
      16              : namespace hccl {
      17           62 : CalcRingTransportReq::CalcRingTransportReq(
      18           62 :     std::vector<std::vector<u32>>& subCommPlaneVector, std::vector<bool>& isBridgeVector, u32 userRank)
      19           62 :     : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank)
      20           61 : {}
      21              : 
      22          124 : CalcRingTransportReq::~CalcRingTransportReq() {}
      23              : 
      24           61 : HcclResult CalcRingTransportReq::CalcTransportRequest(
      25              :     const std::string& tag, TransportMemType inputMemType, TransportMemType outputMemType,
      26              :     const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport,
      27              :     [[maybe_unused]] u32 subUserRankRoot)
      28              : {
      29           61 :     u32 ringSize = subCommPlaneVector_.size();
      30           61 :     commTransport.resize(ringSize);
      31              : 
      32          125 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
      33           55 :         if ((commParaInfo.commPlane == COMM_LEVEL1 || commParaInfo.commPlane == COMM_LEVEL1_ANYPATH_SDMA
      34           55 :              || commParaInfo.commPlane == COMM_LEVEL1_ANYPATH_RDMA)
      35          136 :             && !isBridgeVector_[ringIndex]) {
      36           13 :             continue; // 跳出本次循环
      37              :         }
      38              : 
      39           68 :         u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
      40           68 :         if (rank == INVALID_VALUE_RANKID) {
      41            0 :             continue;
      42              :         }
      43              : 
      44           68 :         u32 rankSize = subCommPlaneVector_[ringIndex].size();
      45           68 :         SingleSubCommTransport& subCommTransport = commTransport[ringIndex];
      46           68 :         subCommTransport.transportRequests.resize(rankSize);
      47              :         // 只有一张卡时不需要建链
      48           67 :         if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
      49           17 :             HCCL_INFO("comm base needn't to create links, rankSize_[%u].", rankSize);
      50           18 :             return HCCL_SUCCESS;
      51              :         }
      52              : 
      53          238 :         for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
      54          188 :             TransportRequest& tmpTransport = subCommTransport.transportRequests[rankIndex];
      55          188 :             if (rankIndex == (rank + rankSize + HCCL_RANK_OFFSET) % rankSize
      56          138 :                 || rankIndex == (rank + rankSize - HCCL_RANK_OFFSET) % rankSize) {
      57           74 :                 tmpTransport.isValid = true;
      58           74 :                 tmpTransport.localUserRank = userRank_;
      59           74 :                 tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][rankIndex];
      60           74 :                 tmpTransport.inputMemType = inputMemType;
      61           74 :                 tmpTransport.outputMemType = outputMemType;
      62           74 :                 HCCL_INFO(
      63              :                     "[CommFactory][CalcRingCommInfo] param_.tag[%s] ringIndex[%u], localRank[%u], "
      64              :                     "remoteRank[%u], inputMemType[%d], outputMemType[%d]",
      65              :                     tag.c_str(), ringIndex, userRank_, tmpTransport.remoteUserRank, inputMemType, outputMemType);
      66              :             } else {
      67          114 :                 tmpTransport.isValid = false;
      68              :             }
      69              :         }
      70           50 :         const u32 rdmaTaskNumRatio = 4;
      71           50 :         if (GetWorkflowMode() != HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE) {
      72           26 :             subCommTransport.taskNum = rankSize * rdmaTaskNumRatio;
      73              :         }
      74              :     }
      75              : 
      76           44 :     return HCCL_SUCCESS;
      77              : }
      78              : 
      79              : HcclResult
      80            0 : CalcRingTransportReq::CalcDstRanks(const u32 rank, const std::vector<u32> commGroups, std::set<u32>& dstRanks)
      81              : {
      82            0 :     CHK_PRT_RET(
      83              :         rank >= commGroups.size(),
      84              :         HCCL_ERROR(
      85              :             "[CalcRingTransportReq][CalcDstRanks] rank [%u] exceed commGroups Size [%u] error", rank,
      86              :             commGroups.size()),
      87              :         HCCL_E_INTERNAL);
      88              : 
      89              :     // 正方向下一个节点的rank号
      90            0 :     const u32 targetRankPos = static_cast<u32>(rank + 1) % commGroups.size();
      91            0 :     dstRanks.insert(commGroups[targetRankPos]);
      92              : 
      93              :     // 反方向下一个节点的rank号
      94            0 :     const u32 targetRankNeg = static_cast<u32>(rank + commGroups.size() - 1) % commGroups.size();
      95              : 
      96            0 :     HCCL_DEBUG(
      97              :         "[CalcRingTransportReq][CalcDstRanks] local rank[%u], remote rank[%u]", commGroups[rank],
      98              :         commGroups[targetRankNeg]);
      99              : 
     100            0 :     dstRanks.insert(commGroups[targetRankNeg]);
     101              : 
     102            0 :     return HCCL_SUCCESS;
     103              : }
     104              : REGISTER_AHC_COMM_CALC_FUNC(
     105              :     AHCTemplateType::AHC_TEMPLATE_RING, CalcRingTransportReq, CalcRingTransportReq::CalcDstRanks);
     106              : } // namespace hccl
        

Generated by: LCOV version 2.0-1