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