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 the 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 the License in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "comm_configer.h"
12 : #include "alg_env_config.h"
13 :
14 : namespace hccl {
15 1229 : CommConfiger& CommConfiger::GetInstance()
16 : {
17 1229 : static CommConfiger configer;
18 1229 : return configer;
19 : }
20 :
21 13 : CommConfiger::CommConfiger() : initialized_(true) {}
22 :
23 408 : HcclResult CommConfiger::SetCommConfig(CommConfig config, const std::string& identifier)
24 : {
25 408 : std::lock_guard<std::mutex> lock(lock_);
26 408 : if (identifier.empty()) {
27 37 : HCCL_WARNING("[CommConfiger][SetCommConfig]: identifier is empty.");
28 37 : return HCCL_SUCCESS;
29 : }
30 371 : auto commConfigIter = commConfigMap_.find(identifier);
31 371 : if (commConfigIter != commConfigMap_.end()) {
32 107 : HCCL_WARNING("[CommConfiger][SetCommConfig]: commConfig of identifier[%s] is already existed.", identifier.c_str());
33 : }
34 371 : commConfigMap_[identifier] = config;
35 371 : HCCL_INFO("[CommConfiger][SetCommConfig]: commConfig of identifier[%s]", identifier.c_str());
36 371 : return HCCL_SUCCESS;
37 408 : }
38 :
39 0 : HcclResult CommConfiger::SetCommConfigExecTimeOut(s32 execTimeOut, const std::string& identifier)
40 : {
41 0 : std::lock_guard<std::mutex> lock(lock_);
42 0 : if (identifier.empty()) {
43 0 : HCCL_WARNING("[CommConfiger][SetCommConfigExecTimeOut]: identifier is empty.");
44 0 : return HCCL_SUCCESS;
45 : }
46 0 : auto commConfigIter = commConfigMap_.find(identifier);
47 0 : if (commConfigIter == commConfigMap_.end()) {
48 0 : HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.",
49 : identifier.c_str());
50 0 : return HCCL_SUCCESS;
51 : }
52 0 : return commConfigMap_[identifier].SetConfigExecTimeOut(execTimeOut);
53 0 : }
54 :
55 11 : s32 CommConfiger::GetCommConfigExecTimeOut(const std::string& identifier)
56 : {
57 11 : std::lock_guard<std::mutex> lock(lock_);
58 11 : s32 execTimeOut = GetInternalExecTimeOut();
59 11 : if (identifier.empty()) {
60 1 : HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: identifier is empty.");
61 1 : return execTimeOut;
62 : }
63 10 : auto commConfigIter = commConfigMap_.find(identifier);
64 10 : if(commConfigIter == commConfigMap_.end()){
65 9 : HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.",
66 : identifier.c_str());
67 9 : return execTimeOut;
68 : }
69 1 : execTimeOut = commConfigMap_[identifier].GetConfigExecTimeOut();
70 1 : HCCL_INFO("[CommConfiger][GetCommConfigExecTimeOut]: identifier[%s], execTimeOut[%d]s",
71 : identifier.c_str(), execTimeOut);
72 1 : return execTimeOut;
73 11 : }
74 :
75 0 : bool CommConfiger::GetCommConfigExecTimeOutSet(const std::string& identifier)
76 : {
77 0 : std::lock_guard<std::mutex> lock(lock_);
78 0 : bool execTimeOutSet = false;
79 0 : if (identifier.empty()) {
80 0 : HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOutSet]: identifier is empty.");
81 0 : return execTimeOutSet;
82 : }
83 0 : auto commConfigIter = commConfigMap_.find(identifier);
84 0 : if(commConfigIter == commConfigMap_.end()){
85 0 : HCCL_WARNING("[CommConfiger][GetCommConfigExecTimeOut]: CommConfig of [%s] is not found.",
86 : identifier.c_str());
87 0 : return execTimeOutSet;
88 : }
89 0 : execTimeOutSet = commConfigMap_[identifier].GetConfigExecTimeOutSet();
90 0 : HCCL_INFO("[CommConfiger][GetCommConfigExecTimeOutSet]: identifier[%s], execTimeOutSet[%d]",
91 : identifier.c_str(), execTimeOutSet);
92 0 : return execTimeOutSet;
93 0 : }
94 :
95 5 : std::vector<HcclAlgoType> CommConfiger::GetCommConfigAlgoConfig(const std::string& identifier, HcclCMDType opType)
96 : {
97 5 : std::lock_guard<std::mutex> lock(lock_);
98 5 : if (identifier.empty()) {
99 0 : HCCL_WARNING("[CommConfiger][GetCommConfigAlgoConfig]: identifier is empty.");
100 0 : return GetExternalInputHcclAlgoConfig(opType);
101 : }
102 5 : auto commConfigIter = commConfigMap_.find(identifier);
103 5 : if (commConfigIter == commConfigMap_.end()) {
104 5 : HCCL_WARNING("[CommConfiger][GetCommConfigAlgoConfig]: CommConfig of [%s] is not found.", identifier.c_str());
105 5 : return GetExternalInputHcclAlgoConfig(opType);
106 : }
107 0 : return commConfigMap_[identifier].GetConfigHcclAlgo(opType);
108 5 : }
109 :
110 :
111 0 : bool CommConfiger::GetCommConfigInterServerRetryEnable(const std::string& identifier)
112 : {
113 0 : std::lock_guard<std::mutex> lock(lock_);
114 0 : bool isRetry = GetExternalInputInterServerRetryEnable();
115 0 : if (identifier.empty()) {
116 0 : HCCL_WARNING("[CommConfiger][GetCommConfigInterServerRetryEnable]: identifier is empty.");
117 0 : return isRetry;
118 : }
119 0 : auto commConfigIter = commConfigMap_.find(identifier);
120 0 : if (commConfigIter == commConfigMap_.end()) {
121 0 : HCCL_WARNING("[CommConfiger][GetCommConfigInterServerRetryEnable]: CommConfig of [%s] is not found.",
122 : identifier.c_str());
123 0 : return isRetry;
124 : }
125 0 : isRetry = commConfigMap_[identifier].GetConfigInterServerRetryEnable();
126 0 : HCCL_INFO("[CommConfiger][GetCommConfigInterServerRetryEnable]: identifier[%s], isRetry[%d].",
127 : identifier.c_str(), isRetry);
128 0 : return isRetry;
129 0 : }
130 :
131 0 : bool CommConfiger::GetCommConfigInterSuperPodRetryEnable(const std::string& identifier)
132 : {
133 0 : std::lock_guard<std::mutex> lock(lock_);
134 0 : bool isRetry = GetExternalInputInterSuperPodRetryEnable();
135 0 : if (identifier.empty()) {
136 0 : HCCL_WARNING("[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: identifier is empty.");
137 0 : return isRetry;
138 : }
139 0 : auto commConfigIter = commConfigMap_.find(identifier);
140 0 : if (commConfigIter == commConfigMap_.end()) {
141 0 : HCCL_WARNING("[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: CommConfig of [%s] is not found.",
142 : identifier.c_str());
143 0 : return isRetry;
144 : }
145 0 : isRetry = commConfigMap_[identifier].GetConfigInterSuperPodRetryEnable();
146 0 : HCCL_INFO("[CommConfiger][GetCommConfigInterSuperPodRetryEnable]: identifier[%s], isRetry[%d].",
147 : identifier.c_str(), isRetry);
148 0 : return isRetry;
149 0 : }
150 :
151 0 : u32 CommConfiger::GetCommConfigRetryMaxCnt(const std::string& identifier)
152 : {
153 0 : std::lock_guard<std::mutex> lock(lock_);
154 0 : u32 retryMaxCnt = GetExternalInputRetryMaxCnt();
155 0 : if (identifier.empty()) {
156 0 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryMaxCnt]: identifier is empty.");
157 0 : return retryMaxCnt;
158 : }
159 0 : auto commConfigIter = commConfigMap_.find(identifier);
160 0 : if (commConfigIter == commConfigMap_.end()) {
161 0 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryMaxCnt]: CommConfig of [%s] is not found.",
162 : identifier.c_str());
163 0 : return retryMaxCnt;
164 : }
165 0 : retryMaxCnt = commConfigMap_[identifier].GetConfigRetryMaxCnt();
166 0 : HCCL_INFO("[CommConfiger][GetCommConfigRetryMaxCnt]: identifier[%s], retryMaxCnt[%d].",
167 : identifier.c_str(), retryMaxCnt);
168 0 : return retryMaxCnt;
169 0 : }
170 :
171 1 : u32 CommConfiger::GetCommConfigRetryHoldTime(const std::string& identifier)
172 : {
173 1 : std::lock_guard<std::mutex> lock(lock_);
174 1 : u32 retryHoldTime = GetExternalInputRetryHoldTime();
175 1 : if (identifier.empty()) {
176 1 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryHoldTime]: identifier is empty.");
177 1 : return retryHoldTime;
178 : }
179 0 : auto commConfigIter = commConfigMap_.find(identifier);
180 0 : if (commConfigIter == commConfigMap_.end()) {
181 0 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryHoldTime]: CommConfig of [%s] is not found.",
182 : identifier.c_str());
183 0 : return retryHoldTime;
184 : }
185 0 : retryHoldTime = commConfigMap_[identifier].GetConfigRetryHoldTime();
186 0 : HCCL_INFO("[CommConfiger][GetCommConfigRetryHoldTime]: identifier[%s], retryHoldTime[%d].",
187 : identifier.c_str(), retryHoldTime);
188 0 : return retryHoldTime;
189 1 : }
190 :
191 0 : u32 CommConfiger::GetCommConfigRetryIntervalTime(const std::string& identifier)
192 : {
193 0 : std::lock_guard<std::mutex> lock(lock_);
194 0 : u32 retryIntervalTime = GetExternalInputRetryIntervalTime();
195 0 : if (identifier.empty()) {
196 0 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryIntervalTime]: identifier is empty.");
197 0 : return retryIntervalTime;
198 : }
199 0 : auto commConfigIter = commConfigMap_.find(identifier);
200 0 : if (commConfigIter == commConfigMap_.end()) {
201 0 : HCCL_WARNING("[CommConfiger][GetCommConfigRetryIntervalTime]: CommConfig of [%s] is not found.",
202 : identifier.c_str());
203 0 : return retryIntervalTime;
204 : }
205 0 : retryIntervalTime = commConfigMap_[identifier].GetConfigRetryIntervalTime();
206 0 : HCCL_INFO("[CommConfiger][GetCommConfigRetryIntervalTime]: identifier[%s], retryIntervalTime[%d].",
207 : identifier.c_str(), retryIntervalTime);
208 0 : return retryIntervalTime;
209 0 : }
210 :
211 804 : void CommConfiger::UnRegisterToCommConfiger(const std::string& identifier)
212 : {
213 804 : if (initialized_ == false) {
214 0 : HCCL_WARNING("CommConfiger has been destroyed");
215 540 : return;
216 : }
217 804 : std::lock_guard<std::mutex> lock(lock_);
218 804 : if (identifier.empty()) {
219 431 : HCCL_WARNING("[CommConfiger][UnRegisterToCommConfiger]: identifier is empty.");
220 431 : return;
221 : }
222 373 : auto commConfigIter = commConfigMap_.find(identifier);
223 373 : if (commConfigIter == commConfigMap_.end()) {
224 109 : HCCL_WARNING("[CommConfiger][UnRegisterToCommConfiger]: CommConfig of [%s] is not found.", identifier.c_str());
225 109 : return;
226 : }
227 264 : commConfigMap_.erase(identifier);
228 804 : }
229 :
230 13 : CommConfiger::~CommConfiger()
231 : {
232 13 : std::lock_guard<std::mutex> lock(lock_);
233 13 : initialized_ = false;
234 13 : commConfigMap_.clear();
235 13 : }
236 : }
|