LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/coll_alg_factory/alg_topo_match - topo_match_concurr_mesh.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 96.9 % 32 31
Test Date: 2026-08-18 17:47:01 Functions: 75.0 % 4 3

            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 "topo_match_concurr_mesh.h"
      12              : 
      13              : namespace Hccl {
      14            2 : TopoMatchConcurrMesh::TopoMatchConcurrMesh(
      15            2 :     const RankId vRank, const u32 rankSize, const RankGraph* rankGraph, const DevType devType)
      16            2 :     : TopoMatchBase(vRank, rankSize, rankGraph, devType)
      17            2 : {}
      18              : 
      19            2 : TopoMatchConcurrMesh::~TopoMatchConcurrMesh() {}
      20              : 
      21            2 : HcclResult TopoMatchConcurrMesh::MatchTopo(
      22              :     std::vector<std::vector<RankId>>& vTopo, std::vector<RankId>& virtRanks, std::map<RankId, u32>& virtRankMap)
      23              : {
      24              :     // 获取并校验当前通信层数
      25            2 :     std::set<u32> levelSet = rankGraph_->GetLevels(myRank_);
      26              : 
      27            2 :     CHK_PRT_RET(
      28              :         (levelSet.size() == COMM_LEVEL_SIZE_0),
      29              :         HCCL_ERROR("[CollAlgFactory] [TopoMatchConcurrMesh] Rank [%d], Invalid virtual topo.", myRank_),
      30              :         HcclResult::HCCL_E_PARA);
      31            2 :     const NetInstance* netInstance = rankGraph_->GetNetInstanceByRankId(0, myRank_);
      32            2 :     std::set<RankId> rankSet = netInstance->GetRankIds();
      33           10 :     for (RankId rankId : rankSet) {
      34            8 :         rankIds_.push_back(rankId);
      35              :     }
      36              :     // 判断level0上的拓扑是否符合 m x n 要求
      37            2 :     CHK_RET(CalcRankOnSamePlaneOfR0(rankOnSameBoardVector_, rankOnSameSlotVector_, numRanksPerBoard_));
      38              : 
      39            2 :     const auto minmxPair = std::minmax_element(numRanksPerBoard_.begin(), numRanksPerBoard_.end());
      40            2 :     u32 minNumRankPerBoard = *minmxPair.first;
      41            2 :     u32 maxNumRankPerBoard = *minmxPair.second;
      42            2 :     CHK_PRT_RET(
      43              :         (minNumRankPerBoard != maxNumRankPerBoard),
      44              :         HCCL_ERROR(
      45              :             "[CollAlgFactory] [TopoMatchConcurrMesh] Rank [%d], Invalid virtual topo for "
      46              :             "multi-dimensional concurrent mesh, min numRanksPerBoard_[%u], max numRanksPerBoard_[%u].",
      47              :             myRank_, minNumRankPerBoard, maxNumRankPerBoard),
      48              :         HcclResult::HCCL_E_PARA);
      49              : 
      50            2 :     CHK_PRT_RET(
      51              :         ((rankSize_ == 1) || (numRanksPerBoard_[0] * numRanksPerBoard_.size() != rankSize_)),
      52              :         HCCL_ERROR(
      53              :             "[CollAlgFactory] [TopoMatchConcurrMesh] Rank [%d], Invalid virtual topo for "
      54              :             "multi-dimensional concurrent mesh "
      55              :             "algorithm with rankSize [%u], ranksPerBoard [%u], ranksPerSlot [%u].",
      56              :             myRank_, rankSize_, numRanksPerBoard_[0], numRanksPerBoard_.size()),
      57              :         HcclResult::HCCL_E_PARA);
      58              : 
      59              :     // 计算当前rankd的virtRanks, vTopo和virtRankMap
      60            2 :     u32 myLocalId = rankGraph_->GetReplacedLocalId(myRank_);
      61            2 :     rankOnSameBoard_ = rankOnSameBoardVector_[myLocalId / RANK_SIZE_EIGHT];
      62            2 :     rankOnSameSlot_ = rankOnSameSlotVector_[myLocalId % RANK_SIZE_EIGHT];
      63              : 
      64            2 :     if ((rankOnSameBoard_.size() == 1) || (rankOnSameSlot_.size() == 1)) {
      65            0 :         HCCL_DEBUG(
      66              :             "[CollAlgFactory] [TopoMatchConcurrMesh] Rank [%d],Virtual topo with rankSize [%u], ranksPerBoard "
      67              :             "[%u], ranksPerSlot [%u]. "
      68              :             "1-D Mesh algorithm is adopted.",
      69              :             myRank_, rankSize_, rankOnSameBoard_.size(), rankOnSameSlot_.size());
      70              :     }
      71            2 :     sort(rankOnSameBoard_.begin(), rankOnSameBoard_.end());
      72            2 :     sort(rankOnSameSlot_.begin(), rankOnSameSlot_.end());
      73            2 :     vTopo.push_back(rankOnSameBoard_);
      74            2 :     vTopo.push_back(rankOnSameSlot_);
      75              : 
      76            2 :     sort(rankIds_.begin(), rankIds_.end());
      77            2 :     virtRanks = rankIds_;
      78              : 
      79            2 :     CHK_PRT_RET(
      80              :         GenVirtRankMapping(virtRanks, virtRankMap) != HcclResult::HCCL_SUCCESS,
      81              :         HCCL_ERROR("[CollAlgFactory] [TopoMatchConcurrMesh] Rank [%d], Fail to generate virtRankMapping.", myRank_),
      82              :         HcclResult::HCCL_E_INTERNAL);
      83              : 
      84            2 :     return HcclResult::HCCL_SUCCESS;
      85            2 : }
      86              : 
      87              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1