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 "rank_graph_interface.h"
12 : #include <set>
13 : #include <functional>
14 : #include <unordered_map>
15 : #include "topo_common_types.h"
16 :
17 : namespace Hccl {
18 :
19 0 : HcclResult IRankGraph::GetRankId(uint32_t *rank)
20 : {
21 0 : CHK_PTR_NULL(rankGraphPtr_);
22 0 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
23 0 : *rank = rankGraph->GetMyRank();
24 0 : return HCCL_SUCCESS;
25 : }
26 :
27 301 : HcclResult IRankGraph::GetRankSize(uint32_t *rankSize)
28 : {
29 301 : CHK_PTR_NULL(rankGraphPtr_);
30 301 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
31 301 : *rankSize = rankGraph->GetRankSize();
32 301 : return HCCL_SUCCESS;
33 : }
34 :
35 2 : HcclResult IRankGraph::GetDevicePort(const uint32_t rank, uint32_t *devPort)
36 : {
37 2 : CHK_PTR_NULL(devPort);
38 2 : CHK_PTR_NULL(rankGraphPtr_);
39 2 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
40 2 : auto peer = rankGraph->GetPeer(rank);
41 2 : CHK_PTR_NULL(peer);
42 2 : *devPort = peer->GetDevicePort();
43 2 : return HCCL_SUCCESS;
44 2 : }
45 :
46 0 : HcclResult IRankGraph::GetHostPort(const uint32_t rank, uint32_t *hostPort)
47 : {
48 0 : CHK_PTR_NULL(hostPort);
49 0 : CHK_PTR_NULL(rankGraphPtr_);
50 0 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
51 0 : auto peer = rankGraph->GetPeer(rank);
52 0 : CHK_PTR_NULL(peer);
53 0 : *hostPort = peer->GetHostPort();
54 0 : return HCCL_SUCCESS;
55 0 : }
56 :
57 0 : HcclResult IRankGraph::GetRankGraphInfo(void **graph, uint32_t *len)
58 : {
59 0 : CHK_PTR_NULL(rankGraphPtr_);
60 0 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
61 0 : *graph = rankGraph;
62 0 : *len = sizeof(RankGraph);
63 0 : return HCCL_SUCCESS;
64 : }
65 :
66 0 : HcclResult IRankGraph::GetDeviceId(uint32_t rankId, uint32_t *deviceId)
67 : {
68 0 : CHK_PTR_NULL(rankGraphPtr_);
69 0 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
70 0 : if (rankGraph->GetPeer(rankId) == nullptr) {
71 0 : HCCL_ERROR("[GetPeer] rankGraph peer is null!");
72 0 : return HCCL_E_PTR;
73 : }
74 0 : *deviceId = rankGraph->GetPeer(rankId)->GetDeviceId();
75 0 : return HCCL_SUCCESS;
76 : }
77 :
78 1 : HcclResult IRankGraph::GetNetLayers(uint32_t** netLayers, uint32_t* netLayerNum)
79 : {
80 1 : CHK_PTR_NULL(rankGraphPtr_);
81 1 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
82 1 : u32 rankId = rankGraph->GetMyRank();
83 1 : std::set<u32> levels = rankGraph->GetLevels(rankId);
84 1 : netLayersVec_.clear();
85 1 : netLayersVec_ = std::vector<u32>(levels.begin(), levels.end());
86 1 : *netLayers = netLayersVec_.data();
87 1 : *netLayerNum = rankGraph->GetLevelNum();
88 1 : return HCCL_SUCCESS;
89 1 : }
90 :
91 2 : HcclResult IRankGraph::GetInstTopoTypeByNetLayer(uint32_t netLayer, CommTopo* topoType)
92 : {
93 2 : CHK_PTR_NULL(rankGraphPtr_);
94 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
95 2 : u32 rankId = rankGraph->GetMyRank();
96 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
97 2 : if (levels.find(netLayer) == levels.end()) {
98 1 : HCCL_ERROR("[IRankGraph::GetInstTopoTypeByNetLayer] netLayer[%u] is invalid", netLayer);
99 1 : return HCCL_E_PARA;
100 : }
101 1 : auto type = rankGraph->GetNetType(netLayer);
102 : static const std::unordered_map<NetType, CommTopo> netTypeMap = {
103 : {NetType::CLOS, CommTopo::COMM_TOPO_CLOS},
104 : {NetType::MESH_1D, CommTopo::COMM_TOPO_1DMESH},
105 : {NetType::A3_SERVER, CommTopo::COMM_TOPO_910_93},
106 : {NetType::A2_AX_SERVER, CommTopo::COMM_TOPO_A2AXSERVER},
107 3 : {NetType::TOPO_FILE_DESC, CommTopo::COMM_TOPO_CUSTOM}};
108 :
109 1 : auto it = netTypeMap.find(type);
110 1 : if (it == netTypeMap.end()) {
111 0 : HCCL_ERROR("[GetInstTopoTypeByNetLayer] netType[%d] not in netTypeMap", type);
112 0 : return HCCL_E_PARA;
113 : }
114 1 : *topoType = it->second;
115 1 : return HCCL_SUCCESS;
116 2 : }
117 :
118 2 : HcclResult IRankGraph::GetInstSizeByNetLayer(uint32_t netLayer, uint32_t* rankNum)
119 : {
120 2 : CHK_PTR_NULL(rankGraphPtr_);
121 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
122 2 : u32 rankId = rankGraph->GetMyRank();
123 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
124 2 : if (levels.find(netLayer) == levels.end()) {
125 1 : HCCL_ERROR("[IRankGraph::GetInstSizeByNetLayer] netLayer[%u] is invalid", netLayer);
126 1 : return HCCL_E_PARA;
127 : }
128 1 : u32 num = rankGraph->GetLocalInstSize(netLayer);
129 1 : *rankNum = static_cast<uint32_t>(num);
130 1 : return HCCL_SUCCESS;
131 2 : }
132 :
133 2 : HcclResult IRankGraph::GetInstRanksByNetLayer(uint32_t netLayer, uint32_t** rankList, uint32_t* rankNum)
134 : {
135 2 : CHK_PTR_NULL(rankGraphPtr_);
136 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
137 2 : u32 rankId = rankGraph->GetMyRank();
138 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
139 2 : if (levels.find(netLayer) == levels.end()) {
140 1 : HCCL_ERROR("[IRankGraph::GetInstRanksByNetLayer] netLayer[%u] is invalid", netLayer);
141 1 : return HCCL_E_PARA;
142 : }
143 1 : u32 num = 0;
144 1 : rankListVec_.clear();
145 1 : rankGraph->GetLocalInstRanks(netLayer, rankListVec_, num);
146 1 : *rankList = rankListVec_.data();
147 1 : *rankNum = num;
148 1 : return HCCL_SUCCESS;
149 2 : }
150 :
151 2 : HcclResult IRankGraph::GetInstSizeListByNetLayer(uint32_t netLayer, uint32_t** instSizeList, uint32_t* listSize)
152 : {
153 2 : CHK_PTR_NULL(rankGraphPtr_);
154 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
155 2 : u32 rankId = rankGraph->GetMyRank();
156 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
157 2 : if (levels.find(netLayer) == levels.end()) {
158 1 : HCCL_ERROR("[IRankGraph::GetInstSizeListByNetLayer] netLayer[%u] is invalid", netLayer);
159 1 : return HCCL_E_PARA;
160 : }
161 1 : u32 size = 0;
162 1 : instSizeVec_.clear();
163 1 : auto ret = rankGraph->GetNetInstanceList(netLayer, instSizeVec_, size);
164 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
165 : HCCL_ERROR("[IRankGraph::GetInstSizeListByNetLayer] Failed to get instSizeList at netLayer[%u], "
166 : "myRank[%u], ret[%d]", netLayer, rankId, ret), ret);
167 1 : *instSizeList = instSizeVec_.data();
168 1 : *listSize = size;
169 1 : return HCCL_SUCCESS;
170 2 : }
171 :
172 2 : static HcclResult SetCommAddress(CommAddr &commAddr, const IpAddress &ipAddr)
173 : {
174 2 : s32 family = ipAddr.GetFamily();
175 2 : if (family == AF_INET) {
176 2 : string addr = ipAddr.GetIpStr();
177 2 : if (ipAddr.IsEID(addr)) {
178 0 : commAddr.type = COMM_ADDR_TYPE_EID;
179 0 : const auto &eid = ipAddr.GetEid();
180 0 : for (u32 i = 0; i < URMA_EID_LEN && i < sizeof(commAddr.eid); i++) {
181 0 : commAddr.eid[i] = eid.raw[i];
182 : }
183 : } else {
184 2 : commAddr.type = COMM_ADDR_TYPE_IP_V4;
185 2 : commAddr.addr = ipAddr.GetBinaryAddress().addr;
186 : }
187 2 : } else if (family == AF_INET6) {
188 0 : commAddr.type = COMM_ADDR_TYPE_IP_V6;
189 0 : commAddr.addr6 = ipAddr.GetBinaryAddress().addr6;
190 : } else {
191 0 : HCCL_ERROR("[IRankGraph::GetLinks] invalid commAddrType");
192 0 : return HCCL_E_INTERNAL;
193 : }
194 2 : return HCCL_SUCCESS;
195 : }
196 :
197 2 : static HcclResult SetEndpointLoc(EndpointLocType &locType, const AddrPosition &position)
198 : {
199 2 : if (position == AddrPosition::DEVICE) {
200 2 : locType = ENDPOINT_LOC_TYPE_DEVICE;
201 0 : } else if (position == AddrPosition::HOST) {
202 0 : locType = ENDPOINT_LOC_TYPE_HOST;
203 : } else {
204 0 : locType = ENDPOINT_LOC_TYPE_RESERVED;
205 : }
206 2 : return HCCL_SUCCESS;
207 : }
208 :
209 1 : static HcclResult InsertInnerLink(const NetInstance::Path &path, std::vector<CommLink> &linkListVec)
210 : {
211 2 : for (const auto &link : path.links) {
212 1 : const NetInstance::Link *peer2peer = &link;
213 2 : for (LinkProtocol protocol : link.GetLinkProtocols()) {
214 : CommLink commLink;
215 1 : CommLinkInit(&commLink, 1);
216 1 : const CommProtocol &commProtocol = LinkProtocolToCommProtocol(protocol);
217 1 : commLink.linkAttr.linkProtocol = commProtocol;
218 1 : commLink.linkAttr.hop = peer2peer->GetHop();
219 1 : commLink.srcEndpointDesc.protocol = commProtocol;
220 1 : commLink.dstEndpointDesc.protocol = commProtocol;
221 :
222 : // 设置源端点
223 1 : std::shared_ptr<NetInstance::ConnInterface> srcConnInterface = link.GetSourceIface();
224 1 : CHK_PTR_NULL(srcConnInterface);
225 1 : HcclResult result = SetCommAddress(commLink.srcEndpointDesc.commAddr, srcConnInterface->GetAddr());
226 1 : if (result != HCCL_SUCCESS) {
227 0 : HCCL_ERROR("[IRankGraph::%s] SetCommAddress FAILED for srcConn: %s.", __func__, srcConnInterface->Describe().c_str());
228 0 : return result;
229 : }
230 1 : CHK_RET(SetEndpointLoc(commLink.srcEndpointDesc.loc.locType, srcConnInterface->GetPos()));
231 :
232 : // 设置目标端点
233 1 : std::shared_ptr<NetInstance::ConnInterface> dstConnInterface = link.GetTargetIface();
234 1 : CHK_PTR_NULL(dstConnInterface);
235 1 : result = SetCommAddress(commLink.dstEndpointDesc.commAddr, dstConnInterface->GetAddr());
236 1 : if (result != HCCL_SUCCESS) {
237 0 : HCCL_ERROR("[IRankGraph::%s] SetCommAddress FAILED for dstConn: %s.", __func__, dstConnInterface->Describe().c_str());
238 0 : return result;
239 : }
240 :
241 1 : CHK_RET(SetEndpointLoc(commLink.dstEndpointDesc.loc.locType, dstConnInterface->GetPos()));
242 :
243 1 : if (commLink.srcEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
244 1 : std::shared_ptr<NetInstance::Node> srcNode = peer2peer->GetSourceNode();
245 1 : std::shared_ptr<NetInstance::Node> dstNode = peer2peer->GetTargetNode();
246 1 : std::shared_ptr<NetInstance::Peer> srcPeer = std::dynamic_pointer_cast<NetInstance::Peer>(srcNode);
247 1 : std::shared_ptr<NetInstance::Peer> dstPeer = std::dynamic_pointer_cast<NetInstance::Peer>(dstNode);
248 1 : commLink.srcEndpointDesc.loc.device.devPhyId = srcPeer->GetDeviceId();
249 1 : commLink.dstEndpointDesc.loc.device.devPhyId = dstPeer->GetDeviceId();
250 1 : }
251 :
252 1 : linkListVec.emplace_back(std::move(commLink));
253 2 : }
254 : }
255 :
256 1 : return HCCL_SUCCESS;
257 : }
258 :
259 0 : static HcclResult InsertClosLinks(const NetInstance::Path &path, std::vector<CommLink> &linkListVec)
260 : {
261 0 : const NetInstance::Link *peer2net = nullptr;
262 0 : const NetInstance::Link *net2peer = nullptr;
263 0 : for (const auto &link : path.links) {
264 0 : bool srcNull = (link.GetSourceIface() == nullptr);
265 0 : bool dstNull = (link.GetTargetIface() == nullptr);
266 0 : if (!srcNull && dstNull) {
267 0 : peer2net = &link;
268 0 : } else if (srcNull && !dstNull) {
269 0 : net2peer = &link;
270 : }
271 : }
272 0 : CHK_PTR_NULL(peer2net);
273 0 : CHK_PTR_NULL(net2peer);
274 :
275 0 : auto srcInterface = peer2net->GetSourceIface();
276 0 : auto dstInterface = net2peer->GetTargetIface();
277 0 : CHK_PTR_NULL(srcInterface);
278 0 : CHK_PTR_NULL(dstInterface);
279 0 : for (LinkProtocol protocol : peer2net->GetLinkProtocols()) {
280 : CommLink commLink;
281 0 : CommLinkInit(&commLink, 1);
282 0 : const CommProtocol &commProtocol = LinkProtocolToCommProtocol(protocol);
283 :
284 0 : commLink.linkAttr.linkProtocol = commProtocol;
285 0 : commLink.linkAttr.hop = peer2net->GetHop();
286 0 : commLink.srcEndpointDesc.protocol = commProtocol;
287 0 : commLink.dstEndpointDesc.protocol = commProtocol;
288 :
289 : // 设置源端点
290 0 : CHK_RET(SetCommAddress(commLink.srcEndpointDesc.commAddr, srcInterface->GetAddr()));
291 0 : CHK_RET(SetEndpointLoc(commLink.srcEndpointDesc.loc.locType, srcInterface->GetPos()));
292 0 : if (commLink.srcEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
293 0 : std::shared_ptr<NetInstance::Node> srcNode = peer2net->GetSourceNode();
294 0 : std::shared_ptr<NetInstance::Peer> srcPeer = std::dynamic_pointer_cast<NetInstance::Peer>(srcNode);
295 0 : commLink.srcEndpointDesc.loc.device.devPhyId = srcPeer->GetDeviceId();
296 0 : }
297 :
298 : // 设置目标端点
299 0 : CHK_RET(SetCommAddress(commLink.dstEndpointDesc.commAddr, dstInterface->GetAddr()));
300 0 : CHK_RET(SetEndpointLoc(commLink.dstEndpointDesc.loc.locType, dstInterface->GetPos()));
301 0 : if (commLink.dstEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
302 0 : std::shared_ptr<NetInstance::Node> dstNode = net2peer->GetTargetNode();
303 0 : std::shared_ptr<NetInstance::Peer> dstPeer = std::dynamic_pointer_cast<NetInstance::Peer>(dstNode);
304 0 : commLink.dstEndpointDesc.loc.device.devPhyId = dstPeer->GetDeviceId();
305 0 : }
306 :
307 0 : linkListVec.emplace_back(std::move(commLink));
308 0 : }
309 0 : return HCCL_SUCCESS;
310 0 : }
311 :
312 2 : HcclResult IRankGraph::GetLinks(uint32_t netLayer, uint32_t srcRank, uint32_t dstRank, CommLink** linkList,
313 : uint32_t* listSize)
314 : {
315 2 : CHK_PTR_NULL(rankGraphPtr_);
316 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
317 2 : u32 rankId = rankGraph->GetMyRank();
318 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
319 2 : if (levels.find(netLayer) == levels.end()) {
320 1 : HCCL_ERROR("[IRankGraph::GetLinks] netLayer[%u] is invalid", netLayer);
321 1 : return HCCL_E_PARA;
322 : }
323 1 : std::vector<NetInstance::Path> paths = rankGraph->GetPaths(netLayer, srcRank, dstRank);
324 1 : linkListVec_.clear();
325 : // 遍历每条path
326 2 : for (const auto& path : paths) {
327 : // 检查是否是Clos网络(有nullptr接口)
328 1 : bool isClos = false;
329 2 : for (const auto& link : path.links) {
330 : // fabric没有接口
331 1 : if (link.GetSourceIface() == nullptr || link.GetTargetIface() == nullptr) {
332 0 : isClos = true;
333 0 : break;
334 : }
335 : }
336 1 : if (!isClos) {
337 : // Peer2Peer网络:直接处理每条link
338 1 : HcclResult ret = InsertInnerLink(path, linkListVec_);
339 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
340 : HCCL_ERROR("[IRankGraph::%s] InsertInnerLink failed for Peer2Peer, linkNum[%zu], ret[%d]",
341 : __func__, path.links.size(), ret),
342 : ret);
343 : } else {
344 : // Clos网络:找到peer2net和net2peer,组合成一条链路
345 0 : HcclResult ret = InsertClosLinks(path, linkListVec_);
346 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
347 : HCCL_ERROR("[IRankGraph::%s] InsertClosLinks failed for Clos, linkNum[%zu], ret[%d]",
348 : __func__, path.links.size(), ret),
349 : ret);
350 : }
351 : }
352 1 : *linkList = linkListVec_.data();
353 1 : *listSize = linkListVec_.size();
354 1 : return HCCL_SUCCESS;
355 2 : }
356 :
357 1 : HcclResult IRankGraph::GetTopoInstsByLayer(uint32_t netLayer, uint32_t** topoInsts, uint32_t* topoInstNum)
358 : {
359 1 : CHK_PTR_NULL(rankGraphPtr_);
360 1 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
361 1 : u32 rankId = rankGraph->GetMyRank();
362 1 : std::set<u32> levels = rankGraph->GetLevels(rankId);
363 1 : if (levels.find(netLayer) == levels.end()) {
364 0 : HCCL_ERROR("[IRankGraph::GetTopoInstsByLayer] netLayer[%u] is invalid", netLayer);
365 0 : return HCCL_E_PARA;
366 : }
367 1 : u32 num = 0;
368 1 : topoInstsVec_.clear();
369 1 : rankGraph->GetTopoInstsByLayer(netLayer, topoInstsVec_, num);
370 1 : *topoInsts = topoInstsVec_.data();
371 1 : *topoInstNum = num;
372 1 : return HCCL_SUCCESS;
373 1 : }
374 :
375 2 : HcclResult IRankGraph::GetTopoType(const uint32_t netLayer, const uint32_t topoInstId, CommTopo* topoType)
376 : {
377 2 : CHK_PTR_NULL(rankGraphPtr_);
378 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
379 2 : u32 rankId = rankGraph->GetMyRank();
380 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
381 2 : if (levels.find(netLayer) == levels.end()) {
382 0 : HCCL_ERROR("[IRankGraph::GetTopoType] netLayer[%u] is invalid", netLayer);
383 0 : return HCCL_E_PARA;
384 : }
385 2 : Hccl::TopoType type;
386 2 : HcclResult ret = rankGraph->GetTopoType(netLayer, topoInstId, type);
387 2 : if (ret != HCCL_SUCCESS) {
388 1 : HCCL_ERROR("[IRankGraph::GetTopoType] Failed to get topo type at netLayer [%u] topoInstId [%u] ret=%d", netLayer, topoInstId, ret);
389 1 : return ret;
390 : }
391 : static const std::unordered_map<Hccl::TopoType, CommTopo> topoTypeMap = {
392 : {Hccl::TopoType::CLOS, COMM_TOPO_CLOS},
393 : {Hccl::TopoType::MESH_1D, COMM_TOPO_1DMESH},
394 : {Hccl::TopoType::A3_SERVER, COMM_TOPO_910_93},
395 3 : {Hccl::TopoType::A2_AX_SERVER, COMM_TOPO_A2AXSERVER}};
396 1 : auto it = topoTypeMap.find(type);
397 1 : if (it != topoTypeMap.end()) {
398 1 : *topoType = it->second;
399 1 : return HCCL_SUCCESS;
400 : }
401 0 : HCCL_ERROR("[IRankGraph::GetTopoType] topoType[%s] is not supported, netLayer[%u], "
402 : "topoInstId[%u], myRank[%u]", type.Describe().c_str(), netLayer, topoInstId, rankId);
403 0 : return HCCL_E_PARA;
404 2 : }
405 :
406 2 : HcclResult IRankGraph::GetRanksByTopoInst(const uint32_t netLayer, const uint32_t topoInstId, uint32_t** ranks,
407 : uint32_t* rankNum)
408 : {
409 2 : CHK_PTR_NULL(rankGraphPtr_);
410 2 : RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
411 2 : u32 rankId = rankGraph->GetMyRank();
412 2 : std::set<u32> levels = rankGraph->GetLevels(rankId);
413 2 : if (levels.find(netLayer) == levels.end()) {
414 0 : HCCL_ERROR("[IRankGraph::GetRanksByTopoInst] netLayer[%u] is invalid", netLayer);
415 0 : return HCCL_E_PARA;
416 : }
417 2 : u32 num = 0;
418 2 : auto ret = rankGraph->GetRanksByTopoInst(netLayer, topoInstId, ranksVec_, num);
419 2 : if (ret != HCCL_SUCCESS) {
420 1 : HCCL_ERROR("[IRankGraph::GetRanksByTopoInst] Failed to get ranks at netLayer [%u] topoInstId [%u] ret=%d", netLayer, topoInstId, ret);
421 1 : return ret;
422 : }
423 1 : *ranks = ranksVec_.data();
424 1 : *rankNum = ranksVec_.size();
425 1 : return HCCL_SUCCESS;
426 2 : }
427 :
428 1 : HcclResult IRankGraph::GetEndpointNum(uint32_t netLayer, uint32_t topoInstId, uint32_t *num)
429 : {
430 1 : CHK_PTR_NULL(rankGraphPtr_);
431 1 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
432 1 : u32 rankId = rankGraph->GetMyRank();
433 1 : std::set<u32> levels = rankGraph->GetLevels(rankId);
434 1 : if (levels.find(netLayer) == levels.end()) {
435 0 : HCCL_ERROR("[IRankGraph::GetEndpointNum] netLayer[%u] is invalid", netLayer);
436 0 : return HCCL_E_PARA;
437 : }
438 1 : auto ret = rankGraph->GetEndpointNum(netLayer, topoInstId, num);
439 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
440 : HCCL_ERROR("[IRankGraph::GetEndpointNum] Failed to get endpoint num at netLayer[%u], "
441 : "topoInstId[%u], myRank[%u], ret[%d]", netLayer, topoInstId, rankId, ret),
442 : ret);
443 1 : return HCCL_SUCCESS;
444 1 : }
445 :
446 1 : HcclResult IRankGraph::GetEndpointDesc(uint32_t netLayer, uint32_t topoInstId, uint32_t *descNum,
447 : EndpointDesc *endpointDesc)
448 : {
449 1 : CHK_PTR_NULL(rankGraphPtr_);
450 1 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
451 1 : u32 rankId = rankGraph->GetMyRank();
452 1 : std::set<u32> levels = rankGraph->GetLevels(rankId);
453 1 : if (levels.find(netLayer) == levels.end()) {
454 0 : HCCL_ERROR("[IRankGraph::GetEndpointDesc] netLayer[%u] is invalid", netLayer);
455 0 : return HCCL_E_PARA;
456 : }
457 1 : auto ret = rankGraph->GetEndpointDesc(netLayer, topoInstId, descNum, endpointDesc);
458 1 : CHK_PRT_RET(ret != HCCL_SUCCESS,
459 : HCCL_ERROR("[IRankGraph::GetEndpointDesc] Failed to get endpoint desc at netLayer[%u], "
460 : "topoInstId[%u], myRank[%u], descNum[%u], ret[%d]", netLayer, topoInstId, rankId,
461 : *descNum, ret),
462 : ret);
463 1 : return HCCL_SUCCESS;
464 1 : }
465 :
466 0 : static const char *EndpointAttrToString(EndpointAttr endpointAttr)
467 : {
468 0 : switch (endpointAttr) {
469 0 : case ENDPOINT_ATTR_BW_COEFF:
470 0 : return "ENDPOINT_ATTR_BW_COEFF";
471 0 : case ENDPOINT_ATTR_DIE_ID:
472 0 : return "ENDPOINT_ATTR_DIE_ID";
473 0 : case ENDPOINT_ATTR_LOCATION:
474 0 : return "ENDPOINT_ATTR_LOCATION";
475 0 : default:
476 0 : return "ENDPOINT_ATTR_INVALID";
477 : }
478 : }
479 :
480 0 : HcclResult IRankGraph::GetEndpointInfo(uint32_t rankId, const EndpointDesc *endPointDesc, EndpointAttr endpointAttr,
481 : uint32_t infoLen, void *info)
482 : {
483 0 : CHK_PTR_NULL(rankGraphPtr_);
484 0 : RankGraph *rankGraph = static_cast<RankGraph *>(rankGraphPtr_);
485 0 : HcclResult ret = rankGraph->GetEndpointInfo(rankId, endPointDesc, endpointAttr, infoLen, info);
486 0 : CHK_PRT_RET(ret != HCCL_SUCCESS,
487 : HCCL_ERROR("[IRankGraph::GetEndpointInfo] Failed to get endpoint info, rankId[%u], "
488 : "endpointAttr[%s], ret[%d]", rankId, EndpointAttrToString(endpointAttr), ret),
489 : ret);
490 0 : return HCCL_SUCCESS;
491 : }
492 :
493 : } // namespace Hccl
|