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: 78.8 % 363 286
Test Date: 2026-07-28 12:11:00 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          808 : HcclCommunicatorAttrs::HcclCommunicatorAttrs()
      21              : {
      22          809 : }
      23              : 
      24          809 : HcclCommunicatorAttrs::~HcclCommunicatorAttrs()
      25              : {
      26          809 : }
      27              : 
      28         1087 : bool HcclCommunicatorAttrs::Is310P3Common()
      29              : {
      30         1087 :     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          531 : bool HcclCommunicatorAttrs::IsDiffDeviceType(const std::vector<RankInfo_t> &rankList) const
      87              : {
      88          531 :     if (rankList.size() <= 1 || isHaveCpuRank_) {
      89          205 :         return false;
      90              :     }
      91         1784 :     for (const RankInfo_t &rankInfo : rankList) {
      92         1458 :         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          326 :     return false;
      99              : }
     100              : 
     101          496 : HcclResult HcclCommunicatorAttrs::SetNiclistInfo(){
     102         1706 :     for (auto &iter : servRankInfo_[serverId_]) {
     103         2421 :         if (((!iter.hostIp.IsInvalid()) || (!iter.deviceInfo.deviceIp[0].IsInvalid())) &&
     104         1210 :             (iter.deviceInfo.devicePhyId != HOST_DEVICE_ID)) {
     105         1210 :             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         1210 :             nicList_.push_back(iter.deviceInfo.devicePhyId);
     114              :         }
     115              :     }
     116          493 :     std::sort(nicList_.begin(), nicList_.end());
     117          493 :     HCCL_DEBUG("nic isDiffDeviceType[%u] userRank[%u] nicList size[%d]", isDiffDeviceType_, userRank_, nicList_.size());
     118          496 :     return HCCL_SUCCESS;
     119              : }
     120              : 
     121          496 : HcclResult HcclCommunicatorAttrs::InitTopoInfo(const RankTable_t &rankTable)
     122              : {
     123          496 :     topoInfoParse_.reset(new (std::nothrow) TopoInfoParse());
     124          493 :     CHK_SMART_PTR_NULL(topoInfoParse_);
     125          496 :     CHK_RET(topoInfoParse_->Init(rankTable, serverId_, deviceNumPerServer_));
     126          496 :     if (isDiffDeviceType_) {
     127            0 :         CHK_RET(GetMixInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取混合组网场景上HCCS、PXI链接的数目
     128              :     } else {
     129          496 :         CHK_RET(topoInfoParse_->GetServerInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取本Server上HCCS、PXI链接的数目
     130              :     }
     131              :     // 初始化阶段判断组网状态
     132          493 :     CHK_RET(topoInfoParse_->IsSingleMeshAggregation(isSingleMeshAggregation_));         // 确认集群中只有一个MeshAggregation
     133          496 :     CHK_RET(topoInfoParse_->IsAllRankSamePlane(isAllRankSamePlane_));                   // 确认集群所有卡在一个平面上
     134          496 :     isStandardCard_ = IsStandardCard();
     135          493 :     is310PDuoCard_ = Is310PDuoCard();
     136          493 :     if (is310PDuoCard_) {
     137            4 :         isCommon310P3DUO_ = IsCommon310P3DUO(rankTable.rankList);
     138              :     }
     139          493 :     CHK_RET(InitHccsPortNum());
     140          496 :     CHK_RET(topoInfoParse_->ParseAndCheck(nicList_));
     141          494 :     return HCCL_SUCCESS;
     142              : }
     143              : 
     144           33 : HcclResult HcclCommunicatorAttrs::InitTopoInfo(const std::vector<RankInfo> &rankList)
     145              : {
     146           33 :     topoInfoParse_.reset(new (std::nothrow) TopoInfoParse());
     147           33 :     CHK_SMART_PTR_NULL(topoInfoParse_);
     148           33 :     CHK_RET(topoInfoParse_->Init(rankList, serverId_, deviceNumPerServer_));
     149           33 :     if (isDiffDeviceType_) {
     150            0 :         CHK_RET(GetMixInnerLinkInfo(pairLinkCounter_, pairLinkInfo_));   // 获取混合组网场景上HCCS、PXI链接的数目
     151              :     } else {
     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          527 : HcclResult HcclCommunicatorAttrs::SetInterModeInSuperPod()
     167              : {
     168              :     // 硬件配置为非超节点模式或软件(ranktable)中未配置sdid,后面按照非超节点形态处理
     169          527 :     if (!useSuperPodMode_) {
     170          527 :         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          498 : HcclResult HcclCommunicatorAttrs::CheckSuperDeviceId(const RankTable_t &rankTable)
     199              : {
     200              :     // 非910_93/910_93非超节点形态 || 用户配置非超节点模式,无需校验SDID合法性
     201          498 :     if (!useSuperPodMode_) {
     202          498 :         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 :     return  HCCL_SUCCESS;
     260           33 : }
     261              : 
     262          496 : HcclResult HcclCommunicatorAttrs::SetRanksPort(const std::vector<RankInfo_t> &rankList)
     263              : {
     264          496 :     bool devicePortSwitchOn = GetExternalInputNpuPortSwitch();
     265          496 :     if (devicePortSwitchOn) {
     266            1 :         nicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     267            1 :         vnicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     268            2 :         for (auto &rankInfo : rankList) {
     269            1 :             nicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.port == HCCL_INVALID_PORT
     270            1 :                 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.port;
     271            1 :             vnicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.vnicPort == HCCL_INVALID_PORT
     272            1 :                 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.vnicPort;
     273              :         }
     274              :     } else {
     275          495 :         nicRanksPort_.resize(userRankSize_, HCCL_INVALID_PORT);
     276         1974 :         for (auto &rankInfo : rankList) {
     277         1481 :             nicRanksPort_[rankInfo.rankId] = rankInfo.deviceInfo.port == HCCL_INVALID_PORT
     278         1481 :                 || rankInfo.deviceInfo.port == 0 ? HETEROG_CCL_PORT : rankInfo.deviceInfo.port;
     279              :         }
     280              :     }
     281          494 :     isUseRankPort_ = ((devicePortSwitchOn && nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_DEVICE) || isHaveCpuRank_
     282          988 :         || nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_HOST) ? true : isUseRankPort_;
     283          494 :     HCCL_INFO("[HcclCommunicatorAttrs][SetRanksPort] devicePortSwitchOn[%u], isHaveCpuRank[%u], isUseRankPort[%u], "
     284              :         "nicRanksPort size[%u], vnicRanksPort size[%u].",
     285              :         devicePortSwitchOn, isHaveCpuRank_, isUseRankPort_, nicRanksPort_.size(), vnicRanksPort_.size());
     286          496 :     return HCCL_SUCCESS;
     287              : }
     288              : 
     289          498 : HcclResult HcclCommunicatorAttrs::InitRankInfo(const RankTable_t &rankTable)
     290              : {
     291              :     // 获取serverId
     292          498 :     CHK_RET(SetServerId(rankTable));
     293              :     // 获取server数
     294          496 :     CHK_RET(SetServerNum(rankTable.rankList));
     295          496 :     CHK_PRT_RET(serverNum_ != rankTable.serverNum,
     296              :         HCCL_ERROR("[HcclCommunicatorAttrs][InitRankInfo]calculated serverNum[%u] is not equal to ranktable serverNum[%u]",
     297              :         serverNum_, rankTable.serverNum), HCCL_E_PARA);
     298              :     // 本节点的sdid配置有效(ranktable v1.2)且环境配置server id有效时, 使能superPod
     299          496 :     if (superDeviceId_ != INVALID_UINT) {
     300            0 :         CHK_RET(IsSuperPodMode(useSuperPodMode_)); // 使能superPod
     301              :     }
     302              :     // 获取server内设备数, 赋值 ishavecpurank_
     303          496 :     CHK_RET(SetInnerServerAverageDevice(rankTable));
     304              :     // 根据server整理rank信息
     305          496 :     CHK_RET(TransformRankInfoByServerId(rankTable.rankList, servRankInfo_));
     306              :     // 获取module相关信息,moduleNum_, isDiffDeviceModule_, multiModuleDiffDeviceNumMode_;
     307          496 :     CHK_RET(SetModuleInfo(rankTable.rankList));
     308              :     // 获取超节点相关信息,superPodNum_, multiSuperPodDiffServerNumMode_
     309          496 :     CHK_RET(SetSuperPodInfo(rankTable.rankList));
     310              :     // 生成nicList
     311          496 :     CHK_RET(SetNiclistInfo());
     312              :     // 解析拓扑信息
     313          496 :     CHK_RET(InitTopoInfo(rankTable));
     314              :     // 设置超节点内节点间模式,包括是否使用sdid获取vnicip、节点间是否使能HCCS
     315          494 :     CHK_RET(SetInterModeInSuperPod());
     316              :     // 解析ranktable信息(生成rankInfoList_),供给commfactory使用
     317          494 :     CHK_RET(SetRankInfoList(rankTable));
     318              :     // 解析当前Rank信息
     319          494 :     CHK_RET(SetLocalRankInfo());
     320              :     // 解析rank和port的映射信息
     321          495 :     CHK_RET(SetRanksPort(rankTable.rankList));
     322              : 
     323              :     // 通过关键字打印通信域及本端的rank关键信息,方便在日志中直接检索
     324          495 :     HCCL_RUN_INFO("[%s]identifier[%s] rankSize[%u] serverNum[%u] moduleNum[%u] superPodNum[%u] "
     325              :         "multiModuleDiffDeviceNumMode[%u] multiSuperPodDiffServerNumMode[%u]",
     326              :         LOG_KEYWORDS_COMMUNICATOR.c_str(), identifier_.c_str(), userRankSize_, serverNum_, moduleNum_, superPodNum_,
     327              :         multiModuleDiffDeviceNumMode_, multiSuperPodDiffServerNumMode_);
     328          495 :     HCCL_RUN_INFO("[%s]userRank[%u] hostIp[%s] devicePhyId[%u] server[%s] deviceIp[%s] superPodId[%s] useSuperPodMode[%d] isStandardCard[%d]",
     329              :         LOG_KEYWORDS_LOCALRANK.c_str(), userRank_, hostIp_.GetReadableAddress(), devicePhyId_, serverId_.c_str(),
     330              :         devIpAddr_.empty() ? "" : devIpAddr_[0].GetReadableAddress(), superPodId_.c_str(), useSuperPodMode_, isStandardCard_);
     331              : 
     332          495 :     interServer_ = rankTable.serverNum > 1; // serverNum为1时,不进行roce初始化
     333          495 :     nicDeployment_ = rankTable.nicDeploy;
     334          495 :     rankTableVersion_ = rankTable.version;
     335          495 :     return HCCL_SUCCESS;
     336              : }
     337              : 
     338          488 : void HcclCommunicatorAttrs::GenCollectiveId(HcclCommParams &params, const RankTable_t &rankTable)
     339              : {
     340          893 :     collectiveId_ = rankTable.collectiveId.empty() ? params.id.internal : rankTable.collectiveId;
     341          488 : }
     342              : 
     343           34 : HcclResult HcclCommunicatorAttrs::InitRankInfoSubGroup(const std::vector<RankInfo> &rankList,
     344              :     WorldGroupInfo &groupCommonData)
     345              : {
     346              :     //填充心跳信息
     347           34 :     SethbRankInfo(rankList,groupCommonData);
     348              :     // 获取server内平均device数
     349           34 :     CHK_RET(SetInnerServerAverageDevice(rankList));
     350              :     // 将子通信域的ranklist结构体形式转换成全局通信域的
     351           34 :     std::vector<RankInfo_t> rankListNew;
     352           34 :     CHK_RET(TransformRankList(rankList, rankListNew));
     353              :     // 获取server数
     354           34 :     CHK_RET(SetServerNum(rankListNew));
     355              :     // 获取module相关信息,moduleNum_, isDiffDeviceModule_, multiModuleDiffDeviceNumMode_;
     356           34 :     CHK_RET(SetModuleInfo(rankListNew));
     357              :     // 获取超节点相关信息,superPodNum_, multiSuperPodDiffServerNumMode_
     358           34 :     CHK_RET(SetSuperPodInfo(rankListNew));
     359              :     // 根据server整理rank信息
     360           34 :     CHK_RET(TransformRankInfoByServerId(rankListNew, servRankInfo_));
     361              :     // 解析拓扑信息
     362           34 :     CHK_RET(InitTopoInfo(rankList));
     363              :     //  inline reduce 开关
     364           34 :     inlineReduceSwitchOn_ = groupCommonData.inlineReduceSwitchOn;
     365              :     // 设置rank关联信息
     366           34 :     CHK_RET(SetLocalRankInfoSubGroup(rankList));
     367              :     // 设置超节点内节点间模式,包括是否使用sdid获取vnicip、节点间是否使用HCCS
     368           34 :     CHK_RET(SetInterModeInSuperPod());
     369              : 
     370           34 :     if (HcclCheckLogLevel(DLOG_DEBUG)) {
     371              :         // 打印原来的nicList_
     372           33 :         std::ostringstream stringRepresentation;
     373           33 :         for (std::vector<uint32_t>::iterator it = nicList_.begin(); it != nicList_.end(); it++) {
     374            0 :             stringRepresentation << *it << " ";
     375              :         }
     376           33 :         std::string nicListString = stringRepresentation.str();
     377           33 :         const char *charNicList = nicListString.c_str();
     378           33 :         HCCL_DEBUG("[HcclCommunicatorAttrs][Init] The original nicList_: %s", charNicList);
     379           33 :     }
     380           34 :     interServer_ = serverNum_ > 1; // serverNum为1时,不进行roce初始化
     381              :     // 更新成跟子通信域相关的nicList_
     382           34 :     CHK_RET(UpdateNicList());
     383              :     // 检查当前user_rank 对应的devid和rt查到的一致
     384           34 :     CHK_RET(CheckLocalRankInfo());
     385           34 :     CHK_RET(CalAndSetMeshAggRankSize());
     386              : 
     387           34 :     if (IsEnableRoce()) {
     388            6 :         isUsedRdmaLevel0_ = IsUsedRdmaLevel0AndIpInvalid();
     389              :     }
     390              : 
     391           34 :     CHK_RET(SetWorldGroupInfo(groupCommonData.phyIdNicInfoMap, groupCommonData.worldRankInfoList,
     392              :         groupCommonData.ranksPort, groupCommonData.vnicRanksPort));
     393           34 :     for (auto &rankInfo : worldRankInfoList_) {
     394            0 :         if (rankInfo.devicePhyId == HOST_DEVICE_ID) {
     395            0 :             isUseRankPort_ = true;
     396            0 :             break;
     397              :         }
     398              :     }
     399           34 :     CHK_RET(IsHostUseDevNic(isHostUseDevNic_));
     400              : 
     401           34 :     groupNicRanksPort_.resize(rankInfoList_.size(), HCCL_INVALID_PORT);
     402           34 :     if (nicRanksPort_.size() != 0) {
     403            0 :         for (auto &rankInfo : rankInfoList_) {
     404            0 :             groupNicRanksPort_[rankInfo.userRank] = nicRanksPort_[rankInfo.worldRank];
     405            0 :             HCCL_INFO("hostIp[%s], nicIp[%s], rankInfo.userRank[%u], rankInfo.worldRank[%u], "
     406              :                 "nic port[%u], devicePhyId[%d]",
     407              :                 rankInfo.hostIp.GetReadableAddress(), rankInfo.nicIp[0].GetReadableAddress(),
     408              :                 rankInfo.userRank, rankInfo.worldRank, groupNicRanksPort_[rankInfo.userRank], rankInfo.devicePhyId);
     409              :         }
     410              :     }
     411           34 :     bool devicePortSwitchOn = groupCommonData.devPortSwitchOn;
     412           34 :     if (devicePortSwitchOn) {
     413            1 :         groupVnicRanksPort_.resize(rankInfoList_.size(), HCCL_INVALID_PORT);
     414            1 :         if (vnicRanksPort_.size() != 0) {
     415            1 :             for (auto &rankInfo : rankInfoList_) {
     416            0 :                 groupVnicRanksPort_[rankInfo.userRank] = vnicRanksPort_[rankInfo.worldRank];
     417            0 :                 HCCL_INFO("hostIp[%s], nicIp[%s], rankInfo.userRank[%u], rankInfo.worldRank[%u], "
     418              :                     "vnic port[%u], devicePhyId[%d]",
     419              :                     rankInfo.hostIp.GetReadableAddress(), rankInfo.nicIp[0].GetReadableAddress(),
     420              :                     rankInfo.userRank, rankInfo.worldRank, groupVnicRanksPort_[rankInfo.userRank],
     421              :                     rankInfo.devicePhyId);
     422              :             }
     423              :         }
     424              :     }
     425           34 :     isUseRankPort_ = ((devicePortSwitchOn && nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_DEVICE) || isHaveCpuRank_
     426           68 :         || nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_HOST) ? true : isUseRankPort_;
     427           34 :     HCCL_INFO("[InitRankInfoSubGroup]:isUsedRdmaLevel0_[%d]", isUsedRdmaLevel0_);
     428           34 :     return HCCL_SUCCESS;
     429           34 : }
     430              : 
     431            0 : void HcclCommunicatorAttrs::GenUsedRdmaLevel0()
     432              : {
     433            0 :     isUsedRdmaLevel0_ = IsSupportEnableRoce();
     434            0 : }
     435              : 
     436              : #ifndef OPEN_HCCL_TEST
     437          153 : void HcclCommunicatorAttrs::GenSupportRdmaLite()
     438              : {
     439          153 :     isSupportRdmaLite_ = IsSupportRDMALite(deviceLogicId_);
     440          153 : }
     441          154 : HcclResult HcclCommunicatorAttrs::GenSupportHccsAndSio()
     442              : {
     443          154 :      CHK_RET(IsSupportHccsAndSio(isSupportHccsAndSio_));
     444          154 :      return HCCL_SUCCESS;
     445              : }
     446              : #endif
     447              : 
     448           33 : bool HcclCommunicatorAttrs::GetUsedRdmaLevel0()
     449              : {
     450           33 :     return isUsedRdmaLevel0_;
     451              : }
     452              : 
     453          153 : bool HcclCommunicatorAttrs::GetSupportRdmaLite()
     454              : {
     455          153 :     return isSupportRdmaLite_;
     456              : }
     457          154 : bool HcclCommunicatorAttrs::GetSupportHccsAndSio()
     458              : {
     459          154 :     return isSupportHccsAndSio_;
     460              : }
     461              : 
     462          527 : std::string HcclCommunicatorAttrs::GetServerId()
     463              : {
     464          527 :     return serverId_;
     465              : }
     466              : 
     467          529 : u32 HcclCommunicatorAttrs::GetServerNum()
     468              : {
     469          529 :     return serverNum_;
     470              : }
     471          529 : std::string HcclCommunicatorAttrs::GetSuperPodId()
     472              : {
     473          529 :     return superPodId_;
     474              : }
     475              : 
     476          528 : u32 HcclCommunicatorAttrs::GetSuperDeviceId()
     477              : {
     478          528 :     return superDeviceId_;
     479              : }
     480              : 
     481          529 : bool HcclCommunicatorAttrs::GetSuperPodMode()
     482              : {
     483          529 :     return useSuperPodMode_;
     484              : }
     485              : 
     486          529 : u32 HcclCommunicatorAttrs::GetSuperPodNums()
     487              : {
     488          529 :     return superPodNum_;
     489              : }
     490              : 
     491          529 : u32 HcclCommunicatorAttrs::GetDeviceNumPerAggregation()
     492              : {
     493          529 :     return deviceNumPerAggregation_;
     494              : }
     495              : 
     496          529 : u32 HcclCommunicatorAttrs::GetDeviceNumPerServer()
     497              : {
     498          529 :     return deviceNumPerServer_;
     499              : }
     500              : 
     501         5429 : DevType HcclCommunicatorAttrs::GetRankInfoDevType(const RankInfo_t &rankInfo) const
     502              : {
     503         5429 :     if (rankInfo.deviceInfo.deviceType == DevType::DEV_TYPE_NOSOC) {
     504         5120 :         return deviceType_; // 兼容非混合组网场景,rankInfo中deviceType字段可能没有赋值
     505              :     }
     506          309 :     return rankInfo.deviceInfo.deviceType;
     507              : }
     508              : 
     509          529 : bool HcclCommunicatorAttrs::GetDiffDeviceType()
     510              : {
     511          529 :     return isDiffDeviceType_;
     512              : }
     513              : 
     514          529 : u32 HcclCommunicatorAttrs::GetGcdDeviceNumPerAggregation()
     515              : {
     516          529 :     return gcdDeviceNumPerAggregation_;
     517              : }
     518          529 : ServRankInfo HcclCommunicatorAttrs::GetServRankInfo()
     519              : {
     520          529 :     return servRankInfo_;
     521              : }
     522              : 
     523          529 : bool HcclCommunicatorAttrs::GetDiffDeviceModule()
     524              : {
     525          529 :     return isDiffDeviceModule_;
     526              : }
     527              : 
     528          529 : bool HcclCommunicatorAttrs::GetSupportARS()
     529              : {
     530          529 :     return isARSDoubleRing_;
     531              : }
     532              : 
     533          529 : u32 HcclCommunicatorAttrs::GetModuleNum()
     534              : {
     535          529 :     return moduleNum_;
     536              : }
     537              : 
     538          529 : bool HcclCommunicatorAttrs::GetMultiModuleDiffDeviceNumMode()
     539              : {
     540          529 :     return multiModuleDiffDeviceNumMode_;
     541              : }
     542              : 
     543          529 : bool HcclCommunicatorAttrs::GetMultiSuperPodDiffServerNumMode()
     544              : {
     545          529 :     return multiSuperPodDiffServerNumMode_;
     546              : }
     547              : 
     548          526 : bool HcclCommunicatorAttrs::GetmultiSuperPodDiffDeviceNumMode()
     549              : {
     550          526 :     return multiSuperPodDiffDeviceNumMode_;
     551              : }
     552              : 
     553          529 : std::vector<u32> HcclCommunicatorAttrs::GetNicList()
     554              : {
     555          529 :     return nicList_;
     556              : }
     557              : 
     558          529 : bool HcclCommunicatorAttrs::GetSingleMeshAggregation()
     559              : {
     560          529 :     return isSingleMeshAggregation_;
     561              : }
     562              : 
     563          528 : bool HcclCommunicatorAttrs::GetAllRankSamePlane()
     564              : {
     565          528 :     return isAllRankSamePlane_;
     566              : }
     567              : 
     568          529 : bool HcclCommunicatorAttrs::GetStandardCard()
     569              : {
     570          529 :     return isStandardCard_;
     571              : }
     572              : 
     573          529 : bool HcclCommunicatorAttrs::Get310PDuoCard()
     574              : {
     575          529 :     return is310PDuoCard_;
     576              : }
     577              : 
     578          529 : bool HcclCommunicatorAttrs::GetIsCommon310P3DUO()
     579              : {
     580          529 :     return isCommon310P3DUO_;
     581              : }
     582              : 
     583          529 : s32 HcclCommunicatorAttrs::GetHccsPortNum()
     584              : {
     585          529 :     return hccsPortNum_;
     586              : }
     587              : 
     588          529 : void HcclCommunicatorAttrs::GetPairLinkCounter(std::unordered_map<u32, u32> &pairLinkCounter)
     589              : {
     590          529 :     pairLinkCounter = pairLinkCounter_;
     591          526 : }
     592              : 
     593          529 : void HcclCommunicatorAttrs::GetPairLinkInfo(
     594              :     std::unordered_map<u32, std::unordered_map<int, std::vector<int>>> &pairLinkInfo)
     595              : {
     596          529 :     pairLinkInfo = pairLinkInfo_;
     597          528 : }
     598              : 
     599          528 : bool HcclCommunicatorAttrs::GetUsedInterHccsMode()
     600              : {
     601          528 :     return isUsedInterHccsMode_;
     602              : }
     603              : 
     604          528 : std::vector<RankInfo> HcclCommunicatorAttrs::GetRankInfoList()
     605              : {
     606          528 :     return rankInfoList_;
     607              : }
     608              : 
     609          528 : std::vector<HcclIpAddress> HcclCommunicatorAttrs::GetDevIpAddr()
     610              : {
     611          528 :     return devIpAddr_;
     612              : }
     613              : 
     614          528 : std::vector<HcclIpAddress> HcclCommunicatorAttrs::GetDevBackupIpAddr()
     615              : {
     616          528 :     return devBackupIpAddr_;
     617              : }
     618              : 
     619          528 : u32 HcclCommunicatorAttrs::GetBackupDevPort()
     620              : {
     621          528 :     return devBackupPort_;
     622              : }
     623              : 
     624          528 : u32 HcclCommunicatorAttrs::GetDevicePhyId()
     625              : {
     626          528 :     return devicePhyId_;
     627              : }
     628              : 
     629          528 : HcclIpAddress HcclCommunicatorAttrs::GetHostIp()
     630              : {
     631          528 :     return hostIp_;
     632              : }
     633              : 
     634          528 : u32 HcclCommunicatorAttrs::GetHostPort()
     635              : {
     636          528 :     return hostPort_;
     637              : }
     638              : 
     639          495 : u32 HcclCommunicatorAttrs::GetLocalRank()
     640              : {
     641          495 :     return localRank_;
     642              : }
     643              : 
     644          488 : std::string HcclCommunicatorAttrs::GetCollectiveId()
     645              : {
     646          488 :     return collectiveId_;
     647              : }
     648              : 
     649            1 : std::string HcclCommunicatorAttrs::GetRankTableVersion()
     650              : {
     651            1 :     return rankTableVersion_;
     652              : }
     653              : 
     654          495 : s32 HcclCommunicatorAttrs::GetDeviceLogicId()
     655              : {
     656          495 :     return deviceLogicId_;
     657              : }
     658              : 
     659          529 : bool HcclCommunicatorAttrs::GetInterServe()
     660              : {
     661          529 :     return interServer_;
     662              : }
     663              : 
     664          529 : NICDeployment HcclCommunicatorAttrs::GetNicDeployment()
     665              : {
     666          529 :     return nicDeployment_;
     667              : }
     668              : 
     669          529 : bool HcclCommunicatorAttrs::GetHaveCpuRank()
     670              : {
     671          529 :     return isHaveCpuRank_;
     672              : }
     673              : 
     674          521 : u32 HcclCommunicatorAttrs::GetMeshAggregationRankSize()
     675              : {
     676          521 :     return meshAggregationRankSize_;
     677              : }
     678              : 
     679           33 : bool HcclCommunicatorAttrs::GetInlineReduceSwitchOn()
     680              : {
     681           33 :     return inlineReduceSwitchOn_;
     682              : }
     683              : 
     684            0 : u32 HcclCommunicatorAttrs::GetHostPort(s32 devicePhyId)
     685              : {
     686            0 :     if (GetExternalInputHcclIfBasePort() == HCCL_INVALID_PORT) {
     687            0 :         return (devicePhyId + HOST_PARA_BASE_PORT);
     688              :     } else {
     689            0 :         return (devicePhyId + GetExternalInputHcclIfBasePort() + HCCL_AISERVER_DEVICE_NUM);
     690              :     }
     691              : }
     692              : 
     693            0 : void HcclCommunicatorAttrs::SetNeedInitNicFlag(const bool isNeedInitNic)
     694              : {
     695            0 :     isNeedInitNic_ = isNeedInitNic;
     696            0 : }
     697              : 
     698              : // 判断是否是双环
     699          758 : bool CheckDoubleRingWithRohTopo(const std::vector<u32> &nicList)
     700              : {
     701          758 :     std::vector<u32> topoList;
     702          758 :     std::vector<u32> tmpNicList(nicList);
     703          758 :     std::sort(tmpNicList.begin(), tmpNicList.end());
     704          758 :     SearchPath searchPath;
     705          758 :     topoList = searchPath.Search(tmpNicList, true);
     706          757 :     if (topoList.empty()) {
     707          474 :         return false;
     708              :     }
     709          281 :     return true;
     710          755 : }
     711              : }
        

Generated by: LCOV version 2.0-1