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 "broadcast_auto_selector.h"
12 : #include "selector_registry.h"
13 : #include "coll_operator.h"
14 :
15 : namespace Hccl {
16 0 : SelectorStatus BroadcastAutoSelector::SelectCcuMsAlgo(
17 : const TopoInfo& topoInfo, const CollAlgOperator& op,
18 : const std::map<OpType, std::vector<HcclAlgoType>>& configAlgMap, std::string& primQueueGenName) const
19 : {
20 : (void)op;
21 : (void)configAlgMap;
22 0 : HCCL_DEBUG("[BroadcastAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
23 :
24 0 : if (topoInfo.levelNum > 1) {
25 0 : HCCL_WARNING("[Algo][BroadcastAutoSelector] levelNum > 1 is not supported yet for ccu_ms mode.");
26 0 : return SelectorStatus::NOT_MATCH;
27 : } else {
28 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
29 0 : if (Is2DieFullMesh()) {
30 0 : HCCL_WARNING("[Algo][BroadcastAutoSelector] 2DieFullMesh is not supported yet for ccu_ms mode.");
31 0 : return SelectorStatus::NOT_MATCH;
32 : } else {
33 0 : primQueueGenName = "CcuBroadcastMesh1D";
34 : }
35 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
36 0 : primQueueGenName = "CcuBroadcastMesh2D";
37 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
38 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
39 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
40 0 : primQueueGenName = "CcuBroadcastMesh1D";
41 : } else { // MS 不支持
42 0 : HCCL_WARNING(
43 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
44 : topoInfo.level0Shape);
45 0 : return SelectorStatus::NOT_MATCH;
46 : }
47 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
48 0 : HCCL_WARNING(
49 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
50 : topoInfo.level0Shape);
51 0 : return SelectorStatus::NOT_MATCH;
52 : } else {
53 0 : HCCL_WARNING(
54 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu_ms mode.",
55 : topoInfo.level0Shape);
56 0 : return SelectorStatus::NOT_MATCH;
57 : }
58 : }
59 0 : HCCL_INFO("[Algo][BroadcastAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
60 0 : return SelectorStatus::MATCH;
61 : }
62 :
63 0 : SelectorStatus BroadcastAutoSelector::SelectCcuScheduleAlgo(
64 : const TopoInfo& topoInfo, const CollAlgOperator& op,
65 : const std::map<OpType, std::vector<HcclAlgoType>>& configAlgMap, std::string& primQueueGenName) const
66 : {
67 : (void)op;
68 : (void)configAlgMap;
69 0 : HCCL_DEBUG("[BroadcastAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
70 :
71 0 : if (topoInfo.levelNum > 1) {
72 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
73 0 : if (topoInfo.netLayerDetails.localNetInsSizeOfLayer[0] == 1) {
74 : // 每框出 1 卡
75 0 : primQueueGenName = "CcuBroadcastNHRMem2Mem1D";
76 0 : } else if (Is2DieFullMesh()) {
77 0 : HCCL_WARNING("[Algo][BroadcastAutoSelector] 2DieFullMesh is not supported yet for schedule mode.");
78 0 : return SelectorStatus::NOT_MATCH;
79 : } else {
80 0 : primQueueGenName = "CcuBroadcastParallelMesh1DNHR";
81 : }
82 : } else {
83 0 : HCCL_WARNING(
84 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
85 : topoInfo.level0Shape);
86 0 : return SelectorStatus::NOT_MATCH;
87 : }
88 : } else {
89 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
90 0 : if (Is2DieFullMesh()) {
91 0 : HCCL_WARNING("[Algo][BroadcastAutoSelector] 2DieFullMesh is not supported yet for ccu schedule mode.");
92 0 : return SelectorStatus::NOT_MATCH;
93 : } else {
94 0 : primQueueGenName = "CcuBroadcastMeshMem2Mem1D";
95 : }
96 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
97 0 : primQueueGenName = "CcuBroadcastMeshMem2Mem2D";
98 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
99 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
100 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
101 0 : primQueueGenName = "CcuBroadcastMeshMem2Mem1D";
102 : } else {
103 0 : primQueueGenName = "CcuBroadcastParallelMesh1DNHR";
104 : }
105 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
106 0 : HCCL_WARNING(
107 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
108 : topoInfo.level0Shape);
109 0 : return SelectorStatus::NOT_MATCH;
110 : } else {
111 0 : HCCL_WARNING(
112 : "[Algo][BroadcastAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
113 : topoInfo.level0Shape);
114 0 : return SelectorStatus::NOT_MATCH;
115 : }
116 : }
117 0 : HCCL_INFO("[Algo][BroadcastAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
118 0 : return SelectorStatus::MATCH;
119 : }
120 :
121 0 : SelectorStatus BroadcastAutoSelector::SelectAicpuAlgo(
122 : const TopoInfo& topoInfo, const CollAlgOperator& op,
123 : const std::map<OpType, std::vector<HcclAlgoType>>& configAlgMap, std::string& primQueueGenName) const
124 : {
125 : (void)configAlgMap;
126 : (void)op;
127 0 : HCCL_DEBUG("[BroadcastAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
128 0 : if (topoInfo.levelNum > 1) {
129 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
130 0 : primQueueGenName = (topoInfo.netLayerDetails.localNetInsSizeOfLayer[0] == 1) ?
131 : "InsBroadcastNHR" :
132 0 : "AiCpuInsBroadcastParallelMesh1DNHR";
133 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
134 0 : primQueueGenName = "InsBroadcastNHR";
135 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
136 0 : primQueueGenName = "InsBroadcastNHR";
137 : } else {
138 0 : return SelectorStatus::NOT_MATCH;
139 : }
140 : } else {
141 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
142 0 : if (IsSmallData(dataSize_)) {
143 0 : primQueueGenName = "InsBroadcastMesh1DOneShot";
144 : } else {
145 0 : primQueueGenName = "InsBroadcastMesh1DTwoShot";
146 : }
147 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
148 0 : primQueueGenName = "InsBroadcastMesh2DTwoShot";
149 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
150 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
151 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
152 0 : if (IsSmallData(dataSize_)) {
153 0 : primQueueGenName = "InsBroadcastMesh1DOneShot";
154 : } else {
155 0 : primQueueGenName = "InsBroadcastMesh1DTwoShot";
156 : }
157 : } else {
158 0 : if (topoInfo.level0PcieMix) { // 预留PCIE mix入口,如果要更新算法可以直接改
159 0 : primQueueGenName = "InsBroadcastParallelMesh1DNHRPcie";
160 : } else {
161 0 : primQueueGenName = "AiCpuInsBroadcastParallelMesh1DNHR";
162 : }
163 : }
164 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
165 0 : primQueueGenName = "InsBroadcastNHR";
166 : } else {
167 0 : HCCL_WARNING("[BroadcastAutoSelector] topo not match");
168 0 : return SelectorStatus::NOT_MATCH;
169 : }
170 : }
171 0 : HCCL_INFO("[Algo][BroadcastAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
172 0 : return SelectorStatus::MATCH;
173 : }
174 :
175 0 : SelectorStatus BroadcastAutoSelector::SelectMeshAlgoAicpu(
176 : const TopoInfo& topoInfo, const CollAlgOperator& op, std::string& primQueueGenName) const
177 : {
178 : (void)topoInfo;
179 : (void)op;
180 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
181 0 : if (IsSmallData(dataSize_)) {
182 0 : primQueueGenName = "InsBroadcastMesh1DOneShot";
183 : } else {
184 0 : primQueueGenName = "InsBroadcastMesh1DTwoShot";
185 : }
186 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
187 0 : primQueueGenName = "InsBroadcastMesh2DTwoShot";
188 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
189 0 : primQueueGenName = "InsBroadcastNHR";
190 : } else {
191 0 : HCCL_WARNING("[BroadcastAutoSelector] topo not match");
192 0 : return SelectorStatus::NOT_MATCH;
193 : }
194 0 : return SelectorStatus::MATCH;
195 : }
196 :
197 0 : SelectorStatus BroadcastAutoSelector::SelectAivAlgo(
198 : const TopoInfo& topoInfo, const CollAlgOperator& op,
199 : const std::map<OpType, std::vector<HcclAlgoType>>& configAlgMap, std::string& primQueueGenName) const
200 : {
201 : (void)op;
202 : (void)configAlgMap;
203 0 : HCCL_DEBUG("[BroadcastAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
204 :
205 : // aiv 直接走打平 mesh
206 0 : primQueueGenName = "AivBroadcastMesh1D";
207 :
208 0 : HCCL_INFO("[Algo][BroadcastAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
209 0 : return SelectorStatus::MATCH;
210 : }
211 :
212 : REGISTER_SELECTOR_BY_OPTYPE(OpType::BROADCAST, 18, BroadcastAutoSelector);
213 : } // namespace Hccl
|