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(
20 : "[ConnectedLinkMgr][GetLinks] level[%u], dstRank[%d], links.size[%u]", levelMap.first, dstRank,
21 : levelRankPairLinkDataMap[levelMap.first][dstRank].size());
22 1 : return levelRankPairLinkDataMap[levelMap.first][dstRank];
23 : }
24 1 : }
25 3 : HCCL_WARNING("[ConnectedLinkMgr][GetLinks] links is empty, dstRank[%d]", dstRank);
26 1 : return levelRankPairLinkDataMap[0][dstRank];
27 : }
28 :
29 1 : const std::vector<LinkData>& ConnectedLinkMgr::GetLinks(u32 level, RankId dstRank)
30 : {
31 1 : if (levelRankPairLinkDataMap.find(level) == levelRankPairLinkDataMap.end()
32 1 : || levelRankPairLinkDataMap[level].find(dstRank) == levelRankPairLinkDataMap[level].end()) {
33 0 : HCCL_WARNING("[ConnectedLinkMgr][GetLinks] links is empty, dstRank[%d]", dstRank);
34 : }
35 1 : return levelRankPairLinkDataMap[level][dstRank];
36 : }
37 :
38 1 : void ConnectedLinkMgr::Reset() { levelRankPairLinkDataMap.clear(); }
39 :
40 1 : void ConnectedLinkMgr::ParsePackedData(std::vector<char>& data)
41 : {
42 : u32 levelRankPairsNum;
43 : u32 linkSize;
44 1 : std::vector<std::pair<u32, RankId>> leveRankPairs;
45 1 : std::vector<u32> numVec;
46 1 : BinaryStream binaryStream(data);
47 1 : binaryStream >> levelRankPairsNum;
48 1 : binaryStream >> linkSize;
49 3 : HCCL_INFO("levelRankPairsNum=%u, linkSize=%u", levelRankPairsNum, linkSize);
50 3 : for (u32 idx = 0; idx < levelRankPairsNum; idx++) {
51 : u32 level;
52 : RankId rank;
53 : u32 num;
54 2 : binaryStream >> level;
55 2 : binaryStream >> rank;
56 2 : binaryStream >> num;
57 2 : leveRankPairs.emplace_back(level, rank);
58 2 : numVec.push_back(num);
59 6 : HCCL_INFO("level=%u, RankId=%d, num=%u", level, rank, numVec[idx]);
60 : }
61 :
62 1 : std::vector<LinkData> allLinkVec;
63 3 : for (u32 idx = 0; idx < linkSize; idx++) {
64 2 : std::vector<char> linkUniqueId;
65 2 : binaryStream >> linkUniqueId;
66 2 : allLinkVec.emplace_back(linkUniqueId);
67 2 : }
68 :
69 1 : u32 linkIdx = 0;
70 3 : for (u32 idx = 0; idx < levelRankPairsNum; idx++) {
71 2 : u32 level = leveRankPairs[idx].first;
72 2 : RankId dRank = leveRankPairs[idx].second;
73 6 : HCCL_INFO("level=%u, RankId=%d, num=%u", level, dRank, numVec[idx]);
74 2 : std::vector<LinkData> linkVec;
75 4 : for (u32 i = 0; i < numVec[idx]; i++) {
76 6 : HCCL_INFO("ConnectedLinkMgr::ParsePackedData: %s", allLinkVec[linkIdx].Describe().c_str());
77 2 : linkVec.push_back(allLinkVec[linkIdx++]);
78 : }
79 :
80 2 : if (levelRankPairLinkDataMap.find(level) == levelRankPairLinkDataMap.end()
81 2 : || levelRankPairLinkDataMap[level].find(dRank) == levelRankPairLinkDataMap[level].end()) {
82 2 : levelRankPairLinkDataMap[level][dRank] = linkVec;
83 : }
84 2 : }
85 1 : }
86 : } // namespace Hccl
|