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