LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/communicator - calc_hd_transport_req.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 94.6 % 37 35
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 4 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 "alg_template_base_pub.h"
      12              : #include "calc_hd_transport_req.h"
      13              : 
      14              : namespace hccl {
      15           34 : CalcHDTransportReq::CalcHDTransportReq(
      16           34 :     std::vector<std::vector<u32>>& subCommPlaneVector, std::vector<bool>& isBridgeVector, u32 userRank)
      17           34 :     : CalcTransportReqBase(subCommPlaneVector, isBridgeVector, userRank)
      18           34 : {}
      19              : 
      20           68 : CalcHDTransportReq::~CalcHDTransportReq() {}
      21              : 
      22           34 : HcclResult CalcHDTransportReq::CalcTransportRequest(
      23              :     const std::string& tag, TransportMemType inputMemType, TransportMemType outputMemType,
      24              :     const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport, u32 subUserRankRoot)
      25              : {
      26           34 :     u32 ringSize = subCommPlaneVector_.size();
      27           34 :     commTransport.resize(ringSize);
      28              : 
      29           82 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
      30           76 :         if (commParaInfo.commPlane == COMM_LEVEL1 && !isBridgeVector_[ringIndex]) {
      31           42 :             continue; // 跳出本次循环
      32              :         }
      33              : 
      34           34 :         u32 rank = GetSubCollectiveRank(subCommPlaneVector_[ringIndex]);
      35           34 :         if (rank == INVALID_VALUE_RANKID) {
      36            0 :             continue;
      37              :         }
      38              : 
      39           34 :         u32 rankSize = subCommPlaneVector_[ringIndex].size();
      40           34 :         SingleSubCommTransport& subCommTransport = commTransport[ringIndex];
      41           34 :         subCommTransport.transportRequests.resize(rankSize);
      42              :         // 只有一张卡时不需要建链
      43           34 :         if (rankSize == HCCL_RANK_SIZE_EQ_ONE) {
      44           28 :             HCCL_INFO("comm base needn't to create links, rankSize_[%u].", rankSize);
      45           28 :             return HCCL_SUCCESS;
      46              :         }
      47              : 
      48            6 :         u32 subRoot = INVALID_VALUE_RANKID;
      49            6 :         if (subUserRankRoot != INVALID_VALUE_RANKID) {
      50            0 :             CHK_RET(GetRankByUserRank(subCommPlaneVector_[ringIndex], subUserRankRoot, subRoot));
      51              :         }
      52              : 
      53              :         std::vector<bool> linkRelation = AlgTemplateBase::CalcLinksRelation(
      54            6 :             rank, rankSize, subRoot, HalvingDoublingType::RECURSIVE_HALVING_DOUBLING);
      55              : 
      56           18 :         for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
      57           12 :             TransportRequest& tmpTransport = subCommTransport.transportRequests[rankIndex];
      58           12 :             if (linkRelation[rankIndex] == true) {
      59            6 :                 tmpTransport.isValid = true;
      60            6 :                 tmpTransport.localUserRank = userRank_;
      61            6 :                 tmpTransport.remoteUserRank = subCommPlaneVector_[ringIndex][rankIndex];
      62            6 :                 tmpTransport.inputMemType = inputMemType;
      63            6 :                 tmpTransport.outputMemType = outputMemType;
      64            6 :                 HCCL_INFO(
      65              :                     "[CommFactory][CalcHDCommInfo] param_.tag[%s] ringIndex[%u], localRank[%u], "
      66              :                     "remoteRank[%u], inputMemType[%d], outputMemType[%d]",
      67              :                     tag.c_str(), ringIndex, userRank_, tmpTransport.remoteUserRank, inputMemType, outputMemType);
      68              :             } else {
      69            6 :                 tmpTransport.isValid = false;
      70              :             }
      71              :         }
      72            6 :         subCommTransport.supportDataReceivedAck = true;
      73            6 :     }
      74            6 :     return HCCL_SUCCESS;
      75              : }
      76              : 
      77              : } // namespace hccl
        

Generated by: LCOV version 2.0-1