LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/impl - topo_matcher.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 56.2 % 365 205
Test Date: 2026-08-04 10:52:23 Functions: 66.7 % 45 30

            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 <condition_variable>
      12              : #include "externalinput_pub.h"
      13              : #include "coll_alg_param.h"
      14              : #include "search_path.h"
      15              : #include "calc_p2p_transport_req.h"
      16              : #include "calc_hccs_plus_sio_transport_req_pub.h"
      17              : #include "topo_matcher.h"
      18              : namespace hccl {
      19              : 
      20          595 : TopoMatcher::TopoMatcher(const std::vector<std::vector<std::vector<u32>>> CommPlaneRanks,
      21              :                          const std::vector<bool> isBridgeVector,
      22              :                          HcclTopoInfo &topoInfo,
      23              :                          HcclAlgoInfo &algoInfo,
      24              :                          HcclExternalEnable &externalEnable,
      25          595 :                          std::vector<std::vector<std::vector<u32>>> &serverAndsuperPodToRank)
      26          595 :     : CommPlaneVector_(CommPlaneRanks), isBridgeVector_(isBridgeVector),
      27          595 :       topoInfo_(topoInfo), algoInfo_(algoInfo), externalEnable_(externalEnable), userRank_(topoInfo.userRank),
      28          595 :       serverAndsuperPodToRank_(serverAndsuperPodToRank)
      29              : {
      30          595 :     SetRankMap();
      31          595 : }
      32              : 
      33          171 : HcclResult TopoMatcher::CalcCommPlaneInfo(const std::string &tag, const CommParaInfo &commParaInfo,
      34              :     std::vector<SingleSubCommTransport> &commTransport, TransportMemType inputMemType, TransportMemType outputMemType)
      35              : {
      36          171 :     HcclUs startut = TIME_NOW();
      37          172 :     HcclResult ret = HCCL_SUCCESS;
      38          172 :     HCCL_INFO("[Calc][CommPlane]tag[%s], commPlane[%d], commType[%d]",
      39              :         tag.c_str(), commParaInfo.commPlane, commParaInfo.commType);
      40              : 
      41          172 :     u32 subUserRankRoot = INVALID_VALUE_RANKID;
      42          172 :     if (commParaInfo.root != INVALID_VALUE_RANKID) {
      43            8 :         if (commParaInfo.commPlane == COMM_LEVEL2) {
      44            0 :             subUserRankRoot = GetSubRootUserRankWithSuperPod(userRank_, commParaInfo.root);
      45              :         } else {
      46            8 :             subUserRankRoot = GetSubRootUserRank(userRank_, commParaInfo.root);
      47              :         }
      48            8 :         if (subUserRankRoot == INVALID_VALUE_RANKID) {
      49            0 :             HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo]get sub root userrank value[%u] invalid.", subUserRankRoot);
      50            0 :             return HCCL_E_PARA;
      51              :         }
      52              :     }
      53              : 
      54          172 :     std::unique_ptr<CalcTransportReqBase> calcTransportReq;
      55          172 :     bool isAHCType = false;
      56          172 :     switch (commParaInfo.commType) {
      57           62 :         case CommType::COMM_TAG_RING_INNER:
      58              :         case CommType::COMM_TAG_RING_COMBINED: {
      59          124 :             calcTransportReq.reset(new (std::nothrow) CalcRingTransportReq(CommPlaneVector_[commParaInfo.commPlane],
      60          124 :                 isBridgeVector_, userRank_));
      61           62 :             break;
      62              :         }
      63           34 :         case CommType::COMM_TAG_HALVING_DOUBLING: {
      64           68 :             calcTransportReq.reset(new (std::nothrow) CalcHDTransportReq(CommPlaneVector_[commParaInfo.commPlane],
      65           68 :                 isBridgeVector_, userRank_));
      66           34 :             break;
      67              :         }
      68           15 :         case CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING:
      69              :         case CommType::COMM_TAG_WHOLE_NHR:{
      70           30 :             calcTransportReq.reset(new (std::nothrow) CalcNHRTransportReq(CommPlaneVector_[commParaInfo.commPlane],
      71           30 :                 isBridgeVector_, userRank_));
      72           15 :             break;
      73              :         }
      74            0 :         case CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING_V1:
      75              :         case CommType::COMM_TAG_WHOLE_NHR_V1: {
      76            0 :             calcTransportReq.reset(new (std::nothrow) CalcNHRV1TransportReq(CommPlaneVector_[commParaInfo.commPlane],
      77            0 :                 isBridgeVector_, userRank_));
      78            0 :             break;
      79              :         }
      80            0 :         case CommType::COMM_TAG_ASYMMETRIC_HIERARCHICAL_CONCATENATE:
      81              :         case CommType::COMM_TAG_WHOLE_AHC: {
      82            0 :             isAHCType = true;
      83            0 :             CHK_PRT_RET(static_cast<u32>(topoInfo_.CommPlaneSubGroupVector.size()) <
      84              :                 (static_cast<u32>(commParaInfo.commPlane) + 1) ||
      85              :                 topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane].size() == 0,
      86              :                 HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo] CommPlaneSubGroupVector para init error."), HCCL_E_PARA);
      87            0 :             calcTransportReq.reset(new (std::nothrow) CalcAHCTransportReq(CommPlaneVector_[commParaInfo.commPlane],
      88            0 :                 isBridgeVector_, userRank_, topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane], topoInfo_.ahcAlgOption, topoInfo_.isUsedRdmaMap));
      89            0 :             break;
      90              :         }
      91            0 :         case CommType::COMM_TAG_ASYMMETRIC_HIERARCHICAL_CONCATENATE_BROKE:
      92              :         case CommType::COMM_TAG_WHOLE_AHC_BROKE: {
      93            0 :             isAHCType = true;
      94            0 :             CHK_PRT_RET(static_cast<u32>(topoInfo_.CommPlaneSubGroupVector.size()) <
      95              :                 (static_cast<u32>(commParaInfo.commPlane) + 1) ||
      96              :                 topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane].size() == 0,
      97              :                 HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo] CommPlaneSubGroupVector para init error."), HCCL_E_PARA);
      98            0 :             calcTransportReq.reset(new (std::nothrow) CalcAHCBrokeTransportReq(CommPlaneVector_[commParaInfo.commPlane],
      99            0 :                 isBridgeVector_, userRank_, topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane], topoInfo_.ahcAlgOption, topoInfo_.isUsedRdmaMap));
     100            0 :             break;
     101              :         }
     102            0 :         case CommType::COMM_TAG_NONUNIFORM_BRUCK:
     103              :         case CommType::COMM_TAG_WHOLE_NB: {
     104            0 :             calcTransportReq.reset(new (std::nothrow) CalcNBTransportReq(CommPlaneVector_[commParaInfo.commPlane],
     105            0 :                 isBridgeVector_, userRank_));
     106            0 :             break;
     107              :         }
     108           61 :         case CommType::COMM_TAG_MESH: {
     109          122 :             calcTransportReq.reset(new (std::nothrow) CalcMeshTransportReq(CommPlaneVector_[commParaInfo.commPlane],
     110          122 :                 isBridgeVector_, userRank_));
     111           59 :             break;
     112              :         }
     113            0 :         case CommType::COMM_TAG_PARTIAL_MESH_COMBINED: {
     114            0 :             calcTransportReq.reset(new (std::nothrow) CalcPartialMeshTransportReq
     115            0 :                 (CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
     116            0 :             break;
     117              :         }
     118            0 :         case CommType::COMM_TAG_P2P: {
     119            0 :             calcTransportReq.reset(new (std::nothrow) CalcP2PTransportReq(CommPlaneVector_[commParaInfo.commPlane],
     120            0 :                 isBridgeVector_, userRank_));
     121            0 :             break;
     122              :         }
     123            0 :         case CommType::COMM_TAG_HCCS_PLUS_SIO: {
     124            0 :             calcTransportReq.reset(new (std::nothrow) CalcHccsPlusSioTransportReq(CommPlaneVector_[commParaInfo.commPlane],
     125            0 :                 isBridgeVector_, userRank_));
     126            0 :             break;
     127              :         }
     128            0 :         default: {
     129            0 :             HCCL_ERROR("[Calc][CommPlane]commType[%d] is invalid", commParaInfo.commType);
     130            0 :             return HCCL_E_PARA;
     131              :         }
     132              :     }
     133              : 
     134          170 :     CHK_SMART_PTR_NULL(calcTransportReq);
     135          170 :     ret = calcTransportReq->CalcTransportRequest(tag, inputMemType, outputMemType, commParaInfo, commTransport,
     136              :                                                  subUserRankRoot);
     137              :     //AHC内部单独刷新,外部不需要再刷新
     138          172 :     if (!isAHCType) {
     139          171 :         CHK_RET(SetIsUsedRdma(commParaInfo, commTransport));
     140              :     }
     141          173 :     CHK_RET(GetRankMap(commParaInfo, commTransport));
     142              : 
     143          166 :     CHK_PRT_RET(ret != HCCL_SUCCESS,
     144              :         HCCL_ERROR("[Calc][CommPlane]failed, tag[%s], commPlane[%d], commType[%d]",
     145              :         tag.c_str(), commParaInfo.commPlane, commParaInfo.commType), ret);
     146              : 
     147          166 :     HCCL_INFO("complete commPlane[%d] commType[%d] Calculation, Time:%lld us",
     148              :         commParaInfo.commPlane, commParaInfo.commType, DURATION_US(TIME_NOW() - startut));
     149          171 :     return HCCL_SUCCESS;
     150          171 : }
     151              : 
     152          172 : HcclResult TopoMatcher::GetRankMap(const CommParaInfo &commParaInfo, std::vector<SingleSubCommTransport> &commTransport)
     153              : {
     154          172 :     u32 ringSize = commTransport.size();
     155              : 
     156          478 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
     157          313 :         SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
     158              :         // 有建链诉求,则记录从userRank到subCommRank 和 从subCommRank到userRank的映射
     159          312 :         if (subCommTransport.transportRequests.size() != 0) {
     160          207 :             if (commParaInfo.commType == CommType::COMM_TAG_PARTIAL_MESH_COMBINED ||
     161          207 :                 commParaInfo.commType == CommType::COMM_TAG_HCCS_PLUS_SIO) {
     162            1 :                 CHK_RET(GetSub2UserRankMap(commParaInfo.commPlane, 0, subCommTransport.subCommRank2UserRank));
     163            0 :                 CHK_RET(GetUserRank2SubMap(commParaInfo.commPlane, 0, subCommTransport.userRank2subCommRank));
     164            0 :             } else {
     165          206 :                 CHK_RET(GetSub2UserRankMap(commParaInfo.commPlane, ringIndex, subCommTransport.subCommRank2UserRank));
     166          203 :                 CHK_RET(GetUserRank2SubMap(commParaInfo.commPlane, ringIndex, subCommTransport.userRank2subCommRank));
     167              :             }
     168              :         }
     169              :     }
     170          165 :     return HCCL_SUCCESS;
     171              : }
     172              : 
     173          595 : HcclResult TopoMatcher::SetRankMap()
     174              : {
     175              :     // 构建由UserRank到子通信域的映射
     176          595 :     CHK_PRT_RET(CommPlaneVector_.size() > COMM_LEVEL_RESERVED,
     177              :         HCCL_ERROR("[TopoMatcher][SetRankMap]CommPlaneVector.size[%u] > COMM_LEVEL_RESERVED[%u]",
     178              :         CommPlaneVector_.size(), COMM_LEVEL_RESERVED), HCCL_E_PARA);
     179          595 :     subCommRank2UserRank_.resize(static_cast<u32>(COMM_LEVEL_RESERVED));
     180          595 :     userRank2subCommRank_.resize(static_cast<u32>(COMM_LEVEL_RESERVED));
     181         9014 :     for (u32 levelIndex = 0; levelIndex < CommPlaneVector_.size(); levelIndex++) {
     182         8419 :         u32 ringSize = CommPlaneVector_[levelIndex].size();
     183         8419 :         subCommRank2UserRank_[levelIndex].resize(ringSize);
     184         8419 :         userRank2subCommRank_[levelIndex].resize(ringSize);
     185        14216 :         for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
     186         5797 :             u32 rankSize = CommPlaneVector_[levelIndex][ringIndex].size();
     187        17519 :             for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
     188        11722 :                 u32 userRank = CommPlaneVector_[levelIndex][ringIndex][rankIndex];
     189        11722 :                 subCommRank2UserRank_[levelIndex][ringIndex][rankIndex] = userRank;
     190        11722 :                 userRank2subCommRank_[levelIndex][ringIndex][userRank] = rankIndex;
     191              :             }
     192              :         }
     193              :     }
     194          595 :     return HCCL_SUCCESS;
     195              : }
     196              : 
     197          172 : HcclResult TopoMatcher::GetIsUsedRdma(const CommParaInfo &commParaInfo, bool &isUsedRdma)
     198              : {
     199          172 :     std::vector<std::vector<u32> > commP2PPlaneVec;
     200          171 :     if (commParaInfo.commType == CommType::COMM_TAG_P2P) {
     201              :         // P2P只需要判断两张卡之间的连接关系
     202            1 :         bool invalidcheck = (topoInfo_.isUsedRdmaMap.size() <= topoInfo_.userRank) ||
     203            0 :                             (topoInfo_.isUsedRdmaMap.size() <= commParaInfo.peerUserRank);
     204            0 :         CHK_PRT_RET(invalidcheck, HCCL_ERROR("[GetIsUsedRdma]dstUserRank[%u] or userRank[%u] is bigger than "\
     205              :             "rankVector size[%u]", commParaInfo.peerUserRank, topoInfo_.userRank, topoInfo_.isUsedRdmaMap.size()),
     206              :             HCCL_E_PARA);
     207              : 
     208            0 :         std::vector<u32> commP2PRankVec;
     209            0 :         commP2PRankVec.push_back(topoInfo_.userRank);
     210            0 :         commP2PRankVec.push_back(commParaInfo.peerUserRank);
     211            0 :         commP2PPlaneVec.push_back(commP2PRankVec);
     212            0 :     }
     213              : 
     214          170 :     std::vector<std::vector<u32> > &commPlaneVec = (commParaInfo.commType == CommType::COMM_TAG_P2P) ?
     215          170 :         commP2PPlaneVec : CommPlaneVector_[commParaInfo.commPlane];
     216              : 
     217          440 :     for (const std::vector<u32> &commPlane : commPlaneVec) {
     218         1058 :         for (const u32 dstRank : commPlane) {
     219          752 :             if (topoInfo_.isUsedRdmaMap[dstRank]) {
     220           50 :                 isUsedRdma = true;
     221           50 :                 return HCCL_SUCCESS;
     222              :             }
     223              :         }
     224              :     }
     225          114 :     isUsedRdma = false;
     226          114 :     return HCCL_SUCCESS;
     227          164 : }
     228              : 
     229          172 : HcclResult TopoMatcher::SetIsUsedRdma(const CommParaInfo &commParaInfo,
     230              :     std::vector<SingleSubCommTransport> &commTransport)
     231              : {
     232          172 :     bool isUsedRdma = false;
     233          172 :     CHK_RET(GetIsUsedRdma(commParaInfo, isUsedRdma));
     234          165 :     u32 ringSize = commTransport.size();
     235              : 
     236          471 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
     237          306 :         SingleSubCommTransport &subCommTransport = commTransport[ringIndex];
     238          910 :         for (auto &transportRequest : subCommTransport.transportRequests) {
     239          609 :             transportRequest.isUsedRdma = isUsedRdma;
     240              :         }
     241              :     }
     242          165 :     HCCL_INFO("[TopoMatcher][SetIsUsedRdma] commPlane[%d] isUsedRdma[%d]", commParaInfo.commPlane, isUsedRdma);
     243          172 :     return HCCL_SUCCESS;
     244              : }
     245              : 
     246          206 : HcclResult TopoMatcher::GetSub2UserRankMap(CommPlane commPlane, u32 ringIndex,
     247              :     std::map<u32, u32> &subCommRank2UserRank)
     248              : {
     249          206 :     subCommRank2UserRank = subCommRank2UserRank_[static_cast<u32>(commPlane)][ringIndex];
     250          203 :     return HCCL_SUCCESS;
     251              : }
     252              : 
     253          203 : HcclResult TopoMatcher::GetUserRank2SubMap(CommPlane commPlane, u32 ringIndex,
     254              :     std::map<u32, u32> &userRank2subCommRank)
     255              : {
     256          203 :     userRank2subCommRank = userRank2subCommRank_[static_cast<u32>(commPlane)][ringIndex];
     257          202 :     return HCCL_SUCCESS;
     258              : }
     259              : 
     260          170 : HcclTopoInfo TopoMatcher::GetTopoInfo()
     261              : {
     262          170 :     return topoInfo_;
     263              : }
     264              : 
     265          184 : HcclAlgoInfo TopoMatcher::GetAlgoInfo()
     266              : {
     267          184 :     return algoInfo_;
     268              : }
     269              : 
     270            0 : u32 TopoMatcher::GetExternalInputHcclEnableFfts()
     271              : {
     272            0 :     return externalEnable_.enableFfts;
     273              : }
     274              : 
     275           64 : u32 TopoMatcher::GetExternalInputHcclDeterministic()
     276              : {
     277           64 :     return externalEnable_.deterministic;
     278              : }
     279              : 
     280            0 : u32 TopoMatcher::GetExternalInputIntraRoceSwitch()
     281              : {
     282            0 :     return externalEnable_.intraRoceSwitch;
     283              : }
     284              : 
     285            0 : u32 TopoMatcher::GetExternalInputHcclDumpDebug()
     286              : {
     287            0 :     return externalEnable_.dumpDebug;
     288              : }
     289              : 
     290            2 : u32 TopoMatcher::GetExternalInputInterHccsDisable()
     291              : {
     292            2 :     return externalEnable_.interHccsDisable;
     293              : }
     294              : 
     295          138 : bool TopoMatcher::GetARSFlag()
     296              : {
     297          411 :     bool isARSTrue = (topoInfo_.deviceType == DevType::DEV_TYPE_910_93) && 
     298          138 :         static_cast<bool>(topoInfo_.multiModuleDiffDeviceNumMode) && 
     299            0 :         !static_cast<bool>(topoInfo_.multiSuperPodDiffDeviceNumMode);
     300          138 :     return isARSTrue;
     301              : }
     302              :  
     303            0 : HcclResult TopoMatcher::EditCommPlaneVector(CommPlane commPlane, std::vector<std::vector<u32>> commVector) {
     304            0 :     CommPlaneVector_[commPlane] = commVector;
     305            0 :     return HCCL_SUCCESS;
     306              : }
     307              :  
     308            0 : std::vector<std::vector<u32>> TopoMatcher::GetCommPlaneRanks(CommPlane commPlane) {
     309            0 :     return CommPlaneVector_[commPlane];
     310              : }
     311              : 
     312            0 : bool CheckRankNeighbors(const std::vector<u32> &nicList)
     313              : {
     314              :     // 组成ROH环路必须偶数个,且2节点不能组成双环?
     315            0 :     if (nicList.size() % 2 != 0 || nicList.size() < HCCL_DEVICE_NUM_FOUR) {
     316            0 :         return false;
     317              :     }
     318              : 
     319            0 :     std::vector<u32> tmpNicList(nicList);
     320            0 :     std::sort(tmpNicList.begin(), tmpNicList.end());
     321            0 :     u32 halfNum = 2;
     322            0 :     for (u32 i = 0; i < tmpNicList.size() / halfNum; i++) {
     323            0 :         auto nicIndex = i * halfNum;
     324              :         // 检查相邻下标的节点,devID是否相邻
     325            0 :         if (tmpNicList[nicIndex] + 1 != tmpNicList[nicIndex + 1]) {
     326            0 :             return false;
     327              :         }
     328              :     }
     329              : 
     330            0 :     return true;
     331            0 : }
     332              : 
     333              : // 适配ROH平面网段隔离,奇数rank互通,偶数rank互通,奇偶不通
     334            0 : bool TopoMatcher::CheckSdmaWithRohTopo(const std::vector<u32> &nicList, std::vector<u32> &topoList)
     335              : {
     336            0 :     std::vector<u32> tmpNicList(nicList);
     337            0 :     std::sort(tmpNicList.begin(), tmpNicList.end());
     338            0 :     SearchPath searchPath;
     339            0 :     topoList = searchPath.Search(tmpNicList);
     340            0 :     if (topoList.empty()) {
     341            0 :         return false;
     342              :     }
     343            0 :     return true;
     344            0 : }
     345              : 
     346            0 : u32 TopoMatcher::GetSubCollectiveRank(const std::vector<u32> &vecPara) const
     347              : {
     348              :     // 在vecPara数据中,查询本user rank,查询到的vec下标就是rank值
     349            0 :     u32 tmpRank = INVALID_VALUE_RANKID;
     350              : 
     351            0 :     HCCL_DEBUG("[TopoMatcher]GetSubCollectiveRank begins.");
     352            0 :     for (u32 rankIndex = 0; rankIndex < vecPara.size(); rankIndex++) {
     353            0 :         if (userRank_ == vecPara[rankIndex]) {
     354            0 :             tmpRank = rankIndex;
     355            0 :             break;
     356              :         }
     357              :     }
     358              : 
     359            0 :     return tmpRank;
     360              : }
     361              : 
     362            0 : HcclResult TopoMatcher::GetSubRootForScatter(const u32 root, u32& subRoot)
     363              : {
     364              :     // 通过root找到ringIndex, 通过userRank找到level1中的rank
     365            0 :     u32 planeIdx = INVALID_VALUE_RANKID;
     366            0 :     u32 ringSize = CommPlaneVector_[COMM_LEVEL1_INDEX].size();
     367              : 
     368            0 :     CHK_PRT_RET(ringSize == 0, HCCL_ERROR("[GET][GetSubRootForScatter]bridgeRankVector size is zero."), HCCL_E_PARA);
     369            0 :     CHK_PRT_RET(isBridgeVector_.size() != ringSize,
     370              :         HCCL_ERROR("[GET][GetSubRootForScatter]bridgeRankVector is not equal ringSize."), HCCL_E_PARA);
     371              : 
     372            0 :     u32 rank = INVALID_VALUE_RANKID;
     373            0 :     for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
     374            0 :         if (isBridgeVector_[ringIndex]) {
     375            0 :             rank = GetSubCollectiveRank(CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex]); // 确定userRank在level1中的rank号
     376              :         }
     377            0 :         for (u32 idx = 0; idx < CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex].size(); idx++) {
     378            0 :             if (root == CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex][idx]) {  // 获取root所在的平面
     379            0 :                 planeIdx = ringIndex;
     380              :             }
     381              :         }
     382              :     }
     383            0 :     CHK_PRT_RET(rank == INVALID_VALUE_RANKID,
     384              :         HCCL_ERROR("[GET][GetSubRootForScatter]get rankId in level1 failed."), HCCL_E_PARA);
     385            0 :     CHK_PRT_RET(planeIdx == INVALID_VALUE_RANKID,
     386              :         HCCL_ERROR("[GET][GetSubRootForScatter]get root[%u] planeIdx[%u] failed.", root, planeIdx), HCCL_E_PARA);
     387            0 :     subRoot = CommPlaneVector_[COMM_LEVEL1_INDEX][planeIdx][rank];
     388            0 :     HCCL_DEBUG("[GetSubRootForScatter] userRank_:[%u] subRoot:[%u]", userRank_, subRoot);
     389            0 :     return HCCL_SUCCESS;
     390              : }
     391              : 
     392            8 : u32 TopoMatcher::GetSubRootUserRank(const u32 userRank, const u32 rootUserRank)
     393              : {
     394            8 :     u32 tmpUserRank = INVALID_VALUE_RANKID;
     395              : 
     396            8 :     u32 serverIdx = INVALID_VALUE_RANKID;
     397           16 :     for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
     398            8 :         for (u32 j = 0; j < serverAndsuperPodToRank_[0][i].size(); j++) {
     399            8 :             if (serverAndsuperPodToRank_[0][i][j] == rootUserRank) {
     400            8 :                 serverIdx = i;
     401            8 :                 break;
     402              :             }
     403              :         }
     404              :     }
     405            8 :     u32 rankIdx = INVALID_VALUE_RANKID;
     406           16 :     for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
     407           20 :         for (u32 j = 0; j < serverAndsuperPodToRank_[0][i].size(); j++) {
     408           20 :             if (serverAndsuperPodToRank_[0][i][j] == userRank) {
     409            8 :                 rankIdx = j;
     410            8 :                 break;
     411              :             }
     412              :         }
     413              :     }
     414              : 
     415            8 :     if (serverIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
     416            8 :         tmpUserRank = serverAndsuperPodToRank_[0][serverIdx][rankIdx];
     417              :     }
     418            8 :     HCCL_DEBUG("[GetSubRootUserRank] userRank:[%u] rootUserRank:[%u], tmpUserRank[%u]",
     419              :         userRank, rootUserRank, tmpUserRank);
     420            8 :     return tmpUserRank;
     421              : }
     422              : 
     423            0 : u32 TopoMatcher::GetSubRootUserRankWithSuperPod(const u32 userRank, const u32 rootUserRank)
     424              : {
     425            0 :     u32 tmpUserRank = INVALID_VALUE_RANKID;
     426              : 
     427            0 :     u32 superPodIdx = INVALID_VALUE_RANKID;
     428            0 :     for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
     429            0 :         for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
     430            0 :             if (serverAndsuperPodToRank_[1][i][j] == rootUserRank) {
     431            0 :                 superPodIdx = i;
     432            0 :                 break;
     433              :             }
     434              :         }
     435              :     }
     436            0 :     u32 rankIdx = INVALID_VALUE_RANKID;
     437            0 :     for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
     438            0 :         for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
     439            0 :             if (serverAndsuperPodToRank_[1][i][j] == userRank) {
     440            0 :                 rankIdx = j;
     441            0 :                 break;
     442              :             }
     443              :         }
     444              :     }
     445              : 
     446            0 :     if (superPodIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
     447            0 :         tmpUserRank = serverAndsuperPodToRank_[1][superPodIdx][rankIdx];
     448              :     }
     449            0 :     HCCL_DEBUG("GetSubRootUserRankWithSuperPod userRank[%u], rootUserRank[%u], ret[%u]",
     450              :         userRank, rootUserRank, tmpUserRank);
     451            0 :     return tmpUserRank;
     452              : }
     453              : 
     454            0 : u32 TopoMatcher::GetSubRootWithSuperPod(const u32 userRank, const u32 rootUserRank)
     455              : {
     456            0 :     u32 tmpUserRank = INVALID_VALUE_RANKID;
     457              : 
     458            0 :     u32 superPodIdx = INVALID_VALUE_RANKID;
     459            0 :     for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
     460            0 :         for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
     461            0 :             if (serverAndsuperPodToRank_[1][i][j] == userRank) {
     462            0 :                 superPodIdx = i;
     463            0 :                 break;
     464              :             }
     465              :         }
     466              :     }
     467            0 :     u32 rankIdx = INVALID_VALUE_RANKID;
     468            0 :     for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
     469            0 :         for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
     470            0 :             if (serverAndsuperPodToRank_[1][i][j] == rootUserRank) {
     471            0 :                 rankIdx = j;
     472            0 :                 break;
     473              :             }
     474              :         }
     475              :     }
     476              : 
     477            0 :     if (superPodIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
     478            0 :         tmpUserRank = serverAndsuperPodToRank_[1][superPodIdx][rankIdx];
     479              :     }
     480            0 :     HCCL_DEBUG("GetSubRootWithSuperPod superPodIdx[%u], rankIdx[%u], ret[%u]", superPodIdx, rankIdx, tmpUserRank);
     481            0 :     return tmpUserRank;
     482              : }
     483              : 
     484            1 : HcclResult TopoMatcher::GetLocalSuperPodRankSize(const u32 userRank, u32& devNumInlocalPod, u32& rankIdxInPod)
     485              : {
     486            1 :     u32 superPodIdx = INVALID_VALUE_RANKID;
     487            3 :     for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
     488            2 :         std::vector<u32> userRankInSuperPod(serverAndsuperPodToRank_[1][i]);
     489            2 :         std::sort(userRankInSuperPod.begin(), userRankInSuperPod.end());
     490           14 :         for (u32 j = 0; j < userRankInSuperPod.size(); j++) {
     491           13 :             if (userRankInSuperPod[j] == userRank) {
     492            1 :                 superPodIdx = i;
     493            1 :                 rankIdxInPod = j;
     494            1 :                 break;
     495              :             }
     496              :         }
     497            2 :     }
     498            1 :     if (superPodIdx == INVALID_VALUE_RANKID || rankIdxInPod == INVALID_VALUE_RANKID) {
     499            0 :         HCCL_ERROR("[GET][GetLocalSuperPodRankSize]get rankId in level1 failed.");
     500            0 :         return HCCL_E_PARA;
     501              :     }
     502            1 :     devNumInlocalPod = serverAndsuperPodToRank_[1][superPodIdx].size();
     503            1 :     HCCL_DEBUG("[GetLocalSuperPodRankSize] userRank[%u], superPodIdx[%u], rankIdxInPod[%u] devNumInlocalPod[%u]",
     504              :         userRank, superPodIdx, rankIdxInPod, devNumInlocalPod);
     505            1 :     return HCCL_SUCCESS;
     506              : }
     507              : 
     508            1 : HcclResult TopoMatcher::GetLocalServerRankSize(const u32 userRank, u32& devNumInlocalServer, u32& rankIdxInServer)
     509              : {
     510            1 :     u32 serverIdx = INVALID_VALUE_RANKID;
     511            5 :     for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
     512            4 :         std::vector<u32> userRankInServer(serverAndsuperPodToRank_[0][i]);
     513            4 :         std::sort(userRankInServer.begin(), userRankInServer.end());
     514           16 :         for (u32 j = 0; j < userRankInServer.size(); j++) {
     515           13 :             if (userRankInServer[j] == userRank) {
     516            1 :                 serverIdx = i;
     517            1 :                 rankIdxInServer = j;
     518            1 :                 break;
     519              :             }
     520              :         }
     521            4 :     }
     522            1 :     if (serverIdx == INVALID_VALUE_RANKID || rankIdxInServer == INVALID_VALUE_RANKID) {
     523            0 :         HCCL_ERROR("[GET][GetLocalServerRankSize]get rankId in level1 failed.");
     524            0 :         return HCCL_E_PARA;
     525              :     }
     526            1 :     devNumInlocalServer = serverAndsuperPodToRank_[0][serverIdx].size();
     527            1 :     HCCL_DEBUG("[GetLocalServerRankSize] userRank[%u], serverIdx[%u], rankIdxInServer[%u] devNumInlocalServer[%u]",
     528              :         userRank, serverIdx, rankIdxInServer, devNumInlocalServer);
     529            1 :     return HCCL_SUCCESS;
     530              : }
     531              : 
     532          234 : HcclResult TopoMatcher::SetDeterministicConfig(const u8 deterministic)
     533              : {
     534          234 :     if (deterministic > DETERMINISTIC_STRICT) {
     535            0 :         HCCL_ERROR("[SetDeterministicConfig] deterministic should be 0, 1 or 2.");
     536            0 :         return HCCL_E_PARA;
     537              :     }
     538          234 :     HCCL_INFO("[SetDeterministicConfig]deterministic is set to [%d]", deterministic);
     539          234 :     externalEnable_.deterministic = deterministic;
     540          234 :     return HCCL_SUCCESS;
     541              : }
     542              : 
     543          242 : u8 TopoMatcher::GetDeterministicConfig() const
     544              : {
     545          242 :     return externalEnable_.deterministic;
     546              : }
     547              : 
     548          234 : HcclResult TopoMatcher::SetOnlyAivModeConfig(const bool isOnlyAiv)
     549              : {   
     550          234 :     if (isOnlyAiv) {
     551            0 :         externalEnable_.aivMode = isOnlyAiv;
     552            0 :         externalEnable_.isOnlyAiv = isOnlyAiv;
     553              :     }
     554          234 :     HCCL_RUN_INFO("[SetOnlyAivModeConfig]isOnlyAiv is set to [%d]", isOnlyAiv);
     555          234 :     return HCCL_SUCCESS;
     556              : }
     557              : 
     558          137 : bool TopoMatcher::GetIsOnlyAivConfig() const
     559              : {
     560          137 :     return externalEnable_.isOnlyAiv;
     561              : }
     562              : 
     563          235 : HcclResult TopoMatcher::SetAivModeConfig(const bool aivMode)
     564              : {   
     565          235 :     HCCL_INFO("[SetAivMode]AivMode is set to [%d]", aivMode);
     566          235 :     externalEnable_.aivMode = aivMode;
     567          235 :     return HCCL_SUCCESS;
     568              : }
     569              : 
     570          176 : bool TopoMatcher::GetAivModeConfig() const
     571              : {
     572          176 :     return externalEnable_.aivMode;
     573              : }
     574              : 
     575          234 : HcclResult TopoMatcher::SetAicpuUnfoldConfig(const bool aicpuUnfold)
     576              : {   
     577          234 :     HCCL_INFO("[SetAicpuMode]Aicpu is set to [%d]", aicpuUnfold);
     578          234 :     externalEnable_.aicpuUnfold = aicpuUnfold;
     579          234 :     return HCCL_SUCCESS;
     580              : }
     581              : 
     582            0 : bool TopoMatcher::GetAicpuUnfoldConfig() const
     583              : {
     584            0 :     return externalEnable_.aicpuUnfold;
     585              : }
     586              : 
     587          234 : HcclResult TopoMatcher::SetExecTimeOutConfig(const s32 execTimeOut)
     588              : {
     589          234 :     HCCL_INFO("[SetExecTimeOutConfig]execTimeOut is set to [%d]", execTimeOut);
     590          234 :     externalEnable_.execTimeOut = execTimeOut;
     591          234 :     return HCCL_SUCCESS;
     592              : }
     593              : 
     594          234 : HcclResult TopoMatcher::SetAlgoConfig(const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoMap)
     595              : {
     596        24570 :     for (u32 opType = 0; opType < static_cast<u32>(HcclCMDType::HCCL_CMD_MAX); opType++) {
     597        24336 :         externalEnable_.algoConfig[static_cast<HcclCMDType>(opType)] = algoMap.at(static_cast<HcclCMDType>(opType));
     598              :     }
     599          234 :     return HCCL_SUCCESS;
     600              : }
     601              :  
     602            5 : s32 TopoMatcher::GetExecTimeOutConfig() const
     603              : {
     604            5 :     return externalEnable_.execTimeOut;
     605              : }
     606              : 
     607           10 : std::vector<HcclAlgoType> TopoMatcher::GetAlgoConfig(HcclCMDType opType)
     608              : {
     609           10 :     return externalEnable_.algoConfig[opType];
     610              : }
     611              : 
     612            9 : HcclResult TopoMatcher::GetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>> &globalSubGroups)
     613              : {
     614            9 :     globalSubGroups = topoInfo_.CommPlaneSubGroupVector[level];
     615            9 :     CHK_PRT_RET(globalSubGroups.size() == 0,
     616              :         HCCL_ERROR("[TopoMatcher][GetGlobalSubGroups] globalSubGroups para init error."), HCCL_E_PARA);
     617            9 :     return HCCL_SUCCESS;
     618              : }
     619              : 
     620            0 : HcclResult TopoMatcher::SetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>> &globalSubGroups)
     621              : {
     622            0 :     topoInfo_.CommPlaneSubGroupVector[level] = globalSubGroups;
     623            0 :     return HCCL_SUCCESS;
     624              : }
     625              : 
     626            0 : HcclResult TopoMatcher::GetCommPlaneSubGroupVector(std::vector<std::vector<std::vector<std::vector<u32>>>> &commPlaneSubGroupVector)
     627              : {
     628            0 :     commPlaneSubGroupVector = topoInfo_.CommPlaneSubGroupVector;
     629            0 :     return HCCL_SUCCESS;
     630              : }
     631              : 
     632            0 : HcclResult TopoMatcher::SetCommPlaneSubGroupVector(std::vector<std::vector<std::vector<std::vector<u32>>>> &commPlaneSubGroupVector)
     633              : {
     634            0 :     topoInfo_.CommPlaneSubGroupVector = commPlaneSubGroupVector;
     635            0 :     return HCCL_SUCCESS;
     636              : }
     637              : 
     638            9 : void TopoMatcher::GetAHCAlgOption(std::map<AHCConcOpType, TemplateType> &ahcAlgOption)
     639              : {
     640            9 :     ahcAlgOption = topoInfo_.ahcAlgOption;
     641            9 : }
     642              : 
     643            9 : void TopoMatcher::SetAHCAlgOption(std::map<AHCConcOpType, TemplateType> &ahcAlgOption)
     644              : {
     645            9 :     topoInfo_.ahcAlgOption = ahcAlgOption;
     646            9 : }
     647              : 
     648              : }
        

Generated by: LCOV version 2.0-1