LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/common/src/topo - topoinfo_ranktableStandard.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 53.9 % 373 201
Test Date: 2026-08-18 17:47:01 Functions: 72.7 % 22 16

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "topoinfo_ranktableStandard.h"
      12              : 
      13              : #include <map>
      14              : #include <vector>
      15              : #include <string>
      16              : #include <fstream>
      17              : #include <algorithm>
      18              : #include <unistd.h>
      19              : #include <chrono>
      20              : #include <iostream>
      21              : #include <arpa/inet.h>
      22              : 
      23              : // ltm指定config路径
      24              : #include "common/src/config.h"
      25              : #include "workflow_pub.h"
      26              : 
      27              : using namespace std;
      28              : using namespace hccl;
      29              : 
      30          388 : TopoinfoRanktableStandard::TopoinfoRanktableStandard(const std::string& rankTableM, const std::string& identify)
      31          388 :     : TopoInfoRanktableParser(rankTableM, identify)
      32          387 : {}
      33              : 
      34          776 : TopoinfoRanktableStandard::~TopoinfoRanktableStandard() {}
      35              : 
      36          387 : HcclResult TopoinfoRanktableStandard::Init()
      37              : {
      38          387 :     CHK_RET(LoadRankTableString(rankTableFile_));
      39          388 :     HcclResult ret = ParserClusterInfo(params_, rankTable_);
      40          388 :     if (ret != HCCL_SUCCESS) {
      41            1 :         HCCL_ERROR("[TopoinfoRanktableStandard][Init] RanktableStandard init failed! Please check if the ranktable file"
      42              :                    " is configured with a 'version' field.");
      43            1 :         return ret;
      44              :     }
      45          387 :     return HCCL_SUCCESS;
      46              : }
      47              : 
      48          387 : HcclResult TopoinfoRanktableStandard::GetSelfClusterInfo(HcclCommParams& params)
      49              : {
      50              :     // 获取芯片类型信息
      51          387 :     CHK_RET(hrtGetDeviceType(params.deviceType));
      52          387 :     params.rank = params_.rank;
      53          387 :     params.userRank = params_.rank;
      54          387 :     params.logicDevId = params_.logicDevId;
      55          387 :     params.totalRanks = params_.totalRanks;
      56          387 :     params.serverId = params_.serverId;
      57          387 :     return HCCL_SUCCESS;
      58              : }
      59              : 
      60          387 : HcclResult TopoinfoRanktableStandard::GetClusterInfo(hccl::HcclCommParams& params, hccl::RankTable_t& rankTable)
      61              : {
      62          387 :     CHK_RET(GetClusterInfo(rankTable));
      63          387 :     CHK_RET(GetSelfClusterInfo(params));
      64          387 :     return HCCL_SUCCESS;
      65              : }
      66          387 : HcclResult TopoinfoRanktableStandard::GetClusterInfo(RankTable_t& clusterInfo)
      67              : {
      68          387 :     clusterInfo.nicDeploy = rankTable_.nicDeploy;
      69          387 :     clusterInfo.deviceNum = rankTable_.deviceNum;
      70          387 :     clusterInfo.serverNum = rankTable_.serverNum;
      71          387 :     clusterInfo.groupNum = rankTable_.groupNum;
      72          387 :     clusterInfo.nicNum = rankTable_.nicNum;
      73          387 :     clusterInfo.nicNames = rankTable_.nicNames;
      74          387 :     clusterInfo.rankNum = rankTable_.rankNum;
      75          387 :     clusterInfo.rankList = rankTable_.rankList;
      76          387 :     clusterInfo.serverList = rankTable_.serverList;
      77              : 
      78          387 :     return HCCL_SUCCESS;
      79              : }
      80              : 
      81          388 : HcclResult TopoinfoRanktableStandard::ParserClusterInfo(hccl::HcclCommParams& params, hccl::RankTable_t& rankTable)
      82              : {
      83          388 :     CHK_RET(GetDeployMode(cloudFlag_));
      84          387 :     HCCL_INFO("deploy mode is %s", cloudFlag_ ? "cloud" : "Laborratory");
      85          388 :     if (!IsTaskNumCalMode()) {
      86          388 :         CHK_RET(hrtGetDeviceType(params.deviceType));
      87              :     }
      88              : 
      89          388 :     u32 rankId = INVALID_VALUE_RANKID;
      90          388 :     if (cloudFlag_) {
      91            0 :         CHK_RET(GetCloudHcomInfo(params, rankTable, identify_, rankId));
      92              :     } else {
      93          388 :         if (!IsTaskNumCalMode()) {
      94          388 :             CHK_RET(CheckRankId(identify_.c_str()));
      95          388 :             if (SalStrToULong(identify_, HCCL_BASE_DECIMAL, rankId) != HCCL_SUCCESS) {
      96            0 :                 RPT_INPUT_ERR(
      97              :                     true, "EI0014", std::vector<std::string>({"value", "variable", "expect"}),
      98              :                     std::vector<std::string>({identify_, "rank_id", "a valid integer."}));
      99            0 :                 HCCL_ERROR(
     100              :                     "[%s][%s]errNo[0x%016llx] identify[%s] is invalid", LOG_KEYWORDS_INIT_GROUP.c_str(),
     101              :                     LOG_KEYWORDS_RANKTABLE_CHECK.c_str(), HCOM_ERROR_CODE(HCCL_E_PARA), identify_.c_str());
     102            0 :                 return HCCL_E_PARA;
     103              :             }
     104              :         }
     105          388 :         CHK_RET(GetHcomInfo(params, rankTable));
     106              :     }
     107              : 
     108          388 :     if (!IsTaskNumCalMode()) {
     109          388 :         std::sort(
     110              :             rankTable.rankList.begin(), rankTable.rankList.end(),
     111         1498 :             [&](const RankInfo_t& a, const RankInfo_t& b) -> bool {
     112         1498 :                 return a.rankId < b.rankId;
     113              :             });
     114              : 
     115              :         // 校验rank id合法性
     116          388 :         if (rankId >= rankTable.rankList.size()) {
     117           14 :             RPT_INPUT_ERR(
     118              :                 true, "EI0014", std::vector<std::string>({"value", "variable", "expect"}),
     119              :                 std::vector<std::string>({identify_, "rank_id", "a valid integer"}));
     120            1 :             HCCL_ERROR(
     121              :                 "[%s][%s]rankid[%u] is invalid", LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RANKTABLE_CHECK.c_str(),
     122              :                 rankId);
     123            1 :             return HCCL_E_PARA;
     124              :         }
     125          387 :         CHK_PRT_RET(
     126              :             rankId != rankTable.rankList[rankId].rankId,
     127              :             HCCL_ERROR(
     128              :                 "[Parse][ClusterInfo]check rankList[%u] rankId[%u] failed", rankId, rankTable.rankList[rankId].rankId),
     129              :             HCCL_E_UNAVAIL);
     130          386 :         u32 devId = rankTable.rankList[rankId].deviceInfo.devicePhyId;
     131          386 :         CHK_RET(hrtGetDevice(&params.logicDevId));
     132              : 
     133          386 :         u32 devicePhyId = 0;
     134          386 :         CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<u32>(params.logicDevId), devicePhyId));
     135              : 
     136          387 :         CHK_PRT_RET(
     137              :             devicePhyId != static_cast<u32>(devId),
     138              :             HCCL_ERROR("[Parse][ClusterInfo]ranktable config devId[%d],but local devId[%u]", devId, devicePhyId),
     139              :             HCCL_E_UNAVAIL);
     140              : 
     141          387 :         params.rank = rankId;
     142          387 :         params.totalRanks = rankTable.rankNum;
     143          387 :         params.serverId = rankTable.rankList[rankId].serverId;
     144              :     }
     145          387 :     return HCCL_SUCCESS;
     146            2 : }
     147              : 
     148          388 : HcclResult TopoinfoRanktableStandard::GetHcomInfo(hccl::HcclCommParams& params, hccl::RankTable_t& rankTable)
     149              : {
     150              :     // para_plane_location
     151          388 :     std::string paraPlaneLocation;
     152          388 :     CHK_RET(GetJsonProperty(fileContent_, "para_plane_nic_location", paraPlaneLocation, false));
     153              : 
     154          388 :     HCCL_DEBUG("%s.json -> para_plane_location: %s", fileName_.c_str(), paraPlaneLocation.c_str());
     155              : 
     156          388 :     if (paraPlaneLocation == "host") { // 不支持host 网卡
     157            0 :         HCCL_ERROR("[Get][HcomInfo]errNo[0x%016llx] host nic is unsupported", HCOM_ERROR_CODE(HCCL_E_PARA));
     158            0 :         return HCCL_E_PARA;
     159              :     }
     160              : 
     161          138 :     if ((params.deviceType == DevType::DEV_TYPE_910 || params.deviceType == DevType::DEV_TYPE_910B
     162            9 :          || params.deviceType == DevType::DEV_TYPE_910_93)
     163          526 :         && paraPlaneLocation != "device") {
     164            0 :         HCCL_ERROR(
     165              :             "[Get][HcomInfo]errNo[0x%016llx] paraPlaneLocation should be 'device'", HCOM_ERROR_CODE(HCCL_E_PARA));
     166            0 :         return HCCL_E_PARA;
     167              :     }
     168              :     // 当前只支持device侧的网卡
     169              :     rankTable.nicDeploy
     170          388 :         = ((paraPlaneLocation == "device") ? NICDeployment::NIC_DEPLOYMENT_DEVICE :
     171              :                                              NICDeployment::NIC_DEPLOYMENT_RESERVED);
     172              :     // group_count
     173          387 :     std::string groupCount;
     174          387 :     CHK_RET(GetJsonProperty(fileContent_, "group_count", groupCount, false));
     175              : 
     176          387 :     HCCL_DEBUG("%s.json -> group_count: %s", fileName_.c_str(), groupCount.c_str());
     177          388 :     CHK_RET(SalStrToULong(groupCount, HCCL_BASE_DECIMAL, rankTable.groupNum));
     178              :     // 校验groupCount ,groupCount不能为0
     179          388 :     if (rankTable.groupNum == 0) {
     180            0 :         HCCL_ERROR("[Get][HcomInfo]errNo[0x%016llx] groupNum is zero", HCOM_ERROR_CODE(HCCL_E_PARA));
     181            0 :         return HCCL_E_PARA;
     182              :     }
     183              :     // group_list
     184          388 :     CHK_RET(GetGroupList(params, rankTable));
     185              : 
     186          388 :     return HCCL_SUCCESS;
     187          388 : }
     188              : 
     189            0 : HcclResult TopoinfoRanktableStandard::GetServerList(
     190              :     const nlohmann::json& obj, u32 objIndex, hccl::RankTable_t& rankTable, u32 serverNum)
     191              : {
     192            0 :     if (serverNum == 0) {
     193            0 :         HCCL_ERROR("[Get][ServerList]errNo[0x%016llx] server num is zero", HCOM_ERROR_CODE(HCCL_E_PARA));
     194            0 :         return HCCL_E_PARA;
     195              :     }
     196            0 :     HCCL_DEBUG("get serverList[%u]", objIndex);
     197            0 :     rankTable.serverList.clear();
     198            0 :     nlohmann::json serverList;
     199            0 :     CHK_RET(GetJsonArrayMemberProperty(obj, objIndex, "server_list", serverList, false));
     200              : 
     201            0 :     HCCL_DEBUG("%s.json -> server_list[%u]: size:%zu", fileName_.c_str(), objIndex, serverList.size());
     202            0 :     if (serverList.size() == 0) {
     203            0 :         HCCL_ERROR(
     204              :             "[Get][ServerList]errNo[0x%016llx] serverList[%u] size is zero", HCOM_ERROR_CODE(HCCL_E_PARA), objIndex);
     205            0 :         return HCCL_E_PARA;
     206              :     }
     207            0 :     if (serverList.size() != serverNum) {
     208            0 :         HCCL_ERROR(
     209              :             "[Get][ServerList]errNo[0x%016llx] serverList[%u] size[%zu] neq server num[%u]",
     210              :             HCOM_ERROR_CODE(HCCL_E_PARA), objIndex, serverList.size(), serverNum);
     211            0 :         return HCCL_E_PARA;
     212              :     }
     213              : 
     214            0 :     for (u32 index = 0; index < serverList.size(); index++) {
     215            0 :         CHK_RET(GetSingleServer(serverList, index, rankTable));
     216              :     }
     217              : 
     218            0 :     return HCCL_SUCCESS;
     219            0 : }
     220              : 
     221            0 : HcclResult TopoinfoRanktableStandard::GetSingleServer(
     222              :     const nlohmann::json& serverListObj, u32 objIndex, hccl::RankTable_t& rankTable)
     223              : {
     224            0 :     ServerInfo_t serverInfo;
     225            0 :     std::string serverId;
     226            0 :     CHK_RET(GetJsonArrayMemberProperty(serverListObj, objIndex, "server_id", serverId, false));
     227              : 
     228            0 :     CHK_RET(CheckUniqueAndInsertPool(
     229              :         JsonUniqueInfoType::UNIQUE_INFO_TYPE_SERVER_ID, serverId, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     230            0 :     HCCL_DEBUG("server id[%u]:[%s]", objIndex, serverId.c_str());
     231            0 :     serverInfo.serverId = serverId;
     232              :     // 解析内层-参数平面的网卡信息
     233            0 :     nlohmann::json paraPlaneInfo;
     234            0 :     CHK_RET(GetJsonArrayMemberProperty(serverListObj, objIndex, "para_plane_info", paraPlaneInfo, false));
     235              :     // server list中的网卡个数应该与ranktable中的网卡个数一致
     236            0 :     if (paraPlaneInfo.size() != rankTable.nicNum) {
     237            0 :         HCCL_ERROR(
     238              :             "[Get][SingleServer]errNo[0x%016llx] paraPlaneInfo[%u] size[%zu] neq nicNum[%u]",
     239              :             HCOM_ERROR_CODE(HCCL_E_PARA), objIndex, paraPlaneInfo.size(), rankTable.nicNum);
     240            0 :         return HCCL_E_PARA;
     241              :     }
     242            0 :     serverInfo.networkInfo.clear();
     243              : 
     244            0 :     for (u32 innerIndex = 0; innerIndex < rankTable.nicNames.size(); innerIndex++) {
     245            0 :         NetworkInfo_t networdInfo;
     246            0 :         networdInfo.ethName = rankTable.nicNames[innerIndex];
     247              : 
     248              :         // 依照nicNames来搜索
     249            0 :         for (u32 i = 0; i < paraPlaneInfo.size(); i++) {
     250            0 :             auto findEth = paraPlaneInfo.at(i).find(networdInfo.ethName);
     251            0 :             if (findEth != paraPlaneInfo.at(i).end()) { // 找到ethName
     252            0 :                 std::string ethIp = findEth->get<std::string>();
     253            0 :                 CHK_RET(CheckUniqueAndInsertPool(
     254              :                     JsonUniqueInfoType::UNIQUE_INFO_TYPE_ETH_IP, ethIp, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     255            0 :                 CHK_RET(ConvertIpAddress(ethIp, networdInfo.ipAddr));
     256            0 :                 break;
     257            0 :             }
     258              :         }
     259            0 :         if (networdInfo.ipAddr.IsInvalid()) {
     260            0 :             HCCL_ERROR(
     261              :                 "[Get][SingleServer]errNo[0x%016llx] networdInfo [%s] ipAddr is invalid", HCOM_ERROR_CODE(HCCL_E_PARA),
     262              :                 networdInfo.ethName.c_str());
     263            0 :             return HCCL_E_PARA;
     264              :         }
     265            0 :         HCCL_DEBUG(
     266              :             "networdInfo[%u] [%s] ipAddr[%s]", objIndex, networdInfo.ethName.c_str(),
     267              :             networdInfo.ipAddr.GetReadableAddress());
     268            0 :         serverInfo.networkInfo.push_back(networdInfo);
     269            0 :     }
     270              : 
     271            0 :     rankTable.serverList.push_back(serverInfo);
     272            0 :     return HCCL_SUCCESS;
     273            0 : }
     274              : 
     275            0 : HcclResult TopoinfoRanktableStandard::GetCloudHcomInfo(
     276              :     hccl::HcclCommParams& params, hccl::RankTable_t& rankTable, const std::string& identify, u32& rank)
     277              : {
     278            0 :     HCCL_DEBUG("get cloud hcom info: identify[%s]", identify.c_str());
     279              :     // group_count
     280            0 :     std::string groupCount;
     281            0 :     CHK_RET(GetJsonProperty(fileContent_, "group_count", groupCount, false));
     282            0 :     HCCL_DEBUG("%s.json -> group_count: %s", fileName_.c_str(), groupCount.c_str());
     283              : 
     284            0 :     CHK_RET(SalStrToULong(groupCount, HCCL_BASE_DECIMAL, rankTable.groupNum));
     285              :     // 校验groupCount ,groupCount不能为0
     286            0 :     if (rankTable.groupNum == 0) {
     287            0 :         HCCL_ERROR("[Get][CloudHcomInfo]errNo[0x%016llx] group num is zero", HCOM_ERROR_CODE(HCCL_E_PARA));
     288            0 :         return HCCL_E_PARA;
     289              :     }
     290            0 :     devMap_.clear();
     291              :     // group_list
     292            0 :     CHK_RET(GetGroupList(params, rankTable));
     293            0 :     CHK_RET(GetSortClouldRankList(rankTable));
     294              : 
     295            0 :     if (!IsTaskNumCalMode()) {
     296              :         // 获取当前操作的逻辑ID并转换为物理ID
     297            0 :         s32 deviceLogicId = -1; // device logic id 的无效值
     298            0 :         CHK_RET(hrtGetDevice(&deviceLogicId));
     299              : 
     300            0 :         u32 devicePhyId = INVALID_UINT; // device phy id 的无效值
     301            0 :         CHK_RET(hrtGetDevicePhyIdByIndex(static_cast<u32>(deviceLogicId), devicePhyId));
     302              : 
     303            0 :         for (u32 index = 0; index < rankTable.rankList.size(); index++) {
     304            0 :             HCCL_INFO(
     305              :                 " rank: %u phyId:%u identify:%s podName:%s", rank, devicePhyId, identify.c_str(),
     306              :                 rankTable.rankList[index].podName.c_str());
     307            0 :             if ((rankTable.rankList[index].podName == identify)
     308            0 :                 && (rankTable.rankList[index].deviceInfo.devicePhyId == static_cast<s32>(devicePhyId))) {
     309            0 :                 rank = rankTable.rankList[index].rankId;
     310            0 :                 break;
     311              :             }
     312              :         }
     313              :     }
     314              : 
     315            0 :     CHK_RET(GetDevNum(rankTable.rankList, rankTable.deviceNum));
     316            0 :     rankTable.serverNum = devMap_.size();
     317            0 :     rankTable.nicDeploy = NICDeployment::NIC_DEPLOYMENT_DEVICE; // 910A 对应的nicDeploy
     318            0 :     rankTable.rankNum = rankTable.rankList.size();
     319              : 
     320              :     // alg_type
     321            0 :     HCCL_INFO(
     322              :         "%s.json -> rank %u : deviceNum is %u, serverNum is %u, nicDeploy is %u, rankNum is %u", fileName_.c_str(),
     323              :         rank, rankTable.deviceNum, rankTable.serverNum, rankTable.nicDeploy, rankTable.rankNum);
     324              : 
     325            0 :     return HCCL_SUCCESS;
     326            0 : }
     327              : 
     328            0 : HcclResult TopoinfoRanktableStandard::GetSortClouldRankList(hccl::RankTable_t& rankTable)
     329              : {
     330              :     // sort device id in each server
     331            0 :     for (auto iter = devMap_.begin(); iter != devMap_.end(); iter++) {
     332            0 :         if (!(iter->second).empty()) {
     333            0 :             std::sort(
     334            0 :                 (iter->second).begin(), (iter->second).end(), [&](const RankInfo_t& a, const RankInfo_t& b) -> bool {
     335            0 :                     return a.deviceInfo.devicePhyId < b.deviceInfo.devicePhyId;
     336              :                 });
     337              :         }
     338              :     }
     339              : 
     340              :     // sort rank and filling rankList
     341            0 :     rankTable.rankList.clear();
     342            0 :     u32 initialRank = 0;
     343            0 :     for (auto iterMap = devMap_.begin(); iterMap != devMap_.end(); iterMap++) {
     344            0 :         if (!(iterMap->second).empty()) {
     345            0 :             for (u32 vecIndex = 0; vecIndex < (iterMap->second).size(); vecIndex++) {
     346            0 :                 (iterMap->second)[vecIndex].rankId = initialRank;
     347            0 :                 rankTable.rankList.push_back((iterMap->second)[vecIndex]);
     348            0 :                 initialRank++;
     349              :             }
     350              :         }
     351              :     }
     352            0 :     return HCCL_SUCCESS;
     353              : }
     354              : 
     355          388 : HcclResult TopoinfoRanktableStandard::GetSingleGroupDeviceCount(
     356              :     nlohmann::json& obj, u32 objIndex, hccl::RankTable_t& rankTable, u32& deviceNum)
     357              : {
     358              :     // device_num
     359          388 :     std::string strDeviceNum;
     360              : 
     361          388 :     if (!cloudFlag_) {
     362          388 :         CHK_RET(GetJsonArrayMemberProperty(obj, objIndex, "device_num", strDeviceNum, false));
     363              :     } else {
     364            0 :         CHK_RET(GetJsonArrayMemberProperty(obj, objIndex, "device_count", strDeviceNum, false));
     365              :     }
     366          388 :     HCCL_DEBUG("%s.json -> device_num: %s", fileName_.c_str(), strDeviceNum.c_str());
     367          388 :     CHK_RET(SalStrToULong(strDeviceNum, HCCL_BASE_DECIMAL, deviceNum));
     368          388 :     if (deviceNum == 0) {
     369            0 :         HCCL_ERROR("[Get][SingleGroupDeviceCount]errNo[0x%016llx] device num is zero", HCOM_ERROR_CODE(HCCL_E_PARA));
     370            0 :         return HCCL_E_PARA;
     371              :     }
     372          388 :     rankTable.deviceNum += deviceNum;
     373              : 
     374          388 :     return HCCL_SUCCESS;
     375          388 : }
     376              : 
     377          388 : HcclResult TopoinfoRanktableStandard::GetLabSingleGroup(
     378              :     nlohmann::json& obj, u32 objIndex, hccl::HcclCommParams& params, hccl::RankTable_t& rankTable, u32 instanceNum)
     379              : {
     380          388 :     u32 uDeviceNum = 0;
     381          388 :     u32 uServerNum = 0;
     382              :     // device_num
     383          388 :     CHK_RET(GetSingleGroupDeviceCount(obj, objIndex, rankTable, uDeviceNum));
     384              : 
     385              :     // server_num
     386          388 :     std::string serverNum;
     387          388 :     CHK_RET(GetJsonArrayMemberProperty(obj, objIndex, "server_num", serverNum, false));
     388          388 :     HCCL_DEBUG("%s.json -> server_num: %s", fileName_.c_str(), serverNum.c_str());
     389              : 
     390          388 :     CHK_RET(SalStrToULong(serverNum, HCCL_BASE_DECIMAL, uServerNum));
     391          388 :     if (uServerNum == 0) {
     392            0 :         HCCL_ERROR("[Get][LabSingleGroup]errNo[0x%016llx] server num is zero", HCOM_ERROR_CODE(HCCL_E_PARA));
     393            0 :         return HCCL_E_PARA;
     394              :     }
     395          388 :     rankTable.serverNum += uServerNum;
     396              : 
     397          388 :     if (params.deviceType != DevType::DEV_TYPE_310P3) {
     398          388 :         CHK_RET(CheckAverageDev(uDeviceNum, uServerNum));
     399              :     }
     400              :     // server_list
     401          388 :     if (static_cast<u32>(rankTable.nicDeploy) == 0) { // 网卡挂载在host侧
     402            0 :         CHK_RET(GetServerList(obj, objIndex, rankTable, uServerNum));
     403              :     }
     404              : 
     405          388 :     if (instanceNum != uDeviceNum) {
     406            0 :         HCCL_ERROR("[Get][LabSingleGroup]errNo[0x%016llx] instance num error", HCOM_ERROR_CODE(HCCL_E_PARA));
     407            0 :         return HCCL_E_PARA;
     408              :     }
     409          388 :     rankTable.rankNum += instanceNum;
     410              : 
     411          388 :     return HCCL_SUCCESS;
     412          388 : }
     413              : 
     414          387 : HcclResult TopoinfoRanktableStandard::GetGroupList(hccl::HcclCommParams& params, hccl::RankTable_t& rankTable)
     415              : {
     416          387 :     rankTable.rankList.clear();
     417          388 :     nlohmann::json groupList;
     418          388 :     CHK_RET(GetJsonProperty(fileContent_, "group_list", groupList, false));
     419              : 
     420          388 :     HCCL_DEBUG("group_list.size[%zu] groupNum[%u]", groupList.size(), rankTable.groupNum);
     421          388 :     CHK_PRT_RET(
     422              :         groupList.size() != rankTable.groupNum,
     423              :         HCCL_ERROR(
     424              :             "[Get][GroupList]errNo[0x%016llx] "
     425              :             "groupList size[%zu] error, groupNum[%u]",
     426              :             HCOM_ERROR_CODE(HCCL_E_PARA), groupList.size(), rankTable.groupNum),
     427              :         HCCL_E_PARA);
     428              : 
     429          388 :     rankTable.deviceNum = 0;
     430          388 :     rankTable.serverNum = 0;
     431          388 :     rankTable.rankNum = 0;
     432          776 :     for (u32 index = 0; index < groupList.size(); index++) {
     433              :         // group_name
     434          388 :         std::string groupName;
     435          388 :         CHK_RET(GetJsonArrayMemberProperty(groupList, index, "group_name", groupName, false));
     436              : 
     437          388 :         CHK_RET(CheckUniqueAndInsertPool(
     438              :             JsonUniqueInfoType::UNIQUE_INFO_TYPE_GROUP_NAME, groupName, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     439          388 :         HCCL_DEBUG("%s.json -> group_name: %s", fileName_.c_str(), groupName.c_str());
     440              : 
     441              :         // instance_count
     442          388 :         std::string instanceCount;
     443          388 :         CHK_RET(GetJsonArrayMemberProperty(groupList, index, "instance_count", instanceCount, false));
     444          388 :         HCCL_DEBUG("%s.json -> rank_count: %s", fileName_.c_str(), instanceCount.c_str());
     445              : 
     446          388 :         u32 instanceNum = 0;
     447          388 :         CHK_RET(SalStrToULong(instanceCount, HCCL_BASE_DECIMAL, instanceNum));
     448          388 :         if (instanceNum == 0) {
     449            0 :             HCCL_ERROR(
     450              :                 "[Get][GroupList]errNo[0x%016llx] instance num[%u] invalid", HCOM_ERROR_CODE(HCCL_E_PARA), instanceNum);
     451            0 :             return HCCL_E_PARA;
     452              :         }
     453          388 :         u32 deviceNum = 0;
     454          388 :         if (!cloudFlag_) {
     455          388 :             CHK_RET(GetLabSingleGroup(groupList, index, params, rankTable, instanceNum));
     456          388 :             deviceNum = instanceNum;
     457              :         } else {
     458            0 :             CHK_RET(GetSingleGroupDeviceCount(groupList, index, rankTable, deviceNum));
     459              :         }
     460              : 
     461          388 :         nlohmann::json instanceList;
     462          388 :         CHK_RET(GetJsonArrayMemberProperty(groupList, index, "instance_list", instanceList, false));
     463              : 
     464          388 :         CHK_RET(GetInstanceList(instanceList, params, rankTable, instanceNum, deviceNum));
     465          388 :     }
     466              : 
     467          388 :     return HCCL_SUCCESS;
     468          388 : }
     469              : 
     470          388 : HcclResult TopoinfoRanktableStandard::GetInstanceList(
     471              :     nlohmann::json& instanceList, hccl::HcclCommParams& params, hccl::RankTable_t& rankTable, u32 instanceNum,
     472              :     u32 deviceNum)
     473              : {
     474          388 :     HCCL_DEBUG("get instanceList: instanceNum[%u], deviceNum[%u]", instanceNum, deviceNum);
     475          388 :     u32 checkCount = 0;
     476          388 :     u32 checkDevCount = 0;
     477              : 
     478         1526 :     for (u32 podIndex = 0; podIndex < instanceList.size(); podIndex++) {
     479         1138 :         std::string serverId;
     480         1138 :         CHK_RET(GetJsonArrayMemberProperty(instanceList, podIndex, "server_id", serverId, false));
     481         1138 :         HCCL_DEBUG("%s.json -> server_id: %s", fileName_.c_str(), serverId.c_str());
     482         1138 :         if ((!cloudFlag_) && (static_cast<u32>(rankTable.nicDeploy) == 0)) {
     483            0 :             CHK_RET(CheckUniqueAndInsertPool(
     484              :                 JsonUniqueInfoType::UNIQUE_INFO_TYPE_SERVER_ID, serverId, JsonCheckOpType::CHECK_OP_TYPE_FIND));
     485              :         }
     486              : 
     487         1138 :         if (serverId.empty()) {
     488            0 :             HCCL_ERROR(
     489              :                 "[Get][GetInstanceList]errNo[0x%016llx] serverId[%s] is empty", HCOM_ERROR_CODE(HCCL_E_PARA),
     490              :                 serverId.c_str());
     491            0 :             return HCCL_E_PARA;
     492              :         }
     493              : 
     494         1138 :         if (serverId.length() > SERVERID_MAX_LENGTH) {
     495            0 :             HCCL_ERROR(
     496              :                 "[Get][GetInstanceList]errNo[0x%016llx] serverId[%s] length[%u] is more than %u",
     497              :                 HCOM_ERROR_CODE(HCCL_E_PARA), serverId.c_str(), serverId.length(), SERVERID_MAX_LENGTH);
     498            0 :             return HCCL_E_PARA;
     499              :         }
     500              : 
     501              :         u32 serverIdx;
     502         1138 :         GenerateServerIdx(serverId, serverIdx);
     503         1135 :         HCCL_DEBUG("instance id[%u]:[%s], serverIdx[%u]", podIndex, serverId.c_str(), serverIdx);
     504              : 
     505         1138 :         nlohmann::json deviceList;
     506         1137 :         CHK_RET(GetJsonArrayMemberProperty(instanceList, podIndex, "devices", deviceList, false));
     507         1137 :         if (cloudFlag_) {
     508            0 :             CHK_RET(GetCloudDevList(instanceList, podIndex, deviceList, serverId, serverIdx));
     509              :         } else {
     510         1137 :             CHK_RET(GetDevList(instanceList, podIndex, deviceList, params, rankTable, serverId, serverIdx));
     511              :         }
     512         1138 :         checkDevCount = checkDevCount + deviceList.size();
     513         1138 :         checkCount++;
     514         1138 :     }
     515              : 
     516          388 :     HCCL_DEBUG("instance_num %u, check_count %u", instanceNum, checkCount);
     517          388 :     bool hcclCheck = (instanceNum != checkCount) || (deviceNum != checkDevCount);
     518          388 :     CHK_PRT_RET(
     519              :         hcclCheck,
     520              :         HCCL_ERROR(
     521              :             "[Get][InstanceList]errNo[0x%016llx] check instanceNum[%u] or devNum[%u] error, checkInstance[%u], "
     522              :             "checkDev[%u]",
     523              :             HCOM_ERROR_CODE(HCCL_E_PARA), instanceNum, deviceNum, checkCount, checkDevCount),
     524              :         HCCL_E_PARA);
     525              : 
     526          388 :     return HCCL_SUCCESS;
     527              : }
     528              : 
     529            0 : HcclResult TopoinfoRanktableStandard::GetCloudDevList(
     530              :     nlohmann::json& instanceList, u32 podIndex, nlohmann::json& deviceList, std::string& serverId, u32& serverIdx)
     531              : {
     532            0 :     std::string podName;
     533            0 :     CHK_RET(GetJsonArrayMemberProperty(instanceList, podIndex, "pod_name", podName, false));
     534            0 :     HCCL_DEBUG("%s.json -> pod_name: %s", fileName_.c_str(), podName.c_str());
     535              : 
     536            0 :     CHK_RET(CheckUniqueAndInsertPool(
     537              :         JsonUniqueInfoType::UNIQUE_INFO_TYPE_POD_NAME, podName, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     538            0 :     for (u32 deviceIndex = 0; deviceIndex < deviceList.size(); deviceIndex++) {
     539            0 :         std::string strDevid;
     540            0 :         CHK_RET(GetJsonArrayMemberProperty(deviceList, deviceIndex, "device_id", strDevid, false));
     541              : 
     542            0 :         u32 devicePhyId = 0;
     543            0 :         CHK_RET(SalStrToULong(strDevid, HCCL_BASE_DECIMAL, devicePhyId));
     544            0 :         if (devicePhyId > (HCCL_AISERVER_DEVICE_NUM - 1)) { // deviceid in 0 ~ 7
     545            0 :             HCCL_ERROR(
     546              :                 "[Get][CloudDevList]errNo[0x%016llx] devicePhyId[%u] more than [%u] is invalid",
     547              :                 HCOM_ERROR_CODE(HCCL_E_PARA), devicePhyId, HCCL_AISERVER_DEVICE_NUM - 1);
     548            0 :             return HCCL_E_PARA;
     549              :         }
     550            0 :         HCCL_DEBUG("%s.json -> device_id: %s", fileName_.c_str(), strDevid.c_str());
     551              : 
     552            0 :         RankInfo_t rankinfo;
     553              :         // 1.非cloud场景下,网卡挂载在device侧2.cloud场景
     554            0 :         HcclIpAddress ipAddr;
     555            0 :         if (instanceList.size() > 1) {
     556            0 :             std::string deviceIp;
     557            0 :             CHK_RET(GetJsonArrayMemberProperty(deviceList, deviceIndex, "device_ip", deviceIp, false));
     558            0 :             HCCL_DEBUG("%s.json -> device_ip: %s", fileName_.c_str(), deviceIp.c_str());
     559            0 :             if (!deviceIp.empty()) {
     560            0 :                 CHK_RET(CheckUniqueAndInsertPool(
     561              :                     JsonUniqueInfoType::UNIQUE_INFO_TYPE_DEVICE_IP, deviceIp, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     562              : 
     563            0 :                 HcclResult ret = ConvertIpAddress(deviceIp, ipAddr);
     564            0 :                 CHK_PRT_RET(
     565              :                     ret != HCCL_SUCCESS, HCCL_ERROR("[Get][CloudDevList]deviceIp[%s] is invalid", deviceIp.c_str()),
     566              :                     ret);
     567              :             }
     568            0 :         } else {
     569            0 :             HCCL_INFO("single server don't need devIP");
     570              :         }
     571            0 :         rankinfo.deviceInfo.deviceIp.push_back(ipAddr);
     572            0 :         rankinfo.serverId = serverId;
     573            0 :         rankinfo.serverIdx = serverIdx;
     574            0 :         rankinfo.deviceInfo.devicePhyId = devicePhyId;
     575            0 :         rankinfo.podName = podName;
     576              : 
     577              :         // 回填dev_map_
     578            0 :         auto iter = devMap_.find(serverId);
     579            0 :         if (iter != devMap_.end()) {
     580            0 :             iter->second.push_back(rankinfo); // 存在该服务器内相关dev的对应信息
     581              :         } else {
     582            0 :             std::vector<RankInfo_t> vecDev;
     583            0 :             vecDev.push_back(rankinfo);
     584            0 :             devMap_.insert(std::make_pair(serverId, vecDev)); // 不存在则新增一条map记录
     585            0 :         }
     586            0 :         HCCL_DEBUG(
     587              :             "%s.json->serverId[%s], podName[%s], devicePhyId[%d]", fileName_.c_str(), rankinfo.serverId.c_str(),
     588              :             rankinfo.podName.c_str(), rankinfo.deviceInfo.devicePhyId);
     589            0 :     }
     590            0 :     return HCCL_SUCCESS;
     591            0 : }
     592              : 
     593         1137 : HcclResult TopoinfoRanktableStandard::GetDevList(
     594              :     nlohmann::json& instanceList, u32 podIndex, nlohmann::json& deviceList, hccl::HcclCommParams& params,
     595              :     hccl::RankTable_t& rankTable, std::string& serverId, u32& serverIdx)
     596              : {
     597         1137 :     std::string rankId;
     598         1137 :     CHK_RET(GetJsonArrayMemberProperty(instanceList, podIndex, "rank_id", rankId, false));
     599         1138 :     HCCL_DEBUG("%s.json -> rankId: %s", fileName_.c_str(), rankId.c_str());
     600         2276 :     for (u32 deviceIndex = 0; deviceIndex < deviceList.size(); deviceIndex++) {
     601         1138 :         std::string strDevid;
     602         1138 :         CHK_RET(GetJsonArrayMemberProperty(deviceList, deviceIndex, "device_id", strDevid, false));
     603              : 
     604         1136 :         u32 devicePhyId = 0;
     605         1136 :         CHK_RET(SalStrToULong(strDevid, HCCL_BASE_DECIMAL, devicePhyId));
     606         1138 :         if ((params.deviceType != DevType::DEV_TYPE_310P3 && params.deviceType != DevType::DEV_TYPE_910B
     607          473 :              && params.deviceType != DevType::DEV_TYPE_910_93)
     608          440 :             && (devicePhyId > (HCCL_AISERVER_DEVICE_NUM - 1))) {
     609            0 :             HCCL_ERROR(
     610              :                 "[Get][DevList]errNo[0x%016llx] device_id[%u] more than 7 is invalid", HCOM_ERROR_CODE(HCCL_E_PARA),
     611              :                 devicePhyId);
     612            0 :             return HCCL_E_PARA;
     613              :         }
     614         1138 :         HCCL_DEBUG("%s.json -> device_id: %s", fileName_.c_str(), strDevid.c_str());
     615              : 
     616         1138 :         RankInfo_t rankinfo;
     617              :         // 1.非cloud场景下,网卡挂载在device侧2.cloud场景
     618              :         // 推荐网络场景,单servere需要使用RDMA网卡
     619         1138 :         HcclIpAddress ipAddr;
     620         1138 :         if (rankTable.nicDeploy == NICDeployment::NIC_DEPLOYMENT_DEVICE && (rankTable.serverNum > 0)) {
     621         1138 :             std::string deviceIp;
     622         1138 :             CHK_RET(GetJsonArrayMemberProperty(deviceList, deviceIndex, "device_ip", deviceIp, false));
     623         1137 :             HCCL_DEBUG("%s.json -> device_ip: %s", fileName_.c_str(), deviceIp.c_str());
     624         1138 :             if (deviceIp.compare("") != 0) {
     625         1138 :                 CHK_RET(CheckUniqueAndInsertPool(
     626              :                     JsonUniqueInfoType::UNIQUE_INFO_TYPE_DEVICE_IP, deviceIp, JsonCheckOpType::CHECK_OP_TYPE_INSERT));
     627         1138 :                 HcclResult ret = ConvertIpAddress(deviceIp, ipAddr);
     628         1138 :                 CHK_PRT_RET(
     629              :                     ret != HCCL_SUCCESS, HCCL_ERROR("[Get][DevList]deviceIp[%s] is invalid", deviceIp.c_str()), ret);
     630              :             }
     631         2276 :         } else {
     632            0 :             HCCL_INFO("single server don't need devIP");
     633              :         }
     634         1138 :         rankinfo.deviceInfo.deviceIp.push_back(ipAddr);
     635              : 
     636         1138 :         rankinfo.serverId = serverId;
     637         1138 :         rankinfo.serverIdx = serverIdx;
     638         1138 :         rankinfo.deviceInfo.devicePhyId = devicePhyId;
     639         1138 :         if (SalStrToULong(rankId, HCCL_BASE_DECIMAL, rankinfo.rankId) != HCCL_SUCCESS) {
     640            0 :             RPT_INPUT_ERR(
     641              :                 true, "EI0014", std::vector<std::string>({"value", "variable", "expect"}),
     642              :                 std::vector<std::string>({rankId, "rank_id", "a valid integer"}));
     643            0 :             HCCL_ERROR(
     644              :                 "[%s][%s]errNo[0x%016llx] rankid[%s] is invalid", LOG_KEYWORDS_INIT_GROUP.c_str(),
     645              :                 LOG_KEYWORDS_RANKTABLE_CHECK.c_str(), HCOM_ERROR_CODE(HCCL_E_PARA), rankId.c_str());
     646            0 :             return HCCL_E_PARA;
     647              :         }
     648              : 
     649         1138 :         rankinfo.podName = ""; // podname在实验室场景下置空
     650         1138 :         rankId = "";
     651         1138 :         rankTable.rankList.push_back(rankinfo);
     652         1136 :         HCCL_DEBUG(
     653              :             "%s.json->rankId[%u], serverId[%s], devicePhyId[%d]", fileName_.c_str(), rankinfo.rankId,
     654              :             rankinfo.serverId.c_str(), rankinfo.deviceInfo.devicePhyId);
     655         1138 :     }
     656         1138 :     return HCCL_SUCCESS;
     657         1138 : }
     658              : 
     659          388 : HcclResult TopoinfoRanktableStandard::GetDeployMode(bool& cloudFlag) const
     660              : {
     661          388 :     cloudFlag = fileContent_.find("deploy_mode") == fileContent_.end();
     662          387 :     return HCCL_SUCCESS;
     663              : }
        

Generated by: LCOV version 2.0-1