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 : #ifndef TOPO_MATCHER_H
12 : #define TOPO_MATCHER_H
13 :
14 : #include <condition_variable>
15 : #include "dispatcher.h"
16 : #include "comm_base_pub.h"
17 : #include "externalinput_pub.h"
18 : #include "coll_alg_param.h"
19 : #include "comm_factory_pub.h"
20 : #include "hccl_common.h"
21 : #include "calc_impl.h"
22 : #include "alg_env_config.h"
23 :
24 : namespace hccl {
25 : constexpr u32 COMM_LEVEL1_INDEX = COMM_LEVEL1;
26 : using HcclAlgoInfo = struct HcclAlgoInfoDef {
27 : bool inlineReduceSwitchOn; // 收到数量时同时完成Reduce计算
28 : std::string identifier;
29 : bool isUsedRdmaLevel0;
30 : bool isSupportAtomicWrite;
31 :
32 614 : HcclAlgoInfoDef()
33 614 : : inlineReduceSwitchOn(true),
34 1228 : identifier(""),
35 614 : isUsedRdmaLevel0(false),
36 614 : isSupportAtomicWrite(false)
37 614 : {}
38 : };
39 :
40 : struct HcclTopoInfo {
41 : u32 userRank; // 通信域 RankID
42 : u32 userRankSize; // 通信域的 Rank数量
43 : u32 devicePhyId;
44 : s32 deviceLogicId;
45 : std::vector<u32> nicList;
46 : bool isSingleMeshAggregation;
47 : u32 deviceNumPerAggregation; // 每个module中的Device数量
48 : u32 superPodNum; // 集群中总的超节点数
49 : DevType deviceType;
50 : TopoType topoType;
51 : bool is310P3Common;
52 : u32 serverNum;
53 : u32 meshAggregationRankSize;
54 : u32 multiModuleDiffDeviceNumMode;
55 : u32 multiSuperPodDiffServerNumMode;
56 : u32 multiSuperPodDiffDeviceNumMode;
57 : bool isDiffDeviceType;
58 : u32 gcdDeviceNumPerAggregation;
59 : u32 realUserRank;
60 : bool isDiffDeviceModule;
61 : u32 moduleNum;
62 : bool useSuperPodMode;
63 : std::unordered_map<u32, bool> isUsedRdmaMap;
64 : std::unordered_map<u32, u32> pairLinkCounter; // server内所有device间的链路类型计数
65 : bool isARSDoubleRing;
66 :
67 : std::vector<std::vector<std::vector<std::vector<u32>>>> CommPlaneSubGroupVector; // 保存所有 level 的通信分组信息
68 : std::map<AHCConcOpType, TemplateType> ahcAlgOption;
69 :
70 635 : HcclTopoInfo()
71 635 : : userRank(0),
72 635 : userRankSize(0),
73 635 : devicePhyId(0),
74 635 : deviceLogicId(0),
75 1270 : nicList(0),
76 635 : isSingleMeshAggregation(false),
77 635 : deviceNumPerAggregation(0),
78 635 : superPodNum(0),
79 635 : deviceType(DevType::DEV_TYPE_COUNT),
80 635 : topoType(TopoType::TOPO_TYPE_COMMON),
81 635 : is310P3Common(false),
82 635 : serverNum(0),
83 635 : meshAggregationRankSize(0),
84 635 : multiModuleDiffDeviceNumMode(0),
85 635 : multiSuperPodDiffServerNumMode(0),
86 635 : multiSuperPodDiffDeviceNumMode(0),
87 635 : isDiffDeviceType(false),
88 635 : realUserRank(0),
89 635 : isDiffDeviceModule(false),
90 635 : moduleNum(0),
91 635 : useSuperPodMode(false),
92 635 : isARSDoubleRing(true)
93 635 : {}
94 : };
95 :
96 : using HcclExternalEnable = struct HcclExternalEnableDef {
97 : u32 enableFfts;
98 : u32 deterministic;
99 : u32 intraRoceSwitch;
100 : u32 dumpDebug;
101 : u32 interHccsDisable;
102 : bool aivMode;
103 : bool aicpuUnfold;
104 : bool isOnlyAiv;
105 : s32 execTimeOut;
106 : std::map<HcclCMDType, std::vector<HcclAlgoType>> algoConfig;
107 :
108 614 : HcclExternalEnableDef()
109 614 : : enableFfts(1),
110 614 : deterministic(0),
111 614 : intraRoceSwitch(0),
112 614 : dumpDebug(0),
113 614 : interHccsDisable(0),
114 614 : aivMode(false),
115 614 : aicpuUnfold(false),
116 614 : isOnlyAiv(false),
117 614 : execTimeOut(GetInternalExecTimeOut())
118 : {
119 614 : SetDefaultAlgo();
120 614 : }
121 614 : void SetDefaultAlgo()
122 : {
123 64470 : for (u32 opType = 0; opType < static_cast<u32>(HcclCMDType::HCCL_CMD_MAX); opType++) {
124 63856 : algoConfig[static_cast<HcclCMDType>(opType)] = GetExternalInputHcclAlgoConfig(static_cast<HcclCMDType>(opType));
125 : }
126 614 : }
127 : };
128 :
129 : bool CheckRankNeighbors(const std::vector<u32> &nicList);
130 : bool CheckSdmaWithRohTopo(const std::vector<u32> &nicList, std::vector<u32> &topoList);
131 :
132 : class TopoMatcher {
133 : public:
134 : explicit TopoMatcher(const std::vector<std::vector<std::vector<u32>>> CommPlaneRanks,
135 : const std::vector<bool> isBridgeVector,
136 : HcclTopoInfo& topoInfo,
137 : HcclAlgoInfo& algoInfo,
138 : HcclExternalEnable& externalEnable,
139 : std::vector<std::vector<std::vector<u32>>>& serverAndsuperPodToRank);
140 : HcclResult CalcCommPlaneInfo(const std::string &tag, const CommParaInfo &commParaInfo,
141 : std::vector<SingleSubCommTransport> &commTransport, TransportMemType inputMemType,
142 : TransportMemType outputMemType);
143 : HcclTopoInfo GetTopoInfo();
144 : HcclAlgoInfo GetAlgoInfo();
145 : u32 GetExternalInputHcclEnableFfts();
146 : u32 GetExternalInputHcclDeterministic();
147 : u32 GetExternalInputIntraRoceSwitch();
148 : u32 GetExternalInputHcclDumpDebug();
149 : u32 GetExternalInputInterHccsDisable();
150 : bool GetARSFlag();
151 : bool CheckSdmaWithRohTopo(const std::vector<u32> &nicList, std::vector<u32> &topoList);
152 : HcclResult GetSubRootForScatter(const u32 root, u32& subRoot);
153 : u32 GetSubRootUserRank(const u32 userRank, const u32 rootUserRank);
154 : u32 GetSubRootUserRankWithSuperPod(const u32 userRank, const u32 rootUserRank);
155 : u32 GetSubRootWithSuperPod(const u32 userRank, const u32 rootUserRank);
156 : HcclResult GetLocalSuperPodRankSize(const u32 userRank, u32& devNumInlocalPod, u32& rankIdxInPod);
157 : HcclResult GetLocalServerRankSize(const u32 userRank, u32& devNumInlocalServer, u32& rankIdxInServer);
158 : HcclResult SetDeterministicConfig(const u8 deterministic);
159 : HcclResult SetAivModeConfig(const bool aivMode);
160 : HcclResult SetOnlyAivModeConfig(const bool isOnlyAiv);
161 : bool GetIsOnlyAivConfig() const;
162 : HcclResult SetAicpuUnfoldConfig(const bool aicpuUnfold);
163 : HcclResult SetExecTimeOutConfig(const s32 execTimeOut);
164 : HcclResult SetAlgoConfig(const std::map<HcclCMDType, std::vector<HcclAlgoType>>& algoMap);
165 : u8 GetDeterministicConfig() const;
166 : bool GetAivModeConfig() const;
167 : bool GetAicpuUnfoldConfig() const;
168 : s32 GetExecTimeOutConfig() const;
169 : std::vector<HcclAlgoType> GetAlgoConfig(HcclCMDType opType = HcclCMDType::HCCL_CMD_ALL);
170 : HcclResult GetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>> &globalSubGroups);
171 : HcclResult SetGlobalSubGroups(const CommPlane level, std::vector<std::vector<std::vector<u32>>> &globalSubGroups);
172 : HcclResult GetCommPlaneSubGroupVector(std::vector<std::vector<std::vector<std::vector<u32>>>> &commPlaneSubGroupVector);
173 : HcclResult SetCommPlaneSubGroupVector(std::vector<std::vector<std::vector<std::vector<u32>>>> &commPlaneSubGroupVector);
174 : void GetAHCAlgOption(std::map<AHCConcOpType, TemplateType> &ahcAlgOption);
175 : void SetAHCAlgOption(std::map<AHCConcOpType, TemplateType> &ahcAlgOption);
176 : std::vector<std::vector<u32>> GetCommPlaneRanks(CommPlane commPlane);
177 : HcclResult SetRankMap();
178 : HcclResult EditCommPlaneVector(CommPlane commPlane, std::vector<std::vector<u32>> commVector);
179 : protected:
180 :
181 : private:
182 :
183 : HcclResult GetRankMap(const CommParaInfo &commParaInfo, std::vector<SingleSubCommTransport> &commTransport);
184 :
185 : HcclResult SetIsUsedRdma(const CommParaInfo &commParaInfo, std::vector<SingleSubCommTransport> &commTransport);
186 :
187 : HcclResult GetSub2UserRankMap(CommPlane commPlane, u32 ringIndex, std::map<u32, u32> &subCommRank2UserRank);
188 :
189 : HcclResult GetUserRank2SubMap(CommPlane commPlane, u32 ringIndex, std::map<u32, u32> &userRank2subCommRank);
190 :
191 : HcclResult GetIsUsedRdma(const CommParaInfo &commParaInfo, bool &isUsedRdma);
192 :
193 : u32 GetSubCollectiveRank(const std::vector<u32> &vecPara) const;
194 :
195 : std::vector<std::vector<std::vector<u32>>> CommPlaneVector_;
196 : std::vector<bool> isBridgeVector_;
197 : HcclTopoInfo topoInfo_;
198 : HcclAlgoInfo algoInfo_;
199 : HcclExternalEnable externalEnable_;
200 : u32 userRank_;
201 : std::vector<std::vector<std::map<u32, u32>>> subCommRank2UserRank_;
202 : std::vector<std::vector<std::map<u32, u32>>> userRank2subCommRank_;
203 :
204 : // serverAndsuperPodToRank_[0]: 通信域在当前superPod内, 按照serverIdx划分的所有rank信息
205 : // serverAndsuperPodToRank_[1]: 通信域所有rank的信息, 按照superPodId -> RankInfo 的结构划分
206 : std::vector<std::vector<std::vector<u32>>> serverAndsuperPodToRank_;
207 :
208 : u32 userRankIdx_ = 0;
209 : };
210 : } // namespace hccl
211 :
212 : #endif /* * TOPO_MATCHER_H */
|