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 "common/src/config.h"
14 : #include "externalinput_pub.h"
15 : #include "env_config.h"
16 :
17 : using namespace std;
18 :
19 : namespace hccl
20 : {
21 0 : HcclResult HcclCommunicatorAttrs::Init(HcclCommParams ¶ms, const RankTable_t &rankTable)
22 : {
23 0 : CHK_RET(InitCommParams(params));
24 0 : CHK_RET(InitRankInfo(rankTable));
25 0 : return HCCL_SUCCESS;
26 : }
27 :
28 498 : HcclResult HcclCommunicatorAttrs::Init(HcclCommParams ¶ms, const RankTable_t &rankTable,
29 : const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoConfigMap)
30 : {
31 498 : algoConfigMap_ = algoConfigMap;
32 498 : CHK_RET(InitCommParams(params));
33 498 : CHK_RET(InitRankInfo(rankTable));
34 494 : return HCCL_SUCCESS;
35 : }
36 :
37 0 : HcclResult HcclCommunicatorAttrs::Init(HcclCommParams ¶ms, const std::vector<RankInfo> &rankList,
38 : WorldGroupInfo &groupCommonData)
39 : {
40 0 : CHK_RET(InitCommParams(params));
41 0 : CHK_RET(InitRankInfoSubGroup(rankList, groupCommonData));
42 0 : return HCCL_SUCCESS;
43 : }
44 :
45 33 : HcclResult HcclCommunicatorAttrs::Init(HcclCommParams ¶ms, const std::vector<RankInfo> &rankList,
46 : WorldGroupInfo &groupCommonData,
47 : const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoConfigMap)
48 : {
49 33 : algoConfigMap_ = algoConfigMap;
50 33 : CHK_RET(InitCommParams(params));
51 33 : CHK_RET(InitRankInfoSubGroup(rankList, groupCommonData));
52 33 : return HCCL_SUCCESS;
53 : }
54 :
55 526 : bool HcclCommunicatorAttrs::IsStandardCard()
56 : {
57 526 : if (Is310P3Common())
58 : {
59 4 : HCCL_INFO("The current device just support this StandardCard case.");
60 4 : return true;
61 : }
62 523 : if (isDiffDeviceType_) {
63 0 : return false;
64 : }
65 817 : return ((pairLinkInfo_[static_cast<u32>(LinkTypeInServer::HCCS_TYPE)].size() == 0) &&
66 817 : (pairLinkInfo_[static_cast<u32>(LinkTypeInServer::HCCS_SW_TYPE)].size() == 0) &&
67 809 : (pairLinkInfo_[static_cast<u32>(LinkTypeInServer::SIO_TYPE)].size() == 0));
68 : }
69 :
70 528 : bool HcclCommunicatorAttrs::Is310PDuoCard()
71 : {
72 528 : return (Is310P3Common() && (pairLinkInfo_[static_cast<u32>(LinkTypeInServer::HCCS_TYPE)].size() == userRankSize_));
73 : }
74 :
75 4 : bool HcclCommunicatorAttrs::IsCommon310P3DUO(const std::vector<RankInfo_t> &rankList)
76 : {
77 4 : std::vector<u32> devIdList;
78 4 : std::vector<std::vector<u32>> checkDevList;
79 4 : checkDevList.resize(FACTOR_NUM_TWO);
80 :
81 20 : for (RankInfo_t rankInfo : rankList)
82 : {
83 16 : u32 curId = rankInfo.deviceInfo.devicePhyId;
84 16 : devIdList.push_back(curId);
85 16 : }
86 4 : if (devIdList.size() == DEVICE_PER_MODULE)
87 : {
88 0 : return true;
89 : }
90 4 : std::sort(devIdList.begin(), devIdList.end());
91 20 : for (u32 i = 0; i < devIdList.size(); i++)
92 : {
93 16 : if (devIdList[i] % FACTOR_NUM_TWO == 0)
94 : {
95 8 : checkDevList[0].push_back(devIdList[i]); // 主die
96 : }
97 : else
98 : {
99 8 : checkDevList[1].push_back(devIdList[i]); // 从die
100 : }
101 : }
102 4 : if (devIdList.size() == (DEVICE_PER_MODULE / FACTOR_NUM_TWO) && checkDevList[0].size() == checkDevList[1].size())
103 : {
104 8 : return ((checkDevList[1][0] - checkDevList[0][0]) == 1) &&
105 8 : ((checkDevList[1][1] - checkDevList[0][1]) != 0);
106 : }
107 : else
108 : {
109 0 : return false;
110 : }
111 : return false;
112 4 : }
113 :
114 1996 : bool HcclCommunicatorAttrs::CompareWithUserRank(const RankInfo &left, const RankInfo &right)
115 : {
116 1996 : return left.userRank < right.userRank;
117 : }
118 :
119 1491 : HcclResult HcclCommunicatorAttrs::CheckDeviceType(const DevType deviceType) const
120 : {
121 1491 : if ((deviceType >= DevType::DEV_TYPE_COUNT) || (deviceType < DevType::DEV_TYPE_910))
122 : {
123 0 : HCCL_ERROR("[Check][DeviceType]errNo[0x%016llx] device Type[%d] out of range[%d, %d]",
124 : HCCL_ERROR_CODE(HCCL_E_PARA), deviceType, DevType::DEV_TYPE_910, DevType::DEV_TYPE_NOSOC);
125 0 : return HCCL_E_PARA;
126 : }
127 1491 : HCCL_INFO("[HcclCommunicatorAttrs][CheckDeviceType] CheckDeviceType done");
128 1490 : return HCCL_SUCCESS;
129 : }
130 :
131 1489 : HcclResult HcclCommunicatorAttrs::GetNicInfo(const NICDeployment &nicDeploy, const u32 curRankIndex,
132 : const std::vector<RankInfo_t> &servRankList, RankInfo &rankInfo) const
133 : {
134 1489 : CHK_PRT_RET(servRankList.empty(), HCCL_ERROR("[Get][NicInfo]errNo[0x%016llx] server rank list is empty", HCCL_ERROR_CODE(HCCL_E_PARA)), HCCL_E_PARA);
135 1487 : CHK_PRT_RET(curRankIndex >= servRankList.size(), HCCL_ERROR("[Get][NicInfo]rankindex[%u] invalid,rank list "
136 : "size is[%zu]",
137 : curRankIndex, servRankList.size()),
138 : HCCL_E_PARA);
139 1487 : rankInfo.nicDeploy = nicDeploy;
140 1487 : const RankInfo_t &curRankInfo = servRankList[curRankIndex];
141 1486 : if (nicDeploy == NICDeployment::NIC_DEPLOYMENT_HOST && curRankInfo.deviceInfo.deviceIp.size() == 0) {
142 : // 检查网卡个数
143 : // 网卡挂载位置在host时,按rank index从网卡列表中获取
144 0 : rankInfo.nicIp.push_back(curRankInfo.hostIp);
145 : } else {
146 1487 : CHK_PRT_RET(curRankInfo.deviceInfo.deviceIp.size() == 0,
147 : HCCL_ERROR("[Get][NicInfo]rankindex[%u] invalid,deviceIp is zero", curRankIndex), HCCL_E_PARA);
148 1488 : rankInfo.nicIp.push_back(curRankInfo.deviceInfo.deviceIp[0]);
149 1489 : if (curRankInfo.deviceInfo.backupDeviceIp.size() == 0)
150 : {
151 1490 : HcclIpAddress invalidAddr;
152 1490 : rankInfo.backupNicIp.push_back(invalidAddr);
153 1491 : }
154 : else
155 : {
156 0 : rankInfo.backupNicIp.push_back(curRankInfo.deviceInfo.backupDeviceIp[0]);
157 : }
158 1490 : rankInfo.deviceNicPort = curRankInfo.deviceInfo.port;
159 1490 : rankInfo.deviceVnicPort = curRankInfo.deviceInfo.vnicPort;
160 1490 : rankInfo.backupDevicePort = curRankInfo.deviceInfo.backupPort;
161 1490 : HCCL_INFO("[Get][NicInfo]serverId[%s], serverIdx[%u], rankIndex[%u], nicIp[%s], backupNicIp[%s], "
162 : "deviceNicPort[%u], deviceVnicPort[%u], backupDevicePort[%u]",
163 : rankInfo.serverId.c_str(), rankInfo.serverIdx, curRankIndex,
164 : rankInfo.nicIp[0].GetReadableIP(), rankInfo.backupNicIp[0].GetReadableIP(),
165 : rankInfo.deviceNicPort, rankInfo.deviceVnicPort, rankInfo.backupDevicePort);
166 : }
167 1491 : HCCL_INFO("[HcclCommunicatorAttrs][GetNicInfo] GetNicInfo done");
168 1491 : return HCCL_SUCCESS;
169 : }
170 :
171 : // private
172 531 : HcclResult HcclCommunicatorAttrs::InitCommParams(HcclCommParams ¶ms)
173 : {
174 531 : userRank_ = params.rank;
175 531 : realUserRank_ = params.userRank;
176 531 : userRankSize_ = params.totalRanks;
177 531 : deviceLogicId_ = params.logicDevId;
178 531 : deviceType_ = params.deviceType;
179 :
180 531 : identifier_ = params.identifier;
181 531 : collectiveId_ = params.id.internal;
182 531 : commWorkMode_ = params.commWorkMode;
183 531 : HCCL_DEBUG(
184 : "userRank_: %u realUserRank_: %u userRankSize_: %u deviceLogicId_: %u deviceType_: %u commWorkMode_: %u.",
185 : userRank_, realUserRank_, userRankSize_, deviceLogicId_, deviceType_, commWorkMode_);
186 531 : return HCCL_SUCCESS;
187 : }
188 :
189 498 : HcclResult HcclCommunicatorAttrs::SetServerId(const RankTable_t &rankTable)
190 : {
191 807 : for (u32 i = 0; i < rankTable.rankList.size(); i++)
192 : {
193 805 : if (rankTable.rankList[i].rankId == userRank_)
194 : {
195 496 : serverId_ = rankTable.rankList[i].serverId;
196 496 : superPodId_ = rankTable.rankList[i].superPodId;
197 496 : superDeviceId_ = rankTable.rankList[i].superDeviceId;
198 496 : break;
199 : }
200 : }
201 :
202 498 : if (serverId_.empty())
203 : {
204 2 : HCCL_ERROR("[Set][ServerId]SetServerId fail");
205 2 : return HCCL_E_PARA;
206 : }
207 496 : HCCL_INFO("[HcclCommunicatorAttrs][SetServerId] SetServerId done");
208 496 : return HCCL_SUCCESS;
209 : }
210 :
211 529 : HcclResult HcclCommunicatorAttrs::SetServerNum(const std::vector<RankInfo_t> &ranks)
212 : {
213 529 : std::vector<std::string> serverIds;
214 2177 : for (u32 index = 0; index < ranks.size(); index++)
215 : {
216 1648 : std::vector<std::string>::iterator found = find(serverIds.begin(), serverIds.end(), ranks[index].serverId);
217 1648 : if (found == serverIds.end())
218 : {
219 753 : serverIds.push_back(ranks[index].serverId);
220 : }
221 : }
222 529 : serverNum_ = serverIds.size();
223 529 : HCCL_INFO("[HcclCommunicatorAttrs][SetServerNum] SetServerNum done");
224 529 : return HCCL_SUCCESS;
225 529 : }
226 :
227 496 : HcclResult HcclCommunicatorAttrs::SetInnerServerAverageDevice(const RankTable_t &rankTable)
228 : {
229 496 : deviceNumPerServer_ = 0;
230 496 : bool isConnectedWithHCCS = true;
231 496 : LinkTypeInServer linkType = LinkTypeInServer::HCCS_TYPE;
232 1987 : for (u32 i = 0; i < rankTable.rankList.size(); i++)
233 : {
234 : // 同一server的标识IP 是一样的,所以可以以此推算出平均dev个数
235 1491 : if (rankTable.rankList[i].deviceInfo.devicePhyId == HOST_DEVICE_ID && isHaveCpuRank_ != true)
236 : {
237 0 : isHaveCpuRank_ = true;
238 : }
239 2712 : if (serverId_ == rankTable.rankList[i].serverId &&
240 1221 : rankTable.rankList[i].deviceInfo.devicePhyId != HOST_DEVICE_ID)
241 : {
242 1221 : deviceNumPerServer_++;
243 : }
244 : else
245 : {
246 270 : continue;
247 : }
248 1221 : if (Is310PDevice())
249 : {
250 0 : continue;
251 : }
252 1221 : CHK_RET(GetPairDeviceLinkType(rankTable, i, isConnectedWithHCCS, linkType));
253 : }
254 496 : if (deviceType_ == DevType::DEV_TYPE_910B && !isConnectedWithHCCS)
255 : {
256 0 : deviceNumPerAggregation_ = deviceNumPerServer_ / FACTOR_NUM_TWO;
257 : }
258 : else
259 : {
260 496 : deviceNumPerAggregation_ = deviceNumPerServer_;
261 : }
262 496 : return HCCL_SUCCESS;
263 : }
264 :
265 : // sub group适配获取server内设配数
266 33 : HcclResult HcclCommunicatorAttrs::SetInnerServerAverageDevice(const std::vector<RankInfo> &rankList)
267 : {
268 33 : deviceNumPerServer_ = 0;
269 33 : bool isConnectedWithHCCS = true;
270 33 : LinkTypeInServer linkType = LinkTypeInServer::HCCS_TYPE;
271 190 : for (u32 i = 0; i < rankList.size(); i++)
272 : {
273 : // 同一server的标识IP 是一样的,所以可以以此推算出平均dev个数
274 157 : if (serverId_ == rankList[i].serverId && rankList[i].devicePhyId != HOST_DEVICE_ID)
275 : {
276 118 : deviceNumPerServer_++;
277 : }
278 : else
279 : {
280 39 : continue;
281 : }
282 118 : if (Is310PDevice() || isHaveCpuRank_)
283 : {
284 : // 异构场景无需获取链路类型并校验
285 0 : continue;
286 : }
287 419 : for (u32 j = i + 1; j < rankList.size(); j++)
288 : {
289 301 : if (rankList[i].serverId == rankList[j].serverId)
290 : {
291 262 : CHK_RET(hrtGetPairDeviceLinkType(rankList[i].devicePhyId, rankList[j].devicePhyId, linkType));
292 : }
293 301 : if (linkType != LinkTypeInServer::HCCS_TYPE)
294 : {
295 0 : isConnectedWithHCCS = false;
296 : }
297 : }
298 : }
299 33 : if (deviceType_ == DevType::DEV_TYPE_910B && !isConnectedWithHCCS)
300 : {
301 0 : deviceNumPerAggregation_ = deviceNumPerServer_ / FACTOR_NUM_TWO;
302 : }
303 : else
304 : {
305 33 : deviceNumPerAggregation_ = deviceNumPerServer_;
306 : }
307 33 : return HCCL_SUCCESS;
308 : }
309 :
310 529 : HcclResult HcclCommunicatorAttrs::TransformRankInfoByServerId(
311 : const std::vector<RankInfo_t> &rankList, ServRankInfo &servRankInfo) const
312 : {
313 2177 : for (size_t index = 0; index < rankList.size(); ++index)
314 : {
315 1647 : const RankInfo_t &rankInfo = rankList[index];
316 1648 : std::string serverId = SalTrim(rankInfo.serverId);
317 1648 : ServRankInfo::iterator itr = servRankInfo.find(serverId);
318 1648 : if (itr != servRankInfo.end())
319 : {
320 895 : itr->second.push_back(rankInfo);
321 : }
322 : else
323 : {
324 753 : std::vector<RankInfo_t> rankInfoList;
325 753 : rankInfoList.push_back(rankInfo);
326 753 : std::pair<std::string, std::vector<RankInfo_t>> rankInfoPair(serverId, rankInfoList);
327 753 : servRankInfo.insert(rankInfoPair);
328 752 : }
329 1648 : }
330 : // 每个server下的rank列表按 设备Id 从小到大的顺序排序
331 1283 : for (auto &iter : servRankInfo)
332 : {
333 753 : std::sort(iter.second.begin(), iter.second.end(), CompareWithDevicePhyId);
334 : }
335 530 : return HCCL_SUCCESS;
336 : }
337 :
338 1788 : bool HcclCommunicatorAttrs::CompareWithDevicePhyId(const RankInfo_t &left, const RankInfo_t &right)
339 : {
340 1788 : return left.deviceInfo.devicePhyId < right.deviceInfo.devicePhyId;
341 : }
342 :
343 530 : HcclResult HcclCommunicatorAttrs::SetModuleInfo(const std::vector<RankInfo_t> &rankList)
344 : {
345 530 : isDiffDeviceModule_ = IsDiffDeviceModule(rankList);
346 531 : multiModuleDiffDeviceNumMode_ = false;
347 531 : moduleNum_ = serverNum_;
348 :
349 531 : std::map<u32, std::vector<RankInfo_t>> moduleMap;
350 2194 : for (RankInfo_t rankInfo : rankList)
351 : {
352 1661 : u32 moduleIdx = INVALID_UINT;
353 1661 : CHK_RET(GetModuleIdx(rankInfo, moduleIdx)); // 这里不判断混合组网,只提取每个server实际的moduleidx
354 1662 : if (static_cast<s32>(rankInfo.deviceInfo.devicePhyId) == HOST_DEVICE_ID)
355 : {
356 0 : continue;
357 : }
358 1662 : auto iter = moduleMap.find(moduleIdx);
359 1662 : if (iter == moduleMap.end())
360 : {
361 758 : std::vector<RankInfo_t> rankInfoList;
362 758 : rankInfoList.push_back(rankInfo);
363 758 : moduleMap.insert(std::make_pair(moduleIdx, rankInfoList));
364 757 : }
365 : else
366 : {
367 904 : iter->second.push_back(rankInfo);
368 : }
369 1661 : }
370 531 : if (moduleMap.size() == 0)
371 : {
372 0 : return HCCL_SUCCESS;
373 : }
374 :
375 531 : std::vector<u32> moduleDeviceNumVec;
376 :
377 531 : moduleNum_ = moduleMap.size();
378 531 : u32 preDeviceNum = moduleMap.begin()->second.size();
379 531 : u32 curDeviceNum = preDeviceNum;
380 531 : std::vector<u32> devicePhyIdInfoList;
381 1289 : for (auto &moduleInfo : moduleMap)
382 : {
383 758 : curDeviceNum = moduleInfo.second.size();
384 758 : if (curDeviceNum != preDeviceNum)
385 : {
386 17 : multiModuleDiffDeviceNumMode_ = true;
387 : }
388 :
389 758 : moduleDeviceNumVec.push_back(curDeviceNum);
390 :
391 758 : HCCL_INFO("module[%d] contains [%d]devices", moduleInfo.first, moduleInfo.second.size());
392 757 : devicePhyIdInfoList.clear();
393 2420 : for (auto &rankInfo : moduleInfo.second)
394 : {
395 1659 : devicePhyIdInfoList.push_back(rankInfo.deviceInfo.devicePhyId);
396 1658 : HCCL_INFO("moduleIdx[%d] Info: rankId[%d], serverId[%s], serverIdx[%d], devicePhyId[%d]",
397 : moduleInfo.first, rankInfo.rankId, rankInfo.serverId.c_str(), rankInfo.serverIdx,
398 : rankInfo.deviceInfo.devicePhyId);
399 : }
400 758 : if (!CheckDoubleRingWithRohTopo(devicePhyIdInfoList)) {
401 474 : isARSDoubleRing_ = false;
402 474 : HCCL_DEBUG("SetModuleInfo isARSDoubleRing[%llu]", isARSDoubleRing_);
403 : }
404 : }
405 :
406 530 : if (isDiffDeviceType_)
407 : {
408 0 : gcdDeviceNumPerAggregation_ = CalGCD(moduleDeviceNumVec);
409 0 : multiModuleDiffDeviceNumMode_ = false;
410 0 : deviceNumPerAggregation_ = gcdDeviceNumPerAggregation_;
411 0 : useSuperPodMode_ = false;
412 0 : HCCL_INFO("[HcclCommunicatorAttrs][SetModuleInfo]mix mode, set multiModuleDiffDeviceNumMode to false, "
413 : "gcdDeviceNumPerAggregation [%u] deviceNumPerAggregation [%u]",
414 : gcdDeviceNumPerAggregation_, deviceNumPerAggregation_);
415 : }
416 :
417 530 : HCCL_RUN_INFO("different module contains different numbers of cards:[%d]", multiModuleDiffDeviceNumMode_);
418 531 : HCCL_RUN_INFO("different module contains different type of cards:[%d]", isDiffDeviceType_);
419 531 : return HCCL_SUCCESS;
420 531 : }
421 :
422 528 : HcclResult HcclCommunicatorAttrs::SetSuperPodInfo(const std::vector<RankInfo_t> &rankList)
423 : {
424 : // 1.超节点数目 2.超节点间server数是否一致 3.
425 528 : superPodNum_ = 0;
426 528 : multiSuperPodDiffServerNumMode_ = false;
427 528 : multiSuperPodDiffDeviceNumMode_ = false;
428 528 : std::map<std::string, std::set<u32>> superPodToServerNum; // 记录每个超节点中的server数目
429 528 : std::map<std::string, std::vector<RankInfo_t>> superPodToDeviceNum; //记录每个超节点中的设备(rank)数目
430 598 : for (RankInfo_t rankInfo : rankList)
431 : {
432 : // superPodId为空时, 返回超节点数量为0, 按照非超节点模式处理
433 586 : CHK_PRT_RET(rankInfo.superPodId.empty(),
434 : HCCL_DEBUG("ranks[%u] superPodId[%s] is empty, set superPodNum to zero", rankInfo.rankId,
435 : rankInfo.superPodId.c_str()),
436 : HCCL_SUCCESS);
437 :
438 69 : superPodToServerNum[rankInfo.superPodId].insert(rankInfo.serverIdx);
439 69 : auto iter = superPodToDeviceNum.find(rankInfo.superPodId);
440 69 : if (iter == superPodToDeviceNum.end()) {
441 30 : std::vector<RankInfo_t> rankInfoList;
442 30 : rankInfoList.push_back(rankInfo);
443 30 : superPodToDeviceNum.insert(std::make_pair(rankInfo.superPodId, rankInfoList));
444 30 : } else {
445 39 : iter->second.push_back(rankInfo);
446 : }
447 586 : }
448 12 : superPodNum_ = superPodToServerNum.size();
449 12 : std::vector<u32> superPodServerNumVec;
450 12 : u32 preServerNum = superPodToServerNum.begin()->second.size();
451 12 : u32 curServerNum = preServerNum;
452 42 : for (auto superPodItem : superPodToServerNum)
453 : {
454 30 : curServerNum = superPodItem.second.size();
455 30 : if (curServerNum != preServerNum)
456 : {
457 11 : multiSuperPodDiffServerNumMode_ = true;
458 : }
459 30 : superPodServerNumVec.push_back(curServerNum);
460 30 : HCCL_INFO("[Set][SuperPodInfo]SuperPod[%s] contains [%d]servers", superPodItem.first.c_str(), superPodItem.second.size());
461 30 : }
462 12 : HCCL_RUN_INFO("[Set][SuperPodInfo]different surperPod contains different numbers of servers:[%d]",
463 : multiSuperPodDiffServerNumMode_);
464 :
465 : // 计算最大公约数
466 12 : if (!IsConfigAHCAlgo(algoConfigMap_) && !multiModuleDiffDeviceNumMode_ && multiSuperPodDiffServerNumMode_)
467 : {
468 8 : gcdServerNumPerSuperPod_ = CalGCD(superPodServerNumVec);
469 8 : multiSuperPodDiffServerNumMode_ = false; // 取公约数不存在server数不一致场景
470 8 : superPodNum_ = serverNum_ / gcdServerNumPerSuperPod_;
471 8 : HCCL_RUN_INFO("[Set][SuperPodInfo] gcdServerNumPerSuperPod[%u] original superPodNum[%u] converted superPodNum[%u]",
472 : gcdServerNumPerSuperPod_, superPodToServerNum.size(), superPodNum_);
473 : }
474 :
475 12 : if (isDiffDeviceType_)
476 : {
477 0 : multiSuperPodDiffServerNumMode_ = false;
478 0 : HCCL_RUN_INFO("mix mode, set multiSuperPodDiffServerNumMode to false");
479 : }
480 :
481 42 : for (auto item: superPodToDeviceNum) {
482 30 : u32 curDeviceNum = item.second.size();
483 30 : if (curDeviceNum != superPodToDeviceNum.begin()->second.size()) {
484 11 : multiSuperPodDiffDeviceNumMode_ = true;
485 : }
486 30 : HCCL_INFO("[Set][SuperPodInfo]SuperPod[%s] contains [%d] devices", item.first.c_str(), item.second.size());
487 30 : }
488 12 : return HCCL_SUCCESS;
489 529 : }
490 :
491 : // 集群中存在910B A+X时,0-7卡: moduleIdx = 2 * serverIdx; 8-15卡: moduleIdx = 2 * serverIdx + 1
492 : // 集群中不存在910B A+X时,moduleIdx = serverIdx
493 1661 : HcclResult HcclCommunicatorAttrs::GetModuleIdx(const RankInfo_t &rankInfo, u32 &moduleIdx)
494 : {
495 1661 : CHK_PRT_RET(rankInfo.serverIdx == INVALID_UINT,
496 : HCCL_ERROR("serverIdx is invalid:[%u], rankId:[%u]", rankInfo.serverIdx, rankInfo.rankId), HCCL_E_PARA);
497 1661 : CHK_PRT_RET(deviceType_ == DevType::DEV_TYPE_COUNT,
498 : HCCL_ERROR("deviceType_ is invalid:[%d], rankId:[%u]", deviceType_, rankInfo.rankId), HCCL_E_PARA);
499 1661 : u32 serverIdx = rankInfo.serverIdx;
500 1661 : if (GetRankInfoDevType(rankInfo) == DevType::DEV_TYPE_910B && isDiffDeviceModule_)
501 : {
502 17 : moduleIdx = serverIdx * FACTOR_NUM_TWO + rankInfo.deviceInfo.devicePhyId / DEVICE_PER_MODULE;
503 : }
504 1646 : else if (isDiffDeviceType_)
505 : {
506 0 : moduleIdx = serverIdx * FACTOR_NUM_TWO;
507 : }
508 : else
509 : {
510 1646 : moduleIdx = serverIdx;
511 : }
512 1663 : CHK_PRT_RET(moduleIdx == INVALID_UINT,
513 : HCCL_ERROR("GetModuleIdx failed. moduleIdx:[%d], rankId:[%u]", moduleIdx, rankInfo.rankId), HCCL_E_PARA);
514 1663 : return HCCL_SUCCESS;
515 : }
516 :
517 : // 用于标识集群中是否存在 910B A+X形态
518 530 : bool HcclCommunicatorAttrs::IsDiffDeviceModule(const std::vector<RankInfo_t> &rankList) const
519 : {
520 530 : bool minDevice = false;
521 530 : bool maxDevice = false;
522 530 : bool isDiffMeshAggregation = false;
523 530 : if (!isDiffDeviceType_ && (deviceType_ != DevType::DEV_TYPE_910B || rankList.size() == 0))
524 : {
525 365 : HCCL_INFO("[IsDiffDeviceModule] deviceType_[%d], rankList.size[%u]", deviceType_, rankList.size());
526 365 : return false;
527 : }
528 :
529 982 : for (const RankInfo_t &rankInfo : rankList)
530 : {
531 817 : if (GetRankInfoDevType(rankInfo) == DevType::DEV_TYPE_910B && !isStandardCard_)
532 : {
533 673 : if (rankInfo.deviceInfo.devicePhyId < DEVICE_PER_MODULE)
534 : {
535 665 : minDevice = true;
536 : }
537 : else
538 : {
539 8 : maxDevice = true;
540 : }
541 : }
542 : }
543 166 : if (minDevice && maxDevice)
544 : {
545 3 : isDiffMeshAggregation = true;
546 : }
547 166 : return isDiffMeshAggregation;
548 : }
549 :
550 527 : HcclResult HcclCommunicatorAttrs::InitHccsPortNum()
551 : {
552 : DevType deviceType;
553 527 : CHK_RET(hrtGetDeviceType(deviceType));
554 529 : if (deviceType == DevType::DEV_TYPE_910_93)
555 : {
556 9 : CHK_RET(hrtGetHccsPortNum(deviceLogicId_, hccsPortNum_));
557 : }
558 529 : return HCCL_SUCCESS;
559 : }
560 :
561 496 : HcclResult HcclCommunicatorAttrs::SetRankInfoList(const RankTable_t &rankTable)
562 : {
563 : // 检查rank table入参正确性
564 496 : CHK_RET(CheckRankTable(rankTable, servRankInfo_));
565 : // 获取芯片类型
566 495 : DevType deviceType = DevType::DEV_TYPE_COUNT;
567 495 : CHK_RET(hrtGetDeviceType(deviceType));
568 :
569 : // 遍历rank table获取rank信息
570 496 : rankInfoList_.clear();
571 1176 : for (auto iter = servRankInfo_.begin(); iter != servRankInfo_.end(); ++iter)
572 : {
573 2171 : for (u32 index = 0; index < iter->second.size(); ++index)
574 : {
575 1490 : const RankInfo_t &orgRankInfo = iter->second[index];
576 : // 构建comm 使用的rank 信息
577 1489 : RankInfo rankInfo;
578 1491 : rankInfo.userRank = orgRankInfo.rankId;
579 1491 : rankInfo.worldRank = orgRankInfo.rankId;
580 :
581 1491 : rankInfo.deviceType = GetRankInfoDevType(orgRankInfo);
582 1490 : CHK_RET(CheckDeviceType(rankInfo.deviceType));
583 :
584 1491 : if (rankInfo.deviceType != DevType::DEV_TYPE_910B || rankInfo.deviceType != DevType::DEV_TYPE_910_93)
585 : {
586 : // 910B、910_93形态不做devicePhyId最大值的判断
587 1491 : CHK_RET(CheckDevPhyId(orgRankInfo.deviceInfo.devicePhyId));
588 : }
589 1491 : rankInfo.devicePhyId = orgRankInfo.deviceInfo.devicePhyId;
590 1491 : rankInfo.deviceNicPort = orgRankInfo.deviceInfo.port;
591 1491 : rankInfo.deviceVnicPort = orgRankInfo.deviceInfo.vnicPort;
592 :
593 1491 : rankInfo.serverId = orgRankInfo.serverId;
594 1491 : rankInfo.serverIdx = orgRankInfo.serverIdx;
595 1491 : rankInfo.hostIp = orgRankInfo.hostIp;
596 1489 : rankInfo.hostPort = orgRankInfo.hostPort;
597 1489 : rankInfo.localRank = orgRankInfo.localRank;
598 1489 : rankInfo.superDeviceId = orgRankInfo.superDeviceId;
599 1489 : if (gcdServerNumPerSuperPod_ > 0) {
600 49 : u32 gcdSuperPodIdx = rankInfo.serverIdx / gcdServerNumPerSuperPod_;
601 49 : rankInfo.superPodId = orgRankInfo.superPodId + "_" + std::to_string(gcdSuperPodIdx);
602 49 : rankInfo.superPodIdx = gcdSuperPodIdx;
603 49 : if (userRank_ == rankInfo.userRank) {
604 8 : HCCL_RUN_INFO("[SetRankInfoList] userRank[%u] serverId[%s] serverIdx[%u] original superPodId[%s] "
605 : "superPodIdx[%u] converted superPodId[%s] superPodIdx[%u]",
606 : userRank_, rankInfo.serverId.c_str(), rankInfo.serverIdx, orgRankInfo.superPodId.c_str(),
607 : orgRankInfo.superPodIdx, rankInfo.superPodId.c_str(), rankInfo.superPodIdx);
608 : }
609 : } else {
610 1440 : rankInfo.superPodId = orgRankInfo.superPodId;
611 1441 : rankInfo.superPodIdx = orgRankInfo.superPodIdx;
612 : }
613 1490 : CHK_RET(GetNicInfo(orgRankInfo.deviceInfo.nicDeploy, index, iter->second, rankInfo));
614 1490 : rankInfo.nicIdx.assign(nicList_.begin(), nicList_.end());
615 1490 : rankInfoList_.push_back(rankInfo);
616 1491 : }
617 : }
618 : // 将rank id从小到大的顺序返回
619 495 : CHK_RET(SortRankInfoList());
620 495 : return HCCL_SUCCESS;
621 : }
622 :
623 497 : HcclResult HcclCommunicatorAttrs::CheckRankTable(const RankTable_t &rankTable, const ServRankInfo &servRankInfo)
624 : {
625 : // 检查网卡挂载位置
626 497 : if (CheckNicDeploy(rankTable.nicDeploy, deviceType_) != HCCL_SUCCESS)
627 : {
628 1 : HCCL_ERROR("[Check][RankTable]errNo[0x%016llx] nicDeploy[%d] out of range[%d, %d]",
629 : HCCL_ERROR_CODE(HCCL_E_PARA), rankTable.nicDeploy,
630 : static_cast<int32_t>(NICDeployment::NIC_DEPLOYMENT_HOST),
631 : static_cast<int32_t>(NICDeployment::NIC_DEPLOYMENT_DEVICE));
632 1 : return HCCL_E_PARA;
633 : }
634 :
635 500 : if (Is310PDevice())
636 : {
637 : // 异构场景无需检查server内device个数
638 0 : return HCCL_SUCCESS;
639 : }
640 :
641 500 : if (CheckSuperDeviceId(rankTable) != HCCL_SUCCESS)
642 : {
643 0 : HCCL_ERROR("[Check][RankTable]errNo[0x%016llx] super_device_id is invalid in ranktable, "
644 : "ranktable config value: rankId[%u], superDeviceId[0x%x]",
645 : HCCL_ERROR_CODE(HCCL_E_PARA), userRank_, superDeviceId_);
646 0 : return HCCL_E_PARA;
647 : }
648 :
649 : // 检查服务器上的设备信息
650 500 : ServRankInfo::const_iterator iterBegin = servRankInfo.begin();
651 500 : u32 devNum = 0;
652 500 : CHK_RET(GetDevNum(iterBegin->second, devNum));
653 :
654 499 : bool multiServerDiffDeviceNumMode = false;
655 1185 : for (ServRankInfo::const_iterator iter = iterBegin; iter != servRankInfo.end(); ++iter)
656 : {
657 : // 检测每个服务器内的设备数是否相等,如果不相同即为多server不同卡模式
658 688 : u32 curServerDevNum = 0;
659 688 : CHK_RET(GetDevNum(iter->second, curServerDevNum));
660 686 : if (devNum != curServerDevNum)
661 : {
662 17 : HCCL_WARNING("[Check][RankTable] devnum isn't same,(serverA:[%s],serverB:[%s])"
663 : "devNum(%u, %u)",
664 : iterBegin->first.c_str(), iter->first.c_str(), devNum, curServerDevNum);
665 17 : multiServerDiffDeviceNumMode = true;
666 : }
667 : }
668 :
669 : // 非多server不同卡模式下,判断实际设备数目和userRank_table中的记录一致
670 500 : if (multiServerDiffDeviceNumMode == false && rankTable.deviceNum != devNum * servRankInfo.size())
671 : {
672 2 : HCCL_WARNING("[Check][RankTable]errNo[0x%016llx] devnum isn't same, number in rankTable:[%u], actual:[%llu]",
673 : HCCL_ERROR_CODE(HCCL_E_PARA), rankTable.deviceNum, devNum * servRankInfo.size());
674 2 : return HCCL_E_PARA;
675 : }
676 :
677 : // 910模组:服务器内设备的数目必须是2的次幂,在此check(非模组形态无此限制不check)
678 : // 910B、910_93模组形态未定,服务器内设备的数目校验规则后续补充
679 658 : if (pairLinkInfo_[static_cast<u32>(LinkTypeInServer::HCCS_TYPE)].size() > 0 && devNum > HCCL_DEVICE_NUM_TWO &&
680 160 : (deviceType_ != DevType::DEV_TYPE_910B && deviceType_ != DevType::DEV_TYPE_910_93 && !Is310P3Common()))
681 : {
682 30 : CHK_PRT_RET(CheckDevCount(devNum) != HCCL_SUCCESS,
683 : HCCL_ERROR("[Check][RankTable]errNo[0x%016llx] devnum is invalid in server.",
684 : HCCL_ERROR_CODE(HCCL_E_PARA)),
685 : HCCL_E_PARA);
686 : }
687 498 : return HCCL_SUCCESS;
688 : }
689 :
690 1491 : HcclResult HcclCommunicatorAttrs::CheckDevPhyId(const s32 &devicePhyId) const
691 : {
692 1491 : if (devicePhyId > COMM_MAX_DEVICE_ID && devicePhyId != HOST_DEVICE_ID)
693 : {
694 0 : HCCL_ERROR("[Check][DevPhyId]errNo[0x%016llx] devicePhyId[%d] out of range[-1, %d]",
695 : HCCL_ERROR_CODE(HCCL_E_PARA), devicePhyId, COMM_MAX_DEVICE_ID);
696 0 : return HCCL_E_PARA;
697 : }
698 1491 : return HCCL_SUCCESS;
699 : }
700 :
701 496 : HcclResult HcclCommunicatorAttrs::SortRankInfoList()
702 : {
703 : // 按rank id从小到大的顺序返回
704 496 : std::sort(rankInfoList_.begin(), rankInfoList_.end(), CompareWithUserRank);
705 :
706 1986 : for (u32 index = 0; index < rankInfoList_.size(); ++index)
707 : {
708 1491 : CHK_PRT_RET((index != rankInfoList_[index].userRank),
709 : HCCL_ERROR("[HcclCommunicatorAttrs][SortRankInfoList]errNo[0x%016llx] index[%u] != rankInfoList.userRank[%u]",
710 : HCCL_ERROR_CODE(HCCL_E_PARA), index, rankInfoList_[index].userRank),
711 : HCCL_E_PARA);
712 : }
713 495 : return HCCL_SUCCESS;
714 : }
715 :
716 501 : HcclResult HcclCommunicatorAttrs::CheckNicDeploy(NICDeployment nicDeploy, DevType deviceType) const
717 : {
718 : (void)deviceType;
719 501 : if (nicDeploy >= NICDeployment::NIC_DEPLOYMENT_RESERVED)
720 : {
721 1 : HCCL_ERROR("[Check][NicDeploy]errNo[0x%016llx] nicDeploy[%u] out of range[%d, %d]",
722 : HCCL_ERROR_CODE(HCCL_E_PARA), nicDeploy,
723 : static_cast<int32_t>(NICDeployment::NIC_DEPLOYMENT_HOST),
724 : static_cast<int32_t>(NICDeployment::NIC_DEPLOYMENT_DEVICE));
725 1 : return HCCL_E_PARA;
726 : }
727 500 : return HCCL_SUCCESS;
728 : }
729 :
730 32 : HcclResult HcclCommunicatorAttrs::CheckDevCount(const u32 devNum)
731 : {
732 32 : if (devNum > HCCL_AISERVER_DEVICE_NUM)
733 : {
734 1 : HCCL_ERROR("[Check][DevCount]errNo[0x%016llx] devNum[%u] out of range[%u, %u]", HCCL_ERROR_CODE(HCCL_E_PARA),
735 : devNum, 0, HCCL_AISERVER_DEVICE_NUM);
736 1 : return HCCL_E_PARA;
737 : }
738 : // 其他拓扑算法设备数目: 1 server: 1, 2, 4, 8
739 : // n server: 1*n, 2*n, 4*n, 8*n
740 31 : if (!Check2N(devNum))
741 : {
742 14 : RPT_ENV_ERR(true,
743 : "EI0014",
744 : std::vector<std::string>({ "value", "variable" ,"expect" }),
745 : std::vector<std::string>({std::to_string(devNum), "devNum", "to be 1, 2 or 4, or a multiple of 8"}));
746 1 : HCCL_ERROR("[%s][%s]errNo[0x%016llx] devNum[%u] devNum must be divisible by 8, or equal to 1, 2 or 4",
747 : LOG_KEYWORDS_INIT_GROUP.c_str(), LOG_KEYWORDS_RANKTABLE_CHECK.c_str(),
748 : HCCL_ERROR_CODE(HCCL_E_PARA), devNum);
749 1 : return HCCL_E_PARA;
750 : }
751 30 : return HCCL_SUCCESS;
752 2 : }
753 :
754 32 : bool HcclCommunicatorAttrs::Check2N(u32 num) const
755 : {
756 32 : if (num < 1)
757 : {
758 0 : return false;
759 : }
760 : else
761 : {
762 32 : return ((num & (num - 1)) == 0);
763 : }
764 : }
765 :
766 495 : HcclResult HcclCommunicatorAttrs::SetLocalRankInfo()
767 : {
768 802 : for (u32 i = 0; i < rankInfoList_.size(); i++)
769 : {
770 802 : HCCL_DEBUG(" host ip: %s host port: %u dev phy id: %d.", rankInfoList_[i].hostIp.GetReadableAddress(),
771 : rankInfoList_[i].hostPort, rankInfoList_[i].devicePhyId);
772 801 : if (rankInfoList_[i].userRank == userRank_)
773 : {
774 495 : devicePhyId_ = rankInfoList_[i].devicePhyId;
775 495 : devIpAddr_ = rankInfoList_[i].nicIp;
776 495 : devBackupIpAddr_ = rankInfoList_[i].backupNicIp;
777 495 : devBackupPort_ = rankInfoList_[i].backupDevicePort;
778 495 : hostIp_ = rankInfoList_[i].hostIp;
779 494 : hostPort_ = rankInfoList_[i].hostPort;
780 495 : localRank_ = rankInfoList_[i].localRank;
781 495 : HCCL_DEBUG("localRank_[%u].", localRank_);
782 495 : break;
783 : }
784 : }
785 : // 在确定 servRankInfo_ 和 serverId_ 信息后,就完成初始判断
786 494 : HCCL_DEBUG("[HcclCommunicatorAttrs][Init]deviceType[%u].", deviceType_);
787 495 : if (static_cast<s32>(devicePhyId_) == HOST_DEVICE_ID)
788 : {
789 0 : HCCL_ERROR("[HcclCommunicatorAttrs][Init]not support cpu rank");
790 0 : return HCCL_E_NOT_SUPPORT;
791 : }
792 : else
793 : {
794 495 : HCCL_DEBUG("[HcclCommunicatorAttrs][Init]devicePhyId[%u] != HOST_DEVICE_ID", devicePhyId_);
795 495 : CHK_RET(hrtGetDevice(&deviceLogicId_));
796 : }
797 494 : return HCCL_SUCCESS;
798 : }
799 :
800 33 : HcclResult HcclCommunicatorAttrs::SetLocalRankInfoSubGroup(const std::vector<RankInfo> &rankList)
801 : {
802 33 : rankInfoList_.assign(rankList.begin(), rankList.end());
803 33 : for (u32 i = 0; i < rankInfoList_.size(); i++)
804 : {
805 33 : if (rankInfoList_[i].userRank == userRank_)
806 : {
807 33 : devIpAddr_ = rankInfoList_[i].nicIp;
808 33 : devBackupIpAddr_ = rankInfoList_[i].backupNicIp;
809 33 : devBackupPort_ = rankInfoList_[i].backupDevicePort;
810 33 : devicePhyId_ = rankInfoList_[i].devicePhyId;
811 33 : superPodId_ = rankInfoList_[i].superPodId;
812 33 : superDeviceId_ = rankInfoList_[i].superDeviceId;
813 33 : hostIp_ = rankInfoList_[i].hostIp;
814 33 : hostPort_ = rankInfoList_[i].hostPort;
815 33 : nicList_.assign(rankInfoList_[i].nicIdx.begin(), rankInfoList_[i].nicIdx.end());
816 33 : nicDeployment_ = rankInfoList_[i].nicDeploy;
817 33 : break;
818 : }
819 : }
820 33 : return HCCL_SUCCESS;
821 : }
822 :
823 521 : HcclResult HcclCommunicatorAttrs::CheckLocalRankInfo()
824 : {
825 2147 : for (u32 i = 0; i < rankInfoList_.size(); ++i)
826 : {
827 1626 : if (userRank_ == rankInfoList_[i].userRank)
828 : {
829 521 : CHK_PRT_RET(static_cast<s32>(devicePhyId_) != rankInfoList_[i].devicePhyId,
830 : HCCL_ERROR("[Init][Para]errNo[0x%016llx] parameter check failed, "
831 : "userrank[%u] == rankInfoList.userrank[%u], phyid[%d] != rankInfoList.devid[%d]",
832 : HCCL_ERROR_CODE(HCCL_E_PARA), userRank_, rankInfoList_[i].userRank,
833 : static_cast<s32>(devicePhyId_), rankInfoList_[i].devicePhyId),
834 : HCCL_E_PARA);
835 : }
836 : }
837 521 : return HCCL_SUCCESS;
838 : }
839 :
840 91 : u32 HcclCommunicatorAttrs::CalMeshAggRankSize(int halfDevNum) const
841 : {
842 91 : u32 size = INVALID_VALUE_RANKSIZE;
843 182 : for (auto iter = servRankInfo_.begin(); iter != servRankInfo_.end(); ++iter)
844 : {
845 91 : u32 aggregationRankSize0 = 0;
846 91 : u32 aggregationRankSize1 = 0;
847 462 : for (u32 index = 0; index < iter->second.size(); ++index)
848 : {
849 371 : const RankInfo_t &orgRankInfo = iter->second[index];
850 371 : if (orgRankInfo.deviceInfo.devicePhyId < halfDevNum)
851 : {
852 275 : aggregationRankSize0++;
853 : }
854 : else
855 : {
856 96 : aggregationRankSize1++;
857 : }
858 : }
859 91 : u32 tmpsize = INVALID_VALUE_RANKSIZE;
860 91 : if ((aggregationRankSize0 != 0) && (aggregationRankSize1 != 0))
861 : {
862 24 : tmpsize = aggregationRankSize0;
863 : }
864 : else
865 : {
866 67 : tmpsize = iter->second.size();
867 : }
868 91 : size = size > tmpsize ? tmpsize : size;
869 : }
870 91 : return size;
871 : }
872 :
873 521 : HcclResult HcclCommunicatorAttrs::SetMeshAggregationRankSize(u32 size)
874 : {
875 521 : HCCL_INFO("[Set][HcclCommunicatorAttrs][MeshAggregationRankSize]set MeshAggregationRankSize[%u].", size);
876 521 : meshAggregationRankSize_ = size;
877 521 : return HCCL_SUCCESS;
878 : }
879 :
880 521 : HcclResult HcclCommunicatorAttrs::CalAndSetMeshAggRankSize()
881 : {
882 521 : u32 size = INVALID_VALUE_RANKSIZE;
883 521 : if ((deviceType_ == DevType::DEV_TYPE_910B) && isDiffDeviceModule_)
884 : { // 910B 16p场景
885 0 : size = CalMeshAggRankSize(HCCL_DEVICE_NUM_EIGHT);
886 : }
887 521 : else if (deviceType_ == DevType::DEV_TYPE_910)
888 : {
889 321 : if (pairLinkInfo_[static_cast<u32>(LinkTypeInServer::HCCS_TYPE)].size() == 0)
890 : { // 标卡
891 230 : size = 1;
892 : }
893 : else
894 : { // 模组
895 91 : size = CalMeshAggRankSize(HCCL_DEVICE_NUM_FOUR);
896 : }
897 : }
898 : else
899 : { // 910B的8卡、310P 直接返回server内的size数量
900 200 : size = servRankInfo_.begin()->second.size();
901 : }
902 521 : CHK_RET(SetMeshAggregationRankSize(size));
903 521 : return HCCL_SUCCESS;
904 : }
905 :
906 34 : HcclResult HcclCommunicatorAttrs::SetWorldGroupInfo(
907 : std::unordered_map<std::string, std::map<u32, HcclIpAddress>> &phyIdNicInfoMap,
908 : std::vector<RankInfo> &worldRankInfoList, std::vector<u32> &nicRanksPort, std::vector<u32> &vnicRanksPort)
909 : {
910 34 : for (auto &ipInfo : phyIdNicInfoMap)
911 : {
912 0 : for (auto &devInfo : ipInfo.second)
913 : {
914 0 : rankDevicePhyIdNicInfoMap_[ipInfo.first][devInfo.first] = devInfo.second;
915 0 : HCCL_DEBUG("phyIdNicInfoMap print hostIp[%s] devId[%u] devIp[%s]",
916 : ipInfo.first.c_str(), devInfo.first, devInfo.second.GetReadableAddress());
917 : }
918 : }
919 :
920 34 : for (auto &rankInfo : worldRankInfoList)
921 : {
922 0 : worldRankInfoList_.push_back(rankInfo);
923 : }
924 :
925 34 : for (auto &port : nicRanksPort)
926 : {
927 0 : nicRanksPort_.push_back(port);
928 0 : HCCL_DEBUG("nicRanksPort port[%u]", port);
929 : }
930 35 : for (auto &port : vnicRanksPort)
931 : {
932 1 : vnicRanksPort_.push_back(port);
933 1 : HCCL_DEBUG("vnicRanksPort port[%u]", port);
934 : }
935 34 : return HCCL_SUCCESS;
936 : }
937 :
938 33 : HcclResult HcclCommunicatorAttrs::TransformRankList(
939 : const std::vector<RankInfo> &rankListIn, std::vector<RankInfo_t> &rankListOut)
940 : {
941 190 : for (size_t index = 0; index < rankListIn.size(); ++index)
942 : {
943 157 : RankInfo_t rankInfoTmp;
944 157 : rankInfoTmp.serverId = rankListIn[index].serverId;
945 157 : rankInfoTmp.deviceInfo.devicePhyId = rankListIn[index].devicePhyId;
946 157 : rankInfoTmp.deviceInfo.deviceType = rankListIn[index].deviceType;
947 157 : rankInfoTmp.serverIdx = rankListIn[index].serverIdx;
948 157 : rankInfoTmp.rankId = rankListIn[index].userRank;
949 157 : rankInfoTmp.hostIp = rankListIn[index].hostIp;
950 157 : rankInfoTmp.hostPort = rankListIn[index].hostPort;
951 157 : rankInfoTmp.localRank = rankListIn[index].localRank;
952 157 : rankInfoTmp.superDeviceId = rankListIn[index].superDeviceId;
953 157 : rankInfoTmp.superPodId = rankListIn[index].superPodId;
954 157 : rankInfoTmp.superPodIdx = rankListIn[index].superPodIdx;
955 157 : rankListOut.push_back(rankInfoTmp);
956 157 : }
957 33 : return HCCL_SUCCESS;
958 : }
959 :
960 722 : bool HcclCommunicatorAttrs::IsEnableRoce()
961 : {
962 : // 910B单机两种使能roce场景:1、a+x同时使用两module 2.标卡
963 722 : bool roceSwitch = IsSupportEnableRoce();
964 722 : bool isInterServerVnic = false;
965 : // 910_93超节点内节点间走HCCS通信 && Vnic建链, 不需要使能NIC
966 722 : if (useSuperPodMode_ && superPodNum_ == 1 && GetExternalInputInterHccsDisable() == false)
967 : {
968 0 : isInterServerVnic = true;
969 : }
970 722 : bool ret = (interServer_ && !isInterServerVnic) || roceSwitch;
971 722 : HCCL_INFO("IsEnableRoce ret: %d, interServer_: %d, isInterServerVnic: %d, roceSwitch: %d, "
972 : "isSingleMeshAggregation_: %u",
973 : ret, interServer_, isInterServerVnic, roceSwitch, isSingleMeshAggregation_);
974 721 : return ret;
975 : }
976 :
977 : // a+x mesh间需要同时保证ip有效和roce开关打开才能走rdma
978 6 : bool HcclCommunicatorAttrs::IsUsedRdmaLevel0AndIpInvalid()
979 : {
980 6 : u32 nicNum = devIpAddr_.size();
981 6 : bool ipInvalid = true;
982 12 : for (u32 i = 0; i < nicNum; i++)
983 : {
984 6 : if (devIpAddr_[i].IsInvalid())
985 : {
986 0 : HCCL_INFO("[Init][Nic]nic num[%u] deviceip is invalid, total nicNum[%u]", i, nicNum);
987 0 : ipInvalid = false;
988 0 : continue;
989 : }
990 : }
991 : // 机间卡数不一致场景下,IP有效情况下就走RDMA
992 : // 机间卡数一致场景下,需环境变量ROCE打开(多机环境下未对IsEnableRoce开关进行控制)且IP有效情况下走RDMA
993 6 : return ((GetExternalInputIntraRoceSwitch() != 0 || multiModuleDiffDeviceNumMode_ || isDiffDeviceType_) && ipInvalid);
994 : }
995 :
996 722 : bool HcclCommunicatorAttrs::IsSupportEnableRoce()
997 : {
998 : // 910B单机两种使能roce场景:1、a+x同时使用两module 2.标卡
999 722 : bool roceSwitch = false;
1000 722 : HCCL_INFO("[HcclCommunicator]IsSupportEnableRoce");
1001 722 : if (isDiffDeviceType_)
1002 : {
1003 0 : roceSwitch = true;
1004 : }
1005 722 : else if (deviceType_ == DevType::DEV_TYPE_910B)
1006 : {
1007 672 : roceSwitch = ((GetExternalInputIntraRoceSwitch() != 0) && (!isSingleMeshAggregation_ || isStandardCard_)) ||
1008 336 : multiModuleDiffDeviceNumMode_;
1009 : }
1010 386 : else if (deviceType_ == DevType::DEV_TYPE_910_93)
1011 : {
1012 480 : roceSwitch = multiSuperPodDiffServerNumMode_ ||
1013 240 : (multiModuleDiffDeviceNumMode_ && superPodNum_ > 1);
1014 : }
1015 : else
1016 : { // 其他单机场景为了防止用户误用roce开关
1017 146 : roceSwitch = isStandardCard_ ? GetExternalInputIntraRoceSwitch() : false;
1018 : }
1019 722 : return roceSwitch;
1020 : }
1021 :
1022 1275 : void HcclCommunicatorAttrs::GetTopoAttr(HcclTopoAttr &topoAttr)
1023 : {
1024 1275 : topoAttr.serverNum = serverNum_;
1025 1275 : topoAttr.superPodNum = superPodNum_;
1026 1275 : topoAttr.moduleNum = moduleNum_;
1027 1275 : topoAttr.deviceNumPerServer = deviceNumPerServer_;
1028 1275 : topoAttr.deviceNumPerAggregation = deviceNumPerAggregation_;
1029 1275 : topoAttr.multiModuleDiffDeviceNumMode = multiModuleDiffDeviceNumMode_;
1030 1275 : topoAttr.multiSuperPodDiffServerNumMode = multiSuperPodDiffServerNumMode_;
1031 1275 : topoAttr.multiSuperPodDiffDeviceNumMode = multiSuperPodDiffDeviceNumMode_;
1032 1275 : topoAttr.meshAggregationRankSize = meshAggregationRankSize_;
1033 1275 : topoAttr.isDiffDeviceModule = isDiffDeviceModule_;
1034 1275 : topoAttr.isDiffDeviceType = isDiffDeviceType_;
1035 1275 : topoAttr.gcdDeviceNumPerAggregation = gcdDeviceNumPerAggregation_;
1036 1275 : topoAttr.isSingleMeshAggregation = isSingleMeshAggregation_;
1037 1275 : topoAttr.isAllRankSamePlane = isAllRankSamePlane_;
1038 1275 : topoAttr.userRank = userRank_;
1039 1275 : topoAttr.realUserRank = realUserRank_;
1040 1275 : topoAttr.userRankSize = userRankSize_;
1041 1275 : topoAttr.devicePhyId = devicePhyId_;
1042 1275 : topoAttr.useSuperPodMode = useSuperPodMode_;
1043 1275 : topoAttr.deviceLogicId = deviceLogicId_;
1044 1275 : topoAttr.deviceType = deviceType_;
1045 1275 : topoAttr.isStandardCard = isStandardCard_;
1046 1275 : topoAttr.is310PDuoCard = is310PDuoCard_;
1047 1275 : topoAttr.isCommon310P3DUO = isCommon310P3DUO_;
1048 1275 : topoAttr.hccsPortNum = hccsPortNum_;
1049 1275 : topoAttr.nicList = nicList_;
1050 1275 : topoAttr.pairLinkCounter = pairLinkCounter_;
1051 1275 : topoAttr.pairLinkInfo = pairLinkInfo_;
1052 1275 : topoAttr.rankInfoList = rankInfoList_;
1053 1275 : topoAttr.isSupportRdmaLite = isSupportRdmaLite_;
1054 1275 : topoAttr.isSupportHccsAndSio = isSupportHccsAndSio_;
1055 1275 : topoAttr.localNicPort = GetLocalNicPort(NicType::DEVICE_NIC_TYPE);
1056 1275 : topoAttr.isNeedInitNic = isNeedInitNic_;
1057 1275 : topoAttr.isARSDoubleRing = isARSDoubleRing_;
1058 1275 : }
1059 :
1060 521 : void HcclCommunicatorAttrs::GetAlgoAttr(HcclAlgoAttr &algoAttr)
1061 : {
1062 521 : algoAttr.isHaveCpuRank = isHaveCpuRank_;
1063 521 : algoAttr.inlineReduceSwitchOn = inlineReduceSwitchOn_;
1064 521 : algoAttr.isUsedRdmaLevel0 = isUsedRdmaLevel0_;
1065 521 : HCCL_INFO("[CollectAlgoAttr]:isUsedRdmaLevel0:[%d]", isUsedRdmaLevel0_);
1066 521 : algoAttr.isUsedInterHccsMode = isUsedInterHccsMode_;
1067 521 : algoAttr.identifier = identifier_;
1068 521 : algoAttr.collectiveId = collectiveId_;
1069 521 : algoAttr.nicDeployment = nicDeployment_;
1070 521 : algoAttr.commWorkMode = commWorkMode_;
1071 521 : algoAttr.commAlgoConfig = algoConfigMap_;
1072 521 : }
1073 :
1074 1275 : u32 HcclCommunicatorAttrs::GetLocalNicPort(NicType nicType)
1075 : {
1076 1275 : if (nicDeployment_ == NICDeployment::NIC_DEPLOYMENT_HOST)
1077 : {
1078 0 : return GetHostPort(devicePhyId_);
1079 : }
1080 : // isUseRankPort_在ranksPort初始化时一同配置:1. 异构场景 2. 开启device侧端口配置
1081 : // groupRanksPort_为空说明此时处于全局通信域,要从ranksPort_取监听端口;否则取groupRanksPort_
1082 1275 : if (nicType == NicType::HOST_NIC_TYPE)
1083 : {
1084 0 : return GetHostPort(devicePhyId_);
1085 : }
1086 1275 : if (nicType == NicType::VNIC_TYPE && GetExternalInputNpuPortSwitch())
1087 : {
1088 : // vnic ports仅在开启device侧端口配置时单独配置
1089 0 : std::vector<u32> &ranksPorts = groupVnicRanksPort_.empty() ? vnicRanksPort_ : groupVnicRanksPort_;
1090 0 : return GetNicPort(devicePhyId_, ranksPorts, userRank_, isUseRankPort_);
1091 : }
1092 : else
1093 : {
1094 : // 1. 开启device侧端口配置时的nic port时使用ranksPorts
1095 : // 2. 异构场景使用ranksPorts
1096 : // 3. 其余场景场景isUseRankPort_应当为false,使用默认port
1097 1275 : std::vector<u32> &ranksPorts = groupNicRanksPort_.empty() ? nicRanksPort_ : groupNicRanksPort_;
1098 1275 : return GetNicPort(devicePhyId_, ranksPorts, userRank_, isUseRankPort_);
1099 : }
1100 : }
1101 : }
|