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 <condition_variable>
12 : #include "externalinput_pub.h"
13 : #include "coll_alg_param.h"
14 : #include "search_path.h"
15 : #include "calc_p2p_transport_req.h"
16 : #include "calc_hccs_plus_sio_transport_req_pub.h"
17 : #include "topo_matcher.h"
18 : namespace hccl {
19 :
20 598 : TopoMatcher::TopoMatcher(
21 : const std::vector<std::vector<std::vector<u32>>> CommPlaneRanks, const std::vector<bool> isBridgeVector,
22 : HcclTopoInfo& topoInfo, HcclAlgoInfo& algoInfo, HcclExternalEnable& externalEnable,
23 598 : std::vector<std::vector<std::vector<u32>>>& serverAndsuperPodToRank)
24 598 : : CommPlaneVector_(CommPlaneRanks),
25 598 : isBridgeVector_(isBridgeVector),
26 598 : topoInfo_(topoInfo),
27 598 : algoInfo_(algoInfo),
28 598 : externalEnable_(externalEnable),
29 598 : userRank_(topoInfo.userRank),
30 598 : serverAndsuperPodToRank_(serverAndsuperPodToRank)
31 : {
32 598 : SetRankMap();
33 598 : }
34 :
35 171 : HcclResult TopoMatcher::CalcCommPlaneInfo(
36 : const std::string& tag, const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport,
37 : TransportMemType inputMemType, TransportMemType outputMemType)
38 : {
39 171 : HcclUs startut = TIME_NOW();
40 172 : HcclResult ret = HCCL_SUCCESS;
41 172 : HCCL_INFO(
42 : "[Calc][CommPlane]tag[%s], commPlane[%d], commType[%d]", tag.c_str(), commParaInfo.commPlane,
43 : commParaInfo.commType);
44 :
45 172 : u32 subUserRankRoot = INVALID_VALUE_RANKID;
46 172 : if (commParaInfo.root != INVALID_VALUE_RANKID) {
47 8 : if (commParaInfo.commPlane == COMM_LEVEL2) {
48 0 : subUserRankRoot = GetSubRootUserRankWithSuperPod(userRank_, commParaInfo.root);
49 : } else {
50 8 : subUserRankRoot = GetSubRootUserRank(userRank_, commParaInfo.root);
51 : }
52 8 : if (subUserRankRoot == INVALID_VALUE_RANKID) {
53 0 : HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo]get sub root userrank value[%u] invalid.", subUserRankRoot);
54 0 : return HCCL_E_PARA;
55 : }
56 : }
57 :
58 172 : std::unique_ptr<CalcTransportReqBase> calcTransportReq;
59 172 : bool isAHCType = false;
60 172 : switch (commParaInfo.commType) {
61 62 : case CommType::COMM_TAG_RING_INNER:
62 : case CommType::COMM_TAG_RING_COMBINED: {
63 123 : calcTransportReq.reset(new (std::nothrow) CalcRingTransportReq(
64 124 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
65 61 : break;
66 : }
67 34 : case CommType::COMM_TAG_HALVING_DOUBLING: {
68 68 : calcTransportReq.reset(new (std::nothrow) CalcHDTransportReq(
69 68 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
70 34 : break;
71 : }
72 15 : case CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING:
73 : case CommType::COMM_TAG_WHOLE_NHR: {
74 30 : calcTransportReq.reset(new (std::nothrow) CalcNHRTransportReq(
75 30 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
76 15 : break;
77 : }
78 0 : case CommType::COMM_TAG_NONUNIFORM_HIERARCHICAL_RING_V1:
79 : case CommType::COMM_TAG_WHOLE_NHR_V1: {
80 0 : calcTransportReq.reset(new (std::nothrow) CalcNHRV1TransportReq(
81 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
82 0 : break;
83 : }
84 0 : case CommType::COMM_TAG_ASYMMETRIC_HIERARCHICAL_CONCATENATE:
85 : case CommType::COMM_TAG_WHOLE_AHC: {
86 0 : isAHCType = true;
87 0 : CHK_PRT_RET(
88 : static_cast<u32>(topoInfo_.CommPlaneSubGroupVector.size())
89 : < (static_cast<u32>(commParaInfo.commPlane) + 1)
90 : || topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane].size() == 0,
91 : HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo] CommPlaneSubGroupVector para init error."), HCCL_E_PARA);
92 0 : calcTransportReq.reset(new (std::nothrow) CalcAHCTransportReq(
93 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_,
94 0 : topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane], topoInfo_.ahcAlgOption,
95 0 : topoInfo_.isUsedRdmaMap));
96 0 : break;
97 : }
98 0 : case CommType::COMM_TAG_ASYMMETRIC_HIERARCHICAL_CONCATENATE_BROKE:
99 : case CommType::COMM_TAG_WHOLE_AHC_BROKE: {
100 0 : isAHCType = true;
101 0 : CHK_PRT_RET(
102 : static_cast<u32>(topoInfo_.CommPlaneSubGroupVector.size())
103 : < (static_cast<u32>(commParaInfo.commPlane) + 1)
104 : || topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane].size() == 0,
105 : HCCL_ERROR("[TopoMatcher][CalcCommPlaneInfo] CommPlaneSubGroupVector para init error."), HCCL_E_PARA);
106 0 : calcTransportReq.reset(new (std::nothrow) CalcAHCBrokeTransportReq(
107 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_,
108 0 : topoInfo_.CommPlaneSubGroupVector[commParaInfo.commPlane], topoInfo_.ahcAlgOption,
109 0 : topoInfo_.isUsedRdmaMap));
110 0 : break;
111 : }
112 0 : case CommType::COMM_TAG_NONUNIFORM_BRUCK:
113 : case CommType::COMM_TAG_WHOLE_NB: {
114 0 : calcTransportReq.reset(new (std::nothrow) CalcNBTransportReq(
115 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
116 0 : break;
117 : }
118 61 : case CommType::COMM_TAG_MESH: {
119 122 : calcTransportReq.reset(new (std::nothrow) CalcMeshTransportReq(
120 122 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
121 60 : break;
122 : }
123 0 : case CommType::COMM_TAG_PARTIAL_MESH_COMBINED: {
124 0 : calcTransportReq.reset(new (std::nothrow) CalcPartialMeshTransportReq(
125 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
126 0 : break;
127 : }
128 0 : case CommType::COMM_TAG_P2P: {
129 0 : calcTransportReq.reset(new (std::nothrow) CalcP2PTransportReq(
130 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
131 0 : break;
132 : }
133 0 : case CommType::COMM_TAG_HCCS_PLUS_SIO: {
134 0 : calcTransportReq.reset(new (std::nothrow) CalcHccsPlusSioTransportReq(
135 0 : CommPlaneVector_[commParaInfo.commPlane], isBridgeVector_, userRank_));
136 0 : break;
137 : }
138 0 : default: {
139 0 : HCCL_ERROR("[Calc][CommPlane]commType[%d] is invalid", commParaInfo.commType);
140 0 : return HCCL_E_PARA;
141 : }
142 : }
143 :
144 170 : CHK_SMART_PTR_NULL(calcTransportReq);
145 170 : ret = calcTransportReq->CalcTransportRequest(
146 : tag, inputMemType, outputMemType, commParaInfo, commTransport, subUserRankRoot);
147 : // AHC内部单独刷新,外部不需要再刷新
148 172 : if (!isAHCType) {
149 172 : CHK_RET(SetIsUsedRdma(commParaInfo, commTransport));
150 : }
151 172 : CHK_RET(GetRankMap(commParaInfo, commTransport));
152 :
153 168 : CHK_PRT_RET(
154 : ret != HCCL_SUCCESS,
155 : HCCL_ERROR(
156 : "[Calc][CommPlane]failed, tag[%s], commPlane[%d], commType[%d]", tag.c_str(), commParaInfo.commPlane,
157 : commParaInfo.commType),
158 : ret);
159 :
160 168 : HCCL_INFO(
161 : "complete commPlane[%d] commType[%d] Calculation, Time:%lld us", commParaInfo.commPlane, commParaInfo.commType,
162 : DURATION_US(TIME_NOW() - startut));
163 169 : return HCCL_SUCCESS;
164 169 : }
165 :
166 172 : HcclResult TopoMatcher::GetRankMap(const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport)
167 : {
168 172 : u32 ringSize = commTransport.size();
169 :
170 483 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
171 316 : SingleSubCommTransport& subCommTransport = commTransport[ringIndex];
172 : // 有建链诉求,则记录从userRank到subCommRank 和 从subCommRank到userRank的映射
173 316 : if (subCommTransport.transportRequests.size() != 0) {
174 208 : if (commParaInfo.commType == CommType::COMM_TAG_PARTIAL_MESH_COMBINED
175 208 : || commParaInfo.commType == CommType::COMM_TAG_HCCS_PLUS_SIO) {
176 0 : CHK_RET(GetSub2UserRankMap(commParaInfo.commPlane, 0, subCommTransport.subCommRank2UserRank));
177 0 : CHK_RET(GetUserRank2SubMap(commParaInfo.commPlane, 0, subCommTransport.userRank2subCommRank));
178 0 : } else {
179 208 : CHK_RET(GetSub2UserRankMap(commParaInfo.commPlane, ringIndex, subCommTransport.subCommRank2UserRank));
180 207 : CHK_RET(GetUserRank2SubMap(commParaInfo.commPlane, ringIndex, subCommTransport.userRank2subCommRank));
181 : }
182 : }
183 : }
184 167 : return HCCL_SUCCESS;
185 : }
186 :
187 598 : HcclResult TopoMatcher::SetRankMap()
188 : {
189 : // 构建由UserRank到子通信域的映射
190 598 : CHK_PRT_RET(
191 : CommPlaneVector_.size() > COMM_LEVEL_RESERVED,
192 : HCCL_ERROR(
193 : "[TopoMatcher][SetRankMap]CommPlaneVector.size[%u] > COMM_LEVEL_RESERVED[%u]", CommPlaneVector_.size(),
194 : COMM_LEVEL_RESERVED),
195 : HCCL_E_PARA);
196 598 : subCommRank2UserRank_.resize(static_cast<u32>(COMM_LEVEL_RESERVED));
197 598 : userRank2subCommRank_.resize(static_cast<u32>(COMM_LEVEL_RESERVED));
198 9065 : for (u32 levelIndex = 0; levelIndex < CommPlaneVector_.size(); levelIndex++) {
199 8467 : u32 ringSize = CommPlaneVector_[levelIndex].size();
200 8467 : subCommRank2UserRank_[levelIndex].resize(ringSize);
201 8467 : userRank2subCommRank_[levelIndex].resize(ringSize);
202 14288 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
203 5821 : u32 rankSize = CommPlaneVector_[levelIndex][ringIndex].size();
204 17577 : for (u32 rankIndex = 0; rankIndex < rankSize; rankIndex++) {
205 11756 : u32 userRank = CommPlaneVector_[levelIndex][ringIndex][rankIndex];
206 11756 : subCommRank2UserRank_[levelIndex][ringIndex][rankIndex] = userRank;
207 11756 : userRank2subCommRank_[levelIndex][ringIndex][userRank] = rankIndex;
208 : }
209 : }
210 : }
211 598 : return HCCL_SUCCESS;
212 : }
213 :
214 172 : HcclResult TopoMatcher::GetIsUsedRdma(const CommParaInfo& commParaInfo, bool& isUsedRdma)
215 : {
216 172 : std::vector<std::vector<u32>> commP2PPlaneVec;
217 172 : if (commParaInfo.commType == CommType::COMM_TAG_P2P) {
218 : // P2P只需要判断两张卡之间的连接关系
219 0 : bool invalidcheck = (topoInfo_.isUsedRdmaMap.size() <= topoInfo_.userRank)
220 0 : || (topoInfo_.isUsedRdmaMap.size() <= commParaInfo.peerUserRank);
221 0 : CHK_PRT_RET(
222 : invalidcheck,
223 : HCCL_ERROR(
224 : "[GetIsUsedRdma]dstUserRank[%u] or userRank[%u] is bigger than "
225 : "rankVector size[%u]",
226 : commParaInfo.peerUserRank, topoInfo_.userRank, topoInfo_.isUsedRdmaMap.size()),
227 : HCCL_E_PARA);
228 :
229 0 : std::vector<u32> commP2PRankVec;
230 0 : commP2PRankVec.push_back(topoInfo_.userRank);
231 0 : commP2PRankVec.push_back(commParaInfo.peerUserRank);
232 0 : commP2PPlaneVec.push_back(commP2PRankVec);
233 0 : }
234 :
235 172 : std::vector<std::vector<u32>>& commPlaneVec = (commParaInfo.commType == CommType::COMM_TAG_P2P) ?
236 : commP2PPlaneVec :
237 172 : CommPlaneVector_[commParaInfo.commPlane];
238 :
239 436 : for (const std::vector<u32>& commPlane : commPlaneVec) {
240 1071 : for (const u32 dstRank : commPlane) {
241 763 : if (topoInfo_.isUsedRdmaMap[dstRank]) {
242 50 : isUsedRdma = true;
243 50 : return HCCL_SUCCESS;
244 : }
245 : }
246 : }
247 117 : isUsedRdma = false;
248 117 : return HCCL_SUCCESS;
249 167 : }
250 :
251 : HcclResult
252 172 : TopoMatcher::SetIsUsedRdma(const CommParaInfo& commParaInfo, std::vector<SingleSubCommTransport>& commTransport)
253 : {
254 172 : bool isUsedRdma = false;
255 172 : CHK_RET(GetIsUsedRdma(commParaInfo, isUsedRdma));
256 167 : u32 ringSize = commTransport.size();
257 :
258 463 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
259 294 : SingleSubCommTransport& subCommTransport = commTransport[ringIndex];
260 902 : for (auto& transportRequest : subCommTransport.transportRequests) {
261 609 : transportRequest.isUsedRdma = isUsedRdma;
262 : }
263 : }
264 169 : HCCL_INFO("[TopoMatcher][SetIsUsedRdma] commPlane[%d] isUsedRdma[%d]", commParaInfo.commPlane, isUsedRdma);
265 172 : return HCCL_SUCCESS;
266 : }
267 :
268 208 : HcclResult TopoMatcher::GetSub2UserRankMap(CommPlane commPlane, u32 ringIndex, std::map<u32, u32>& subCommRank2UserRank)
269 : {
270 208 : subCommRank2UserRank = subCommRank2UserRank_[static_cast<u32>(commPlane)][ringIndex];
271 207 : return HCCL_SUCCESS;
272 : }
273 :
274 208 : HcclResult TopoMatcher::GetUserRank2SubMap(CommPlane commPlane, u32 ringIndex, std::map<u32, u32>& userRank2subCommRank)
275 : {
276 208 : userRank2subCommRank = userRank2subCommRank_[static_cast<u32>(commPlane)][ringIndex];
277 204 : return HCCL_SUCCESS;
278 : }
279 :
280 169 : HcclTopoInfo TopoMatcher::GetTopoInfo() { return topoInfo_; }
281 :
282 183 : HcclAlgoInfo TopoMatcher::GetAlgoInfo() { return algoInfo_; }
283 :
284 0 : u32 TopoMatcher::GetExternalInputHcclEnableFfts() { return externalEnable_.enableFfts; }
285 :
286 64 : u32 TopoMatcher::GetExternalInputHcclDeterministic() { return externalEnable_.deterministic; }
287 :
288 0 : u32 TopoMatcher::GetExternalInputIntraRoceSwitch() { return externalEnable_.intraRoceSwitch; }
289 :
290 0 : u32 TopoMatcher::GetExternalInputHcclDumpDebug() { return externalEnable_.dumpDebug; }
291 :
292 4 : u32 TopoMatcher::GetExternalInputInterHccsDisable() { return externalEnable_.interHccsDisable; }
293 :
294 138 : bool TopoMatcher::GetARSFlag()
295 : {
296 276 : bool isARSTrue = (topoInfo_.deviceType == DevType::DEV_TYPE_910_93)
297 135 : && static_cast<bool>(topoInfo_.multiModuleDiffDeviceNumMode)
298 273 : && !static_cast<bool>(topoInfo_.multiSuperPodDiffDeviceNumMode);
299 138 : return isARSTrue;
300 : }
301 :
302 0 : HcclResult TopoMatcher::EditCommPlaneVector(CommPlane commPlane, std::vector<std::vector<u32>> commVector)
303 : {
304 0 : CommPlaneVector_[commPlane] = commVector;
305 0 : return HCCL_SUCCESS;
306 : }
307 :
308 0 : std::vector<std::vector<u32>> TopoMatcher::GetCommPlaneRanks(CommPlane commPlane)
309 : {
310 0 : return CommPlaneVector_[commPlane];
311 : }
312 :
313 0 : bool CheckRankNeighbors(const std::vector<u32>& nicList)
314 : {
315 : // 组成ROH环路必须偶数个,且2节点不能组成双环?
316 0 : if (nicList.size() % 2 != 0 || nicList.size() < HCCL_DEVICE_NUM_FOUR) {
317 0 : return false;
318 : }
319 :
320 0 : std::vector<u32> tmpNicList(nicList);
321 0 : std::sort(tmpNicList.begin(), tmpNicList.end());
322 0 : u32 halfNum = 2;
323 0 : for (u32 i = 0; i < tmpNicList.size() / halfNum; i++) {
324 0 : auto nicIndex = i * halfNum;
325 : // 检查相邻下标的节点,devID是否相邻
326 0 : if (tmpNicList[nicIndex] + 1 != tmpNicList[nicIndex + 1]) {
327 0 : return false;
328 : }
329 : }
330 :
331 0 : return true;
332 0 : }
333 :
334 : // 适配ROH平面网段隔离,奇数rank互通,偶数rank互通,奇偶不通
335 0 : bool TopoMatcher::CheckSdmaWithRohTopo(const std::vector<u32>& nicList, std::vector<u32>& topoList)
336 : {
337 0 : std::vector<u32> tmpNicList(nicList);
338 0 : std::sort(tmpNicList.begin(), tmpNicList.end());
339 0 : SearchPath searchPath;
340 0 : topoList = searchPath.Search(tmpNicList);
341 0 : if (topoList.empty()) {
342 0 : return false;
343 : }
344 0 : return true;
345 0 : }
346 :
347 0 : u32 TopoMatcher::GetSubCollectiveRank(const std::vector<u32>& vecPara) const
348 : {
349 : // 在vecPara数据中,查询本user rank,查询到的vec下标就是rank值
350 0 : u32 tmpRank = INVALID_VALUE_RANKID;
351 :
352 0 : HCCL_DEBUG("[TopoMatcher]GetSubCollectiveRank begins.");
353 0 : for (u32 rankIndex = 0; rankIndex < vecPara.size(); rankIndex++) {
354 0 : if (userRank_ == vecPara[rankIndex]) {
355 0 : tmpRank = rankIndex;
356 0 : break;
357 : }
358 : }
359 :
360 0 : return tmpRank;
361 : }
362 :
363 0 : HcclResult TopoMatcher::GetSubRootForScatter(const u32 root, u32& subRoot)
364 : {
365 : // 通过root找到ringIndex, 通过userRank找到level1中的rank
366 0 : u32 planeIdx = INVALID_VALUE_RANKID;
367 0 : u32 ringSize = CommPlaneVector_[COMM_LEVEL1_INDEX].size();
368 :
369 0 : CHK_PRT_RET(ringSize == 0, HCCL_ERROR("[GET][GetSubRootForScatter]bridgeRankVector size is zero."), HCCL_E_PARA);
370 0 : CHK_PRT_RET(
371 : isBridgeVector_.size() != ringSize,
372 : HCCL_ERROR("[GET][GetSubRootForScatter]bridgeRankVector is not equal ringSize."), HCCL_E_PARA);
373 :
374 0 : u32 rank = INVALID_VALUE_RANKID;
375 0 : for (u32 ringIndex = 0; ringIndex < ringSize; ringIndex++) {
376 0 : if (isBridgeVector_[ringIndex]) {
377 0 : rank = GetSubCollectiveRank(
378 0 : CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex]); // 确定userRank在level1中的rank号
379 : }
380 0 : for (u32 idx = 0; idx < CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex].size(); idx++) {
381 0 : if (root == CommPlaneVector_[COMM_LEVEL1_INDEX][ringIndex][idx]) { // 获取root所在的平面
382 0 : planeIdx = ringIndex;
383 : }
384 : }
385 : }
386 0 : CHK_PRT_RET(
387 : rank == INVALID_VALUE_RANKID, HCCL_ERROR("[GET][GetSubRootForScatter]get rankId in level1 failed."),
388 : HCCL_E_PARA);
389 0 : CHK_PRT_RET(
390 : planeIdx == INVALID_VALUE_RANKID,
391 : HCCL_ERROR("[GET][GetSubRootForScatter]get root[%u] planeIdx[%u] failed.", root, planeIdx), HCCL_E_PARA);
392 0 : subRoot = CommPlaneVector_[COMM_LEVEL1_INDEX][planeIdx][rank];
393 0 : HCCL_DEBUG("[GetSubRootForScatter] userRank_:[%u] subRoot:[%u]", userRank_, subRoot);
394 0 : return HCCL_SUCCESS;
395 : }
396 :
397 8 : u32 TopoMatcher::GetSubRootUserRank(const u32 userRank, const u32 rootUserRank)
398 : {
399 8 : u32 tmpUserRank = INVALID_VALUE_RANKID;
400 :
401 8 : u32 serverIdx = INVALID_VALUE_RANKID;
402 16 : for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
403 8 : for (u32 j = 0; j < serverAndsuperPodToRank_[0][i].size(); j++) {
404 8 : if (serverAndsuperPodToRank_[0][i][j] == rootUserRank) {
405 8 : serverIdx = i;
406 8 : break;
407 : }
408 : }
409 : }
410 8 : u32 rankIdx = INVALID_VALUE_RANKID;
411 15 : for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
412 20 : for (u32 j = 0; j < serverAndsuperPodToRank_[0][i].size(); j++) {
413 19 : if (serverAndsuperPodToRank_[0][i][j] == userRank) {
414 7 : rankIdx = j;
415 7 : break;
416 : }
417 : }
418 : }
419 :
420 7 : if (serverIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
421 7 : tmpUserRank = serverAndsuperPodToRank_[0][serverIdx][rankIdx];
422 : }
423 7 : HCCL_DEBUG(
424 : "[GetSubRootUserRank] userRank:[%u] rootUserRank:[%u], tmpUserRank[%u]", userRank, rootUserRank, tmpUserRank);
425 8 : return tmpUserRank;
426 : }
427 :
428 0 : u32 TopoMatcher::GetSubRootUserRankWithSuperPod(const u32 userRank, const u32 rootUserRank)
429 : {
430 0 : u32 tmpUserRank = INVALID_VALUE_RANKID;
431 :
432 0 : u32 superPodIdx = INVALID_VALUE_RANKID;
433 0 : for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
434 0 : for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
435 0 : if (serverAndsuperPodToRank_[1][i][j] == rootUserRank) {
436 0 : superPodIdx = i;
437 0 : break;
438 : }
439 : }
440 : }
441 0 : u32 rankIdx = INVALID_VALUE_RANKID;
442 0 : for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
443 0 : for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
444 0 : if (serverAndsuperPodToRank_[1][i][j] == userRank) {
445 0 : rankIdx = j;
446 0 : break;
447 : }
448 : }
449 : }
450 :
451 0 : if (superPodIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
452 0 : tmpUserRank = serverAndsuperPodToRank_[1][superPodIdx][rankIdx];
453 : }
454 0 : HCCL_DEBUG(
455 : "GetSubRootUserRankWithSuperPod userRank[%u], rootUserRank[%u], ret[%u]", userRank, rootUserRank, tmpUserRank);
456 0 : return tmpUserRank;
457 : }
458 :
459 0 : u32 TopoMatcher::GetSubRootWithSuperPod(const u32 userRank, const u32 rootUserRank)
460 : {
461 0 : u32 tmpUserRank = INVALID_VALUE_RANKID;
462 :
463 0 : u32 superPodIdx = INVALID_VALUE_RANKID;
464 0 : for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
465 0 : for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
466 0 : if (serverAndsuperPodToRank_[1][i][j] == userRank) {
467 0 : superPodIdx = i;
468 0 : break;
469 : }
470 : }
471 : }
472 0 : u32 rankIdx = INVALID_VALUE_RANKID;
473 0 : for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
474 0 : for (u32 j = 0; j < serverAndsuperPodToRank_[1][i].size(); j++) {
475 0 : if (serverAndsuperPodToRank_[1][i][j] == rootUserRank) {
476 0 : rankIdx = j;
477 0 : break;
478 : }
479 : }
480 : }
481 :
482 0 : if (superPodIdx != INVALID_VALUE_RANKID && rankIdx != INVALID_VALUE_RANKID) {
483 0 : tmpUserRank = serverAndsuperPodToRank_[1][superPodIdx][rankIdx];
484 : }
485 0 : HCCL_DEBUG("GetSubRootWithSuperPod superPodIdx[%u], rankIdx[%u], ret[%u]", superPodIdx, rankIdx, tmpUserRank);
486 0 : return tmpUserRank;
487 : }
488 :
489 1 : HcclResult TopoMatcher::GetLocalSuperPodRankSize(const u32 userRank, u32& devNumInlocalPod, u32& rankIdxInPod)
490 : {
491 1 : u32 superPodIdx = INVALID_VALUE_RANKID;
492 3 : for (u32 i = 0; i < serverAndsuperPodToRank_[1].size(); i++) {
493 2 : std::vector<u32> userRankInSuperPod(serverAndsuperPodToRank_[1][i]);
494 2 : std::sort(userRankInSuperPod.begin(), userRankInSuperPod.end());
495 14 : for (u32 j = 0; j < userRankInSuperPod.size(); j++) {
496 13 : if (userRankInSuperPod[j] == userRank) {
497 1 : superPodIdx = i;
498 1 : rankIdxInPod = j;
499 1 : break;
500 : }
501 : }
502 2 : }
503 1 : if (superPodIdx == INVALID_VALUE_RANKID || rankIdxInPod == INVALID_VALUE_RANKID) {
504 0 : HCCL_ERROR("[GET][GetLocalSuperPodRankSize]get rankId in level1 failed.");
505 0 : return HCCL_E_PARA;
506 : }
507 1 : devNumInlocalPod = serverAndsuperPodToRank_[1][superPodIdx].size();
508 1 : HCCL_DEBUG(
509 : "[GetLocalSuperPodRankSize] userRank[%u], superPodIdx[%u], rankIdxInPod[%u] devNumInlocalPod[%u]", userRank,
510 : superPodIdx, rankIdxInPod, devNumInlocalPod);
511 1 : return HCCL_SUCCESS;
512 : }
513 :
514 1 : HcclResult TopoMatcher::GetLocalServerRankSize(const u32 userRank, u32& devNumInlocalServer, u32& rankIdxInServer)
515 : {
516 1 : u32 serverIdx = INVALID_VALUE_RANKID;
517 5 : for (u32 i = 0; i < serverAndsuperPodToRank_[0].size(); i++) {
518 4 : std::vector<u32> userRankInServer(serverAndsuperPodToRank_[0][i]);
519 4 : std::sort(userRankInServer.begin(), userRankInServer.end());
520 16 : for (u32 j = 0; j < userRankInServer.size(); j++) {
521 13 : if (userRankInServer[j] == userRank) {
522 1 : serverIdx = i;
523 1 : rankIdxInServer = j;
524 1 : break;
525 : }
526 : }
527 4 : }
528 1 : if (serverIdx == INVALID_VALUE_RANKID || rankIdxInServer == INVALID_VALUE_RANKID) {
529 0 : HCCL_ERROR("[GET][GetLocalServerRankSize]get rankId in level1 failed.");
530 0 : return HCCL_E_PARA;
531 : }
532 1 : devNumInlocalServer = serverAndsuperPodToRank_[0][serverIdx].size();
533 1 : HCCL_DEBUG(
534 : "[GetLocalServerRankSize] userRank[%u], serverIdx[%u], rankIdxInServer[%u] devNumInlocalServer[%u]", userRank,
535 : serverIdx, rankIdxInServer, devNumInlocalServer);
536 1 : return HCCL_SUCCESS;
537 : }
538 :
539 235 : HcclResult TopoMatcher::SetDeterministicConfig(const u8 deterministic)
540 : {
541 235 : if (deterministic > DETERMINISTIC_STRICT) {
542 0 : HCCL_ERROR("[SetDeterministicConfig] deterministic should be 0, 1 or 2.");
543 0 : return HCCL_E_PARA;
544 : }
545 235 : HCCL_INFO("[SetDeterministicConfig]deterministic is set to [%d]", deterministic);
546 235 : externalEnable_.deterministic = deterministic;
547 235 : return HCCL_SUCCESS;
548 : }
549 :
550 246 : u8 TopoMatcher::GetDeterministicConfig() const { return externalEnable_.deterministic; }
551 :
552 235 : HcclResult TopoMatcher::SetOnlyAivModeConfig(const bool isOnlyAiv)
553 : {
554 235 : if (isOnlyAiv) {
555 0 : externalEnable_.aivMode = isOnlyAiv;
556 0 : externalEnable_.isOnlyAiv = isOnlyAiv;
557 : }
558 235 : HCCL_RUN_INFO("[SetOnlyAivModeConfig]isOnlyAiv is set to [%d]", isOnlyAiv);
559 235 : return HCCL_SUCCESS;
560 : }
561 :
562 137 : bool TopoMatcher::GetIsOnlyAivConfig() const { return externalEnable_.isOnlyAiv; }
563 :
564 236 : HcclResult TopoMatcher::SetAivModeConfig(const bool aivMode)
565 : {
566 236 : HCCL_INFO("[SetAivMode]AivMode is set to [%d]", aivMode);
567 236 : externalEnable_.aivMode = aivMode;
568 236 : return HCCL_SUCCESS;
569 : }
570 :
571 179 : bool TopoMatcher::GetAivModeConfig() const { return externalEnable_.aivMode; }
572 :
573 235 : HcclResult TopoMatcher::SetAicpuUnfoldConfig(const bool aicpuUnfold)
574 : {
575 235 : HCCL_INFO("[SetAicpuMode]Aicpu is set to [%d]", aicpuUnfold);
576 235 : externalEnable_.aicpuUnfold = aicpuUnfold;
577 235 : return HCCL_SUCCESS;
578 : }
579 :
580 0 : bool TopoMatcher::GetAicpuUnfoldConfig() const { return externalEnable_.aicpuUnfold; }
581 :
582 235 : HcclResult TopoMatcher::SetExecTimeOutConfig(const s32 execTimeOut)
583 : {
584 235 : HCCL_INFO("[SetExecTimeOutConfig]execTimeOut is set to [%d s]", execTimeOut);
585 235 : externalEnable_.execTimeOut = execTimeOut;
586 235 : return HCCL_SUCCESS;
587 : }
588 :
589 235 : HcclResult TopoMatcher::SetAlgoConfig(const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoMap)
590 : {
591 24675 : for (u32 opType = 0; opType < static_cast<u32>(HcclCMDType::HCCL_CMD_MAX); opType++) {
592 24440 : externalEnable_.algoConfig[static_cast<HcclCMDType>(opType)] = algoMap.at(static_cast<HcclCMDType>(opType));
593 : }
594 235 : return HCCL_SUCCESS;
595 : }
596 :
597 5 : s32 TopoMatcher::GetExecTimeOutConfig() const { return externalEnable_.execTimeOut; }
598 :
599 10 : std::vector<HcclAlgoType> TopoMatcher::GetAlgoConfig(HcclCMDType opType) { return externalEnable_.algoConfig[opType]; }
600 :
601 : HcclResult
602 9 : TopoMatcher::GetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>>& globalSubGroups)
603 : {
604 9 : globalSubGroups = topoInfo_.CommPlaneSubGroupVector[level];
605 9 : CHK_PRT_RET(
606 : globalSubGroups.size() == 0, HCCL_ERROR("[TopoMatcher][GetGlobalSubGroups] globalSubGroups para init error."),
607 : HCCL_E_PARA);
608 9 : return HCCL_SUCCESS;
609 : }
610 :
611 : HcclResult
612 0 : TopoMatcher::SetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>>& globalSubGroups)
613 : {
614 0 : topoInfo_.CommPlaneSubGroupVector[level] = globalSubGroups;
615 0 : return HCCL_SUCCESS;
616 : }
617 :
618 0 : HcclResult TopoMatcher::GetCommPlaneSubGroupVector(
619 : std::vector<std::vector<std::vector<std::vector<u32>>>>& commPlaneSubGroupVector)
620 : {
621 0 : commPlaneSubGroupVector = topoInfo_.CommPlaneSubGroupVector;
622 0 : return HCCL_SUCCESS;
623 : }
624 :
625 0 : HcclResult TopoMatcher::SetCommPlaneSubGroupVector(
626 : std::vector<std::vector<std::vector<std::vector<u32>>>>& commPlaneSubGroupVector)
627 : {
628 0 : topoInfo_.CommPlaneSubGroupVector = commPlaneSubGroupVector;
629 0 : return HCCL_SUCCESS;
630 : }
631 :
632 9 : void TopoMatcher::GetAHCAlgOption(std::map<AHCConcOpType, TemplateType>& ahcAlgOption)
633 : {
634 9 : ahcAlgOption = topoInfo_.ahcAlgOption;
635 9 : }
636 :
637 9 : void TopoMatcher::SetAHCAlgOption(std::map<AHCConcOpType, TemplateType>& ahcAlgOption)
638 : {
639 9 : topoInfo_.ahcAlgOption = ahcAlgOption;
640 9 : }
641 :
642 : } // namespace hccl
|