LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/resource_manager/transport/aicpu - connected_link_mgr.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 98.0 % 51 50
Test Date: 2026-07-28 12:11:00 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              : #include "connected_link_mgr.h"
      11              : #include "binary_stream.h"
      12              : 
      13              : namespace Hccl {
      14            2 : const vector<LinkData> &ConnectedLinkMgr::GetLinks(RankId dstRank)
      15              : {
      16            2 :     for (auto levelMap : levelRankPairLinkDataMap) {
      17            1 :         if (levelRankPairLinkDataMap[levelMap.first].find(dstRank) != levelRankPairLinkDataMap[levelMap.first].end()
      18            1 :             && levelRankPairLinkDataMap[levelMap.first][dstRank].size() > 0) {
      19            3 :             HCCL_INFO("[ConnectedLinkMgr][GetLinks] level[%u], dstRank[%d], links.size[%u]",
      20              :                 levelMap.first, dstRank, levelRankPairLinkDataMap[levelMap.first][dstRank].size());
      21            1 :             return levelRankPairLinkDataMap[levelMap.first][dstRank];
      22              :         }
      23            1 :     }
      24            3 :     HCCL_WARNING("[ConnectedLinkMgr][GetLinks] links is empty, dstRank[%d]", dstRank);
      25            1 :     return levelRankPairLinkDataMap[0][dstRank];
      26              : }
      27              : 
      28            1 : const std::vector<LinkData> &ConnectedLinkMgr::GetLinks(u32 level, RankId dstRank)
      29              : {
      30            1 :     if (levelRankPairLinkDataMap.find(level) == levelRankPairLinkDataMap.end()
      31            1 :         || levelRankPairLinkDataMap[level].find(dstRank) == levelRankPairLinkDataMap[level].end()) {
      32            0 :         HCCL_WARNING("[ConnectedLinkMgr][GetLinks] links is empty, dstRank[%d]", dstRank);
      33              :     }
      34            1 :     return levelRankPairLinkDataMap[level][dstRank];
      35              : }
      36              : 
      37            1 : void ConnectedLinkMgr::Reset()
      38              : {
      39            1 :     levelRankPairLinkDataMap.clear();
      40            1 : }
      41              : 
      42            1 : void ConnectedLinkMgr::ParsePackedData(std::vector<char> &data)
      43              : {
      44              :     u32 levelRankPairsNum;
      45              :     u32 linkSize;
      46            1 :     std::vector<std::pair<u32, RankId>> leveRankPairs;
      47            1 :     std::vector<u32> numVec;
      48            1 :     BinaryStream binaryStream(data);
      49            1 :     binaryStream >> levelRankPairsNum;
      50            1 :     binaryStream >> linkSize;
      51            3 :     HCCL_INFO("levelRankPairsNum=%u, linkSize=%u", levelRankPairsNum, linkSize);
      52            3 :     for (u32 idx = 0; idx < levelRankPairsNum; idx++) {
      53              :         u32 level;
      54              :         RankId rank;
      55              :         u32 num;
      56            2 :         binaryStream >> level;
      57            2 :         binaryStream >> rank;
      58            2 :         binaryStream >> num;
      59            2 :         leveRankPairs.emplace_back(level, rank);
      60            2 :         numVec.push_back(num);
      61            6 :         HCCL_INFO("level=%u, RankId=%d, num=%u", level, rank, numVec[idx]);
      62              :     }
      63              : 
      64            1 :     std::vector<LinkData> allLinkVec;
      65            3 :     for (u32 idx = 0; idx < linkSize; idx++) {
      66            2 :         std::vector<char> linkUniqueId;
      67            2 :         binaryStream >> linkUniqueId;
      68            2 :         allLinkVec.emplace_back(linkUniqueId);
      69            2 :     }
      70              : 
      71            1 :     u32 linkIdx = 0;
      72            3 :     for (u32 idx = 0; idx < levelRankPairsNum; idx++) {
      73            2 :         u32 level = leveRankPairs[idx].first;
      74            2 :         RankId dRank = leveRankPairs[idx].second;
      75            6 :         HCCL_INFO("level=%u, RankId=%d, num=%u", level, dRank, numVec[idx]);
      76            2 :         std::vector<LinkData> linkVec;
      77            4 :         for (u32 i = 0; i < numVec[idx]; i++) {
      78            6 :             HCCL_INFO("ConnectedLinkMgr::ParsePackedData: %s", allLinkVec[linkIdx].Describe().c_str());
      79            2 :             linkVec.push_back(allLinkVec[linkIdx++]);
      80              :         }
      81              : 
      82            3 :         if (levelRankPairLinkDataMap.find(level) == levelRankPairLinkDataMap.end() ||
      83            3 :             levelRankPairLinkDataMap[level].find(dRank) == levelRankPairLinkDataMap[level].end()) {
      84            2 :             levelRankPairLinkDataMap[level][dRank] = linkVec;
      85              :         }
      86            2 :     }
      87            1 : }
      88              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1