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 "all_gather_auto_selector.h"
12 : #include "selector_registry.h"
13 : #include "coll_operator.h"
14 :
15 : namespace Hccl {
16 :
17 :
18 0 : SelectorStatus AllGatherAutoSelector::SelectCcuMsAlgo(const TopoInfo &topoInfo, const CollAlgOperator &op,
19 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap, std::string &primQueueGenName) const
20 : {
21 : (void)op;
22 : (void)configAlgMap;
23 0 : HCCL_DEBUG("[AllGatherAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
24 0 : u32 rankSize_2P = 2;
25 0 : u32 rankSize_4P = 4;
26 0 : HcclDetourType detourType = EnvConfig::GetInstance().GetDetourConfig().GetDetourType();
27 0 : CHK_PRT_RET((detourType == HcclDetourType::HCCL_DETOUR_ENABLE_2P && rankSize_ != rankSize_2P)||
28 : (detourType == HcclDetourType::HCCL_DETOUR_ENABLE_4P && rankSize_ != rankSize_4P),
29 : HCCL_WARNING("[Algo][AllGatherAutoSelector] detourType not match for rankSize."),
30 : SelectorStatus::NOT_MATCH);
31 :
32 0 : CHK_PRT_RET(detourType == HcclDetourType::HCCL_DETOUR_ENABLE_2P_AND_4P,
33 : HCCL_WARNING("[Algo][AllGatherAutoSelector] HCCL_DETOUR_ENABLE_2P_AND_4P is not supported yet."),
34 : SelectorStatus::NOT_MATCH);
35 :
36 0 : if (topoInfo.levelNum > 1) {
37 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] levelNum > 1 is not supported yet for ccu_ms mode.");
38 0 : return SelectorStatus::NOT_MATCH;
39 : } else {
40 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
41 0 : if (Is2DieFullMesh()) {
42 0 : primQueueGenName = "CcuAllGatherMesh1D2Die";
43 0 : } else if ((detourType == HcclDetourType::HCCL_DETOUR_ENABLE_2P && rankSize_ == rankSize_2P)||
44 0 : (detourType == HcclDetourType::HCCL_DETOUR_ENABLE_4P && rankSize_ == rankSize_4P)) {
45 0 : primQueueGenName = "CcuAllGatherMeshDetour1D";
46 : } else {
47 0 : primQueueGenName = "CcuAllGatherMesh1D";
48 : }
49 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
50 0 : primQueueGenName = "CcuAllGatherMesh2D";
51 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
52 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
53 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
54 0 : if ((detourType == HcclDetourType::HCCL_DETOUR_ENABLE_2P && rankSize_ == rankSize_2P)||
55 0 : (detourType == HcclDetourType::HCCL_DETOUR_ENABLE_4P && rankSize_ == rankSize_4P)) {
56 0 : primQueueGenName = "CcuAllGatherMeshDetour1D";
57 0 : } else if (topoInfo.level0PcieMix) {
58 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0 PCIE mix is not supported yet for ccu_ms mode.");
59 0 : return SelectorStatus::NOT_MATCH;
60 : } else {
61 0 : primQueueGenName = "CcuAllGatherMesh1D";
62 : }
63 : } else { // MS 不支持
64 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
65 : topoInfo.level0Shape);
66 0 : return SelectorStatus::NOT_MATCH;
67 : }
68 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
69 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
70 : topoInfo.level0Shape);
71 0 : return SelectorStatus::NOT_MATCH;
72 : } else {
73 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
74 : topoInfo.level0Shape);
75 0 : return SelectorStatus::NOT_MATCH;
76 : }
77 : }
78 0 : HCCL_INFO("[Algo][AllGatherAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
79 0 : return SelectorStatus::MATCH;
80 : }
81 :
82 0 : SelectorStatus AllGatherAutoSelector::SelectCcuScheduleAlgo(const TopoInfo &topoInfo, const CollAlgOperator &op,
83 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap, std::string &primQueueGenName) const
84 : {
85 : (void)op;
86 : (void)configAlgMap;
87 0 : HCCL_DEBUG("[AllGatherAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
88 :
89 0 : if (topoInfo.levelNum > 1) {
90 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
91 0 : if (topoInfo.netLayerDetails.localNetInsSizeOfLayer[0] == 1) {
92 : // 每框出 1 卡
93 0 : primQueueGenName = "CcuAllGatherNHR1D";
94 0 : } else if (Is2DieFullMesh()) {
95 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] 2DieFullMesh is not supported yet for schedule mode.");
96 0 : return SelectorStatus::NOT_MATCH;
97 : } else {
98 0 : primQueueGenName = "CcuAllGatherParallelMesh1DNHR";
99 : }
100 : } else {
101 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
102 : topoInfo.level0Shape);
103 0 : return SelectorStatus::NOT_MATCH;
104 : }
105 : } else {
106 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
107 0 : if (Is2DieFullMesh()) {
108 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] 2DieFullMesh is not supported yet for ccu schedule mode.");
109 0 : return SelectorStatus::NOT_MATCH;
110 : } else {
111 0 : primQueueGenName = "CcuAllGatherMeshMem2Mem1D";
112 : }
113 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
114 0 : primQueueGenName = "CcuAllGatherMeshMem2Mem2D";
115 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
116 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
117 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
118 0 : primQueueGenName = "CcuAllGatherMeshMem2Mem1D";
119 0 : } else if (topoInfo.level0PcieMix) {
120 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0 PCIE mix is not supported yet for ccu schedule mode.");
121 0 : return SelectorStatus::NOT_MATCH;
122 : } else {
123 0 : primQueueGenName = "CcuAllGatherParallelMesh1DNHR";
124 : }
125 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
126 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
127 : topoInfo.level0Shape);
128 0 : return SelectorStatus::NOT_MATCH;
129 : } else {
130 0 : HCCL_WARNING("[Algo][AllGatherAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
131 : topoInfo.level0Shape);
132 0 : return SelectorStatus::NOT_MATCH;
133 : }
134 : }
135 0 : HCCL_INFO("[Algo][AllGatherAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
136 0 : return SelectorStatus::MATCH;
137 : }
138 :
139 0 : SelectorStatus AllGatherAutoSelector::SelectAicpuAlgo(const TopoInfo &topoInfo, const CollAlgOperator &op,
140 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap, std::string &primQueueGenName) const
141 : {
142 : (void)op;
143 : (void)configAlgMap;
144 0 : HCCL_DEBUG("[AllGatherAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
145 :
146 0 : if (topoInfo.levelNum > 1) {
147 0 : if (topoInfo.Level1Nhr) {
148 0 : primQueueGenName = "InsAllGatherNHR";
149 0 : } else if (topoInfo.Level0Nhr) {
150 0 : primQueueGenName = "InsAllGatherParallelNHRNHR";
151 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
152 0 : if (topoInfo.netLayerDetails.localNetInsSizeOfLayer[0] == 1) {
153 0 : primQueueGenName = "InsAllGatherNHR";
154 : } else {
155 0 : primQueueGenName = "InsAllGatherParallelMesh1DNHR";
156 : }
157 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
158 0 : primQueueGenName = "InsAllGatherParallelMesh2DNHR";
159 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
160 0 : primQueueGenName = "InsAllGatherParallelNHRNHR";
161 : } else {
162 0 : return SelectorStatus::NOT_MATCH;
163 : }
164 : } else {
165 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
166 0 : primQueueGenName = "InsAllGatherMesh";
167 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
168 0 : primQueueGenName = "InsAllGatherMesh2D";
169 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
170 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
171 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
172 0 : primQueueGenName = "InsAllGatherMesh";
173 0 : } else if (topoInfo.level0PcieMix) {
174 0 : primQueueGenName = "InsAllGatherParallelMesh1DNHRPcie";
175 : } else {
176 0 : primQueueGenName = "InsAllGatherParallelMesh1DNHR";
177 : }
178 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
179 0 : primQueueGenName = "InsAllGatherNHR";
180 : } else {
181 0 : HCCL_WARNING("[AllGatherAutoSelector] topo not match");
182 0 : return SelectorStatus::NOT_MATCH;
183 : }
184 : }
185 0 : HCCL_INFO("[Algo][AllGatherAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
186 0 : return SelectorStatus::MATCH;
187 : }
188 :
189 0 : SelectorStatus AllGatherAutoSelector::SelectAivAlgo(const TopoInfo &topoInfo, const CollAlgOperator &op,
190 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap, std::string &primQueueGenName) const
191 : {
192 : (void)op;
193 : (void)configAlgMap;
194 0 : HCCL_DEBUG("[AllGatherAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
195 :
196 : // aiv 直接走打平 mesh
197 0 : primQueueGenName = "AivAllGatherMesh1D";
198 :
199 0 : HCCL_INFO("[Algo][AllGatherAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
200 0 : return SelectorStatus::MATCH;
201 : }
202 :
203 : REGISTER_SELECTOR_BY_OPTYPE(OpType::ALLGATHER, 18, AllGatherAutoSelector);
204 : } // namespace Hccl
|