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 "alltoall_auto_selector.h"
12 : #include "selector_registry.h"
13 : #include "coll_operator.h"
14 :
15 : namespace Hccl {
16 0 : SelectorStatus AlltoAllAutoSelector::SelectCcuMsAlgo(const TopoInfo &topoInfo,
17 : const CollAlgOperator &op,
18 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
19 : std::string &primQueueGenName) const
20 : {
21 : (void)topoInfo;
22 : (void)op;
23 : (void)configAlgMap;
24 : (void)primQueueGenName;
25 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] is not supported yet for ccu_ms mode, reset to default.");
26 0 : return SelectorStatus::NOT_MATCH;
27 : }
28 :
29 0 : SelectorStatus AlltoAllAutoSelector::SelectCcuScheduleAlgoLevel1(const TopoInfo &topoInfo,
30 : const CollAlgOperator &op,
31 : std::string &primQueueGenName) const
32 : {
33 0 : if (isMc2_) {
34 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] levelNum > 1 is not supported yet for ccu_schedule mode.");
35 0 : return SelectorStatus::NOT_MATCH;
36 : }
37 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
38 0 : if (topoInfo.netLayerDetails.localNetInsSizeOfLayer[0] == 1) {
39 0 : primQueueGenName = "CcuAlltoAllMesh1D";
40 : } else {
41 0 : if (op.dataType == DataType::INT8) {
42 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] int8 is not supported yet for ccu_schedule mode.");
43 0 : return SelectorStatus::NOT_MATCH;
44 : }
45 0 : primQueueGenName = "CcuAllToAllMesh1D2Die";
46 : }
47 : } else {
48 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
49 : topoInfo.level0Shape);
50 0 : return SelectorStatus::NOT_MATCH;
51 : }
52 0 : return SelectorStatus::MATCH;
53 : }
54 :
55 0 : SelectorStatus AlltoAllAutoSelector::SelectCcuScheduleAlgo(const TopoInfo &topoInfo,
56 : const CollAlgOperator &op,
57 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
58 : std::string &primQueueGenName) const
59 : {
60 : (void)op;
61 : (void)configAlgMap;
62 0 : HCCL_DEBUG("[AlltoAllAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
63 :
64 0 : if (topoInfo.levelNum > 1) {
65 0 : SelectorStatus ret = SelectCcuScheduleAlgoLevel1(topoInfo, op, primQueueGenName);
66 0 : return ret;
67 : } else {
68 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
69 0 : if (Is2DieFullMesh()) {
70 0 : primQueueGenName = "CcuAllToAllMesh1D2Die";
71 : } else {
72 0 : primQueueGenName = "CcuAlltoAllMesh1D";
73 : }
74 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
75 0 : primQueueGenName = "CcuAlltoAllMesh2D";
76 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
77 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
78 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
79 0 : if (Is2DieFullMesh()) {
80 0 : primQueueGenName = "CcuAllToAllMesh1D2Die";
81 : } else {
82 0 : primQueueGenName = "CcuAlltoAllMesh1D";
83 : }
84 0 : } else if (topoInfo.level0PcieMix) {
85 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] level0 PCIE mix is not supported yet for ccu schedule mode.");
86 0 : return SelectorStatus::NOT_MATCH;
87 : } else {
88 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
89 : topoInfo.level0Shape);
90 0 : return SelectorStatus::NOT_MATCH;
91 : }
92 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
93 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
94 : topoInfo.level0Shape);
95 0 : return SelectorStatus::NOT_MATCH;
96 : } else {
97 0 : HCCL_WARNING("[Algo][AlltoAllAutoSelector] level0Shape[%d] is not supported yet for ccu schedule mode.",
98 : topoInfo.level0Shape);
99 0 : return SelectorStatus::NOT_MATCH;
100 : }
101 : }
102 0 : HCCL_INFO("[Algo][AlltoAllAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
103 0 : return SelectorStatus::MATCH;
104 : }
105 :
106 0 : SelectorStatus AlltoAllAutoSelector::SelectAicpuAlgo(const TopoInfo &topoInfo,
107 : const CollAlgOperator &op,
108 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
109 : std::string &primQueueGenName) const
110 : {
111 : (void)op;
112 : (void)configAlgMap;
113 0 : HCCL_DEBUG("[AlltoAllAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
114 :
115 0 : if (topoInfo.levelNum > 1) {
116 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
117 0 : primQueueGenName = "InsAlltoAllMesh";
118 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
119 0 : primQueueGenName = "InsAlltoAllMesh";
120 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
121 0 : primQueueGenName = "InsAlltoAllMesh";
122 : } else {
123 0 : return SelectorStatus::NOT_MATCH;
124 : }
125 : } else {
126 0 : if (topoInfo.level0Shape == Level0Shape::MESH_1D) {
127 0 : primQueueGenName = "InsAlltoAllMesh";
128 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_2D) {
129 0 : primQueueGenName = "InsAlltoAllMesh2D";
130 0 : } else if (topoInfo.level0Shape == Level0Shape::MESH_1D_CLOS) {
131 0 : if (IsLayerAllConnetedWithTopo(topoInfo, 0, TopoType::MESH_1D)) {
132 : // MESH_1D 即可链接所有卡, 使用 MESH_1D 算法
133 0 : primQueueGenName = "InsAlltoAllMesh";
134 0 : } else if (topoInfo.level0PcieMix) {
135 0 : primQueueGenName = "InsAlltoAllMesh";
136 : } else {
137 0 : primQueueGenName = "InsAlltoAllMesh";
138 : }
139 0 : } else if (topoInfo.level0Shape == Level0Shape::CLOS) {
140 0 : primQueueGenName = "InsAlltoAllMesh";
141 : } else {
142 0 : HCCL_WARNING("[AlltoAllAutoSelector] topo not match");
143 0 : return SelectorStatus::NOT_MATCH;
144 : }
145 : }
146 0 : HCCL_INFO("[Algo][AlltoAllAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
147 0 : return SelectorStatus::MATCH;
148 : }
149 :
150 0 : SelectorStatus AlltoAllAutoSelector::SelectAivAlgo(const TopoInfo &topoInfo,
151 : const CollAlgOperator &op,
152 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
153 : std::string &primQueueGenName) const
154 : {
155 : (void)op;
156 : (void)configAlgMap;
157 0 : HCCL_DEBUG("[AlltoAllAutoSelector][%s] start, topoInfo levelNum[%u]", __func__, topoInfo.levelNum);
158 :
159 : // aiv 直接走打平 mesh
160 0 : primQueueGenName = "AivAlltoAllMesh1D";
161 :
162 0 : HCCL_INFO("[Algo][AlltoAllAutoSelector][%s] Algo match [%s]", __func__, primQueueGenName.c_str());
163 0 : return SelectorStatus::MATCH;
164 : }
165 :
166 : REGISTER_SELECTOR_BY_OPTYPE(OpType::ALLTOALL, 18, AlltoAllAutoSelector);
167 : } // namespace Hccl
|