LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/communicator/impl - hccl_communicator_attrs.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 79.1 % 368 291
Test Date: 2026-08-04 10:52:23 Functions: 94.3 % 70 66

            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 "hccl_communicator_attrs.h"
      12              : #include "device_capacity.h"
      13              : #include "externalinput_pub.h"
      14              : #include "env_config.h"
      15              : #include "search_path.h"
      16              : 
      17              : using namespace std;
      18              : 
      19              : namespace hccl {
      20          809 : HcclCommunicatorAttrs::HcclCommunicatorAttrs()
      21              : {
      22          809 : }
      23              : 
      24          809 : HcclCommunicatorAttrs::~HcclCommunicatorAttrs()
      25              : {
      26          809 : }
      27              : 
      28         1089 : bool HcclCommunicatorAttrs::Is310P3Common()
      29              : {
      30         1089 :     return !isHaveCpuRank_ && !Is310PDevice() && deviceType_ == DevType::DEV_TYPE_310P3;
      31              : }
      32              : 
      33         1221 : HcclResult HcclCommunicatorAttrs::GetPairDeviceLinkType(const RankTable_t &rankTable, u32 i,
      34              :     bool &isConnectedWithHCCS, LinkTypeInServer &linkType)
      35              : {
      36         3658 :     for (u32 j = i + 1; j < rankTable.rankList.size(); j++) {
      37         2437 :         if (rankTable.rankList[i].serverId == rankTable.rankList[j].serverId) {
      38         1985 :             bool isValidRanki = rankTable.rankList[i].deviceInfo.devicePhyId == HOST_DEVICE_ID;
      39         1985 :             bool isValidRankj = rankTable.rankList[j].deviceInfo.devicePhyId == HOST_DEVICE_ID;
      40         1985 :             if ( isValidRanki || isValidRankj) {
      41            0 :                 continue;
      42              :             }
      43         1985 :             CHK_RET(hrtGetPairDeviceLinkType(rankTable.rankList[i].deviceInfo.devicePhyId,
      44              :                 rankTable.rankList[j].deviceInfo.devicePhyId, linkType));
      45              :         }
      46         2437 :         if (linkType != LinkTypeInServer::HCCS_TYPE) {
      47           48 :             isConnectedWithHCCS = false;
      48              :         }
      49              :     }
      50         1221 :     return HCCL_SUCCESS;
      51              : }
      52              : 
      53            0 : HcclResult HcclCommunicatorAttrs::GetMixInnerLinkInfo(std::unordered_map<u32, u32> &pairLinkCounter,
      54              :     std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> &pairLinkInfo)
      55              : {
      56            0 :     pairLinkInfo.clear();
      57            0 :     pairLinkCounter[static_cast<u32>(LinkTypeInServer::HCCS_TYPE)] = 0;
      58            0 :     pairLinkCounter[static_cast<u32>(LinkTypeInServer::PXI_TYPE)] = 0;
      59            0 :     pairLinkCounter[static_cast<u32>(LinkTypeInServer::SIO_TYPE)] = 0;
      60            0 :     pairLinkCounter[static_cast<u32>(LinkTypeInServer::HCCS_SW_TYPE)] = 0;
      61            0 :     for (auto &it_local : nicList_) {
      62            0 :         for (auto &it_dest : nicList_) {
      63            0 :             if (it_local == it_dest || static_cast<s32>(it_local) == HOST_DEVICE_ID ||
      64            0 :                 static_cast<s32>(it_dest) == HOST_DEVICE_ID) {
      65            0 :                 continue;
      66              :             }
      67              :             LinkTypeInServer linkType;
      68            0 :             CHK_RET(hrtGetPairDeviceLinkType(it_local, it_dest, linkType));
      69            0 :             pairLinkInfo[static_cast<u32>(linkType)][it_local].push_back(it_dest);
      70            0 :             pairLinkCounter[static_cast<u32>(linkType)]++;
      71              :         }
      72              :     }
      73            0 :     if (HcclCheckLogLevel(DLOG_DEBUG)) {
      74            0 :         for (auto it : pairLinkInfo) {
      75            0 :             HCCL_DEBUG("pair link information linkType[%u], size[%llu]", it.first, it.second.size());
      76            0 :         }
      77            0 :         for (auto it : pairLinkCounter) {
      78            0 :             HCCL_DEBUG("pair link counter information linkType[%u], size[%llu]", it.first, it.second);
      79              :         }
      80              :     }
      81              : 
      82            0 :     return HCCL_SUCCESS;
      83              : }
      84              : 
      85              : // 用于标识集群中是否存在 不同芯片形态
      86          530 : bool HcclCommunicatorAttrs::IsDiffDeviceType(const std::vector<RankInfo_t> &rankList) const
      87              : {
      88          530 :     if (rankList.size() <= 1 || isHaveCpuRank_) {
      89          206 :         return false;
      90              :     }
      91         1767 :     for (const RankInfo_t &rankInfo : rankList) {
      92         1443 :         if (GetRankInfoDevType(rankInfo) != deviceType_) {
      93            0 :             HCCL_INFO("[IsDiffDeviceType] deviceType_[%d], and ranktable contains devicePhyId[%d]-deviceType[%d]",
      94              :                 deviceType_, rankInfo.deviceInfo.devicePhyId, rankInfo.deviceInfo.deviceType);
      95            0 :             return true;
      96              :         }
      97              :     }
      98          324 :     return false;
      99              : }
     100              : 
     101          495 : HcclResult HcclCommunicatorAttrs::SetNiclistInfo(){
     102         1713 :     for (auto &iter : servRankInfo_[serverId_]) {
     103         2439 :         if (((!iter.hostIp.IsInvalid()) || (!iter.deviceInfo.deviceIp[0].IsInvalid())) &&
     104         1219 :             (iter.deviceInfo.devicePhyId != HOST_DEVICE_ID)) {
     105         1219 :             if (isDiffDeviceType_) {
     106            0 :                 u32 gcdIdx = userRank_ / gcdDeviceNumPerAggregation_;
     107            0 :                 u32 gcdUserRankMin = gcdIdx * gcdDeviceNumPerAggregation_;
     108            0 :                 u32 gcdUserRankMax = (gcdIdx + 1) * gcdDeviceNumPerAggregation_ - 1;
     109            0 :                 if (iter.rankId < gcdUserRankMin || iter.rankId > gcdUserRankMax) {
     110            0 :                     continue;
     111              :                 }
     112              :             }
     113         1219 :             nicList_.push_back(iter.deviceInfo.devicePhyId);
     114              :         }
     115              :     }
     116          493 :     std::sort(nicList_.begin(), nicList_.end());
     117          494 :     HCCL_DEBUG("nic isDiffDeviceType[%u] userRank[%u] nicList size[%d]", isDiffDeviceType_, userRank_, nicList_.size());
     118          495 :     if (isDiffDeviceType_) {
     119            0 :         CHK_RET(GetMixInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取混合组网场景上HCCS、PXI链接的数目
     120              :     }
     121          495 :     CHK_SMART_PTR_NULL(topoInfoParse_);
     122          496 :     CHK_RET(topoInfoParse_->ParseAndCheck(nicList_));
     123          495 :     return HCCL_SUCCESS;
     124              : }
     125              : 
     126          495 : HcclResult HcclCommunicatorAttrs::InitTopoInfo(const RankTable_t &rankTable)
     127              : {
     128          495 :     topoInfoParse_.reset(new (std::nothrow) TopoInfoParse());
     129          496 :     CHK_SMART_PTR_NULL(topoInfoParse_);
     130          496 :     CHK_RET(topoInfoParse_->Init(rankTable, serverId_, deviceNumPerServer_));
     131          496 :     if (!isDiffDeviceType_) {
     132          496 :         CHK_RET(topoInfoParse_->GetServerInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取本Server上HCCS、PXI链接的数目
     133              :     }
     134              :     // 初始化阶段判断组网状态
     135          495 :     CHK_RET(topoInfoParse_->IsSingleMeshAggregation(isSingleMeshAggregation_));         // 确认集群中只有一个MeshAggregation
     136          496 :     CHK_RET(topoInfoParse_->IsAllRankSamePlane(isAllRankSamePlane_));                   // 确认集群所有卡在一个平面上
     137          496 :     isStandardCard_ = IsStandardCard();
     138          496 :     is310PDuoCard_ = Is310PDuoCard();
     139          496 :     if (is310PDuoCard_) {
     140            4 :         isCommon310P3DUO_ = IsCommon310P3DUO(rankTable.rankList);
     141              :     }
     142          496 :     CHK_RET(InitHccsPortNum());
     143          496 :     return HCCL_SUCCESS;
     144              : }
     145              : 
     146           33 : HcclResult HcclCommunicatorAttrs::InitTopoInfo(const std::vector<RankInfo> &rankList)
     147              : {
     148           33 :     topoInfoParse_.reset(new (std::nothrow) TopoInfoParse());
     149           33 :     CHK_SMART_PTR_NULL(topoInfoParse_);
     150           33 :     CHK_RET(topoInfoParse_->Init(rankList, serverId_, deviceNumPerServer_));
     151           33 :     if (!isDiffDeviceType_) {
     152           33 :         CHK_RET(topoInfoParse_->GetServerInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取本Server上HCCS、PXI链接的数目
     153              :     }
     154              :     // 初始化阶段判断组网状态
     155           33 :     CHK_RET(topoInfoParse_->IsSingleMeshAggregation(isSingleMeshAggregation_));         // 确认集群中只有一个MeshAggregation
     156           33 :     CHK_RET(topoInfoParse_->IsAllRankSamePlane(isAllRankSamePlane_));                   // 确认集群所有卡在一个平面上
     157           33 :     isStandardCard_ = IsStandardCard();
     158           33 :     is310PDuoCard_ = Is310PDuoCard();
     159           33 :     CHK_RET(InitHccsPortNum());
     160           33 :     if (!isStandardCard_) {
     161           20 :         CHK_RET(topoInfoParse_->Check());
     162              :     }
     163           33 :     return HCCL_SUCCESS;
     164              : }
     165              : 
     166          528 : HcclResult HcclCommunicatorAttrs::SetInterModeInSuperPod()
     167              : {
     168              :     // 硬件配置为非超节点模式或软件(ranktable)中未配置sdid,后面按照非超节点形态处理
     169          528 :     if (!useSuperPodMode_) {
     170          529 :         return HCCL_SUCCESS;
     171              :     }
     172            0 :     HCCL_INFO("[Set][InterModeInSuperPod]: serverNum[%u], superPodNum[%u].", serverNum_, superPodNum_);
     173              :     // 超节点HCCS模式
     174            0 :     if (GetExternalInputInterHccsDisable() == false && serverNum_ > 1 && superPodNum_ > 0) {
     175            0 :         isUsedInterHccsMode_ = true;
     176            0 :         HCCL_RUN_INFO("[Set][InterModeInSuperPod]: will use inter HCCS Mode, superPodId[%s], superDeviceId[0x%x], "
     177              :                       "superPodNum[%u], serverNum[%u], userRank[%u].",
     178              :             superPodId_.c_str(), superDeviceId_, superPodNum_, serverNum_, userRank_);
     179              :     }
     180            0 :     return HCCL_SUCCESS;
     181              : }
     182              : 
     183           33 : HcclResult HcclCommunicatorAttrs::SethbRankInfo(const std::vector<RankInfo> &rankList, 
     184              :     WorldGroupInfo &groupCommonData)
     185              : {
     186              :     // 记录serverId
     187           33 :     serverId_ = groupCommonData.serverId;
     188           33 :     useSuperPodMode_ = groupCommonData.useSuperPodMode;
     189              : 
     190          190 :     for (auto &rankInfo : rankList) {
     191          157 :         if (rankInfo.devicePhyId == HOST_DEVICE_ID) {
     192            0 :             isHaveCpuRank_ = true;
     193              :         }
     194              :     }
     195           33 :     return HCCL_SUCCESS;
     196              : }
     197              : 
     198          500 : HcclResult HcclCommunicatorAttrs::CheckSuperDeviceId(const RankTable_t &rankTable)
     199              : {
     200              :     // 非910_93/910_93非超节点形态 || 用户配置非超节点模式,无需校验SDID合法性
     201          500 :     if (!useSuperPodMode_) {
     202          500 :         return HCCL_SUCCESS;
     203              :     }
     204              : 
     205            0 :     for (u32 i = 0; i < rankTable.rankList.size(); i++) {
     206            0 :         if (rankTable.rankList[i].rankId == userRank_) {
     207            0 :             s64 drvSuperDeviceID = 0;
     208            0 :             CHK_RET(hrtGetDeviceInfo(deviceLogicId_, HcclRtDeviceModuleType::HCCL_RT_MODULE_TYPE_SYSTEM,
     209              :                 HcclRtDeviceInfoType::HCCL_INFO_TYPE_SDID, drvSuperDeviceID));
     210            0 :             if (superDeviceId_ != static_cast<u32>(drvSuperDeviceID)) {
     211            0 :                 RPT_INPUT_ERR(true, "EI0014", std::vector<std::string>({ "value", "variable" ,"expect" }),
     212              :                     std::vector<std::string>({ std::to_string(superDeviceId_), "super_device_id", std::to_string(drvSuperDeviceID) }));
     213            0 :                 HCCL_ERROR("[%s][%s]errNo[0x%016llx] super_device_id is invalid, " \
     214              :                     "expect value [0x%x], ranktable config value [0x%x]", LOG_KEYWORDS_INIT_GROUP.c_str(),
     215              :                     LOG_KEYWORDS_RANKTABLE_CHECK.c_str(), HCOM_ERROR_CODE(HCCL_E_PARA), drvSuperDeviceID,
     216              :                     superDeviceId_);
     217            0 :                 return HCCL_E_PARA;
     218              :             }
     219            0 :             break;
     220              :         }
     221              :     }
     222            0 :     HCCL_RUN_INFO("[Check][SuperDeviceId]: superDevice check success, superPodId[%s], " \
     223              :         "superDeviceId[0x%x], userRank[%u].", superPodId_.c_str(), superDeviceId_, userRank_);
     224            0 :     return HCCL_SUCCESS;
     225            0 : }
     226              : 
     227           33 : HcclResult HcclCommunicatorAttrs::UpdateNicList()
     228              : {
     229           33 :     std::vector<u32> subCommNicList;
     230          190 :     for (u32 i = 0; i < rankInfoList_.size(); i++) {
     231          275 :         if (rankInfoList_[i].serverId == serverId_ &&
     232          275 :             std::find(nicList_.begin(), nicList_.end(), rankInfoList_[i].devicePhyId) != nicList_.end()) {
     233            0 :             if (isDiffDeviceType_) {
     234            0 :                 u32 gcdIdx = userRank_ / gcdDeviceNumPerAggregation_;
     235            0 :                 u32 gcdUserRankMin = gcdIdx * gcdDeviceNumPerAggregation_;
     236            0 :                 u32 gcdUserRankMax = (gcdIdx + 1) * gcdDeviceNumPerAggregation_ - 1;
     237            0 :                 if (rankInfoList_[i].userRank < gcdUserRankMin || rankInfoList_[i].userRank > gcdUserRankMax) {
     238            0 :                     continue;
     239              :                 }
     240              :             }
     241            0 :             subCommNicList.push_back(rankInfoList_[i].devicePhyId);
     242              :         }
     243              :     }
     244           33 :     nicList_ = subCommNicList;
     245           33 :     if (HcclCheckLogLevel(DLOG_DEBUG)) {
     246              :         // 打印更新后的nicList_
     247           33 :         std::ostringstream stringRepresentation;
     248           33 :         for (std::vector<uint32_t>::iterator it = nicList_.begin(); it != nicList_.end(); it++) {
     249            0 :             stringRepresentation << *it << " ";
     250              :         }
     251           33 :         std::string nicListString = stringRepresentation.str();
     252           33 :         const char *charNicList = nicListString.c_str();
     253           33 :         HCCL_DEBUG("[HcclCommunicatorAttrs][Init] The subcommunication domain related nicList_: %s", charNicList);
     254           33 :     }
     255              :     // 将更新的nicList_刷新到rankInfoList_中
     256          190 :     for (u32 i = 0; i < rankInfoList_.size(); i++) {
     257          157 :         rankInfoList_[i].nicIdx.assign(nicList_.begin(), nicList_.end());
     258              :     }
     259           33 :     if (isDiffDeviceType_) {
     260            0 :         CHK_RET(GetMixInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取混合组网场景上HCCS、PXI链接的数目
     261              :     }
     262           33 :     return  HCCL_SUCCESS;
     263           33 : }
     264              : 
     265          496 : HcclResult HcclCommunicatorAttrs::SetRanksPort(const std::vector<RankInfo_t> &rankList)
     266              : {
     267          496 :     bool devicePortSwitchOn = GetExternalInputNpuPortSwitch();
     268          496 :     if (devicePortSwitchOn) {
     269            1 :         nicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     270            1 :         vnicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     271            2 :         for (auto &rankInfo : rankList) {
     272            1 :             nicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.port == HCCL_INVALID_PORT
     273            1 :                 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.port;
     274            1 :             vnicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.vnicPort == HCCL_INVALID_PORT
     275            1 :                 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.vnicPort;
     276              :         }
     277              :     } else {
     278          495 :         nicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     279         1978 :         for (auto &rankInfo : rankList) {
     280         1484 :             nicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.port == HCCL_INVALID_PORT
     281         1484 :                 || rankInfo.deviceInfo.port == 0 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.port;
     282              :         }
     283              :     }
     284          495 :     isUseRankPort_ = ((devicePortSwitchOn && nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_DEVICE) || isHaveCpuRank_
     285          990 :         || nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_HOST) ? true : isUseRankPort_;
     286          495 :     HCCL_INFO("[HcclCommunicatorAttrs][SetRanksPort] devicePortSwitchOn[%u], isHaveCpuRank[%u], isUseRankPort[%u], "
     287              :         "nicRanksPort size[%u], vnicRanksPort size[%u].",
     288              :         devicePortSwitchOn, isHaveCpuRank_, isUseRankPort_, nicRanksPort_.size(), vnicRanksPort_.size());
     289          496 :     return HCCL_SUCCESS;
     290              : }
     291              : 
     292          498 : HcclResult HcclCommunicatorAttrs::InitRankInfo(const RankTable_t &rankTable)
     293              : {
     294              :     // 获取serverId
     295          498 :     CHK_RET(SetServerId(rankTable));
     296              :     // 获取server数
     297          496 :     CHK_RET(SetServerNum(rankTable.rankList));
     298          496 :     CHK_PRT_RET(serverNum_ != rankTable.serverNum,
     299              :         HCCL_ERROR("[HcclCommunicatorAttrs][InitRankInfo]calculated serverNum[%u] is not equal to ranktable serverNum[%u]",
     300              :         serverNum_, rankTable.serverNum), HCCL_E_PARA);
     301              :     // 本节点的sdid配置有效(ranktable v1.2)且环境配置server id有效时, 使能superPod
     302          496 :     if (superDeviceId_ != INVALID_UINT) {
     303            0 :         CHK_RET(IsSuperPodMode(useSuperPodMode_)); // 使能superPod
     304              :     }
     305              :     // 获取server内设备数, 赋值 ishavecpurank_
     306          496 :     CHK_RET(SetInnerServerAverageDevice(rankTable));
     307              :     // 根据server整理rank信息
     308          496 :     CHK_RET(TransformRankInfoByServerId(rankTable.rankList, servRankInfo_));
     309          496 :     isDiffDeviceType_ = IsDiffDeviceType(rankTable.rankList);
     310              :     // 解析拓扑信息
     311          496 :     CHK_RET(InitTopoInfo(rankTable));
     312              :     // 获取module相关信息,moduleNum_, isDiffDeviceModule_, multiModuleDiffDeviceNumMode_;
     313          495 :     CHK_RET(SetModuleInfo(rankTable.rankList));
     314              :     // 获取超节点相关信息,superPodNum_, multiSuperPodDiffServerNumMode_
     315          496 :     CHK_RET(SetSuperPodInfo(rankTable.rankList));
     316              :     // 生成nicList
     317          495 :     CHK_RET(SetNiclistInfo());
     318              :     // 设置超节点内节点间模式,包括是否使用sdid获取vnicip、节点间是否使能HCCS
     319          496 :     CHK_RET(SetInterModeInSuperPod());
     320              :     // 解析ranktable信息(生成rankInfoList_),供给commfactory使用
     321          496 :     CHK_RET(SetRankInfoList(rankTable));
     322              :     // 解析当前Rank信息
     323          495 :     CHK_RET(SetLocalRankInfo());
     324              :     // 解析rank和port的映射信息
     325          494 :     CHK_RET(SetRanksPort(rankTable.rankList));
     326              : 
     327              :     // 通过关键字打印通信域及本端的rank关键信息,方便在日志中直接检索
     328          494 :     HCCL_RUN_INFO("[%s]identifier[%s] rankSize[%u] serverNum[%u] moduleNum[%u] superPodNum[%u] "
     329              :         "multiModuleDiffDeviceNumMode[%u] multiSuperPodDiffServerNumMode[%u]",
     330              :         LOG_KEYWORDS_COMMUNICATOR.c_str(), identifier_.c_str(), userRankSize_, serverNum_, moduleNum_, superPodNum_,
     331              :         multiModuleDiffDeviceNumMode_, multiSuperPodDiffServerNumMode_);
     332          495 :     HCCL_RUN_INFO("[%s]userRank[%u] hostIp[%s] devicePhyId[%u] server[%s] deviceIp[%s] superPodId[%s] useSuperPodMode[%d] isStandardCard[%d]",
     333              :         LOG_KEYWORDS_LOCALRANK.c_str(), userRank_, hostIp_.GetReadableAddress(), devicePhyId_, serverId_.c_str(),
     334              :         devIpAddr_.empty() ? "" : devIpAddr_[0].GetReadableAddress(), superPodId_.c_str(), useSuperPodMode_, isStandardCard_);
     335              : 
     336          494 :     interServer_ = rankTable.serverNum > 1; // serverNum为1时,不进行roce初始化
     337          494 :     nicDeployment_ = rankTable.nicDeploy;
     338          494 :     rankTableVersion_ = rankTable.version;
     339          495 :     return HCCL_SUCCESS;
     340              : }
     341              : 
     342          488 : void HcclCommunicatorAttrs::GenCollectiveId(HcclCommParams &params, const RankTable_t &rankTable)
     343              : {
     344          893 :     collectiveId_ = rankTable.collectiveId.empty() ? params.id.internal : rankTable.collectiveId;
     345          488 : }
     346              : 
     347           34 : HcclResult HcclCommunicatorAttrs::InitRankInfoSubGroup(const std::vector<RankInfo> &rankList,
     348              :     WorldGroupInfo &groupCommonData)
     349              : {
     350              :     //填充心跳信息
     351           34 :     SethbRankInfo(rankList,groupCommonData);
     352              :     // 获取server内平均device数
     353           34 :     CHK_RET(SetInnerServerAverageDevice(rankList));
     354              :     // 将子通信域的ranklist结构体形式转换成全局通信域的
     355           34 :     std::vector<RankInfo_t> rankListNew;
     356           34 :     CHK_RET(TransformRankList(rankList, rankListNew));
     357              :     // 获取server数
     358           34 :     CHK_RET(SetServerNum(rankListNew));
     359           34 :     isDiffDeviceType_ = IsDiffDeviceType(rankListNew);
     360              :     // 解析拓扑信息
     361           34 :     CHK_RET(InitTopoInfo(rankList));
     362              :     // 获取module相关信息,moduleNum_, isDiffDeviceModule_, multiModuleDiffDeviceNumMode_;
     363           34 :     CHK_RET(SetModuleInfo(rankListNew));
     364              :     // 获取超节点相关信息,superPodNum_, multiSuperPodDiffServerNumMode_
     365           34 :     CHK_RET(SetSuperPodInfo(rankListNew));
     366              :     // 根据server整理rank信息
     367           34 :     CHK_RET(TransformRankInfoByServerId(rankListNew, servRankInfo_));
     368              :     //  inline reduce 开关
     369           34 :     inlineReduceSwitchOn_ = groupCommonData.inlineReduceSwitchOn;
     370              :     // 设置rank关联信息
     371           34 :     CHK_RET(SetLocalRankInfoSubGroup(rankList));
     372              :     // 设置超节点内节点间模式,包括是否使用sdid获取vnicip、节点间是否使用HCCS
     373           34 :     CHK_RET(SetInterModeInSuperPod());
     374              : 
     375           34 :     if (HcclCheckLogLevel(DLOG_DEBUG)) {
     376              :         // 打印原来的nicList_
     377           33 :         std::ostringstream stringRepresentation;
     378           33 :         for (std::vector<uint32_t>::iterator it = nicList_.begin(); it != nicList_.end(); it++) {
     379            0 :             stringRepresentation << *it << " ";
     380              :         }
     381           33 :         std::string nicListString = stringRepresentation.str();
     382           33 :         const char *charNicList = nicListString.c_str();
     383           33 :         HCCL_DEBUG("[HcclCommunicatorAttrs][Init] The original nicList_: %s", charNicList);
     384           33 :     }
     385           34 :     interServer_ = serverNum_ > 1; // serverNum为1时,不进行roce初始化
     386              :     // 更新成跟子通信域相关的nicList_
     387           34 :     CHK_RET(UpdateNicList());
     388              :     // 检查当前user_rank 对应的devid和rt查到的一致
     389           34 :     CHK_RET(CheckLocalRankInfo());
     390           34 :     CHK_RET(CalAndSetMeshAggRankSize());
     391              : 
     392           34 :     if (IsEnableRoce()) {
     393            6 :         isUsedRdmaLevel0_ = IsUsedRdmaLevel0AndIpInvalid();
     394              :     }
     395              : 
     396           34 :     CHK_RET(SetWorldGroupInfo(groupCommonData.phyIdNicInfoMap, groupCommonData.worldRankInfoList,
     397              :         groupCommonData.ranksPort, groupCommonData.vnicRanksPort));
     398           34 :     for (auto &rankInfo : worldRankInfoList_) {
     399            0 :         if (rankInfo.devicePhyId == HOST_DEVICE_ID) {
     400            0 :             isUseRankPort_ = true;
     401            0 :             break;
     402              :         }
     403              :     }
     404           34 :     CHK_RET(IsHostUseDevNic(isHostUseDevNic_));
     405              : 
     406           34 :     groupNicRanksPort_.resize(rankInfoList_.size(), HCCL_INVALID_PORT);
     407           34 :     if (nicRanksPort_.size() != 0) {
     408            0 :         for (auto &rankInfo : rankInfoList_) {
     409            0 :             groupNicRanksPort_[rankInfo.userRank] = nicRanksPort_[rankInfo.worldRank];
     410            0 :             HCCL_INFO("hostIp[%s], nicIp[%s], rankInfo.userRank[%u], rankInfo.worldRank[%u], "
     411              :                 "nic port[%u], devicePhyId[%d]",
     412              :                 rankInfo.hostIp.GetReadableAddress(), rankInfo.nicIp[0].GetReadableAddress(),
     413              :                 rankInfo.userRank, rankInfo.worldRank, groupNicRanksPort_[rankInfo.userRank], rankInfo.devicePhyId);
     414              :         }
     415              :     }
     416           34 :     bool devicePortSwitchOn = groupCommonData.devPortSwitchOn;
     417           34 :     if (devicePortSwitchOn) {
     418            1 :         groupVnicRanksPort_.resize(rankInfoList_.size(), HCCL_INVALID_PORT);
     419            1 :         if (vnicRanksPort_.size() != 0) {
     420            1 :             for (auto &rankInfo : rankInfoList_) {
     421            0 :                 groupVnicRanksPort_[rankInfo.userRank] = vnicRanksPort_[rankInfo.worldRank];
     422            0 :                 HCCL_INFO("hostIp[%s], nicIp[%s], rankInfo.userRank[%u], rankInfo.worldRank[%u], "
     423              :                     "vnic port[%u], devicePhyId[%d]",
     424              :                     rankInfo.hostIp.GetReadableAddress(), rankInfo.nicIp[0].GetReadableAddress(),
     425              :                     rankInfo.userRank, rankInfo.worldRank, groupVnicRanksPort_[rankInfo.userRank],
     426              :                     rankInfo.devicePhyId);
     427              :             }
     428              :         }
     429              :     }
     430           34 :     isUseRankPort_ = ((devicePortSwitchOn && nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_DEVICE) || isHaveCpuRank_
     431           68 :         || nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_HOST) ? true : isUseRankPort_;
     432           34 :     HCCL_INFO("[InitRankInfoSubGroup]:isUsedRdmaLevel0_[%d]", isUsedRdmaLevel0_);
     433           34 :     return HCCL_SUCCESS;
     434           34 : }
     435              : 
     436            0 : void HcclCommunicatorAttrs::GenUsedRdmaLevel0()
     437              : {
     438            0 :     isUsedRdmaLevel0_ = IsSupportEnableRoce();
     439            0 : }
     440              : 
     441              : #ifndef OPEN_HCCL_TEST
     442          153 : void HcclCommunicatorAttrs::GenSupportRdmaLite()
     443              : {
     444          153 :     isSupportRdmaLite_ = IsSupportRDMALite(deviceLogicId_);
     445          153 : }
     446          153 : HcclResult HcclCommunicatorAttrs::GenSupportHccsAndSio()
     447              : {
     448          153 :      CHK_RET(IsSupportHccsAndSio(isSupportHccsAndSio_));
     449          154 :      return HCCL_SUCCESS;
     450              : }
     451              : #endif
     452              : 
     453           33 : bool HcclCommunicatorAttrs::GetUsedRdmaLevel0()
     454              : {
     455           33 :     return isUsedRdmaLevel0_;
     456              : }
     457              : 
     458          152 : bool HcclCommunicatorAttrs::GetSupportRdmaLite()
     459              : {
     460          152 :     return isSupportRdmaLite_;
     461              : }
     462          153 : bool HcclCommunicatorAttrs::GetSupportHccsAndSio()
     463              : {
     464          153 :     return isSupportHccsAndSio_;
     465              : }
     466              : 
     467          528 : std::string HcclCommunicatorAttrs::GetServerId()
     468              : {
     469          528 :     return serverId_;
     470              : }
     471              : 
     472          529 : u32 HcclCommunicatorAttrs::GetServerNum()
     473              : {
     474          529 :     return serverNum_;
     475              : }
     476          528 : std::string HcclCommunicatorAttrs::GetSuperPodId()
     477              : {
     478          528 :     return superPodId_;
     479              : }
     480              : 
     481          528 : u32 HcclCommunicatorAttrs::GetSuperDeviceId()
     482              : {
     483          528 :     return superDeviceId_;
     484              : }
     485              : 
     486          528 : bool HcclCommunicatorAttrs::GetSuperPodMode()
     487              : {
     488          528 :     return useSuperPodMode_;
     489              : }
     490              : 
     491          527 : u32 HcclCommunicatorAttrs::GetSuperPodNums()
     492              : {
     493          527 :     return superPodNum_;
     494              : }
     495              : 
     496          528 : u32 HcclCommunicatorAttrs::GetDeviceNumPerAggregation()
     497              : {
     498          528 :     return deviceNumPerAggregation_;
     499              : }
     500              : 
     501          529 : u32 HcclCommunicatorAttrs::GetDeviceNumPerServer()
     502              : {
     503          529 :     return deviceNumPerServer_;
     504              : }
     505              : 
     506         5413 : DevType HcclCommunicatorAttrs::GetRankInfoDevType(const RankInfo_t &rankInfo) const
     507              : {
     508         5413 :     if (rankInfo.deviceInfo.deviceType == DevType::DEV_TYPE_NOSOC) {
     509         5105 :         return deviceType_; // 兼容非混合组网场景,rankInfo中deviceType字段可能没有赋值
     510              :     }
     511          308 :     return rankInfo.deviceInfo.deviceType;
     512              : }
     513              : 
     514          528 : bool HcclCommunicatorAttrs::GetDiffDeviceType()
     515              : {
     516          528 :     return isDiffDeviceType_;
     517              : }
     518              : 
     519          526 : u32 HcclCommunicatorAttrs::GetGcdDeviceNumPerAggregation()
     520              : {
     521          526 :     return gcdDeviceNumPerAggregation_;
     522              : }
     523          529 : ServRankInfo HcclCommunicatorAttrs::GetServRankInfo()
     524              : {
     525          529 :     return servRankInfo_;
     526              : }
     527              : 
     528          528 : bool HcclCommunicatorAttrs::GetDiffDeviceModule()
     529              : {
     530          528 :     return isDiffDeviceModule_;
     531              : }
     532              : 
     533          528 : bool HcclCommunicatorAttrs::GetSupportARS()
     534              : {
     535          528 :     return isARSDoubleRing_;
     536              : }
     537              : 
     538          525 : u32 HcclCommunicatorAttrs::GetModuleNum()
     539              : {
     540          525 :     return moduleNum_;
     541              : }
     542              : 
     543          529 : bool HcclCommunicatorAttrs::GetMultiModuleDiffDeviceNumMode()
     544              : {
     545          529 :     return multiModuleDiffDeviceNumMode_;
     546              : }
     547              : 
     548          528 : bool HcclCommunicatorAttrs::GetMultiSuperPodDiffServerNumMode()
     549              : {
     550          528 :     return multiSuperPodDiffServerNumMode_;
     551              : }
     552              : 
     553          527 : bool HcclCommunicatorAttrs::GetmultiSuperPodDiffDeviceNumMode()
     554              : {
     555          527 :     return multiSuperPodDiffDeviceNumMode_;
     556              : }
     557              : 
     558          529 : std::vector<u32> HcclCommunicatorAttrs::GetNicList()
     559              : {
     560          529 :     return nicList_;
     561              : }
     562              : 
     563          528 : bool HcclCommunicatorAttrs::GetSingleMeshAggregation()
     564              : {
     565          528 :     return isSingleMeshAggregation_;
     566              : }
     567              : 
     568          528 : bool HcclCommunicatorAttrs::GetAllRankSamePlane()
     569              : {
     570          528 :     return isAllRankSamePlane_;
     571              : }
     572              : 
     573          528 : bool HcclCommunicatorAttrs::GetStandardCard()
     574              : {
     575          528 :     return isStandardCard_;
     576              : }
     577              : 
     578          527 : bool HcclCommunicatorAttrs::Get310PDuoCard()
     579              : {
     580          527 :     return is310PDuoCard_;
     581              : }
     582              : 
     583          529 : bool HcclCommunicatorAttrs::GetIsCommon310P3DUO()
     584              : {
     585          529 :     return isCommon310P3DUO_;
     586              : }
     587              : 
     588          529 : s32 HcclCommunicatorAttrs::GetHccsPortNum()
     589              : {
     590          529 :     return hccsPortNum_;
     591              : }
     592              : 
     593          527 : void HcclCommunicatorAttrs::GetPairLinkCounter(std::unordered_map<u32, u32> &pairLinkCounter)
     594              : {
     595          527 :     pairLinkCounter = pairLinkCounter_;
     596          528 : }
     597              : 
     598          528 : void HcclCommunicatorAttrs::GetPairLinkInfo(
     599              :     std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> &pairLinkInfo)
     600              : {
     601          528 :     pairLinkInfo = pairLinkInfo_;
     602          528 : }
     603              : 
     604          529 : bool HcclCommunicatorAttrs::GetUsedInterHccsMode()
     605              : {
     606          529 :     return isUsedInterHccsMode_;
     607              : }
     608              : 
     609          528 : std::vector<RankInfo> HcclCommunicatorAttrs::GetRankInfoList()
     610              : {
     611          528 :     return rankInfoList_;
     612              : }
     613              : 
     614          529 : std::vector<HcclIpAddress> HcclCommunicatorAttrs::GetDevIpAddr()
     615              : {
     616          529 :     return devIpAddr_;
     617              : }
     618              : 
     619          527 : std::vector<HcclIpAddress> HcclCommunicatorAttrs::GetDevBackupIpAddr()
     620              : {
     621          527 :     return devBackupIpAddr_;
     622              : }
     623              : 
     624          527 : u32 HcclCommunicatorAttrs::GetBackupDevPort()
     625              : {
     626          527 :     return devBackupPort_;
     627              : }
     628              : 
     629          527 : u32 HcclCommunicatorAttrs::GetDevicePhyId()
     630              : {
     631          527 :     return devicePhyId_;
     632              : }
     633              : 
     634          528 : HcclIpAddress HcclCommunicatorAttrs::GetHostIp()
     635              : {
     636          528 :     return hostIp_;
     637              : }
     638              : 
     639          529 : u32 HcclCommunicatorAttrs::GetHostPort()
     640              : {
     641          529 :     return hostPort_;
     642              : }
     643              : 
     644          495 : u32 HcclCommunicatorAttrs::GetLocalRank()
     645              : {
     646          495 :     return localRank_;
     647              : }
     648              : 
     649          488 : std::string HcclCommunicatorAttrs::GetCollectiveId()
     650              : {
     651          488 :     return collectiveId_;
     652              : }
     653              : 
     654            1 : std::string HcclCommunicatorAttrs::GetRankTableVersion()
     655              : {
     656            1 :     return rankTableVersion_;
     657              : }
     658              : 
     659          495 : s32 HcclCommunicatorAttrs::GetDeviceLogicId()
     660              : {
     661          495 :     return deviceLogicId_;
     662              : }
     663              : 
     664          528 : bool HcclCommunicatorAttrs::GetInterServe()
     665              : {
     666          528 :     return interServer_;
     667              : }
     668              : 
     669          529 : NICDeployment HcclCommunicatorAttrs::GetNicDeployment()
     670              : {
     671          529 :     return nicDeployment_;
     672              : }
     673              : 
     674          527 : bool HcclCommunicatorAttrs::GetHaveCpuRank()
     675              : {
     676          527 :     return isHaveCpuRank_;
     677              : }
     678              : 
     679          521 : u32 HcclCommunicatorAttrs::GetMeshAggregationRankSize()
     680              : {
     681          521 :     return meshAggregationRankSize_;
     682              : }
     683              : 
     684           33 : bool HcclCommunicatorAttrs::GetInlineReduceSwitchOn()
     685              : {
     686           33 :     return inlineReduceSwitchOn_;
     687              : }
     688              : 
     689            0 : u32 HcclCommunicatorAttrs::GetHostPort(s32 devicePhyId)
     690              : {
     691            0 :     if (GetExternalInputHcclIfBasePort() == HCCL_INVALID_PORT) {
     692            0 :         return (devicePhyId + HOST_PARA_BASE_PORT);
     693              :     } else {
     694            0 :         return (devicePhyId + GetExternalInputHcclIfBasePort() + HCCL_AISERVER_DEVICE_NUM);
     695              :     }
     696              : }
     697              : 
     698            0 : void HcclCommunicatorAttrs::SetNeedInitNicFlag(const bool isNeedInitNic)
     699              : {
     700            0 :     isNeedInitNic_ = isNeedInitNic;
     701            0 : }
     702              : 
     703              : // 判断是否是双环
     704          758 : bool CheckDoubleRingWithRohTopo(const std::vector<u32> &nicList)
     705              : {
     706          758 :     std::vector<u32> topoList;
     707          758 :     std::vector<u32> tmpNicList(nicList);
     708          758 :     std::sort(tmpNicList.begin(), tmpNicList.end());
     709          756 :     SearchPath searchPath;
     710          758 :     topoList = searchPath.Search(tmpNicList, true);
     711          758 :     if (topoList.empty()) {
     712          474 :         return false;
     713              :     }
     714          284 :     return true;
     715          758 : }
     716              : }
        

Generated by: LCOV version 2.0-1