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 "net_instance.h"
12 : #include "exception_util.h"
13 : #include "not_support_exception.h"
14 : #include "invalid_params_exception.h"
15 :
16 : namespace Hccl {
17 :
18 : using namespace std;
19 :
20 846 : NetInstance::NetInstance(const u32 netLayer, const string& netInstId, const NetType netType)
21 : {
22 282 : this->netLayer = netLayer;
23 282 : this->netInstId = netInstId;
24 282 : this->netType = netType;
25 282 : }
26 :
27 1366 : u32 NetInstance::GetNetLayer() const { return netLayer; }
28 :
29 617 : string NetInstance::GetNetInstId() const { return netInstId; }
30 :
31 124 : NetType NetInstance::GetNetType() const { return netType; }
32 :
33 591 : set<RankId> NetInstance::GetRankIds() const { return rankIds; }
34 :
35 24 : u32 NetInstance::GetRankSize() const { return rankIds.size(); }
36 :
37 96 : bool NetInstance::HasNode(const NodeId nodeId) const { return vGraph.HasNode(nodeId); }
38 :
39 37 : const std::unordered_map<RankId, std::shared_ptr<NetInstance::Peer>>& NetInstance::GetPeers() const { return peers; }
40 :
41 51 : const std::vector<std::shared_ptr<NetInstance::Fabric>>& NetInstance::GetFabrics() const { return fabrics; }
42 :
43 206 : Graph<NetInstance::Node, NetInstance::Link>& NetInstance::GetGraph() { return vGraph; }
44 :
45 566 : void NetInstance::AddRankId(const RankId rankId)
46 : {
47 566 : rankIds.insert(rankId);
48 778 : HCCL_DEBUG("[NetInstance::AddRankId] add rank id [%d] to %s", rankId, this->Describe().c_str());
49 566 : }
50 :
51 511 : void NetInstance::AddNode(const shared_ptr<Node>& node)
52 : {
53 511 : NetInstance::Node::NodeType nodeType = node->GetType();
54 511 : if (nodeType == NetInstance::Node::NodeType::PEER) {
55 457 : AddPeer(dynamic_pointer_cast<NetInstance::Peer>(node));
56 54 : } else if (nodeType == NetInstance::Node::NodeType::FABRIC) {
57 54 : AddFabric(dynamic_pointer_cast<NetInstance::Fabric>(node));
58 : } else {
59 0 : THROW<NotSupportException>(StringFormat(
60 : "[NetInstance::AddNode] failed to add %s to %s, "
61 : "only PEER or FABRIC type node can be added.",
62 0 : node->Describe().c_str(), this->Describe().c_str()));
63 : }
64 511 : }
65 :
66 457 : void NetInstance::AddPeer(const shared_ptr<Peer>& peer)
67 : {
68 457 : if (netLayer == 0 && localIdsMap.find(peer->GetLocalId()) != localIdsMap.end()) {
69 0 : THROW<InvalidParamsException>(StringFormat(
70 : "[NetInstance][%s] when netLayer is 0, local id[%u] is repeat. "
71 : "rank id [%u], netInstId[%s]",
72 : __func__, peer->GetLocalId(), peer->GetRankId(), netInstId.c_str()));
73 : }
74 457 : localIdsMap.insert({peer->GetLocalId(), peer->GetRankId()});
75 :
76 457 : peers[peer->GetRankId()] = peer;
77 457 : vGraph.AddNode(peer->GetNodeId(), peer);
78 :
79 635 : HCCL_DEBUG("[NetInstance::AddPeer] add %s to %s", peer->Describe().c_str(), this->Describe().c_str());
80 457 : }
81 :
82 54 : void NetInstance::AddFabric(const shared_ptr<NetInstance::Fabric>& fabric)
83 : {
84 54 : if (netType != NetType::CLOS && netType != NetType::TOPO_FILE_DESC) {
85 0 : THROW<NotSupportException>(StringFormat(
86 : "[NetInstance::AddFabric] failed to add %s to %s, "
87 : "only CLOS type NetInstance can add Fabrics.",
88 0 : fabric->Describe().c_str(), this->Describe().c_str()));
89 : }
90 :
91 54 : NodeId fabricId = fabric->GetNodeId();
92 54 : fabrics.emplace_back(fabric);
93 54 : vGraph.AddNode(fabricId, fabric);
94 :
95 138 : HCCL_DEBUG("[NetInstance::AddFabric] add %s to %s", fabric->Describe().c_str(), this->Describe().c_str());
96 54 : }
97 :
98 599 : void NetInstance::AddLink(const shared_ptr<NetInstance::Link>& link)
99 : {
100 599 : NodeId srcNodeId = link->GetSourceNode()->GetNodeId();
101 599 : NodeId dstNodeId = link->GetTargetNode()->GetNodeId();
102 :
103 599 : bool hasLink = false;
104 599 : vGraph.TraverseEdge(srcNodeId, dstNodeId, [&](shared_ptr<NetInstance::Link> edge) {
105 65 : if (*edge == *link) {
106 17 : hasLink = true;
107 17 : return;
108 : }
109 : });
110 :
111 599 : if (hasLink) {
112 17 : HCCL_WARNING(
113 : "[NetInstance::AddLink] failed to add %s to %s, "
114 : "the fabric group already has the same link.",
115 : link->Describe().c_str(), this->Describe().c_str());
116 17 : return;
117 : }
118 :
119 582 : vGraph.AddEdge(srcNodeId, dstNodeId, link);
120 :
121 1166 : HCCL_DEBUG("[NetInstance::AddLink] add %s to %s", link->Describe().c_str(), this->Describe().c_str());
122 : }
123 :
124 8 : void NetInstance::DeleteLink(const NodeId srcNodeId, const NodeId dstNodeId)
125 : {
126 24 : HCCL_RUN_INFO("[NetInstance::DeleteLink] delete %lu -> %lu", srcNodeId, dstNodeId);
127 8 : vGraph.DeleteEdge(srcNodeId, dstNodeId);
128 8 : vGraph.DeleteEdge(dstNodeId, srcNodeId);
129 8 : }
130 :
131 204 : void NetInstance::UpdateTopoInst(u32 topoInstId, TopoType topoType, RankId rankId)
132 : {
133 204 : auto it = topoInsts_.find(topoInstId);
134 204 : if (it != topoInsts_.end()) {
135 146 : TopoInstance& existingInst = *it->second;
136 146 : existingInst.ranks.insert(rankId);
137 : } else {
138 : // 创建新的TopoInstance
139 58 : TopoInstance newInst;
140 58 : newInst.topoInstId = topoInstId;
141 58 : newInst.topoType = topoType;
142 58 : newInst.ranks.insert(rankId);
143 58 : topoInsts_.emplace(topoInstId, std::make_shared<TopoInstance>(std::move(newInst)));
144 58 : }
145 204 : }
146 :
147 2 : void NetInstance::GetTopoInstsByLayer(std::vector<u32>& topoInsts, u32& topoInstNum) const
148 : {
149 4 : for (const auto& entry : topoInsts_) {
150 2 : topoInsts.push_back(entry.first);
151 : }
152 :
153 2 : topoInstNum = static_cast<u32>(topoInsts.size());
154 2 : }
155 :
156 3 : HcclResult NetInstance::GetTopoType(const u32 topoInstId, TopoType& topoType) const
157 : {
158 3 : auto it = topoInsts_.find(topoInstId);
159 3 : if (it != topoInsts_.end()) {
160 2 : const std::shared_ptr<TopoInstance>& topoInstPtr = it->second;
161 2 : topoType = topoInstPtr->topoType;
162 2 : return HCCL_SUCCESS;
163 : }
164 :
165 1 : HCCL_ERROR("[NetInstance::GetTopoType] Failed to find TopoInstance with ID: %u", topoInstId);
166 1 : return HCCL_E_PARA;
167 : }
168 :
169 3 : HcclResult NetInstance::GetRanksByTopoInst(const u32 topoInstId, std::vector<u32>& ranks, u32& rankNum) const
170 : {
171 3 : auto it = topoInsts_.find(topoInstId);
172 3 : if (it != topoInsts_.end()) {
173 2 : const std::shared_ptr<TopoInstance>& topoInstPtr = it->second;
174 2 : ranks.assign(topoInstPtr->ranks.begin(), topoInstPtr->ranks.end());
175 2 : rankNum = static_cast<u32>(ranks.size());
176 2 : return HCCL_SUCCESS;
177 : }
178 1 : HCCL_ERROR("[NetInstance::GetRanksByTopoInst] Failed to find ranks with ID: %u", topoInstId);
179 1 : return HCCL_E_PARA;
180 : }
181 :
182 1714 : string NetInstance::Describe() const
183 : {
184 : return StringFormat(
185 1714 : "NetInstance[ID=%s, Level=%u, FabType=%s, RankIds_Size=%zu]", netInstId.c_str(), netLayer,
186 3428 : netType.Describe().c_str(), rankIds.size());
187 : }
188 :
189 114 : bool CheckPortGroupSize(u32 netLayer, NetInstance::Link& srcLink, NetInstance::Link& dstLink)
190 : {
191 114 : auto srcConnIface = srcLink.GetSourceIface();
192 114 : auto targetConnIface = dstLink.GetTargetIface();
193 114 : auto srcPortGroupSize = static_cast<u8>(srcConnIface->GetPorts().size());
194 114 : auto tgtPortGroupSize = static_cast<u8>(targetConnIface->GetPorts().size());
195 114 : if (srcPortGroupSize != tgtPortGroupSize) {
196 0 : auto srcPeer = srcLink.GetSourceNode();
197 0 : auto targetPeer = dstLink.GetTargetNode();
198 0 : auto localAddr = srcConnIface->GetAddr();
199 0 : auto remoteAddr = targetConnIface->GetAddr();
200 0 : auto localRankId = std::dynamic_pointer_cast<NetInstance::Peer>(srcPeer)->GetRankId();
201 0 : auto remoteRankId = std::dynamic_pointer_cast<NetInstance::Peer>(targetPeer)->GetRankId();
202 0 : HCCL_WARNING(
203 : "[GetPaths][CheckPortGroupSize] portGroupSize is not equal => src[%u], target[%u]."
204 : "LocatedInfo: NetLayer[%u], localRank[%u], rmtRank[%u], localAddr[%s], rmtAddr[%s]",
205 : srcPortGroupSize, tgtPortGroupSize, netLayer, localRankId, remoteRankId, localAddr.Describe().c_str(),
206 : remoteAddr.Describe().c_str());
207 0 : return false;
208 0 : }
209 114 : return true;
210 114 : }
211 :
212 114 : vector<NetInstance::Path> InnerNetInstance::GetPaths(const RankId srcRankId, const RankId dstRankId) const
213 : {
214 114 : vector<NetInstance::Path> paths;
215 114 : if (peers.count(srcRankId) == 0 || peers.count(dstRankId) == 0) {
216 0 : HCCL_WARNING(
217 : "[InnerNetInstance::GetPaths] srcRankId[%d] or dstRankId[%d] not exist in netInstance, "
218 : "netLayer[%u], netInstId[%s]",
219 : srcRankId, dstRankId, netLayer, netInstId.c_str());
220 0 : return paths;
221 : }
222 114 : NodeId srcPeerId = peers.at(srcRankId)->GetNodeId();
223 114 : NodeId dstPeerId = peers.at(dstRankId)->GetNodeId();
224 : // 1. 获取边
225 114 : vGraph.TraverseEdge(srcPeerId, dstPeerId, [&](shared_ptr<NetInstance::Link> edge) {
226 98 : NetInstance::Path path;
227 196 : path.links = {*edge};
228 98 : path.direction = edge->GetLinkDirection();
229 98 : paths.emplace_back(path);
230 192 : HCCL_DEBUG(
231 : "[InnerNetInstance::GetPaths] netLayer[%u], from src[%s] to dst[%s] get path.", netLayer,
232 : peers.at(srcRankId)->Describe().c_str(), peers.at(dstRankId)->Describe().c_str());
233 192 : HCCL_DEBUG(
234 : "[InnerNetInstance::GetPaths] netLayer[%u], srcRankId[%u], dstRankId[%u], path[%s]", netLayer, srcRankId,
235 : dstRankId, path.links[0].Describe().c_str());
236 196 : });
237 :
238 : // 2. 通过 fabric 的路径
239 146 : for (auto& fabric : fabrics) {
240 32 : NodeId fabricId = fabric->GetNodeId();
241 :
242 : // 所有 src -> fabric 的链路
243 32 : vector<NetInstance::Link> srcToFabricLinks;
244 32 : vGraph.TraverseEdge(srcPeerId, fabricId, [&](shared_ptr<NetInstance::Link> edge) {
245 28 : srcToFabricLinks.push_back(*edge);
246 28 : return;
247 : });
248 :
249 : // 所有 fabric -> dst 的链路
250 32 : vector<NetInstance::Link> fabricToDstLinks;
251 32 : vGraph.TraverseEdge(fabricId, dstPeerId, [&](shared_ptr<NetInstance::Link> edge) {
252 28 : fabricToDstLinks.push_back(*edge);
253 28 : return;
254 : });
255 :
256 32 : if (!srcToFabricLinks.empty() && !fabricToDstLinks.empty()) {
257 48 : for (auto& srcLink : srcToFabricLinks) {
258 48 : for (auto& dstLink : fabricToDstLinks) {
259 24 : if (!CheckPortGroupSize(netLayer, srcLink, dstLink)) {
260 0 : continue;
261 : }
262 24 : NetInstance::Path path;
263 72 : path.links = {srcLink, dstLink};
264 24 : paths.emplace_back(path);
265 24 : }
266 : }
267 : } else {
268 24 : HCCL_WARNING(
269 : "[NetInstance::GetPaths] netLayer[%u], srcRankId[%d], dstRankId[%d], netInstId[%s], "
270 : "from src[%s] to dst[%s] link via fabric[%s] not found.",
271 : netLayer, srcRankId, dstRankId, netInstId.c_str(), peers.at(srcRankId)->Describe().c_str(),
272 : peers.at(dstRankId)->Describe().c_str(), fabric->Describe().c_str());
273 : }
274 32 : }
275 :
276 114 : return paths;
277 24 : }
278 :
279 : const std::unordered_map<u32, std::vector<std::shared_ptr<NetInstance::ConnInterface>>>
280 191 : NetInstance::Node::GetInterfacesMap() const
281 : {
282 191 : return interfacesMap_;
283 : }
284 :
285 46 : vector<NetInstance::Path> ClosNetInstance::GetPaths(const RankId srcRankId, const RankId dstRankId) const
286 : {
287 46 : vector<NetInstance::Path> paths;
288 46 : if (peers.count(srcRankId) == 0 || peers.count(dstRankId) == 0) {
289 0 : HCCL_WARNING(
290 : "[ClosNetInstance::GetPaths] srcRankId[%u] or dstRankId[%u] not exist in netInstance, "
291 : "netLayer[%u], netInstId[%s].",
292 : srcRankId, dstRankId, netLayer, netInstId.c_str());
293 0 : return paths;
294 : }
295 46 : NodeId srcPeerId = peers.at(srcRankId)->GetNodeId();
296 46 : NodeId dstPeerId = peers.at(dstRankId)->GetNodeId();
297 220 : for (auto& fabric : fabrics) {
298 174 : NodeId fabricId = fabric->GetNodeId();
299 :
300 174 : NetInstance::Link srcToFabricLink;
301 174 : vGraph.TraverseEdge(srcPeerId, fabricId, [&](shared_ptr<NetInstance::Link> edge) {
302 90 : srcToFabricLink = *edge;
303 90 : return;
304 : });
305 :
306 174 : NetInstance::Link fabricToDstLink;
307 174 : vGraph.TraverseEdge(fabricId, dstPeerId, [&](shared_ptr<NetInstance::Link> edge) {
308 90 : fabricToDstLink = *edge;
309 90 : return;
310 : });
311 :
312 174 : if (!srcToFabricLink.IsEmpty() && !fabricToDstLink.IsEmpty()) {
313 90 : if (!CheckPortGroupSize(netLayer, srcToFabricLink, fabricToDstLink)) {
314 0 : continue;
315 : }
316 90 : NetInstance::Path path;
317 270 : path.links = {srcToFabricLink, fabricToDstLink};
318 90 : paths.emplace_back(path);
319 90 : } else {
320 84 : HCCL_WARNING(
321 : "[ClosNetInstance::GetPaths] from src[%s] to dst[%s] link by fabric[%s] not found.",
322 : peers.at(srcRankId)->Describe().c_str(), peers.at(dstRankId)->Describe().c_str(),
323 : fabric->Describe().c_str());
324 : }
325 174 : }
326 :
327 46 : return paths;
328 90 : }
329 :
330 925 : void NetInstance::Node::AddConnInterface(u32 layer, const shared_ptr<NetInstance::ConnInterface>& interface)
331 : {
332 925 : auto& interfacesVec = interfacesMap_[layer];
333 1346 : for (const auto& iface : interfacesVec) {
334 552 : if (*iface == *interface) {
335 311 : HCCL_WARNING(
336 : "[NetInstance][Node][AddConnInterface] interface addr[%s] has existed.",
337 : interface->GetAddr().Describe().c_str());
338 131 : return;
339 : }
340 : }
341 :
342 794 : interfacesVec.emplace_back(interface);
343 : }
344 :
345 188 : void NetInstance::Node::AddConnInterfaces(
346 : u32 layer, const std::vector<std::shared_ptr<NetInstance::ConnInterface>>& interfaces)
347 : {
348 188 : if (interfaces.empty()) {
349 0 : return;
350 : }
351 376 : for (auto interface : interfaces) {
352 188 : AddConnInterface(layer, interface);
353 188 : }
354 : }
355 :
356 569 : NetInstance::Node::NodeType NetInstance::Node::GetType() const { return type_; }
357 :
358 43 : std::vector<std::shared_ptr<NetInstance::ConnInterface>> NetInstance::Node::GetIfacesByLayer(u32 layer) const
359 : {
360 43 : auto it = interfacesMap_.find(layer);
361 43 : if (it == interfacesMap_.end()) {
362 2 : HCCL_WARNING("[NetInstance][Node][GetIfacesByLayer] netLayer[%u] not exist.", layer);
363 2 : return std::vector<std::shared_ptr<NetInstance::ConnInterface>>{};
364 : }
365 41 : return it->second;
366 : }
367 :
368 78 : std::vector<std::shared_ptr<NetInstance::ConnInterface>> NetInstance::Node::GetIfaces() const
369 : {
370 78 : std::vector<std::shared_ptr<NetInstance::ConnInterface>> ifaces;
371 108 : for (auto layerIfacesPair : interfacesMap_) {
372 80 : for (auto iface : layerIfacesPair.second) {
373 50 : ifaces.emplace_back(iface);
374 50 : }
375 30 : }
376 78 : return ifaces;
377 0 : }
378 :
379 59 : void NetInstance::Node::SetEndpointToIface(
380 : const CommAddr& commAddr, CommProtocol protocol, const std::shared_ptr<NetInstance::ConnInterface>& iface)
381 : {
382 59 : endpointToIfaceMap_[std::make_pair(commAddr, protocol)] = iface;
383 59 : }
384 :
385 : const std::unordered_map<std::pair<CommAddr, CommProtocol>, std::shared_ptr<NetInstance::ConnInterface>>
386 16 : NetInstance::Node::GetEndpointToIfaceMap() const
387 : {
388 16 : return endpointToIfaceMap_;
389 : }
390 :
391 5034 : NodeId NetInstance::Node::GetNodeId() const { return nodeId_; }
392 :
393 1427 : LocalId NetInstance::Peer::GetLocalId() const { return localId_; }
394 :
395 16 : LocalId NetInstance::Peer::GetReplacedLocalId() const { return replacedLocalId_; }
396 :
397 132 : DeviceId NetInstance::Peer::GetDeviceId() const { return deviceId_; }
398 :
399 8 : u32 NetInstance::Peer::GetDevicePort() const { return devicePort_; }
400 :
401 6 : u32 NetInstance::Peer::GetHostPort() const { return hostPort_; }
402 :
403 2367 : RankId NetInstance::Peer::GetRankId() const { return rankId_; }
404 :
405 108 : set<u32> NetInstance::Peer::GetLevels() const { return netLayers_; }
406 :
407 434 : const NetInstance* NetInstance::Peer::GetNetInstance(u32 netLayer) const
408 : {
409 434 : if (netLayer >= netInsts_.size() || netInsts_.at(netLayer) == nullptr) {
410 68 : HCCL_WARNING("[NetInstance][Peer][GetNetInstance] netLayer[%u] not exist.", netLayer);
411 24 : return nullptr;
412 : }
413 410 : return netInsts_[netLayer];
414 : }
415 :
416 812 : NodeId NetInstance::Peer::GenerateNodeId(RankId rankId)
417 : {
418 812 : return (static_cast<u64>(rankId) | static_cast<u64>(0) << 32); // 第32位为0 + rankId
419 : }
420 :
421 1115 : string NetInstance::Peer::Describe() const
422 : {
423 : return StringFormat(
424 1115 : "NetInstance::Peer[rankId=%d, localId=%u, NodeId=%llu, netLayers_size=%zu]", rankId_, localId_, nodeId_,
425 1115 : netLayers_.size());
426 : }
427 :
428 547 : void NetInstance::Peer::AddNetInstance(const std::shared_ptr<NetInstance>& netInst)
429 : {
430 547 : u32 netLayer = netInst->GetNetLayer();
431 547 : if (netLayer >= netInsts_.size()) {
432 546 : netInsts_.resize(netLayer + 1);
433 : }
434 :
435 547 : if (netInsts_[netLayer] != nullptr) {
436 2 : THROW<InvalidParamsException>(StringFormat(
437 : "[NetInstance][Peer][AddNetInstance]rankId[%d] netLayer[%u] NetInstance has existed", rankId_, netLayer));
438 : }
439 546 : netInsts_[netLayer] = netInst.get();
440 546 : netLayers_.insert(netInst->GetNetLayer());
441 546 : }
442 :
443 50 : void NetInstance::Peer::SetPortPortAddrMapLayer0(std::map<std::string, std::vector<IpAddress>> portAddrMap)
444 : {
445 50 : portAddrMapLayer0_ = std::move(portAddrMap);
446 50 : }
447 :
448 268 : std::map<std::string, std::vector<IpAddress>> NetInstance::Peer::GetPortAddrMapLayer0() const
449 : {
450 268 : return portAddrMapLayer0_;
451 : }
452 :
453 13 : PlaneId NetInstance::Fabric::GetPlaneId() const { return planeId_; }
454 :
455 55 : NodeId NetInstance::Fabric::GenerateNodeId(FabricId fabricId) const
456 : {
457 55 : return (static_cast<u64>(fabricId) | static_cast<u64>(1) << 32); // 第32位为1 + netplaneId
458 : }
459 :
460 243 : string NetInstance::Fabric::Describe() const
461 : {
462 243 : return StringFormat("NetInstance::Fabric[netplaneId=%s, FabricNodeId=%llu]", planeId_.c_str(), nodeId_);
463 : }
464 :
465 31 : LinkType NetInstance::Link::GetType() const { return type_; }
466 :
467 131 : std::set<LinkProtocol> NetInstance::Link::GetLinkProtocols() const { return linkProtocols_; }
468 :
469 127 : LinkDirection NetInstance::Link::GetLinkDirection() const { return direction_; }
470 :
471 119 : u32 NetInstance::Link::GetHop() const { return hop_; }
472 :
473 885 : shared_ptr<NetInstance::Node> NetInstance::Link::GetSourceNode() const { return source_; }
474 :
475 885 : shared_ptr<NetInstance::Node> NetInstance::Link::GetTargetNode() const { return target_; }
476 :
477 269 : shared_ptr<NetInstance::ConnInterface> NetInstance::Link::GetSourceIface() const { return sourceIface_; }
478 :
479 269 : shared_ptr<NetInstance::ConnInterface> NetInstance::Link::GetTargetIface() const { return targetIface_; }
480 :
481 1022 : string NetInstance::Link::Describe() const
482 : {
483 1022 : stringstream iFace;
484 1022 : if (sourceIface_ != nullptr) {
485 788 : iFace << ", srcIface=" << sourceIface_->Describe();
486 : }
487 1022 : if (targetIface_ != nullptr) {
488 788 : iFace << ", dstIface=" << targetIface_->Describe();
489 : }
490 1022 : std::stringstream linkProtocolsStr;
491 2048 : for (auto protocol : linkProtocols_) {
492 1026 : if (!linkProtocolsStr.str().empty()) {
493 4 : linkProtocolsStr << ", ";
494 : }
495 1026 : linkProtocolsStr << protocol;
496 : }
497 : return StringFormat(
498 1022 : "NetInstance::Link[srcId=%llu, dstId=%llu, type=%s, hop=%u, dir=%s, proto=%s%s]", source_->GetNodeId(),
499 3066 : target_->GetNodeId(), type_.Describe().c_str(), hop_, direction_.Describe().c_str(),
500 5110 : linkProtocolsStr.str().c_str(), iFace.str().c_str());
501 1022 : }
502 :
503 264 : bool NetInstance::Link::IsEmpty() const { return (source_ == nullptr) && (target_ == nullptr); }
504 :
505 65 : bool NetInstance::Link::operator==(const NetInstance::Link& rhs) const
506 : {
507 130 : return source_->GetNodeId() == rhs.source_->GetNodeId() && target_->GetNodeId() == rhs.target_->GetNodeId()
508 65 : && sourceIface_ == rhs.sourceIface_ && targetIface_ == rhs.targetIface_ && type_ == rhs.type_
509 130 : && linkProtocols_ == rhs.linkProtocols_ && direction_ == rhs.direction_ && hop_ == rhs.hop_;
510 : }
511 :
512 0 : bool NetInstance::Link::operator!=(const NetInstance::Link& rhs) const { return !(rhs == *this); }
513 :
514 546 : IpAddress NetInstance::ConnInterface::GetAddr() const { return addr; }
515 :
516 230 : std::set<string> NetInstance::ConnInterface::GetPorts() const { return ports; }
517 :
518 440 : AddrPosition NetInstance::ConnInterface::GetPos() const { return pos; }
519 :
520 0 : LinkType NetInstance::ConnInterface::GetLinkType() const { return linkType; }
521 :
522 777 : std::set<LinkProtocol> NetInstance::ConnInterface::GetLinkProtocols() const { return linkProtocols; }
523 :
524 51 : void NetInstance::ConnInterface::SetLocalDieId(u32 dieId) { localDieId_ = dieId; }
525 :
526 44 : u32 NetInstance::ConnInterface::GetLocalDieId() const { return localDieId_; }
527 :
528 33 : TopoType NetInstance::ConnInterface::GetTopoType() const { return topoType; }
529 :
530 56 : u32 NetInstance::ConnInterface::GetTopoInstId() const { return topoInstId; }
531 :
532 1576 : std::string NetInstance::ConnInterface::Describe() const
533 : {
534 : return StringFormat(
535 3152 : "Iface[addr=%s, pos=%s, topoInstId=%u, topoType=%d, localDieId=%u]", addr.Describe().c_str(),
536 4728 : pos.Describe().c_str(), topoInstId, topoType, localDieId_);
537 : }
538 :
539 552 : bool NetInstance::ConnInterface::operator==(const NetInstance::ConnInterface& rhs) const
540 : {
541 707 : return addr == rhs.addr && pos == rhs.pos && linkType == rhs.linkType && linkProtocols == rhs.linkProtocols
542 707 : && ports == rhs.ports && topoInstId == rhs.topoInstId && topoType == rhs.topoType;
543 : }
544 :
545 0 : bool NetInstance::ConnInterface::operator!=(const NetInstance::ConnInterface& rhs) const { return !(rhs == *this); }
546 :
547 : } // namespace Hccl
|