LCOV - code coverage report
Current view: top level - legacy/ascend950/interface - rank_graph_interface.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 64.4 % 331 213
Test Date: 2026-08-18 17:47:01 Functions: 69.6 % 23 16

            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          484 : HcclResult IRankGraph::GetRankSize(uint32_t* rankSize)
      28              : {
      29          484 :     CHK_PTR_NULL(rankGraphPtr_);
      30          484 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
      31          484 :     *rankSize = rankGraph->GetRankSize();
      32          484 :     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("[GetDeviceId] 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[%s] not in netTypeMap", type.Describe().c_str());
     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(
     165              :         ret != HCCL_SUCCESS,
     166              :         HCCL_ERROR(
     167              :             "[IRankGraph::GetInstSizeListByNetLayer] Failed to get instSizeList at netLayer[%u], "
     168              :             "myRank[%u], ret[%d]",
     169              :             netLayer, rankId, ret),
     170              :         ret);
     171            1 :     *instSizeList = instSizeVec_.data();
     172            1 :     *listSize = size;
     173            1 :     return HCCL_SUCCESS;
     174            2 : }
     175              : 
     176            2 : static HcclResult SetCommAddress(CommAddr& commAddr, const IpAddress& ipAddr)
     177              : {
     178            2 :     s32 family = ipAddr.GetFamily();
     179            2 :     if (family == AF_INET) {
     180            2 :         string addr = ipAddr.GetIpStr();
     181            2 :         if (ipAddr.IsEID(addr)) {
     182            0 :             commAddr.type = COMM_ADDR_TYPE_EID;
     183            0 :             const auto& eid = ipAddr.GetEid();
     184            0 :             for (u32 i = 0; i < URMA_EID_LEN && i < sizeof(commAddr.eid); i++) {
     185            0 :                 commAddr.eid[i] = eid.raw[i];
     186              :             }
     187              :         } else {
     188            2 :             commAddr.type = COMM_ADDR_TYPE_IP_V4;
     189            2 :             commAddr.addr = ipAddr.GetBinaryAddress().addr;
     190              :         }
     191            2 :     } else if (family == AF_INET6) {
     192            0 :         commAddr.type = COMM_ADDR_TYPE_IP_V6;
     193            0 :         commAddr.addr6 = ipAddr.GetBinaryAddress().addr6;
     194              :     } else {
     195            0 :         HCCL_ERROR("[SetCommAddress] invalid commAddrType");
     196            0 :         return HCCL_E_INTERNAL;
     197              :     }
     198            2 :     return HCCL_SUCCESS;
     199              : }
     200              : 
     201            2 : static HcclResult SetEndpointLoc(EndpointLocType& locType, const AddrPosition& position)
     202              : {
     203            2 :     if (position == AddrPosition::DEVICE) {
     204            2 :         locType = ENDPOINT_LOC_TYPE_DEVICE;
     205            0 :     } else if (position == AddrPosition::HOST) {
     206            0 :         locType = ENDPOINT_LOC_TYPE_HOST;
     207              :     } else {
     208            0 :         locType = ENDPOINT_LOC_TYPE_RESERVED;
     209              :     }
     210            2 :     return HCCL_SUCCESS;
     211              : }
     212              : 
     213            1 : static HcclResult InsertInnerLink(const NetInstance::Path& path, std::vector<CommLink>& linkListVec)
     214              : {
     215            2 :     for (const auto& link : path.links) {
     216            1 :         const NetInstance::Link* peer2peer = &link;
     217            2 :         for (LinkProtocol protocol : link.GetLinkProtocols()) {
     218              :             CommLink commLink;
     219            1 :             CommLinkInit(&commLink, 1);
     220            1 :             const CommProtocol& commProtocol = LinkProtocolToCommProtocol(protocol);
     221            1 :             commLink.linkAttr.linkProtocol = commProtocol;
     222            1 :             commLink.linkAttr.hop = peer2peer->GetHop();
     223            1 :             commLink.srcEndpointDesc.protocol = commProtocol;
     224            1 :             commLink.dstEndpointDesc.protocol = commProtocol;
     225              : 
     226              :             // 设置源端点
     227            1 :             std::shared_ptr<NetInstance::ConnInterface> srcConnInterface = link.GetSourceIface();
     228            1 :             CHK_PTR_NULL(srcConnInterface);
     229            1 :             HcclResult result = SetCommAddress(commLink.srcEndpointDesc.commAddr, srcConnInterface->GetAddr());
     230            1 :             if (result != HCCL_SUCCESS) {
     231            0 :                 HCCL_ERROR(
     232              :                     "[IRankGraph::%s] SetCommAddress FAILED for srcConn: %s.", __func__,
     233              :                     srcConnInterface->Describe().c_str());
     234            0 :                 return result;
     235              :             }
     236            1 :             CHK_RET(SetEndpointLoc(commLink.srcEndpointDesc.loc.locType, srcConnInterface->GetPos()));
     237              : 
     238              :             // 设置目标端点
     239            1 :             std::shared_ptr<NetInstance::ConnInterface> dstConnInterface = link.GetTargetIface();
     240            1 :             CHK_PTR_NULL(dstConnInterface);
     241            1 :             result = SetCommAddress(commLink.dstEndpointDesc.commAddr, dstConnInterface->GetAddr());
     242            1 :             if (result != HCCL_SUCCESS) {
     243            0 :                 HCCL_ERROR(
     244              :                     "[IRankGraph::%s] SetCommAddress FAILED for dstConn: %s.", __func__,
     245              :                     dstConnInterface->Describe().c_str());
     246            0 :                 return result;
     247              :             }
     248              : 
     249            1 :             CHK_RET(SetEndpointLoc(commLink.dstEndpointDesc.loc.locType, dstConnInterface->GetPos()));
     250              : 
     251            1 :             if (commLink.srcEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
     252            1 :                 std::shared_ptr<NetInstance::Node> srcNode = peer2peer->GetSourceNode();
     253            1 :                 std::shared_ptr<NetInstance::Node> dstNode = peer2peer->GetTargetNode();
     254            1 :                 std::shared_ptr<NetInstance::Peer> srcPeer = std::dynamic_pointer_cast<NetInstance::Peer>(srcNode);
     255            1 :                 std::shared_ptr<NetInstance::Peer> dstPeer = std::dynamic_pointer_cast<NetInstance::Peer>(dstNode);
     256            1 :                 commLink.srcEndpointDesc.loc.device.devPhyId = srcPeer->GetDeviceId();
     257            1 :                 commLink.dstEndpointDesc.loc.device.devPhyId = dstPeer->GetDeviceId();
     258            1 :             }
     259              : 
     260            1 :             linkListVec.emplace_back(std::move(commLink));
     261            2 :         }
     262              :     }
     263              : 
     264            1 :     return HCCL_SUCCESS;
     265              : }
     266              : 
     267            0 : static HcclResult InsertClosLinks(const NetInstance::Path& path, std::vector<CommLink>& linkListVec)
     268              : {
     269            0 :     const NetInstance::Link* peer2net = nullptr;
     270            0 :     const NetInstance::Link* net2peer = nullptr;
     271            0 :     for (const auto& link : path.links) {
     272            0 :         bool srcNull = (link.GetSourceIface() == nullptr);
     273            0 :         bool dstNull = (link.GetTargetIface() == nullptr);
     274            0 :         if (!srcNull && dstNull) {
     275            0 :             peer2net = &link;
     276            0 :         } else if (srcNull && !dstNull) {
     277            0 :             net2peer = &link;
     278              :         }
     279              :     }
     280            0 :     CHK_PTR_NULL(peer2net);
     281            0 :     CHK_PTR_NULL(net2peer);
     282              : 
     283            0 :     auto srcInterface = peer2net->GetSourceIface();
     284            0 :     auto dstInterface = net2peer->GetTargetIface();
     285            0 :     CHK_PTR_NULL(srcInterface);
     286            0 :     CHK_PTR_NULL(dstInterface);
     287            0 :     for (LinkProtocol protocol : peer2net->GetLinkProtocols()) {
     288              :         CommLink commLink;
     289            0 :         CommLinkInit(&commLink, 1);
     290            0 :         const CommProtocol& commProtocol = LinkProtocolToCommProtocol(protocol);
     291              : 
     292            0 :         commLink.linkAttr.linkProtocol = commProtocol;
     293            0 :         commLink.linkAttr.hop = peer2net->GetHop();
     294            0 :         commLink.srcEndpointDesc.protocol = commProtocol;
     295            0 :         commLink.dstEndpointDesc.protocol = commProtocol;
     296              : 
     297              :         // 设置源端点
     298            0 :         CHK_RET(SetCommAddress(commLink.srcEndpointDesc.commAddr, srcInterface->GetAddr()));
     299            0 :         CHK_RET(SetEndpointLoc(commLink.srcEndpointDesc.loc.locType, srcInterface->GetPos()));
     300            0 :         if (commLink.srcEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
     301            0 :             std::shared_ptr<NetInstance::Node> srcNode = peer2net->GetSourceNode();
     302            0 :             std::shared_ptr<NetInstance::Peer> srcPeer = std::dynamic_pointer_cast<NetInstance::Peer>(srcNode);
     303            0 :             commLink.srcEndpointDesc.loc.device.devPhyId = srcPeer->GetDeviceId();
     304            0 :         }
     305              : 
     306              :         // 设置目标端点
     307            0 :         CHK_RET(SetCommAddress(commLink.dstEndpointDesc.commAddr, dstInterface->GetAddr()));
     308            0 :         CHK_RET(SetEndpointLoc(commLink.dstEndpointDesc.loc.locType, dstInterface->GetPos()));
     309            0 :         if (commLink.dstEndpointDesc.loc.locType == ENDPOINT_LOC_TYPE_DEVICE) {
     310            0 :             std::shared_ptr<NetInstance::Node> dstNode = net2peer->GetTargetNode();
     311            0 :             std::shared_ptr<NetInstance::Peer> dstPeer = std::dynamic_pointer_cast<NetInstance::Peer>(dstNode);
     312            0 :             commLink.dstEndpointDesc.loc.device.devPhyId = dstPeer->GetDeviceId();
     313            0 :         }
     314              : 
     315            0 :         linkListVec.emplace_back(std::move(commLink));
     316            0 :     }
     317            0 :     return HCCL_SUCCESS;
     318            0 : }
     319              : 
     320              : HcclResult
     321            2 : IRankGraph::GetLinks(uint32_t netLayer, uint32_t srcRank, uint32_t dstRank, CommLink** linkList, uint32_t* listSize)
     322              : {
     323            2 :     CHK_PTR_NULL(rankGraphPtr_);
     324            2 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     325            2 :     u32 rankId = rankGraph->GetMyRank();
     326            2 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     327            2 :     if (levels.find(netLayer) == levels.end()) {
     328            1 :         HCCL_ERROR("[IRankGraph::GetLinks] netLayer[%u] is invalid", netLayer);
     329            1 :         return HCCL_E_PARA;
     330              :     }
     331            1 :     std::vector<NetInstance::Path> paths = rankGraph->GetPaths(netLayer, srcRank, dstRank);
     332            1 :     linkListVec_.clear();
     333              :     // 遍历每条path
     334            2 :     for (const auto& path : paths) {
     335              :         // 检查是否是Clos网络(有nullptr接口)
     336            1 :         bool isClos = false;
     337            2 :         for (const auto& link : path.links) {
     338              :             // fabric没有接口
     339            1 :             if (link.GetSourceIface() == nullptr || link.GetTargetIface() == nullptr) {
     340            0 :                 isClos = true;
     341            0 :                 break;
     342              :             }
     343              :         }
     344            1 :         if (!isClos) {
     345              :             // Peer2Peer网络:直接处理每条link
     346            1 :             HcclResult ret = InsertInnerLink(path, linkListVec_);
     347            1 :             CHK_PRT_RET(
     348              :                 ret != HCCL_SUCCESS,
     349              :                 HCCL_ERROR(
     350              :                     "[IRankGraph::%s] InsertInnerLink failed for Peer2Peer, linkNum[%zu], ret[%d]", __func__,
     351              :                     path.links.size(), ret),
     352              :                 ret);
     353              :         } else {
     354              :             // Clos网络:找到peer2net和net2peer,组合成一条链路
     355            0 :             HcclResult ret = InsertClosLinks(path, linkListVec_);
     356            0 :             CHK_PRT_RET(
     357              :                 ret != HCCL_SUCCESS,
     358              :                 HCCL_ERROR(
     359              :                     "[IRankGraph::%s] InsertClosLinks failed for Clos, linkNum[%zu], ret[%d]", __func__,
     360              :                     path.links.size(), ret),
     361              :                 ret);
     362              :         }
     363              :     }
     364            1 :     *linkList = linkListVec_.data();
     365            1 :     *listSize = linkListVec_.size();
     366            1 :     return HCCL_SUCCESS;
     367            2 : }
     368              : 
     369            1 : HcclResult IRankGraph::GetTopoInstsByLayer(uint32_t netLayer, uint32_t** topoInsts, uint32_t* topoInstNum)
     370              : {
     371            1 :     CHK_PTR_NULL(rankGraphPtr_);
     372            1 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     373            1 :     u32 rankId = rankGraph->GetMyRank();
     374            1 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     375            1 :     if (levels.find(netLayer) == levels.end()) {
     376            0 :         HCCL_ERROR("[IRankGraph::GetTopoInstsByLayer] netLayer[%u] is invalid", netLayer);
     377            0 :         return HCCL_E_PARA;
     378              :     }
     379            1 :     u32 num = 0;
     380            1 :     topoInstsVec_.clear();
     381            1 :     rankGraph->GetTopoInstsByLayer(netLayer, topoInstsVec_, num);
     382            1 :     *topoInsts = topoInstsVec_.data();
     383            1 :     *topoInstNum = num;
     384            1 :     return HCCL_SUCCESS;
     385            1 : }
     386              : 
     387            2 : HcclResult IRankGraph::GetTopoType(const uint32_t netLayer, const uint32_t topoInstId, CommTopo* topoType)
     388              : {
     389            2 :     CHK_PTR_NULL(rankGraphPtr_);
     390            2 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     391            2 :     u32 rankId = rankGraph->GetMyRank();
     392            2 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     393            2 :     if (levels.find(netLayer) == levels.end()) {
     394            0 :         HCCL_ERROR("[IRankGraph::GetTopoType] netLayer[%u] is invalid", netLayer);
     395            0 :         return HCCL_E_PARA;
     396              :     }
     397            2 :     Hccl::TopoType type;
     398            2 :     HcclResult ret = rankGraph->GetTopoType(netLayer, topoInstId, type);
     399            2 :     if (ret != HCCL_SUCCESS) {
     400            1 :         HCCL_ERROR(
     401              :             "[IRankGraph::GetTopoType] Failed to get topo type at netLayer [%u] topoInstId [%u] ret[%d]", netLayer,
     402              :             topoInstId, ret);
     403            1 :         return ret;
     404              :     }
     405              :     static const std::unordered_map<Hccl::TopoType, CommTopo> topoTypeMap
     406              :         = {{Hccl::TopoType::CLOS, COMM_TOPO_CLOS},
     407              :            {Hccl::TopoType::MESH_1D, COMM_TOPO_1DMESH},
     408              :            {Hccl::TopoType::A3_SERVER, COMM_TOPO_910_93},
     409            3 :            {Hccl::TopoType::A2_AX_SERVER, COMM_TOPO_A2AXSERVER}};
     410            1 :     auto it = topoTypeMap.find(type);
     411            1 :     if (it != topoTypeMap.end()) {
     412            1 :         *topoType = it->second;
     413            1 :         return HCCL_SUCCESS;
     414              :     }
     415            0 :     HCCL_ERROR(
     416              :         "[IRankGraph::GetTopoType] topoType[%s] is not supported, netLayer[%u], "
     417              :         "topoInstId[%u], myRank[%u]",
     418              :         type.Describe().c_str(), netLayer, topoInstId, rankId);
     419            0 :     return HCCL_E_PARA;
     420            2 : }
     421              : 
     422              : HcclResult
     423            2 : IRankGraph::GetRanksByTopoInst(const uint32_t netLayer, const uint32_t topoInstId, uint32_t** ranks, uint32_t* rankNum)
     424              : {
     425            2 :     CHK_PTR_NULL(rankGraphPtr_);
     426            2 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     427            2 :     u32 rankId = rankGraph->GetMyRank();
     428            2 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     429            2 :     if (levels.find(netLayer) == levels.end()) {
     430            0 :         HCCL_ERROR("[IRankGraph::GetRanksByTopoInst] netLayer[%u] is invalid", netLayer);
     431            0 :         return HCCL_E_PARA;
     432              :     }
     433            2 :     u32 num = 0;
     434            2 :     auto ret = rankGraph->GetRanksByTopoInst(netLayer, topoInstId, ranksVec_, num);
     435            2 :     if (ret != HCCL_SUCCESS) {
     436            1 :         HCCL_ERROR(
     437              :             "[IRankGraph::GetRanksByTopoInst] Failed to get ranks at netLayer [%u] topoInstId [%u] ret[%d]", netLayer,
     438              :             topoInstId, ret);
     439            1 :         return ret;
     440              :     }
     441            1 :     *ranks = ranksVec_.data();
     442            1 :     *rankNum = ranksVec_.size();
     443            1 :     return HCCL_SUCCESS;
     444            2 : }
     445              : 
     446            1 : HcclResult IRankGraph::GetEndpointNum(uint32_t netLayer, uint32_t topoInstId, uint32_t* num)
     447              : {
     448            1 :     CHK_PTR_NULL(rankGraphPtr_);
     449            1 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     450            1 :     u32 rankId = rankGraph->GetMyRank();
     451            1 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     452            1 :     if (levels.find(netLayer) == levels.end()) {
     453            0 :         HCCL_ERROR("[IRankGraph::GetEndpointNum] netLayer[%u] is invalid", netLayer);
     454            0 :         return HCCL_E_PARA;
     455              :     }
     456            1 :     auto ret = rankGraph->GetEndpointNum(netLayer, topoInstId, num);
     457            1 :     CHK_PRT_RET(
     458              :         ret != HCCL_SUCCESS,
     459              :         HCCL_ERROR(
     460              :             "[IRankGraph::GetEndpointNum] Failed to get endpoint num at netLayer[%u], "
     461              :             "topoInstId[%u], myRank[%u], ret[%d]",
     462              :             netLayer, topoInstId, rankId, ret),
     463              :         ret);
     464            1 :     return HCCL_SUCCESS;
     465            1 : }
     466              : 
     467              : HcclResult
     468            1 : IRankGraph::GetEndpointDesc(uint32_t netLayer, uint32_t topoInstId, uint32_t* descNum, EndpointDesc* endpointDesc)
     469              : {
     470            1 :     CHK_PTR_NULL(rankGraphPtr_);
     471            1 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     472            1 :     u32 rankId = rankGraph->GetMyRank();
     473            1 :     std::set<u32> levels = rankGraph->GetLevels(rankId);
     474            1 :     if (levels.find(netLayer) == levels.end()) {
     475            0 :         HCCL_ERROR("[IRankGraph::GetEndpointDesc] netLayer[%u] is invalid", netLayer);
     476            0 :         return HCCL_E_PARA;
     477              :     }
     478            1 :     auto ret = rankGraph->GetEndpointDesc(netLayer, topoInstId, descNum, endpointDesc);
     479            1 :     CHK_PRT_RET(
     480              :         ret != HCCL_SUCCESS,
     481              :         HCCL_ERROR(
     482              :             "[IRankGraph::GetEndpointDesc] Failed to get endpoint desc at netLayer[%u], "
     483              :             "topoInstId[%u], myRank[%u], descNum[%u], ret[%d]",
     484              :             netLayer, topoInstId, rankId, *descNum, ret),
     485              :         ret);
     486            1 :     return HCCL_SUCCESS;
     487            1 : }
     488              : 
     489            0 : static const char* EndpointAttrToString(EndpointAttr endpointAttr)
     490              : {
     491            0 :     switch (endpointAttr) {
     492            0 :         case ENDPOINT_ATTR_BW_COEFF:
     493            0 :             return "ENDPOINT_ATTR_BW_COEFF";
     494            0 :         case ENDPOINT_ATTR_DIE_ID:
     495            0 :             return "ENDPOINT_ATTR_DIE_ID";
     496            0 :         case ENDPOINT_ATTR_LOCATION:
     497            0 :             return "ENDPOINT_ATTR_LOCATION";
     498            0 :         default:
     499            0 :             return "ENDPOINT_ATTR_INVALID";
     500              :     }
     501              : }
     502              : 
     503            0 : HcclResult IRankGraph::GetEndpointInfo(
     504              :     uint32_t rankId, const EndpointDesc* endPointDesc, EndpointAttr endpointAttr, uint32_t infoLen, void* info)
     505              : {
     506            0 :     CHK_PTR_NULL(rankGraphPtr_);
     507            0 :     RankGraph* rankGraph = static_cast<RankGraph*>(rankGraphPtr_);
     508            0 :     HcclResult ret = rankGraph->GetEndpointInfo(rankId, endPointDesc, endpointAttr, infoLen, info);
     509            0 :     CHK_PRT_RET(
     510              :         ret != HCCL_SUCCESS,
     511              :         HCCL_ERROR(
     512              :             "[IRankGraph::GetEndpointInfo] Failed to get endpoint info, rankId[%u], "
     513              :             "endpointAttr[%s], ret[%d]",
     514              :             rankId, EndpointAttrToString(endpointAttr), ret),
     515              :         ret);
     516            0 :     return HCCL_SUCCESS;
     517              : }
     518              : 
     519              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1