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 "execute_selector.h"
12 :
13 : #include "base_selector.h"
14 : #include "selector_registry.h"
15 :
16 : namespace Hccl {
17 426 : ExecuteSelector& ExecuteSelector::SetVirtualTopo(RankGraph* rankGraph)
18 : {
19 426 : rankGraph_ = rankGraph;
20 426 : return *this;
21 : }
22 :
23 0 : ExecuteSelector& ExecuteSelector::SetDevType(DevType devType)
24 : {
25 0 : devType_ = devType;
26 0 : return *this;
27 : }
28 :
29 426 : ExecuteSelector& ExecuteSelector::SetMyRank(RankId myRank)
30 : {
31 426 : myRank_ = myRank;
32 426 : return *this;
33 : }
34 :
35 426 : ExecuteSelector& ExecuteSelector::SetRankSize(u32 rankSize)
36 : {
37 426 : rankSize_ = rankSize;
38 426 : return *this;
39 : }
40 :
41 0 : ExecuteSelector& ExecuteSelector::SetSeverId(std::string severId)
42 : {
43 0 : severId_ = severId;
44 0 : return *this;
45 : }
46 :
47 0 : ExecuteSelector& ExecuteSelector::SetDeviceNumPerSever(u32 deviceNumPerSever)
48 : {
49 0 : deviceNumPerSever_ = deviceNumPerSever;
50 0 : return *this;
51 : }
52 :
53 0 : ExecuteSelector& ExecuteSelector::SetServerNum(u32 serverNum)
54 : {
55 0 : serverNum_ = serverNum;
56 0 : return *this;
57 : }
58 :
59 0 : ExecuteSelector& ExecuteSelector::SetOpConfig(OpExecuteConfig opConfig)
60 : {
61 0 : opConfig_ = opConfig;
62 0 : return *this;
63 : }
64 :
65 0 : AlgorithmType ExecuteSelector::GetAlgorithmTypeForMC2CCU(const std::string& name) const
66 : {
67 0 : Mc2Selector mc2Selector;
68 0 : return mc2Selector.GetAlgorithmTypeForMC2CCU(name);
69 0 : }
70 :
71 0 : HcclResult ExecuteSelector::Run(const CollAlgOperator& op, CollAlgParams& params, std::string& primQueueGenName)
72 : {
73 0 : if (rankGraph_ == nullptr) {
74 0 : HCCL_ERROR("[Algo][ExecuteSelector] rankGraph_ is nullptr.");
75 0 : return HcclResult::HCCL_E_PTR;
76 : }
77 0 : std::map<u32, BaseSelector*> selectors = SelectorRegistry::Global()->GetAllSelectors();
78 :
79 0 : if (params.isMc2) {
80 0 : auto iter = selectors.find(18);
81 0 : if (iter == selectors.end()) {
82 0 : HCCL_ERROR("[Algo][Selector] CCU selector is not registried.");
83 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
84 : }
85 0 : iter->second->SetVirtualTopo(rankGraph_)
86 0 : .SetDevType(devType_)
87 0 : .SetMyRank(myRank_)
88 0 : .SetRankSize(rankSize_)
89 0 : .SetSeverId(severId_)
90 0 : .SetDeviceNumPerSever(deviceNumPerSever_)
91 0 : .SetServerNum(serverNum_)
92 0 : .SetIsMc2(params.isMc2);
93 0 : if (iter->second->Select(op, params, primQueueGenName) == SelectorStatus::MATCH) {
94 0 : HCCL_INFO(
95 : "[Algo][Selector] The ccu selector[priority of %u] is matched, the selected algo type is %s",
96 : iter->first, primQueueGenName.c_str());
97 0 : return HcclResult::HCCL_SUCCESS;
98 : }
99 0 : HCCL_ERROR("[Algo][Selector] CCU selector can not match for optype[%d].", op.opType);
100 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
101 : }
102 :
103 0 : selectors = SelectorRegistry::Global()->GetSelectorsByOpType(op.opType);
104 0 : HCCL_INFO(
105 : "[Algo][Selector] The selector nums of optype[%s] is [%zu].", op.opType.Describe().c_str(), selectors.size());
106 0 : for (auto iter : selectors) {
107 0 : HCCL_DEBUG("[Algo][Selector] The selector[priority of %llu] is running.", iter.first);
108 0 : iter.second->SetVirtualTopo(rankGraph_)
109 0 : .SetDevType(devType_)
110 0 : .SetMyRank(myRank_)
111 0 : .SetRankSize(rankSize_)
112 0 : .SetSeverId(severId_)
113 0 : .SetDeviceNumPerSever(deviceNumPerSever_)
114 0 : .SetServerNum(serverNum_)
115 0 : .SetOpConfig(opConfig_);
116 0 : if (iter.second->Select(op, params, primQueueGenName) == SelectorStatus::MATCH) {
117 0 : HCCL_INFO(
118 : "[Algo][Selector] The selector[priority of %llu] is matched, the selected algo type is %s", iter.first,
119 : primQueueGenName.c_str());
120 0 : return HcclResult::HCCL_SUCCESS;
121 : }
122 : }
123 :
124 0 : HCCL_WARNING("[Algo][Selector] No selector is matched.");
125 0 : return HcclResult::HCCL_E_NOT_SUPPORT;
126 0 : }
127 :
128 : } // namespace Hccl
|