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 "platform/platform_info.h"
12 : #include <dirent.h>
13 : #include <string.h>
14 : #include <unordered_set>
15 : #include <algorithm>
16 : #include <cmath>
17 : #include <fstream>
18 : #include <mutex>
19 : #include "platform/platform_info_def.h"
20 : #include "platform_infos_utils.h"
21 :
22 : namespace fe {
23 : namespace {
24 : const std::string FIXPIPE_CONFIG_KEY = "Intrinsic_fix_pipe_";
25 : const std::string INI_FILE_SUFFIX = "ini";
26 : const std::string STR_SOC_VERSION = "SoC_version";
27 : const std::string STR_AIC_VERSION = "AIC_version";
28 : const std::string SHORT_SOC_VERSION = "Short_SoC_version";
29 : const std::string STR_CCEC_AIC_VERSION = "CCEC_AIC_version";
30 : const std::string STR_CCEC_AIV_VERSION = "CCEC_AIV_version";
31 : const std::string STR_IS_SUPPORT_AICPU = "Compiler_aicpu_support_os";
32 : const std::string STR_VERSION = "version";
33 : const std::string STR_SOC_INFO = "SoCInfo";
34 : const std::string STR_AI_CORE_SPEC = "AICoreSpec";
35 : const std::string STR_AI_CORE_MEMORY_RATES = "AICoreMemoryRates";
36 : const std::string STR_CPU_CACHE = "CPUCache";
37 : const std::string STR_SOFTWARE_SPEC = "SoftwareSpec";
38 :
39 : const std::string STR_AI_CORE_INTRINSIC_DTYPE_MAP = "AICoreintrinsicDtypeMap";
40 : const std::string STR_VECTOR_CORE_SPEC = "VectorCoreSpec";
41 : const std::string STR_VECTOR_CORE_MEMORY_RATES = "VectorCoreMemoryRates";
42 : const std::string STR_VECTOR_CORE_INTRINSIC_DTYPE_MAP = "VectorCoreintrinsicDtypeMap";
43 :
44 : const std::string SOC_VERSION_ASCEND910 = "Ascend910";
45 : const std::string SOC_VERSION_ASCEND910A = "Ascend910A";
46 :
47 : const uint32_t PLATFORM_FAILED = 0xFFFFFFFF;
48 : const uint32_t PLATFORM_SUCCESS = 0;
49 :
50 : enum class PlatformInfoType {
51 : EN_VERSION = 0,
52 : EN_SOC_INFO,
53 : EN_AI_CORE_SPEC,
54 : EN_AI_CORE_MEMORY_RATES,
55 : EN_CPU_CACHE,
56 : EN_AI_CORE_INTRINSIC_DTYPE_MAP,
57 : EN_VECTOR_CORE_SPEC,
58 : EN_VECTOR_CORE_MEMORY_RATES,
59 : EN_VECTOR_CORE_INTRINSIC_DTYPE_MAP,
60 : EN_SOFTWARE_SPEC,
61 : };
62 :
63 : std::map<std::string, PlatformInfoType> g_platform_info_type_map{
64 : {STR_VERSION, PlatformInfoType::EN_VERSION},
65 : {STR_SOC_INFO, PlatformInfoType::EN_SOC_INFO},
66 : {STR_AI_CORE_SPEC, PlatformInfoType::EN_AI_CORE_SPEC},
67 : {STR_AI_CORE_MEMORY_RATES, PlatformInfoType::EN_AI_CORE_MEMORY_RATES},
68 : {STR_CPU_CACHE, PlatformInfoType::EN_CPU_CACHE},
69 : {STR_AI_CORE_INTRINSIC_DTYPE_MAP, PlatformInfoType::EN_AI_CORE_INTRINSIC_DTYPE_MAP},
70 : {STR_VECTOR_CORE_SPEC, PlatformInfoType::EN_VECTOR_CORE_SPEC},
71 : {STR_VECTOR_CORE_MEMORY_RATES, PlatformInfoType::EN_VECTOR_CORE_MEMORY_RATES},
72 : {STR_VECTOR_CORE_INTRINSIC_DTYPE_MAP, PlatformInfoType::EN_VECTOR_CORE_INTRINSIC_DTYPE_MAP},
73 : {STR_SOFTWARE_SPEC, PlatformInfoType::EN_SOFTWARE_SPEC}};
74 : } // namespace
75 :
76 : #define CONVERT(name) #name
77 :
78 : std::mutex pc_lock_;
79 :
80 2 : PlatformInfoManager::PlatformInfoManager() : init_flag_(false), runtime_init_flag_(false), opti_compilation_info_() {}
81 :
82 2 : PlatformInfoManager::~PlatformInfoManager() {}
83 :
84 1265 : PlatformInfoManager& PlatformInfoManager::Instance()
85 : {
86 1265 : static PlatformInfoManager platform_info;
87 1265 : return platform_info;
88 : }
89 :
90 117 : PlatformInfoManager& PlatformInfoManager::GeInstance()
91 : {
92 117 : static PlatformInfoManager ge_platform_info;
93 117 : return ge_platform_info;
94 : }
95 :
96 36357 : void PlatformInfoManager::Trim(std::string& str)
97 : {
98 36357 : if (str.empty()) {
99 93 : return;
100 : }
101 36264 : size_t start_pos = str.find_first_not_of(" \t\r\n");
102 36264 : size_t end_pos = str.find_last_not_of(" \t\r\n");
103 36264 : if (start_pos == std::string::npos || start_pos > end_pos) {
104 1 : str.clear();
105 1 : return;
106 : }
107 36263 : str = str.substr(start_pos, end_pos - start_pos + 1);
108 : }
109 :
110 82 : uint32_t PlatformInfoManager::LoadIniFile(std::string ini_file_real_path)
111 : {
112 82 : std::ifstream ifs(ini_file_real_path);
113 82 : if (!ifs.is_open()) {
114 9 : PF_LOGE("Failed to open conf file, it does not exist or is already opened.");
115 9 : return PLATFORM_FAILED;
116 : }
117 :
118 73 : std::map<std::string, std::string> content_map;
119 73 : std::map<std::string, std::map<std::string, std::string>> content_info_map;
120 73 : content_map.clear();
121 73 : content_info_map.clear();
122 73 : std::string line;
123 73 : std::string map_key;
124 19464 : while (std::getline(ifs, line)) {
125 19391 : if (line.empty() || line.find('#') == 0) {
126 1570 : continue;
127 : }
128 :
129 18533 : if (line.find('[') == 0) {
130 712 : if (!map_key.empty() && !content_map.empty()) {
131 631 : content_info_map.emplace(make_pair(map_key, content_map));
132 631 : content_map.clear();
133 : }
134 712 : size_t pos = line.rfind(']');
135 712 : if (pos == std::string::npos) {
136 0 : continue;
137 : }
138 712 : map_key = line.substr(1, pos - 1);
139 712 : Trim(map_key);
140 712 : continue;
141 712 : }
142 :
143 17821 : size_t pos_of_equal = line.find('=');
144 17821 : if (pos_of_equal == std::string::npos) {
145 0 : continue;
146 : }
147 :
148 17821 : std::string key = line.substr(0, pos_of_equal);
149 17821 : Trim(key);
150 17821 : std::string value = line.substr(pos_of_equal + 1, line.length() - pos_of_equal - 1);
151 17821 : Trim(value);
152 17821 : if (!key.empty() && !value.empty()) {
153 17729 : content_map.emplace(make_pair(key, value));
154 : }
155 17821 : }
156 :
157 73 : if (!content_map.empty() && !map_key.empty()) {
158 73 : content_info_map.emplace(make_pair(map_key, content_map));
159 73 : content_map.clear();
160 : }
161 :
162 73 : ifs.close();
163 :
164 73 : if (AssemblePlatformInfoVector(content_info_map) != PLATFORM_SUCCESS) {
165 0 : PF_LOGE("Assemble platform info failed.");
166 0 : return PLATFORM_FAILED;
167 : }
168 :
169 73 : return PLATFORM_SUCCESS;
170 82 : }
171 :
172 88 : uint32_t PlatformInfoManager::EnsureSocVersionLoaded(const std::string& soc_version)
173 : {
174 88 : if (soc_version.empty()) {
175 1 : return PLATFORM_FAILED;
176 : }
177 87 : if (loaded_ini_files_.count(soc_version) > 0) {
178 5 : return PLATFORM_SUCCESS;
179 : }
180 82 : std::string ini_file_path = cfg_file_real_path_ + "/" + soc_version + ".ini";
181 82 : PF_LOGD("Begin to load ini file[%s].", ini_file_path.c_str());
182 82 : if (LoadIniFile(ini_file_path) != PLATFORM_SUCCESS) {
183 9 : PF_LOGE("Failed to load ini file[%s].", ini_file_path.c_str());
184 9 : return PLATFORM_FAILED;
185 : }
186 73 : loaded_ini_files_.insert(soc_version);
187 73 : return PLATFORM_SUCCESS;
188 82 : }
189 :
190 75 : void PlatformInfoManager::ParseVersion(
191 : std::map<std::string, std::string>& version_map, std::string& soc_version, PlatformInfo& platform_info_temp)
192 : {
193 75 : std::map<std::string, std::string>::const_iterator soc = version_map.find(STR_SOC_VERSION);
194 75 : if (soc != version_map.end()) {
195 73 : soc_version = soc->second;
196 : }
197 :
198 75 : std::map<std::string, std::string>::const_iterator aic_version = version_map.find(STR_AIC_VERSION);
199 75 : if (aic_version != version_map.end()) {
200 73 : platform_info_temp.str_info.aic_version = aic_version->second;
201 : }
202 :
203 75 : std::map<std::string, std::string>::const_iterator ccec_aic_version = version_map.find(STR_CCEC_AIC_VERSION);
204 75 : if (ccec_aic_version != version_map.end()) {
205 73 : platform_info_temp.str_info.ccec_aic_version = ccec_aic_version->second;
206 : }
207 :
208 75 : std::map<std::string, std::string>::const_iterator ccec_aiv_version = version_map.find(STR_CCEC_AIV_VERSION);
209 75 : if (ccec_aiv_version != version_map.end()) {
210 62 : platform_info_temp.str_info.ccec_aiv_version = ccec_aiv_version->second;
211 : }
212 :
213 75 : std::map<std::string, std::string>::const_iterator is_support_aicpu = version_map.find(STR_IS_SUPPORT_AICPU);
214 75 : if (is_support_aicpu != version_map.end()) {
215 73 : platform_info_temp.str_info.is_support_ai_cpu_compiler = is_support_aicpu->second;
216 : }
217 :
218 75 : std::map<std::string, std::string>::const_iterator short_soc_version = version_map.find(SHORT_SOC_VERSION);
219 75 : if (short_soc_version != version_map.end()) {
220 73 : platform_info_temp.str_info.short_soc_version = short_soc_version->second;
221 : }
222 :
223 : try {
224 75 : std::map<std::string, std::string>::const_iterator arch_type = version_map.find(CONVERT(Arch_type));
225 75 : if (arch_type != version_map.end()) {
226 70 : platform_info_temp.soc_info.arch_type = stoi(arch_type->second);
227 : }
228 :
229 74 : std::map<std::string, std::string>::const_iterator chip_type = version_map.find(CONVERT(Chip_type));
230 74 : if (chip_type != version_map.end()) {
231 73 : platform_info_temp.soc_info.chip_type = stoi(chip_type->second);
232 : }
233 1 : } catch (...) {
234 1 : PF_LOGE("Failed to parse version");
235 1 : }
236 150 : return;
237 : }
238 :
239 75 : void PlatformInfoManager::ParseSocInfo(
240 : std::map<std::string, std::string>& soc_info_map, PlatformInfo& platform_info_temp)
241 : {
242 : try {
243 75 : std::map<std::string, std::string>::const_iterator ai_core_cnt = soc_info_map.find(CONVERT(ai_core_cnt));
244 75 : if (ai_core_cnt != soc_info_map.end()) {
245 75 : platform_info_temp.soc_info.ai_core_cnt = static_cast<uint32_t>(stoi(ai_core_cnt->second));
246 : }
247 :
248 : std::map<std::string, std::string>::const_iterator vector_core_cnt =
249 74 : soc_info_map.find(CONVERT(vector_core_cnt));
250 74 : if (vector_core_cnt != soc_info_map.end()) {
251 74 : platform_info_temp.soc_info.vector_core_cnt = static_cast<uint32_t>(stoi(vector_core_cnt->second));
252 : }
253 :
254 74 : std::map<std::string, std::string>::const_iterator ai_cpu_cnt = soc_info_map.find(CONVERT(ai_cpu_cnt));
255 74 : if (ai_cpu_cnt != soc_info_map.end()) {
256 70 : platform_info_temp.soc_info.ai_cpu_cnt = static_cast<uint32_t>(stoi(ai_cpu_cnt->second));
257 : }
258 :
259 74 : std::map<std::string, std::string>::const_iterator memory_type = soc_info_map.find(CONVERT(memory_type));
260 74 : if (memory_type != soc_info_map.end()) {
261 9 : platform_info_temp.soc_info.memory_type = static_cast<MemoryType>(stoi(memory_type->second));
262 : }
263 :
264 74 : std::map<std::string, std::string>::const_iterator memory_size = soc_info_map.find(CONVERT(memory_size));
265 74 : if (memory_size != soc_info_map.end()) {
266 63 : platform_info_temp.soc_info.memory_size = static_cast<uint64_t>(stoll(memory_size->second));
267 : }
268 :
269 74 : std::map<std::string, std::string>::const_iterator l2_type = soc_info_map.find(CONVERT(l2_type));
270 74 : if (l2_type != soc_info_map.end()) {
271 74 : platform_info_temp.soc_info.l2_type = static_cast<L2Type>(stoi(l2_type->second));
272 : }
273 :
274 74 : std::map<std::string, std::string>::const_iterator l2_size = soc_info_map.find(CONVERT(l2_size));
275 74 : if (l2_size != soc_info_map.end()) {
276 74 : platform_info_temp.soc_info.l2_size = static_cast<uint64_t>(stoll(l2_size->second));
277 : }
278 :
279 74 : std::map<std::string, std::string>::const_iterator l2PageNum = soc_info_map.find(CONVERT(l2PageNum));
280 74 : if (l2PageNum != soc_info_map.end()) {
281 73 : platform_info_temp.soc_info.l2PageNum = static_cast<uint32_t>(stoi(l2PageNum->second));
282 : }
283 74 : std::map<std::string, std::string>::const_iterator task_num = soc_info_map.find(CONVERT(task_num));
284 74 : if (task_num != soc_info_map.end()) {
285 1 : platform_info_temp.soc_info.task_num = static_cast<uint32_t>(stoi(task_num->second));
286 : }
287 1 : } catch (...) {
288 1 : PF_LOGE("Failed to load SocInfo");
289 1 : }
290 75 : }
291 :
292 76 : void PlatformInfoManager::ParseCubeOfAICoreSpec(
293 : std::map<std::string, std::string>& ai_core_spec_map, PlatformInfo& platform_info_temp)
294 : {
295 : try {
296 76 : std::map<std::string, std::string>::const_iterator cube_freq = ai_core_spec_map.find(CONVERT(cube_freq));
297 76 : if (cube_freq != ai_core_spec_map.end()) {
298 70 : platform_info_temp.ai_core_spec.cube_freq = static_cast<double>(stod(cube_freq->second));
299 : }
300 :
301 76 : std::map<std::string, std::string>::const_iterator cube_m_size = ai_core_spec_map.find(CONVERT(cube_m_size));
302 76 : if (cube_m_size != ai_core_spec_map.end()) {
303 75 : platform_info_temp.ai_core_spec.cube_m_size = static_cast<uint64_t>(stoll(cube_m_size->second));
304 : }
305 :
306 75 : std::map<std::string, std::string>::const_iterator cube_n_size = ai_core_spec_map.find(CONVERT(cube_n_size));
307 75 : if (cube_n_size != ai_core_spec_map.end()) {
308 74 : platform_info_temp.ai_core_spec.cube_n_size = static_cast<uint64_t>(stoll(cube_n_size->second));
309 : }
310 :
311 75 : std::map<std::string, std::string>::const_iterator cube_k_size = ai_core_spec_map.find(CONVERT(cube_k_size));
312 75 : if (cube_k_size != ai_core_spec_map.end()) {
313 74 : platform_info_temp.ai_core_spec.cube_k_size = static_cast<uint64_t>(stoll(cube_k_size->second));
314 : }
315 :
316 : std::map<std::string, std::string>::const_iterator vec_calc_size =
317 75 : ai_core_spec_map.find(CONVERT(vec_calc_size));
318 75 : if (vec_calc_size != ai_core_spec_map.end()) {
319 74 : platform_info_temp.ai_core_spec.vec_calc_size = static_cast<uint64_t>(stoll(vec_calc_size->second));
320 : }
321 :
322 75 : platform_info_temp.ai_core_spec.sparsity = 0;
323 75 : std::map<std::string, std::string>::const_iterator sparse_matrix = ai_core_spec_map.find(CONVERT(sparsity));
324 75 : if (sparse_matrix != ai_core_spec_map.end()) {
325 62 : platform_info_temp.ai_core_spec.sparsity = static_cast<uint8_t>(stoll(sparse_matrix->second));
326 : }
327 1 : } catch (...) {
328 1 : PF_LOGE("Failed to load AICoreSpecs.");
329 1 : }
330 76 : }
331 :
332 76 : void PlatformInfoManager::ParseBufferOfAICoreSpec(
333 : std::map<std::string, std::string>& ai_core_spec_map, PlatformInfo& platform_info_temp)
334 : {
335 : try {
336 76 : std::map<std::string, std::string>::const_iterator l0_a_size = ai_core_spec_map.find(CONVERT(l0_a_size));
337 76 : if (l0_a_size != ai_core_spec_map.end()) {
338 74 : platform_info_temp.ai_core_spec.l0_a_size = static_cast<uint64_t>(stoll(l0_a_size->second));
339 : }
340 :
341 76 : std::map<std::string, std::string>::const_iterator l0_b_size = ai_core_spec_map.find(CONVERT(l0_b_size));
342 76 : if (l0_b_size != ai_core_spec_map.end()) {
343 74 : platform_info_temp.ai_core_spec.l0_b_size = static_cast<uint64_t>(stoll(l0_b_size->second));
344 : }
345 :
346 76 : std::map<std::string, std::string>::const_iterator l0_c_size = ai_core_spec_map.find(CONVERT(l0_c_size));
347 76 : if (l0_c_size != ai_core_spec_map.end()) {
348 74 : platform_info_temp.ai_core_spec.l0_c_size = static_cast<uint64_t>(stoll(l0_c_size->second));
349 : }
350 :
351 76 : std::map<std::string, std::string>::const_iterator l1_size = ai_core_spec_map.find(CONVERT(l1_size));
352 76 : if (l1_size != ai_core_spec_map.end()) {
353 74 : platform_info_temp.ai_core_spec.l1_size = static_cast<uint64_t>(stoll(l1_size->second));
354 : }
355 :
356 76 : std::map<std::string, std::string>::const_iterator smask_buffer = ai_core_spec_map.find(CONVERT(smask_buffer));
357 76 : if (smask_buffer != ai_core_spec_map.end()) {
358 70 : platform_info_temp.ai_core_spec.smask_buffer = static_cast<uint64_t>(stoll(smask_buffer->second));
359 : }
360 0 : } catch (...) {
361 0 : PF_LOGE("Failed to load AICoreSpecs.");
362 0 : }
363 76 : }
364 :
365 77 : void PlatformInfoManager::ParseUBOfAICoreSpec(
366 : std::map<std::string, std::string>& ai_core_spec_map, PlatformInfo& platform_info_temp)
367 : {
368 : try {
369 77 : std::map<std::string, std::string>::const_iterator ub_size = ai_core_spec_map.find(CONVERT(ub_size));
370 77 : if (ub_size != ai_core_spec_map.end()) {
371 76 : platform_info_temp.ai_core_spec.ub_size = static_cast<uint64_t>(stoll(ub_size->second));
372 : }
373 :
374 75 : std::map<std::string, std::string>::const_iterator ubblock_size = ai_core_spec_map.find(CONVERT(ubblock_size));
375 75 : if (ubblock_size != ai_core_spec_map.end()) {
376 74 : platform_info_temp.ai_core_spec.ubblock_size = static_cast<uint64_t>(stoll(ubblock_size->second));
377 : }
378 :
379 75 : std::map<std::string, std::string>::const_iterator ubbank_size = ai_core_spec_map.find(CONVERT(ubbank_size));
380 75 : if (ubbank_size != ai_core_spec_map.end()) {
381 70 : platform_info_temp.ai_core_spec.ubbank_size = static_cast<uint64_t>(stoll(ubbank_size->second));
382 : }
383 :
384 75 : std::map<std::string, std::string>::const_iterator ubbank_num = ai_core_spec_map.find(CONVERT(ubbank_num));
385 75 : if (ubbank_num != ai_core_spec_map.end()) {
386 70 : platform_info_temp.ai_core_spec.ubbank_num = static_cast<uint64_t>(stoll(ubbank_num->second));
387 : }
388 :
389 : std::map<std::string, std::string>::const_iterator ubburst_in_one_block =
390 75 : ai_core_spec_map.find(CONVERT(ubburst_in_one_block));
391 75 : if (ubburst_in_one_block != ai_core_spec_map.end()) {
392 70 : platform_info_temp.ai_core_spec.ubburst_in_one_block =
393 70 : static_cast<uint64_t>(stoll(ubburst_in_one_block->second));
394 : }
395 :
396 : std::map<std::string, std::string>::const_iterator ubbank_group_num =
397 75 : ai_core_spec_map.find(CONVERT(ubbank_group_num));
398 75 : if (ubbank_group_num != ai_core_spec_map.end()) {
399 70 : platform_info_temp.ai_core_spec.ubbank_group_num = static_cast<uint64_t>(stoll(ubbank_group_num->second));
400 : }
401 2 : } catch (...) {
402 2 : PF_LOGE("Failed to load AICoreSpecs.");
403 2 : }
404 77 : }
405 :
406 80 : void PlatformInfoManager::ParseUnzipOfAICoreSpec(
407 : std::map<std::string, std::string>& ai_core_spec_map, PlatformInfo& platform_info_temp)
408 : {
409 : try {
410 : std::map<std::string, std::string>::const_iterator unzip_engines =
411 80 : ai_core_spec_map.find(CONVERT(unzip_engines));
412 80 : if (unzip_engines != ai_core_spec_map.end()) {
413 72 : unsigned long value = std::stoul(unzip_engines->second);
414 70 : if (value > UINT32_MAX) {
415 1 : PF_LOGE("unzip_engines value [%lu] exceeds uint32 range", value);
416 4 : return;
417 : }
418 69 : platform_info_temp.ai_core_spec.unzip_engines = static_cast<uint32_t>(value);
419 : }
420 :
421 : std::map<std::string, std::string>::const_iterator unzip_max_ratios =
422 77 : ai_core_spec_map.find(CONVERT(unzip_max_ratios));
423 77 : if (unzip_max_ratios != ai_core_spec_map.end()) {
424 70 : unsigned long value = std::stoul(unzip_max_ratios->second);
425 70 : if (value > UINT32_MAX) {
426 1 : PF_LOGE("unzip_max_ratios value [%lu] exceeds uint32 range", value);
427 1 : return;
428 : }
429 69 : platform_info_temp.ai_core_spec.unzip_max_ratios = static_cast<uint32_t>(value);
430 : }
431 :
432 : std::map<std::string, std::string>::const_iterator unzip_channels =
433 76 : ai_core_spec_map.find(CONVERT(unzip_channels));
434 76 : if (unzip_channels != ai_core_spec_map.end()) {
435 70 : unsigned long value = std::stoul(unzip_channels->second);
436 70 : if (value > UINT32_MAX) {
437 1 : PF_LOGE("unzip_channels value [%lu] exceeds uint32 range", value);
438 1 : return;
439 : }
440 69 : platform_info_temp.ai_core_spec.unzip_channels = static_cast<uint32_t>(value);
441 : }
442 :
443 : std::map<std::string, std::string>::const_iterator unzip_is_tight =
444 75 : ai_core_spec_map.find(CONVERT(unzip_is_tight));
445 75 : if (unzip_is_tight != ai_core_spec_map.end()) {
446 70 : unsigned long value = std::stoul(unzip_is_tight->second);
447 70 : if (value > UINT8_MAX) {
448 1 : PF_LOGE("unzip_is_tight value [%lu] exceeds uint8 range", value);
449 1 : return;
450 : }
451 69 : platform_info_temp.ai_core_spec.unzip_is_tight = static_cast<uint8_t>(value);
452 : }
453 2 : } catch (const std::invalid_argument& e) {
454 1 : PF_LOGE("Invalid argument in ParseUnzipOfAICoreSpec: %s", e.what());
455 1 : return;
456 2 : } catch (const std::out_of_range& e) {
457 1 : PF_LOGE("Out of range in ParseUnzipOfAICoreSpec: %s", e.what());
458 1 : return;
459 1 : }
460 : }
461 :
462 74 : void PlatformInfoManager::ParseAICoreSpec(
463 : std::map<std::string, std::string>& ai_core_spec_map, PlatformInfo& platform_info_temp)
464 : {
465 74 : (void)ParseCubeOfAICoreSpec(ai_core_spec_map, platform_info_temp);
466 74 : (void)ParseBufferOfAICoreSpec(ai_core_spec_map, platform_info_temp);
467 74 : (void)ParseUBOfAICoreSpec(ai_core_spec_map, platform_info_temp);
468 74 : (void)ParseUnzipOfAICoreSpec(ai_core_spec_map, platform_info_temp);
469 :
470 74 : return;
471 : }
472 :
473 150 : static double CalculateFraction(const std::string& fraction)
474 : {
475 150 : if (fraction.empty()) {
476 1 : PF_LOGE("CalculateFraction: input string is empty.");
477 1 : return 0.0;
478 : }
479 :
480 149 : size_t pos = fraction.find('/');
481 : try {
482 149 : if (pos == std::string::npos) {
483 139 : return std::stod(fraction);
484 : }
485 :
486 10 : if (pos == 0 || pos == fraction.length() - 1) {
487 2 : PF_LOGE("CalculateFraction: invalid fraction format [%s], '/' at boundary.", fraction.c_str());
488 2 : return 0.0;
489 : }
490 :
491 8 : std::string denominator_str = fraction.substr(pos + 1);
492 :
493 : // 在转换前检查字符串是否表示零值(避免浮点数直接比较)
494 8 : std::string trimmed_denominator = denominator_str;
495 8 : size_t start = trimmed_denominator.find_first_not_of(" \t");
496 8 : size_t end = trimmed_denominator.find_last_not_of(" \t");
497 8 : if (start != std::string::npos && end != std::string::npos) {
498 8 : trimmed_denominator = trimmed_denominator.substr(start, end - start + 1);
499 : }
500 22 : if (trimmed_denominator == "0" || trimmed_denominator == "0.0" || trimmed_denominator == "0." ||
501 22 : trimmed_denominator == "-0" || trimmed_denominator == "-0.0" || trimmed_denominator == "-0.") {
502 1 : PF_LOGE("CalculateFraction: denominator is zero in [%s].", fraction.c_str());
503 1 : return 0.0;
504 : }
505 :
506 7 : double denominator = std::stod(denominator_str);
507 :
508 : // 使用 EPSILON 检查接近零的情况(避免直接比较浮点数)
509 7 : constexpr double EPSILON = 1e-10;
510 7 : if (std::abs(denominator) < EPSILON) {
511 1 : PF_LOGE("CalculateFraction: denominator is too small [%s].", fraction.c_str());
512 1 : return 0.0;
513 : }
514 :
515 7 : double numerator = std::stod(fraction.substr(0, pos));
516 5 : double result = numerator / denominator;
517 :
518 : // 检查结果是否有效
519 5 : if (std::isinf(result) || std::isnan(result)) {
520 0 : PF_LOGE("CalculateFraction: invalid result for [%s].", fraction.c_str());
521 0 : return 0.0;
522 : }
523 :
524 5 : return result;
525 11 : } catch (const std::exception& e) {
526 2 : PF_LOGE("CalculateFraction: failed to parse [%s], error: %s.", fraction.c_str(), e.what());
527 2 : return 0.0;
528 2 : } catch (...) {
529 0 : PF_LOGE("CalculateFraction: unknown exception parsing [%s].", fraction.c_str());
530 0 : return 0.0;
531 0 : }
532 : }
533 :
534 72 : void PlatformInfoManager::ParseBufferOfAICoreMemoryRates(
535 : std::map<std::string, std::string>& ai_core_memory_rates_map, PlatformInfo& platform_info_temp)
536 : {
537 : try {
538 72 : std::map<std::string, std::string>::const_iterator ddr_rate = ai_core_memory_rates_map.find(CONVERT(ddr_rate));
539 72 : if (ddr_rate != ai_core_memory_rates_map.end()) {
540 71 : platform_info_temp.ai_core_memory_rates.ddr_rate = static_cast<double>(stod(ddr_rate->second));
541 : }
542 :
543 : std::map<std::string, std::string>::const_iterator ddr_read_rate =
544 71 : ai_core_memory_rates_map.find(CONVERT(ddr_read_rate));
545 71 : if (ddr_read_rate != ai_core_memory_rates_map.end()) {
546 70 : platform_info_temp.ai_core_memory_rates.ddr_read_rate = static_cast<double>(stod(ddr_read_rate->second));
547 : }
548 :
549 : std::map<std::string, std::string>::const_iterator ddr_write_rate =
550 71 : ai_core_memory_rates_map.find(CONVERT(ddr_write_rate));
551 71 : if (ddr_write_rate != ai_core_memory_rates_map.end()) {
552 70 : platform_info_temp.ai_core_memory_rates.ddr_write_rate = static_cast<double>(stod(ddr_write_rate->second));
553 : }
554 :
555 71 : std::map<std::string, std::string>::const_iterator l2_rate = ai_core_memory_rates_map.find(CONVERT(l2_rate));
556 71 : if (l2_rate != ai_core_memory_rates_map.end()) {
557 70 : platform_info_temp.ai_core_memory_rates.l2_rate = static_cast<double>(stod(l2_rate->second));
558 : }
559 :
560 : std::map<std::string, std::string>::const_iterator l2_read_rate =
561 71 : ai_core_memory_rates_map.find(CONVERT(l2_read_rate));
562 71 : if (l2_read_rate != ai_core_memory_rates_map.end()) {
563 70 : platform_info_temp.ai_core_memory_rates.l2_read_rate = static_cast<double>(stod(l2_read_rate->second));
564 : }
565 :
566 : std::map<std::string, std::string>::const_iterator l2_write_rate =
567 71 : ai_core_memory_rates_map.find(CONVERT(l2_write_rate));
568 71 : if (l2_write_rate != ai_core_memory_rates_map.end()) {
569 70 : platform_info_temp.ai_core_memory_rates.l2_write_rate = static_cast<double>(stod(l2_write_rate->second));
570 : }
571 :
572 : std::map<std::string, std::string>::const_iterator l1_to_l0_a_rate =
573 71 : ai_core_memory_rates_map.find(CONVERT(l1_to_l0_a_rate));
574 71 : if (l1_to_l0_a_rate != ai_core_memory_rates_map.end()) {
575 69 : platform_info_temp.ai_core_memory_rates.l1_to_l0_a_rate =
576 69 : static_cast<double>(stod(l1_to_l0_a_rate->second));
577 : }
578 :
579 : std::map<std::string, std::string>::const_iterator l1_to_l0_b_rate =
580 71 : ai_core_memory_rates_map.find(CONVERT(l1_to_l0_b_rate));
581 71 : if (l1_to_l0_b_rate != ai_core_memory_rates_map.end()) {
582 69 : platform_info_temp.ai_core_memory_rates.l1_to_l0_b_rate =
583 69 : static_cast<double>(stod(l1_to_l0_b_rate->second));
584 : }
585 :
586 : std::map<std::string, std::string>::const_iterator l1_to_ub_rate =
587 71 : ai_core_memory_rates_map.find(CONVERT(l1_to_ub_rate));
588 71 : if (l1_to_ub_rate != ai_core_memory_rates_map.end()) {
589 69 : platform_info_temp.ai_core_memory_rates.l1_to_ub_rate = static_cast<double>(stod(l1_to_ub_rate->second));
590 : }
591 :
592 : std::map<std::string, std::string>::const_iterator l0_c_to_ub_rate =
593 71 : ai_core_memory_rates_map.find(CONVERT(l0_c_to_ub_rate));
594 71 : if (l0_c_to_ub_rate != ai_core_memory_rates_map.end()) {
595 69 : platform_info_temp.ai_core_memory_rates.l0_c_to_ub_rate =
596 69 : static_cast<double>(stod(l0_c_to_ub_rate->second));
597 : }
598 1 : } catch (...) {
599 1 : PF_LOGE("Failed to load AICoreMemoryRates.");
600 1 : }
601 72 : }
602 :
603 82 : void PlatformInfoManager::ParseUBOfAICoreMemoryRates(
604 : std::map<std::string, std::string>& ai_core_memory_rates_map, PlatformInfo& platform_info_temp)
605 : {
606 : std::map<std::string, std::string>::const_iterator ub_to_l2_rate =
607 82 : ai_core_memory_rates_map.find(CONVERT(ub_to_l2_rate));
608 82 : if (ub_to_l2_rate != ai_core_memory_rates_map.end()) {
609 81 : platform_info_temp.ai_core_memory_rates.ub_to_l2_rate = CalculateFraction(ub_to_l2_rate->second);
610 : }
611 :
612 : std::map<std::string, std::string>::const_iterator ub_to_ddr_rate =
613 82 : ai_core_memory_rates_map.find(CONVERT(ub_to_ddr_rate));
614 82 : if (ub_to_ddr_rate != ai_core_memory_rates_map.end()) {
615 69 : platform_info_temp.ai_core_memory_rates.ub_to_ddr_rate = CalculateFraction(ub_to_ddr_rate->second);
616 : }
617 :
618 : std::map<std::string, std::string>::const_iterator ub_to_l1_rate =
619 82 : ai_core_memory_rates_map.find(CONVERT(ub_to_l1_rate));
620 82 : if (ub_to_l1_rate != ai_core_memory_rates_map.end()) {
621 : try {
622 70 : platform_info_temp.ai_core_memory_rates.ub_to_l1_rate = static_cast<double>(stod(ub_to_l1_rate->second));
623 1 : } catch (...) {
624 1 : PF_LOGE("Failed to load ub_to_l1_rate [%s].", ub_to_l1_rate->second.c_str());
625 1 : }
626 : }
627 82 : }
628 :
629 69 : void PlatformInfoManager::ParseAICoreMemoryRates(
630 : std::map<std::string, std::string>& ai_core_memory_rates_map, PlatformInfo& platform_info_temp)
631 : {
632 69 : (void)ParseBufferOfAICoreMemoryRates(ai_core_memory_rates_map, platform_info_temp);
633 69 : (void)ParseUBOfAICoreMemoryRates(ai_core_memory_rates_map, platform_info_temp);
634 69 : }
635 :
636 23730 : static std::vector<std::string> Split(const std::string& str, char pattern)
637 : {
638 23730 : std::vector<std::string> res_vec;
639 23730 : if (str.empty()) {
640 0 : return res_vec;
641 : }
642 :
643 23730 : std::string str_and_pattern = str + pattern;
644 23730 : size_t pos = str_and_pattern.find(pattern);
645 23730 : size_t size = str_and_pattern.size();
646 125390 : while (pos != std::string::npos) {
647 101660 : std::string sub_str = str_and_pattern.substr(0, pos);
648 101660 : res_vec.push_back(sub_str);
649 101660 : str_and_pattern = str_and_pattern.substr(pos + 1, size);
650 101660 : pos = str_and_pattern.find(pattern);
651 101660 : }
652 23730 : return res_vec;
653 23730 : }
654 :
655 69 : void PlatformInfoManager::ParseAICoreintrinsicDtypeMap(
656 : std::map<std::string, std::string>& ai_coreintrinsic_dtype_map, PlatformInfo& platform_info_temp)
657 : {
658 69 : std::map<std::string, std::string>::const_iterator iter;
659 7202 : for (iter = ai_coreintrinsic_dtype_map.begin(); iter != ai_coreintrinsic_dtype_map.end(); iter++) {
660 7133 : size_t pos = iter->second.find('|');
661 7133 : if (pos == std::string::npos) {
662 0 : return;
663 : }
664 7133 : std::string key = iter->second.substr(0, pos);
665 7133 : std::string value = iter->second.substr(pos + 1);
666 7133 : std::vector<std::string> dtype_vector = Split(value, ',');
667 7133 : platform_info_temp.ai_core_intrinsic_dtype_map.emplace(make_pair(key, dtype_vector));
668 7133 : }
669 :
670 69 : return;
671 : }
672 :
673 6 : void PlatformInfoManager::ParseVectorCoreSpec(
674 : std::map<std::string, std::string>& vector_core_spec_map, PlatformInfo& platform_info_temp)
675 : {
676 : try {
677 6 : std::map<std::string, std::string>::const_iterator vec_freq = vector_core_spec_map.find(CONVERT(vec_freq));
678 6 : if (vec_freq != vector_core_spec_map.end()) {
679 5 : platform_info_temp.vector_core_spec.vec_freq = static_cast<double>(stod(vec_freq->second));
680 : }
681 :
682 : std::map<std::string, std::string>::const_iterator vec_calc_size =
683 6 : vector_core_spec_map.find(CONVERT(vec_calc_size));
684 6 : if (vec_calc_size != vector_core_spec_map.end()) {
685 5 : platform_info_temp.vector_core_spec.vec_calc_size = static_cast<uint64_t>(stoll(vec_calc_size->second));
686 : }
687 :
688 : std::map<std::string, std::string>::const_iterator smask_buffer =
689 6 : vector_core_spec_map.find(CONVERT(smask_buffer));
690 6 : if (smask_buffer != vector_core_spec_map.end()) {
691 5 : platform_info_temp.vector_core_spec.smask_buffer = static_cast<uint64_t>(stoll(smask_buffer->second));
692 : }
693 :
694 6 : std::map<std::string, std::string>::const_iterator ub_size = vector_core_spec_map.find(CONVERT(ub_size));
695 6 : if (ub_size != vector_core_spec_map.end()) {
696 5 : platform_info_temp.vector_core_spec.ub_size = static_cast<uint64_t>(stoll(ub_size->second));
697 : }
698 :
699 : std::map<std::string, std::string>::const_iterator ubblock_size =
700 6 : vector_core_spec_map.find(CONVERT(ubblock_size));
701 6 : if (ubblock_size != vector_core_spec_map.end()) {
702 5 : platform_info_temp.vector_core_spec.ubblock_size = static_cast<uint64_t>(stoll(ubblock_size->second));
703 : }
704 :
705 : std::map<std::string, std::string>::const_iterator ubbank_size =
706 6 : vector_core_spec_map.find(CONVERT(ubbank_size));
707 6 : if (ubbank_size != vector_core_spec_map.end()) {
708 5 : platform_info_temp.vector_core_spec.ubbank_size = static_cast<uint64_t>(stoll(ubbank_size->second));
709 : }
710 :
711 6 : std::map<std::string, std::string>::const_iterator ubbank_num = vector_core_spec_map.find(CONVERT(ubbank_num));
712 6 : if (ubbank_num != vector_core_spec_map.end()) {
713 5 : platform_info_temp.vector_core_spec.ubbank_num = static_cast<uint64_t>(stoll(ubbank_num->second));
714 : }
715 :
716 : std::map<std::string, std::string>::const_iterator ubburst_in_one_block =
717 6 : vector_core_spec_map.find(CONVERT(ubburst_in_one_block));
718 6 : if (ubburst_in_one_block != vector_core_spec_map.end()) {
719 5 : platform_info_temp.vector_core_spec.ubburst_in_one_block =
720 5 : static_cast<uint64_t>(stoll(ubburst_in_one_block->second));
721 : }
722 :
723 : std::map<std::string, std::string>::const_iterator ubbank_group_num =
724 6 : vector_core_spec_map.find(CONVERT(ubbank_group_num));
725 6 : if (ubbank_group_num != vector_core_spec_map.end()) {
726 5 : platform_info_temp.vector_core_spec.ubbank_group_num =
727 5 : static_cast<uint64_t>(stoll(ubbank_group_num->second));
728 : }
729 :
730 : std::map<std::string, std::string>::const_iterator vector_reg_width =
731 6 : vector_core_spec_map.find(CONVERT(vector_reg_width));
732 6 : if (vector_reg_width != vector_core_spec_map.end()) {
733 0 : platform_info_temp.vector_core_spec.vector_reg_size =
734 0 : static_cast<uint64_t>(stoll(vector_reg_width->second));
735 : }
736 :
737 : std::map<std::string, std::string>::const_iterator predicate_reg_width =
738 6 : vector_core_spec_map.find(CONVERT(predicate_reg_width));
739 6 : if (predicate_reg_width != vector_core_spec_map.end()) {
740 0 : platform_info_temp.vector_core_spec.predicate_reg_size =
741 0 : static_cast<uint64_t>(stoll(predicate_reg_width->second));
742 : }
743 0 : } catch (...) {
744 0 : PF_LOGE("Failed to load VectorCoreSpecs.");
745 0 : }
746 6 : }
747 :
748 6 : void PlatformInfoManager::ParseVectorCoreMemoryRates(
749 : std::map<std::string, std::string>& vector_core_memory_rates_map, PlatformInfo& platform_info_temp)
750 : {
751 : try {
752 : std::map<std::string, std::string>::const_iterator ddr_rate =
753 6 : vector_core_memory_rates_map.find(CONVERT(ddr_rate));
754 6 : if (ddr_rate != vector_core_memory_rates_map.end()) {
755 6 : platform_info_temp.vector_core_memory_rates.ddr_rate = static_cast<double>(stod(ddr_rate->second));
756 : }
757 :
758 : std::map<std::string, std::string>::const_iterator ddr_read_rate =
759 5 : vector_core_memory_rates_map.find(CONVERT(ddr_read_rate));
760 5 : if (ddr_read_rate != vector_core_memory_rates_map.end()) {
761 4 : platform_info_temp.vector_core_memory_rates.ddr_read_rate =
762 4 : static_cast<double>(stod(ddr_read_rate->second));
763 : }
764 :
765 : std::map<std::string, std::string>::const_iterator ddr_write_rate =
766 5 : vector_core_memory_rates_map.find(CONVERT(ddr_write_rate));
767 5 : if (ddr_write_rate != vector_core_memory_rates_map.end()) {
768 4 : platform_info_temp.vector_core_memory_rates.ddr_write_rate =
769 4 : static_cast<double>(stod(ddr_write_rate->second));
770 : }
771 :
772 : std::map<std::string, std::string>::const_iterator l2_rate =
773 5 : vector_core_memory_rates_map.find(CONVERT(l2_rate));
774 5 : if (l2_rate != vector_core_memory_rates_map.end()) {
775 5 : platform_info_temp.vector_core_memory_rates.l2_rate = static_cast<double>(stod(l2_rate->second));
776 : }
777 :
778 : std::map<std::string, std::string>::const_iterator l2_read_rate =
779 5 : vector_core_memory_rates_map.find(CONVERT(l2_read_rate));
780 5 : if (l2_read_rate != vector_core_memory_rates_map.end()) {
781 4 : platform_info_temp.vector_core_memory_rates.l2_read_rate = static_cast<double>(stod(l2_read_rate->second));
782 : }
783 :
784 : std::map<std::string, std::string>::const_iterator l2_write_rate =
785 5 : vector_core_memory_rates_map.find(CONVERT(l2_write_rate));
786 5 : if (l2_write_rate != vector_core_memory_rates_map.end()) {
787 4 : platform_info_temp.vector_core_memory_rates.l2_write_rate =
788 4 : static_cast<double>(stod(l2_write_rate->second));
789 : }
790 :
791 : std::map<std::string, std::string>::const_iterator ub_to_l2_rate =
792 5 : vector_core_memory_rates_map.find(CONVERT(ub_to_l2_rate));
793 5 : if (ub_to_l2_rate != vector_core_memory_rates_map.end()) {
794 5 : platform_info_temp.vector_core_memory_rates.ub_to_l2_rate =
795 5 : static_cast<double>(stod(ub_to_l2_rate->second));
796 : }
797 :
798 : std::map<std::string, std::string>::const_iterator ub_to_ddr_rate =
799 5 : vector_core_memory_rates_map.find(CONVERT(ub_to_ddr_rate));
800 5 : if (ub_to_ddr_rate != vector_core_memory_rates_map.end()) {
801 4 : platform_info_temp.vector_core_memory_rates.ub_to_ddr_rate =
802 4 : static_cast<double>(stod(ub_to_ddr_rate->second));
803 : }
804 1 : } catch (...) {
805 1 : PF_LOGE("Failed to load VectorCoreMemoryRates.");
806 1 : }
807 6 : }
808 :
809 74 : void PlatformInfoManager::ParseCPUCache(
810 : std::map<std::string, std::string>& CPUCacheMap, PlatformInfo& platform_info_temp)
811 : {
812 : try {
813 74 : std::map<std::string, std::string>::const_iterator AICPUSyncBySW = CPUCacheMap.find(CONVERT(AICPUSyncBySW));
814 74 : if (AICPUSyncBySW != CPUCacheMap.end()) {
815 73 : unsigned long value = std::stoul(AICPUSyncBySW->second);
816 73 : if (value > UINT32_MAX) {
817 0 : PF_LOGE("AICPUSyncBySW value [%lu] exceeds uint32 range", value);
818 0 : return;
819 : }
820 73 : platform_info_temp.cpucache.AICPUSyncBySW = static_cast<uint32_t>(value);
821 : }
822 :
823 74 : std::map<std::string, std::string>::const_iterator TSCPUSyncBySW = CPUCacheMap.find(CONVERT(TSCPUSyncBySW));
824 74 : if (TSCPUSyncBySW != CPUCacheMap.end()) {
825 73 : unsigned long value = std::stoul(TSCPUSyncBySW->second);
826 73 : if (value > UINT32_MAX) {
827 0 : PF_LOGE("TSCPUSyncBySW value [%lu] exceeds uint32 range", value);
828 0 : return;
829 : }
830 73 : platform_info_temp.cpucache.TSCPUSyncBySW = static_cast<uint32_t>(value);
831 : }
832 0 : } catch (const std::invalid_argument& e) {
833 0 : PF_LOGE("Invalid argument in ParseCPUCache: %s", e.what());
834 0 : return;
835 0 : } catch (const std::out_of_range& e) {
836 0 : PF_LOGE("Out of range in ParseCPUCache: %s", e.what());
837 0 : return;
838 0 : }
839 : }
840 :
841 62 : void PlatformInfoManager::ParseVectorCoreintrinsicDtypeMap(
842 : std::map<std::string, std::string>& vector_coreintrinsic_dtype_map, PlatformInfo& platform_info_temp)
843 : {
844 62 : std::map<std::string, std::string>::const_iterator iter;
845 4794 : for (iter = vector_coreintrinsic_dtype_map.begin(); iter != vector_coreintrinsic_dtype_map.end(); iter++) {
846 4732 : size_t pos = iter->second.find('|');
847 4732 : if (pos == std::string::npos) {
848 0 : PF_LOGE("The intrinsic_dtype_map string does not contain '|'.");
849 0 : return;
850 : }
851 4732 : std::string key = iter->second.substr(0, pos);
852 4732 : std::string value = iter->second.substr(pos + 1);
853 4732 : std::vector<std::string> dtype_vector = Split(value, ',');
854 4732 : platform_info_temp.vector_core_intrinsic_dtype_map.emplace(make_pair(key, dtype_vector));
855 4732 : }
856 : }
857 :
858 16 : void PlatformInfoManager::ParseSoftwareSpec(
859 : std::map<std::string, std::string>& software_spec_map, PlatformInfo& platform_info_temp)
860 : {
861 : try {
862 : std::map<std::string, std::string>::const_iterator jit_compile_default_value =
863 16 : software_spec_map.find(CONVERT(jit_compile_default_value));
864 16 : if (jit_compile_default_value != software_spec_map.end() && jit_compile_default_value->second == "1") {
865 15 : platform_info_temp.software_spec.jit_compile_default_value = true;
866 15 : platform_info_temp.software_spec.jit_compile_mode = JitCompileMode::COMPILE_ONLINE;
867 : } else {
868 1 : platform_info_temp.software_spec.jit_compile_default_value = false;
869 : }
870 0 : } catch (...) {
871 0 : PF_LOGE("Failed to load software specification.");
872 0 : }
873 16 : }
874 :
875 73 : uint32_t PlatformInfoManager::ParsePlatformInfoFromStrToStruct(
876 : std::map<std::string, std::map<std::string, std::string>>& content_info_map, std::string& soc_version,
877 : PlatformInfo& platform_info_temp)
878 : {
879 73 : std::map<std::string, std::map<std::string, std::string>>::iterator it;
880 777 : for (it = content_info_map.begin(); it != content_info_map.end(); it++) {
881 704 : auto iter = g_platform_info_type_map.find(it->first);
882 704 : if (iter == g_platform_info_type_map.end()) {
883 189 : continue;
884 : }
885 :
886 515 : switch (iter->second) {
887 73 : case PlatformInfoType::EN_VERSION: {
888 73 : ParseVersion(it->second, soc_version, platform_info_temp);
889 73 : break;
890 : }
891 73 : case PlatformInfoType::EN_SOC_INFO: {
892 73 : ParseSocInfo(it->second, platform_info_temp);
893 73 : break;
894 : }
895 73 : case PlatformInfoType::EN_AI_CORE_SPEC: {
896 73 : ParseAICoreSpec(it->second, platform_info_temp);
897 73 : break;
898 : }
899 69 : case PlatformInfoType::EN_AI_CORE_MEMORY_RATES: {
900 69 : ParseAICoreMemoryRates(it->second, platform_info_temp);
901 69 : break;
902 : }
903 73 : case PlatformInfoType::EN_CPU_CACHE: {
904 73 : ParseCPUCache(it->second, platform_info_temp);
905 73 : break;
906 : }
907 69 : case PlatformInfoType::EN_AI_CORE_INTRINSIC_DTYPE_MAP: {
908 69 : ParseAICoreintrinsicDtypeMap(it->second, platform_info_temp);
909 69 : break;
910 : }
911 4 : case PlatformInfoType::EN_VECTOR_CORE_SPEC: {
912 4 : ParseVectorCoreSpec(it->second, platform_info_temp);
913 4 : break;
914 : }
915 4 : case PlatformInfoType::EN_VECTOR_CORE_MEMORY_RATES: {
916 4 : ParseVectorCoreMemoryRates(it->second, platform_info_temp);
917 4 : break;
918 : }
919 62 : case PlatformInfoType::EN_VECTOR_CORE_INTRINSIC_DTYPE_MAP: {
920 62 : ParseVectorCoreintrinsicDtypeMap(it->second, platform_info_temp);
921 62 : break;
922 : }
923 15 : case PlatformInfoType::EN_SOFTWARE_SPEC: {
924 15 : ParseSoftwareSpec(it->second, platform_info_temp);
925 15 : break;
926 : }
927 0 : default: {
928 0 : return PLATFORM_FAILED;
929 : }
930 : }
931 : }
932 :
933 73 : return PLATFORM_SUCCESS;
934 : }
935 :
936 73 : uint32_t PlatformInfoManager::AssemblePlatformInfoVector(
937 : std::map<std::string, std::map<std::string, std::string>>& content_info_map)
938 : {
939 73 : std::string soc_version;
940 73 : PlatformInfo platform_info_temp;
941 73 : uint32_t ret = ParsePlatformInfoFromStrToStruct(content_info_map, soc_version, platform_info_temp);
942 73 : if (ret != PLATFORM_SUCCESS) {
943 0 : PF_LOGE("Parse platform info from content failed.");
944 0 : return PLATFORM_FAILED;
945 : }
946 :
947 73 : if (!soc_version.empty()) {
948 73 : auto iter = platform_info_map_.find(soc_version);
949 73 : if (iter == platform_info_map_.end()) {
950 73 : platform_info_map_.emplace(make_pair(soc_version, platform_info_temp));
951 : }
952 : }
953 :
954 73 : PlatFormInfos platform_infos;
955 73 : if (!platform_infos.Init()) {
956 0 : return PLATFORM_FAILED;
957 : }
958 :
959 73 : if (ParsePlatformInfo(content_info_map, soc_version, platform_infos) != PLATFORM_SUCCESS) {
960 0 : PF_LOGE("Parse platform info from content failed.");
961 0 : return PLATFORM_FAILED;
962 : }
963 73 : FillupFixPipeInfo(platform_infos);
964 73 : if (!soc_version.empty()) {
965 73 : auto iter = platform_infos_map_.find(soc_version);
966 73 : if (iter == platform_infos_map_.end()) {
967 73 : platform_infos_map_.emplace(soc_version, platform_infos);
968 73 : PF_LOGD("The platform info's os soc version[%s] has been initialized.", soc_version.c_str());
969 : }
970 : }
971 73 : return PLATFORM_SUCCESS;
972 73 : }
973 :
974 73 : void PlatformInfoManager::FillupFixPipeInfo(PlatFormInfos& platform_infos)
975 : {
976 73 : std::string is_support_fixpipe_str;
977 427 : if (!platform_infos.GetPlatformResWithLock("AICoreSpec", "support_fixpipe", is_support_fixpipe_str) ||
978 62 : !static_cast<bool>(std::atoi(is_support_fixpipe_str.c_str()))) {
979 11 : return;
980 : }
981 62 : std::map<std::string, std::vector<std::string>> aicore_map = platform_infos.GetAICoreIntrinsicDtype();
982 62 : std::map<std::string, std::vector<std::string>> fixpipe_map_;
983 5978 : for (auto iter = aicore_map.begin(); iter != aicore_map.end(); iter++) {
984 5916 : if (iter->first.find(FIXPIPE_CONFIG_KEY) != iter->first.npos) {
985 928 : fixpipe_map_.emplace(make_pair(iter->first, iter->second));
986 : }
987 : }
988 62 : if (fixpipe_map_.empty()) {
989 4 : return;
990 : }
991 58 : platform_infos.SetFixPipeDtypeMap(fixpipe_map_);
992 81 : }
993 :
994 69 : void PlatformInfoManager::ParseAICoreintrinsicDtypeMap(
995 : std::map<std::string, std::string>& ai_coreintrinsic_dtype_map, PlatFormInfos& platform_info_temp)
996 : {
997 69 : std::map<std::string, std::string>::const_iterator iter;
998 69 : std::map<std::string, std::string> platform_res_map;
999 : std::map<std::string, std::vector<std::string>> aicore_intrinsic_dtypes =
1000 69 : platform_info_temp.GetAICoreIntrinsicDtype();
1001 7202 : for (iter = ai_coreintrinsic_dtype_map.begin(); iter != ai_coreintrinsic_dtype_map.end(); iter++) {
1002 7133 : size_t pos = iter->second.find('|');
1003 7133 : if (pos == std::string::npos) {
1004 0 : return;
1005 : }
1006 7133 : std::string key = iter->second.substr(0, pos);
1007 7133 : std::string value = iter->second.substr(pos + 1);
1008 7133 : std::vector<std::string> dtype_vector = Split(value, ',');
1009 7133 : platform_res_map.emplace(make_pair(key, value));
1010 7133 : aicore_intrinsic_dtypes.emplace(make_pair(key, dtype_vector));
1011 7133 : }
1012 :
1013 69 : platform_info_temp.SetPlatformRes(STR_AI_CORE_INTRINSIC_DTYPE_MAP, platform_res_map);
1014 69 : platform_info_temp.SetAICoreIntrinsicDtype(aicore_intrinsic_dtypes);
1015 69 : }
1016 :
1017 62 : void PlatformInfoManager::ParseVectorCoreintrinsicDtypeMap(
1018 : std::map<std::string, std::string>& vector_coreintrinsic_dtype_map, PlatFormInfos& platform_info_temp)
1019 : {
1020 62 : std::map<std::string, std::string>::const_iterator iter;
1021 62 : std::map<std::string, std::string> platform_res_map;
1022 : std::map<std::string, std::vector<std::string>> vector_core_intrinsic_dtype_map =
1023 62 : platform_info_temp.GetVectorCoreIntrinsicDtype();
1024 4794 : for (iter = vector_coreintrinsic_dtype_map.begin(); iter != vector_coreintrinsic_dtype_map.end(); iter++) {
1025 4732 : size_t pos = iter->second.find('|');
1026 4732 : if (pos == std::string::npos) {
1027 0 : PF_LOGE("The intrinsic_dtype_map string does not contain '|'.");
1028 0 : return;
1029 : }
1030 4732 : std::string key = iter->second.substr(0, pos);
1031 4732 : std::string value = iter->second.substr(pos + 1);
1032 4732 : std::vector<std::string> dtype_vector = Split(value, ',');
1033 4732 : platform_res_map.emplace(make_pair(key, value));
1034 4732 : vector_core_intrinsic_dtype_map.emplace(make_pair(key, dtype_vector));
1035 4732 : }
1036 :
1037 62 : platform_info_temp.SetPlatformRes(STR_VECTOR_CORE_INTRINSIC_DTYPE_MAP, platform_res_map);
1038 62 : platform_info_temp.SetVectorCoreIntrinsicDtype(vector_core_intrinsic_dtype_map);
1039 62 : }
1040 :
1041 573 : void PlatformInfoManager::ParsePlatformRes(
1042 : const std::string& label, std::map<std::string, std::string>& platform_res_map, PlatFormInfos& platform_info_temp)
1043 : {
1044 573 : platform_info_temp.SetPlatformRes(label, platform_res_map);
1045 573 : }
1046 :
1047 73 : uint32_t PlatformInfoManager::ParsePlatformInfo(
1048 : std::map<std::string, std::map<std::string, std::string>>& content_info_map, std::string& soc_version,
1049 : PlatFormInfos& platform_info_temp)
1050 : {
1051 : (void)soc_version;
1052 73 : std::map<std::string, std::map<std::string, std::string>>::iterator it;
1053 777 : for (it = content_info_map.begin(); it != content_info_map.end(); it++) {
1054 704 : if (it->first == STR_AI_CORE_INTRINSIC_DTYPE_MAP) {
1055 69 : ParseAICoreintrinsicDtypeMap(it->second, platform_info_temp);
1056 635 : } else if (it->first == STR_VECTOR_CORE_INTRINSIC_DTYPE_MAP) {
1057 62 : ParseVectorCoreintrinsicDtypeMap(it->second, platform_info_temp);
1058 : } else {
1059 573 : ParsePlatformRes(it->first, it->second, platform_info_temp);
1060 : }
1061 : }
1062 :
1063 73 : return PLATFORM_SUCCESS;
1064 : }
1065 :
1066 138 : __attribute__((visibility("default"))) uint32_t PlatformInfoManager::InitializePlatformInfo()
1067 : {
1068 : // add lock
1069 138 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1070 138 : if (init_flag_) {
1071 1 : return PLATFORM_SUCCESS;
1072 : }
1073 137 : cfg_file_real_path_ = fe::GetConfigFilePath<PlatformInfoManager>();
1074 137 : if (cfg_file_real_path_.empty()) {
1075 0 : PF_LOGE("File path[%s] is not valid.", cfg_file_real_path_.c_str());
1076 0 : return PLATFORM_FAILED;
1077 : }
1078 :
1079 137 : if (!opti_compilation_infos_.Init()) {
1080 0 : PF_LOGE("Failed to initialize optional information.");
1081 0 : return PLATFORM_FAILED;
1082 : }
1083 :
1084 137 : init_flag_ = true;
1085 :
1086 137 : return PLATFORM_SUCCESS;
1087 138 : }
1088 :
1089 6 : __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInfo(
1090 : const std::string SoCVersion, PlatformInfo& platform_info, OptionalInfo& opti_compilation_info)
1091 : {
1092 6 : std::string realSocVersion = SoCVersion;
1093 6 : if (realSocVersion == SOC_VERSION_ASCEND910) {
1094 1 : realSocVersion = SOC_VERSION_ASCEND910A;
1095 : }
1096 6 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1097 6 : auto iter = platform_info_map_.find(realSocVersion);
1098 6 : if (iter == platform_info_map_.end()) {
1099 5 : if (EnsureSocVersionLoaded(realSocVersion) != PLATFORM_SUCCESS) {
1100 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str());
1101 1 : return PLATFORM_FAILED;
1102 : }
1103 4 : iter = platform_info_map_.find(realSocVersion);
1104 4 : if (iter == platform_info_map_.end()) {
1105 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str());
1106 1 : return PLATFORM_FAILED;
1107 : }
1108 : }
1109 4 : platform_info = iter->second;
1110 4 : opti_compilation_info = opti_compilation_info_;
1111 4 : return PLATFORM_SUCCESS;
1112 6 : }
1113 :
1114 : __attribute__((visibility("default"))) uint32_t
1115 4 : PlatformInfoManager::GetPlatformInfoWithOutSocVersion(PlatformInfo& platform_info, OptionalInfo& opti_compilation_info)
1116 : {
1117 4 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1118 4 : if (opti_compilation_info_.soc_version.empty()) {
1119 1 : PF_LOGW("Can not found platform_info.");
1120 1 : return PLATFORM_FAILED;
1121 : }
1122 3 : auto iter = platform_info_map_.find(opti_compilation_info_.soc_version);
1123 3 : if (iter == platform_info_map_.end()) {
1124 2 : if (EnsureSocVersionLoaded(opti_compilation_info_.soc_version) != PLATFORM_SUCCESS) {
1125 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_info_.soc_version.c_str());
1126 1 : return PLATFORM_FAILED;
1127 : }
1128 1 : iter = platform_info_map_.find(opti_compilation_info_.soc_version);
1129 1 : if (iter == platform_info_map_.end()) {
1130 0 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_info_.soc_version.c_str());
1131 0 : return PLATFORM_FAILED;
1132 : }
1133 : }
1134 2 : platform_info = iter->second;
1135 2 : opti_compilation_info = opti_compilation_info_;
1136 2 : return PLATFORM_SUCCESS;
1137 4 : }
1138 :
1139 4 : void PlatformInfoManager::SetOptionalCompilationInfo(OptionalInfo& opti_compilation_info)
1140 : {
1141 : // add lock
1142 4 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1143 4 : opti_compilation_info_ = opti_compilation_info;
1144 4 : if (opti_compilation_info_.soc_version == SOC_VERSION_ASCEND910) {
1145 1 : opti_compilation_info_.soc_version = SOC_VERSION_ASCEND910A;
1146 : }
1147 4 : }
1148 :
1149 59 : __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInfos(
1150 : const std::string SoCVersion, PlatFormInfos& platform_info, OptionalInfos& opti_compilation_info)
1151 : {
1152 59 : std::string realSocVersion = SoCVersion;
1153 59 : if (realSocVersion == SOC_VERSION_ASCEND910) {
1154 1 : realSocVersion = SOC_VERSION_ASCEND910A;
1155 : }
1156 59 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1157 59 : auto iter = platform_infos_map_.find(realSocVersion);
1158 59 : if (iter == platform_infos_map_.end()) {
1159 54 : if (EnsureSocVersionLoaded(realSocVersion) != PLATFORM_SUCCESS) {
1160 2 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str());
1161 2 : return PLATFORM_FAILED;
1162 : }
1163 52 : iter = platform_infos_map_.find(realSocVersion);
1164 52 : if (iter == platform_infos_map_.end()) {
1165 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str());
1166 1 : return PLATFORM_FAILED;
1167 : }
1168 : }
1169 56 : platform_info = iter->second;
1170 56 : opti_compilation_info = opti_compilation_infos_;
1171 56 : opti_compilation_info.SetFixPipeDtypeMap(platform_info.GetFixPipeDtypeMap());
1172 56 : return PLATFORM_SUCCESS;
1173 59 : }
1174 :
1175 40 : __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInfoWithOutSocVersion(
1176 : PlatFormInfos& platform_info, OptionalInfos& opti_compilation_info)
1177 : {
1178 40 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1179 40 : std::string real_soc = opti_compilation_infos_.GetSocVersion();
1180 40 : if (real_soc.empty()) {
1181 10 : PF_LOGW("Cannot find platform_info.");
1182 10 : return PLATFORM_FAILED;
1183 : }
1184 30 : auto iter = platform_infos_map_.find(real_soc);
1185 30 : if (iter == platform_infos_map_.end()) {
1186 3 : if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) {
1187 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", real_soc.c_str());
1188 1 : return PLATFORM_FAILED;
1189 : }
1190 2 : iter = platform_infos_map_.find(real_soc);
1191 2 : if (iter == platform_infos_map_.end()) {
1192 1 : PF_LOGE("Cannot find platform_info by SoCVersion %s.", real_soc.c_str());
1193 1 : return PLATFORM_FAILED;
1194 : }
1195 : }
1196 28 : platform_info = iter->second;
1197 28 : if (!platform_info.GetFixPipeDtypeMap().empty()) {
1198 28 : opti_compilation_infos_.SetFixPipeDtypeMap(platform_info.GetFixPipeDtypeMap());
1199 : }
1200 28 : opti_compilation_info = opti_compilation_infos_;
1201 28 : return PLATFORM_SUCCESS;
1202 40 : }
1203 :
1204 : __attribute__((visibility("default"))) uint32_t
1205 9 : PlatformInfoManager::GetPlatformInstanceByDevice(const uint32_t& device_id, PlatFormInfos& platform_info)
1206 : {
1207 9 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1208 9 : std::string real_soc = opti_compilation_infos_.GetSocVersion();
1209 9 : auto iter = device_platform_infos_map_.find(device_id);
1210 9 : if (iter == device_platform_infos_map_.end()) {
1211 9 : if (real_soc.empty()) {
1212 2 : PF_LOGW("Not initialize soc_version of optional_infos.");
1213 2 : return PLATFORM_FAILED;
1214 : }
1215 7 : if (platform_infos_map_.find(real_soc) == platform_infos_map_.end()) {
1216 6 : if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) {
1217 1 : PF_LOGW("Failed to initialize platform info map.");
1218 1 : return PLATFORM_FAILED;
1219 : }
1220 5 : if (platform_infos_map_.find(real_soc) == platform_infos_map_.end()) {
1221 1 : PF_LOGW("Failed to initialize platform info map.");
1222 1 : return PLATFORM_FAILED;
1223 : }
1224 : }
1225 5 : device_platform_infos_map_[device_id] = platform_infos_map_[real_soc];
1226 : }
1227 5 : platform_info = device_platform_infos_map_[device_id];
1228 5 : return PLATFORM_SUCCESS;
1229 9 : }
1230 :
1231 49 : void PlatformInfoManager::SetOptionalCompilationInfo(OptionalInfos& opti_compilation_info)
1232 : {
1233 : // add lock
1234 49 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1235 49 : opti_compilation_infos_ = opti_compilation_info;
1236 49 : if (opti_compilation_infos_.GetSocVersion() == SOC_VERSION_ASCEND910) {
1237 1 : opti_compilation_infos_.SetSocVersion(SOC_VERSION_ASCEND910A);
1238 : }
1239 49 : }
1240 :
1241 5 : uint32_t PlatformInfoManager::UpdatePlatformInfos(fe::PlatFormInfos& platform_info)
1242 : {
1243 : // add lock
1244 5 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1245 5 : if (opti_compilation_infos_.GetSocVersion().empty()) {
1246 2 : PF_LOGE("Soc_version in the optional information is empty.");
1247 2 : return PLATFORM_FAILED;
1248 : }
1249 3 : auto iter = platform_infos_map_.find(opti_compilation_infos_.GetSocVersion());
1250 3 : if (iter == platform_infos_map_.end()) {
1251 2 : if (EnsureSocVersionLoaded(opti_compilation_infos_.GetSocVersion()) != PLATFORM_SUCCESS) {
1252 1 : PF_LOGE(
1253 : "Platform info for soc_version [%s] is not initialized.",
1254 : opti_compilation_infos_.GetSocVersion().c_str());
1255 1 : return PLATFORM_FAILED;
1256 : }
1257 1 : iter = platform_infos_map_.find(opti_compilation_infos_.GetSocVersion());
1258 1 : if (iter == platform_infos_map_.end()) {
1259 0 : PF_LOGE(
1260 : "Platform info for soc_version [%s] is not initialized.",
1261 : opti_compilation_infos_.GetSocVersion().c_str());
1262 0 : return PLATFORM_FAILED;
1263 : }
1264 : }
1265 2 : platform_infos_map_[opti_compilation_infos_.GetSocVersion()] = platform_info;
1266 2 : return PLATFORM_SUCCESS;
1267 5 : }
1268 :
1269 6 : uint32_t PlatformInfoManager::UpdatePlatformInfos(const std::string& soc_version, fe::PlatFormInfos& platform_info)
1270 : {
1271 : // add lock
1272 6 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1273 6 : if (soc_version.empty()) {
1274 1 : PF_LOGE("Soc_version is empty.");
1275 1 : return PLATFORM_FAILED;
1276 : }
1277 5 : std::string real_soc = soc_version;
1278 5 : if (real_soc == SOC_VERSION_ASCEND910) {
1279 1 : real_soc = SOC_VERSION_ASCEND910A;
1280 : }
1281 5 : auto iter = platform_infos_map_.find(real_soc);
1282 5 : if (iter == platform_infos_map_.end()) {
1283 4 : if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) {
1284 1 : PF_LOGE("Platform info for soc_version [%s] is not initialized.", real_soc.c_str());
1285 1 : return PLATFORM_FAILED;
1286 : }
1287 3 : iter = platform_infos_map_.find(real_soc);
1288 3 : if (iter == platform_infos_map_.end()) {
1289 0 : PF_LOGE("Platform info for soc_version [%s] is not initialized.", real_soc.c_str());
1290 0 : return PLATFORM_FAILED;
1291 : }
1292 : }
1293 4 : opti_compilation_infos_.SetSocVersionWithLock(real_soc);
1294 4 : platform_infos_map_[real_soc] = platform_info;
1295 4 : return PLATFORM_SUCCESS;
1296 6 : }
1297 :
1298 152 : uint32_t PlatformInfoManager::Finalize()
1299 : {
1300 : // add lock
1301 152 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1302 152 : if (!init_flag_) {
1303 15 : return PLATFORM_SUCCESS;
1304 : }
1305 :
1306 137 : platform_info_map_.clear();
1307 :
1308 137 : platform_infos_map_.clear();
1309 :
1310 137 : device_platform_infos_map_.clear();
1311 :
1312 137 : runtime_device_platform_infos_map_.clear();
1313 :
1314 137 : loaded_ini_files_.clear();
1315 :
1316 137 : cfg_file_real_path_.clear();
1317 :
1318 137 : init_flag_ = false;
1319 :
1320 137 : return PLATFORM_SUCCESS;
1321 152 : }
1322 :
1323 12 : uint32_t PlatformInfoManager::GetRuntimePlatformInfosByDevice(
1324 : const uint32_t& device_id, PlatFormInfos& platform_infos, bool need_deep_copy)
1325 : {
1326 12 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1327 12 : const auto it = runtime_device_platform_infos_map_.find(device_id);
1328 12 : PlatFormInfos device_platform_infos;
1329 12 : if (it == runtime_device_platform_infos_map_.end()) {
1330 10 : PF_LOGD("Add new platform info with device_id %u.", device_id);
1331 10 : PlatformInfosUtils::GetInstance().Clone(device_platform_infos, runtime_platform_infos_);
1332 10 : runtime_device_platform_infos_map_[device_id] = device_platform_infos;
1333 : } else {
1334 2 : PF_LOGD("Return the platform infos with device_id %u.", device_id);
1335 2 : device_platform_infos = it->second;
1336 : }
1337 12 : if (need_deep_copy) {
1338 0 : PlatformInfosUtils::GetInstance().Clone(platform_infos, device_platform_infos);
1339 : } else {
1340 12 : platform_infos = device_platform_infos;
1341 : }
1342 12 : return PLATFORM_SUCCESS;
1343 12 : }
1344 :
1345 4 : uint32_t PlatformInfoManager::UpdateRuntimePlatformInfosByDevice(
1346 : const uint32_t& device_id, PlatFormInfos& platform_infos)
1347 : {
1348 4 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1349 4 : PF_LOGD("Update the platform info with device_id %u.", device_id);
1350 4 : PlatFormInfos device_platform_infos;
1351 4 : PlatformInfosUtils::GetInstance().Clone(device_platform_infos, platform_infos);
1352 4 : runtime_device_platform_infos_map_[device_id] = device_platform_infos;
1353 4 : return PLATFORM_SUCCESS;
1354 4 : }
1355 :
1356 9 : uint32_t PlatformInfoManager::InitRuntimePlatformInfos(const std::string& SoCVersion)
1357 : {
1358 9 : std::lock_guard<std::mutex> lock_guard(pc_lock_);
1359 9 : if (runtime_init_flag_) {
1360 1 : return PLATFORM_SUCCESS;
1361 : }
1362 :
1363 8 : if (cfg_file_real_path_.empty()) {
1364 7 : cfg_file_real_path_ = fe::GetConfigFilePath<PlatformInfoManager>();
1365 7 : if (cfg_file_real_path_.empty()) {
1366 0 : PF_LOGE("File path[%s] is not valid.", cfg_file_real_path_.c_str());
1367 0 : return PLATFORM_FAILED;
1368 : }
1369 : }
1370 :
1371 8 : std::string real_soc = SoCVersion;
1372 8 : if (real_soc == SOC_VERSION_ASCEND910) {
1373 1 : real_soc = SOC_VERSION_ASCEND910A;
1374 : }
1375 :
1376 8 : if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) {
1377 1 : PF_LOGE("Failed to load ini file for soc[%s].", real_soc.c_str());
1378 1 : return PLATFORM_FAILED;
1379 : }
1380 :
1381 7 : const auto it = platform_infos_map_.find(real_soc);
1382 7 : if (it == platform_infos_map_.end()) {
1383 0 : std::string errLevel = "E20101";
1384 0 : std::vector<const char*> args_keys;
1385 0 : const char* SocVersion = SoCVersion.c_str();
1386 0 : std::vector<const char*> args_values;
1387 0 : args_keys.push_back("value");
1388 0 : args_keys.push_back("parameter");
1389 0 : args_keys.push_back("reason");
1390 0 : args_values.push_back(SocVersion);
1391 0 : args_values.push_back("SoCVersion");
1392 0 : args_values.push_back("SocVersion may be incorrect");
1393 0 : REPORT_PREDEFINED_ERRMSG_3PARAMS(errLevel.c_str(), args_keys, args_values);
1394 0 : PF_LOGE("Not find platformInfos, SocVersion: [%s]", SoCVersion.c_str());
1395 0 : return PLATFORM_FAILED;
1396 0 : }
1397 7 : PlatformInfosUtils::GetInstance().Clone(runtime_platform_infos_, it->second);
1398 7 : runtime_init_flag_ = true;
1399 7 : return PLATFORM_SUCCESS;
1400 9 : }
1401 :
1402 : } // namespace fe
|