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 "auto_selector_base.h"
12 : #include "coll_operator.h"
13 : #include "coll_alg_params.h"
14 :
15 : namespace Hccl {
16 :
17 0 : SelectorStatus AutoSelectorBase::Select(const CollAlgOperator &op, CollAlgParams ¶ms,
18 : std::string &primQueueGenName)
19 : {
20 0 : HCCL_DEBUG("[AutoSelectorBase][%s] start", __func__);
21 0 : TopoInfo topoInfo;
22 0 : HCCL_DEBUG("[AutoSelectorBase][%s] CalcTopoShape start", __func__);
23 0 : CalcTopoShape(topoInfo);
24 0 : HCCL_DEBUG("[AutoSelectorBase][%s] end, levelNum[%u]", __func__, topoInfo.levelNum);
25 0 : std::map<OpType, std::vector<HcclAlgoType>> configAlgMap = EnvConfig::GetInstance().GetAlgoConfig().GetAlgoConfig();
26 0 : SelectorStatus ret = SelectorStatus::NOT_MATCH;
27 0 : HCCL_DEBUG("[AutoSelectorBase][%s] params.opExecuteConfig.accelerator[%s]", __func__, params.opExecuteConfig.accState.Describe().c_str());
28 0 : dataSize_ = op.dataCount * DataTypeSizeGet(op.dataType);;
29 0 : if (params.opExecuteConfig.accState == AcceleratorState::CCU_MS) {
30 0 : ret = SelectCcuMsAlgo(topoInfo, op, configAlgMap, primQueueGenName);
31 0 : if (ret == SelectorStatus::NOT_MATCH) {
32 0 : params.opExecuteConfig.accState = AcceleratorState::CCU_SCHED;
33 : } else {
34 0 : return ret;
35 : }
36 : }
37 0 : if (params.opExecuteConfig.accState == AcceleratorState::CCU_SCHED) {
38 0 : ret = SelectCcuScheduleAlgo(topoInfo, op, configAlgMap, primQueueGenName);
39 0 : if (ret == SelectorStatus::NOT_MATCH) {
40 0 : params.opExecuteConfig.accState = AcceleratorState::CCU_FALLBACK;
41 : } else {
42 0 : return ret;
43 : }
44 : }
45 0 : if (params.opExecuteConfig.accState == AcceleratorState::AIV) {
46 0 : if (op.opType != OpType::BARRIER) {
47 0 : ret = SelectAivAlgo(topoInfo, op, configAlgMap, primQueueGenName);
48 : }
49 0 : if (ret == SelectorStatus::MATCH) {
50 0 : return ret;
51 : }
52 0 : params.opExecuteConfig.accState = AcceleratorState::CCU_FALLBACK;
53 : }
54 :
55 0 : if (params.opExecuteConfig.accState == AcceleratorState::AIV_ONLY) {
56 0 : return (op.opType == OpType::BARRIER) ? SelectorStatus::NOT_MATCH :
57 0 : SelectAivAlgo(topoInfo, op, configAlgMap, primQueueGenName);
58 : }
59 0 : if (IsStarsState(params.opExecuteConfig)) {
60 : // level0是PCIE混合的场景,且CLOS规模大于8,选择AIV_ONLY算法
61 0 : if (topoInfo.level0PcieMix && topoInfo.level0BigClosRange) {
62 0 : params.opExecuteConfig.accState = AcceleratorState::AIV_ONLY;
63 0 : return (op.opType == OpType::BARRIER) ? SelectorStatus::NOT_MATCH :
64 0 : SelectAivAlgo(topoInfo, op, configAlgMap, primQueueGenName);
65 : }
66 0 : ret = SelectAicpuAlgo(topoInfo, op, configAlgMap, primQueueGenName);
67 0 : if ((ret == SelectorStatus::MATCH)&&(params.opExecuteConfig.accState == AcceleratorState::CCU_FALLBACK)) {
68 0 : params.opExecuteConfig.accState = AcceleratorState::AICPU_TS;
69 : }
70 0 : return ret;
71 : }
72 0 : return SelectorStatus::NOT_MATCH;
73 0 : }
74 :
75 0 : bool AutoSelectorBase::IsStarsState(const OpExecuteConfig &opExecuteConfig) const
76 : {
77 0 : return (opExecuteConfig.accState == AcceleratorState::AICPU_TS ||
78 0 : opExecuteConfig.accState == AcceleratorState::HOSTCPU_TS ||
79 0 : opExecuteConfig.accState == AcceleratorState::CCU_FALLBACK);
80 : }
81 :
82 0 : bool AutoSelectorBase::IsDefaultAlg(const HcclAlgoType algoType) const
83 : {
84 0 : return (algoType == HcclAlgoType::HCCL_ALGO_TYPE_DEFAULT) || (algoType == HcclAlgoType::HCCL_ALGO_TYPE_NA);
85 : }
86 :
87 0 : HcclAlgoType AutoSelectorBase::GetLevel0AlgoType(const CollAlgOperator &op, const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap) const
88 : {
89 0 : HcclAlgoType levle0Algo = HcclAlgoType::HCCL_ALGO_TYPE_DEFAULT;
90 0 : auto it = configAlgMap.find(op.opType);
91 0 : if ((it != configAlgMap.end()) && (it->second.size() > 0)) {
92 0 : levle0Algo = it->second[0];
93 : }
94 0 : return levle0Algo;
95 : }
96 :
97 0 : bool AutoSelectorBase::IsSmallData(const u64 dataSize) const
98 : {
99 0 : return dataSize < SMALL_COUNT_512KB;
100 : }
101 :
102 0 : bool AutoSelectorBase::IsLargeData(const u64 dataSize) const
103 : {
104 0 : return dataSize >= LARGE_COUNT_1024KB;
105 : }
106 :
107 0 : bool AutoSelectorBase::IsSmallDataCCU(const u64 dataSize, const u64 rankSize) const
108 : {
109 0 : if (rankSize == 0) {
110 0 : HCCL_WARNING("the selector is not set RankSize");
111 : }
112 0 : return (dataSize <= CCU_PARALLEL_MAX_DATA_SIZE) ? true : false;
113 : }
114 :
115 0 : SelectorStatus AutoSelectorBase::SelectCcuMsAlgo(const TopoInfo &topoInfo,
116 : const CollAlgOperator &op,
117 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
118 : std::string &primQueueGenName) const
119 : {
120 : (void)topoInfo;
121 : (void)op;
122 : (void)configAlgMap;
123 : (void)primQueueGenName;
124 0 : return SelectorStatus::NOT_MATCH;
125 : }
126 :
127 0 : SelectorStatus AutoSelectorBase::SelectCcuScheduleAlgo(const TopoInfo &topoInfo,
128 : const CollAlgOperator &op,
129 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
130 : std::string &primQueueGenName) const
131 : {
132 : (void)topoInfo;
133 : (void)op;
134 : (void)configAlgMap;
135 : (void)primQueueGenName;
136 0 : return SelectorStatus::NOT_MATCH;
137 : }
138 :
139 0 : SelectorStatus AutoSelectorBase::SelectAicpuAlgo(const TopoInfo &topoInfo,
140 : const CollAlgOperator &op,
141 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
142 : std::string &primQueueGenName) const
143 : {
144 : (void)topoInfo;
145 : (void)op;
146 : (void)configAlgMap;
147 : (void)primQueueGenName;
148 0 : return SelectorStatus::NOT_MATCH;
149 : }
150 :
151 0 : SelectorStatus AutoSelectorBase::SelectAivAlgo(const TopoInfo &topoInfo,
152 : const CollAlgOperator &op,
153 : const std::map<OpType, std::vector<HcclAlgoType>> &configAlgMap,
154 : std::string &primQueueGenName) const
155 : {
156 : (void)topoInfo;
157 : (void)op;
158 : (void)configAlgMap;
159 : (void)primQueueGenName;
160 0 : return SelectorStatus::NOT_MATCH;
161 : }
162 :
163 : }
|