已合并
【PR】: 简要描述 新增aclplatfom的对外接口 #2453
【PR】: 简要描述 新增aclplatfom的对外接口 #2453
已合并
jiang-mingming01创建于 5月28日
9 个文件变更+830-14
@@ -0,0 +1,123 @@
1+/**
2+ * Copyright (c) 2026 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+/**
12+ * @file acl_platform.h
13+ *
14+ * @brief ACL Platform Query Interface.
15+ *
16+ * Provides APIs to query device hardware information and instruction
17+ * availability based on core type.
18+ */
19+ 
20+#ifndef INC_PKG_PLATFORM_ACL_PLATFORM_H_
21+#define INC_PKG_PLATFORM_ACL_PLATFORM_H_
22+ 
23+#include <stdint.h>
24+#include "acl_base.h"
25+ 
26+#ifdef __cplusplus
27+extern "C" {
28+#endif
29+ 
30+typedef enum aclplatformDevInfo {
31+ ACL_PLATFORM_AICORE_CNT = 0,
32+ ACL_PLATFORM_AICORE_UB_SIZE = 1,
33+ ACL_PLATFORM_CUBE_CORE_CNT = 2,
34+ ACL_PLATFORM_VECTOR_CORE_CNT = 3,
35+ ACL_PLATFORM_L2_SIZE = 4,
36+ ACL_PLATFORM_MEMORY_SIZE = 5,
37+ ACL_PLATFORM_CUBE_FREQ = 6,
38+ ACL_PLATFORM_VEC_FREQ = 7,
39+ ACL_PLATFORM_BT_SIZE = 8,
40+ ACL_PLATFORM_L0_A_SIZE = 9,
41+ ACL_PLATFORM_L0_B_SIZE = 10,
42+ ACL_PLATFORM_L0_C_SIZE = 11,
43+ ACL_PLATFORM_L1_SIZE = 12,
44+ ACL_PLATFORM_SHORT_SOC_VERSION = 13,
45+ ACL_PLATFORM_SOC_VERSION = 14,
46+ ACL_PLATFORM_AIC_VERSION = 15,
47+ ACL_PLATFORM_NPU_ARCH = 16,
48+ ACL_PLATFORM_MEMORY_TYPE = 17,
49+} aclplatformDevInfo;
50+ 
51+typedef enum aclplatformCoreType {
52+ ACL_PLATFORM_CORE_TYPE_AI_CORE = 0, /**< AI Core (cube core) */
53+ ACL_PLATFORM_CORE_TYPE_VECTOR_CORE = 1, /**< Vector core */
54+} aclplatformCoreType;
55+ 
56+aclError aclplatformGetDeviceInfo(aclplatformDevInfo infoType, char *value, uint32_t maxLen);
57+ 
58+aclError aclplatformGetInstructionInfo(aclplatformCoreType type,
59+ const char *instruction,
60+ char *value,
61+ uint32_t maxLen);
62+ 
63+enum class aclplatformNpuArch : uint32_t {
64+ DAV_1001 = 1001,
65+ DAV_1002 = 1002,
66+ DAV_1003 = 1003,
67+ DAV_1004 = 1004,
68+ DAV_1999 = 1999,
69+ DAV_2002 = 2002,
70+ DAV_2003 = 2003,
71+ DAV_2004 = 2004,
72+ DAV_2006 = 2006,
73+ DAV_2102 = 2102,
74+ DAV_2103 = 2103,
75+ DAV_2104 = 2104,
76+ DAV_2201 = 2201,
77+ DAV_3002 = 3002,
78+ DAV_3003 = 3003,
79+ DAV_3004 = 3004,
80+ DAV_3102 = 3102,
81+ DAV_3103 = 3103,
82+ DAV_3113 = 3113,
83+ DAV_3502 = 3502,
84+ DAV_3505 = 3505,
85+ DAV_3510 = 3510,
86+ DAV_3801 = 3801,
87+ DAV_5101 = 5101,
88+ DAV_5102 = 5102,
89+ DAV_5161 = 5161,
90+ DAV_9201 = 9201,
91+ DAV_9202 = 9202,
92+ DAV_9301 = 9301,
93+ DAV_RESV = 0xFFFF
94+};
95+ 
96+// --------------------------------------------------------------------------
97+// Mapping: aclplatformDevInfo enum value → (ini section, ini key)
98+// Indexed by enum value; order MUST match aclplatformDevInfo definition.
99+//
100+// aclplatformLocalMemType → aclplatformDevInfo 对应关系:
101+// L0_A (0) → ACL_PLATFORM_L0_A_SIZE (9)
102+// L0_B (1) → ACL_PLATFORM_L0_B_SIZE (10)
103+// L0_C (2) → ACL_PLATFORM_L0_C_SIZE (11)
104+// L1 (3) → ACL_PLATFORM_L1_SIZE (12)
105+// L2 (4) → ACL_PLATFORM_L2_SIZE (4)
106+// UB (5) → ACL_PLATFORM_AICORE_UB_SIZE (1)
107+// HBM (6) → ACL_PLATFORM_MEMORY_SIZE (5)
108+// --------------------------------------------------------------------------
109+enum class aclplatformLocalMemType {
110+ L0_A = 0,
111+ L0_B = 1,
112+ L0_C = 2,
113+ L1 = 3,
114+ L2 = 4,
115+ UB = 5,
116+ HBM = 6
117+};
118+ 
119+#ifdef __cplusplus
120+}
121+#endif
122+ 
123+#endif // INC_PKG_PLATFORM_ACL_PLATFORM_H_
@@ -47,10 +47,6 @@ class PlatFormInfos {
47 void GetLocalMemSize(const LocalMemType &mem_type, uint64_t &size);47 void GetLocalMemSize(const LocalMemType &mem_type, uint64_t &size);
48 void GetLocalMemBw(const LocalMemType &mem_type, uint64_t &bw_size);48 void GetLocalMemBw(const LocalMemType &mem_type, uint64_t &bw_size);
49 49 
50- std::map<std::string, std::vector<std::string>> GetAICoreIntrinsicDtype() const;
51- std::map<std::string, std::vector<std::string>> GetVectorCoreIntrinsicDtype() const;
52- bool GetPlatformRes(const std::string &label, const std::string &key, std::string &val) const;
53- 
54 void SetAICoreIntrinsicDtype(std::map<std::string, std::vector<std::string>> &intrinsic_dtypes);50 void SetAICoreIntrinsicDtype(std::map<std::string, std::vector<std::string>> &intrinsic_dtypes);
55 void SetVectorCoreIntrinsicDtype(std::map<std::string, std::vector<std::string>> &intrinsic_dtypes);51 void SetVectorCoreIntrinsicDtype(std::map<std::string, std::vector<std::string>> &intrinsic_dtypes);
56 void SetPlatformRes(const std::string &label, std::map<std::string, std::string> &res);52 void SetPlatformRes(const std::string &label, std::map<std::string, std::string> &res);
@@ -66,6 +62,8 @@ class PlatFormInfos {
66 private:62 private:
67 friend class PlatformInfosUtils;63 friend class PlatformInfosUtils;
68 bool InitByInstance();64 bool InitByInstance();
65+ bool GetPlatformResWithOutLock(const std::string &label, const std::string &key, std::string &val);
66+ 
69 uint32_t core_num_ {0};67 uint32_t core_num_ {0};
70 PlatFormInfosImplPtr platform_infos_impl_ {nullptr};68 PlatFormInfosImplPtr platform_infos_impl_ {nullptr};
71};69};
@@ -81,11 +79,6 @@ class OptionalInfos {
81 std::string GetL1FusionFlag();79 std::string GetL1FusionFlag();
82 std::map<std::string, std::vector<std::string>> GetFixPipeDtypeMap();80 std::map<std::string, std::vector<std::string>> GetFixPipeDtypeMap();
83 81 
84- std::string GetSocVersion() const;
85- std::string GetCoreType() const;
86- uint32_t GetAICoreNum() const;
87- std::string GetL1FusionFlag() const;
88- std::map<std::string, std::vector<std::string>> GetFixPipeDtypeMap() const;
89 void SetFixPipeDtypeMap(const std::map<std::string, std::vector<std::string>> &fixpipe_dtype_map);82 void SetFixPipeDtypeMap(const std::map<std::string, std::vector<std::string>> &fixpipe_dtype_map);
90 void SetSocVersion(std::string soc_version);83 void SetSocVersion(std::string soc_version);
91 void SetSocVersionWithLock(std::string soc_version);84 void SetSocVersionWithLock(std::string soc_version);
@@ -117,6 +117,7 @@
117 <file value="acl_rt_api.h" install_mod="440" entity="true"/>117 <file value="acl_rt_api.h" install_mod="440" entity="true"/>
118 <file value="acl_base_rt.h" install_mod="440" entity="true"/>118 <file value="acl_base_rt.h" install_mod="440" entity="true"/>
119 <file value="acl_base.h" install_mod="440" entity="true"/>119 <file value="acl_base.h" install_mod="440" entity="true"/>
120+ <file value="acl_platform.h" install_mod="440" entity="true"/>
120 <file value="acl_tdt.h" install_mod="440" entity="true"/>121 <file value="acl_tdt.h" install_mod="440" entity="true"/>
121 <file value="acl_tdt_queue.h" install_mod="440" entity="true"/>122 <file value="acl_tdt_queue.h" install_mod="440" entity="true"/>
122 <file value="acl_dump.h" install_mod="440" entity="true"/>123 <file value="acl_dump.h" install_mod="440" entity="true"/>
@@ -3,6 +3,7 @@ project(platform)
3add_library(platform_headers INTERFACE)3add_library(platform_headers INTERFACE)
4 4 
5set(STATICPLATFORMFILE5set(STATICPLATFORMFILE
6+ ${CMAKE_CURRENT_LIST_DIR}/acl_platform.cpp
6 ${CMAKE_CURRENT_LIST_DIR}/platform_info.cpp7 ${CMAKE_CURRENT_LIST_DIR}/platform_info.cpp
7 ${CMAKE_CURRENT_LIST_DIR}/platform_infos_def.cpp8 ${CMAKE_CURRENT_LIST_DIR}/platform_infos_def.cpp
8 ${CMAKE_CURRENT_LIST_DIR}/platform_infos_impl.cpp9 ${CMAKE_CURRENT_LIST_DIR}/platform_infos_impl.cpp
@@ -24,6 +25,7 @@ if((DEFINED PRODUCT) AND (PRODUCT STREQUAL "ascend031"))
24 "stub/platform_manager_v2_stub.cpp")25 "stub/platform_manager_v2_stub.cpp")
25else()26else()
26 set(PLATFORMFILE27 set(PLATFORMFILE
28+ "acl_platform.cpp"
27 "platform_info.cpp"29 "platform_info.cpp"
28 "platform_infos_def.cpp"30 "platform_infos_def.cpp"
29 "platform_infos_impl.cpp"31 "platform_infos_impl.cpp"
@@ -67,6 +69,7 @@ target_include_directories(platform PRIVATE
67 ${CMAKE_CURRENT_LIST_DIR}69 ${CMAKE_CURRENT_LIST_DIR}
68 ${CMAKE_CURRENT_LIST_DIR}/proto/google70 ${CMAKE_CURRENT_LIST_DIR}/proto/google
69 ${RUNTIME_DIR}/pkg_inc71 ${RUNTIME_DIR}/pkg_inc
72+ ${RUNTIME_DIR}/include/external
70 ${RUNTIME_DIR}/src/dfx/error_manager73 ${RUNTIME_DIR}/src/dfx/error_manager
71 ${RUNTIME_DIR}/include/dfx/base74 ${RUNTIME_DIR}/include/dfx/base
72 $<INSTALL_INTERFACE:include>75 $<INSTALL_INTERFACE:include>
@@ -97,6 +100,7 @@ target_include_directories(platform_static PRIVATE
97 ${CMAKE_CURRENT_LIST_DIR}/inc100 ${CMAKE_CURRENT_LIST_DIR}/inc
98 ${RUNTIME_DIR}/src/dfx/error_manager101 ${RUNTIME_DIR}/src/dfx/error_manager
99 ${RUNTIME_DIR}/include/dfx/base102 ${RUNTIME_DIR}/include/dfx/base
103+ ${RUNTIME_DIR}/include/external
100 $<INSTALL_INTERFACE:include>104 $<INSTALL_INTERFACE:include>
101 $<INSTALL_INTERFACE:include/platform>105 $<INSTALL_INTERFACE:include/platform>
102 $<INSTALL_INTERFACE:include/platform/platform>106 $<INSTALL_INTERFACE:include/platform/platform>
@@ -0,0 +1,210 @@
1+/**
2+ * Copyright (c) 2026 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 "acl/acl_platform.h"
12+ 
13+#include <cstring>
14+#include <map>
15+#include <string>
16+#include <utility>
17+#include <vector>
18+#include <securec.h>
19+ 
20+#include "platform/platform_info.h"
21+#include "platform/platform_infos_def.h"
22+#include "platform_log.h"
23+ 
24+namespace {
25+aclError CopyToBuffer(const std::string &src, char *dst, uint32_t max_len)
26+{
27+ if (src.size() + 1U > static_cast<size_t>(max_len)) {
28+ PF_LOGE("Buffer too small: need %zu bytes, got %u.", src.size() + 1U, max_len);
29+ return ACL_ERROR_INVALID_PARAM;
30+ }
31+ if (memcpy_s(dst, static_cast<size_t>(max_len), src.c_str(), src.size() + 1U) != 0) {
32+ PF_LOGE("memcpy_s failed.");
33+ return ACL_ERROR_INVALID_PARAM;
34+ }
35+ return ACL_SUCCESS;
36+}
37+ 
38+// Try to obtain a valid PlatFormInfos from the given manager.
39+// Strategy 1: runtime device binding (device 0).
40+// Strategy 2: fallback via OptionalInfos soc_version.
41+// Returns true and fills |platform_infos| on success.
42+bool TryGetPlatFormInfos(fe::PlatformInfoManager &mgr, fe::PlatFormInfos &platform_infos, std::string &source)
43+{
44+ auto IsValid = [&]() -> bool {
45+ std::string probe;
46+ return platform_infos.GetPlatformResWithLock("SoCInfo", "ai_core_cnt", probe) && !probe.empty();
47+ };
48+ 
49+ fe::OptionalInfos optional_infos;
50+ if (mgr.GetPlatformInfoWithOutSocVersion(platform_infos, optional_infos) == 0U && IsValid()) {
51+ source = "optional_infos";
52+ return true;
53+ }
54+ 
55+ if (mgr.GetRuntimePlatformInfosByDevice(0U, platform_infos) == 0U && IsValid()) {
56+ source = "device_binding";
57+ return true;
58+ }
59+ 
60+ return false;
61+}
62+ 
63+// Query order:
64+// 1. Instance – GetPlatformInfoWithOutSocVersion
65+// 2. Instance – GetRuntimePlatformInfosByDevice
66+// 3. GeInstance – GetPlatformInfoWithOutSocVersion
67+// 4. GeInstance – GetRuntimePlatformInfosByDevice
68+bool GetPlatFormInfos(fe::PlatFormInfos &platform_infos)
69+{
70+ std::string source;
71+ const char *instance_name = nullptr;
72+ 
73+ if (TryGetPlatFormInfos(fe::PlatformInfoManager::Instance(), platform_infos, source)) {
74+ instance_name = "Instance";
75+ } else if (TryGetPlatFormInfos(fe::PlatformInfoManager::GeInstance(), platform_infos, source)) {
76+ instance_name = "GeInstance";
77+ }
78+ 
79+ if (instance_name != nullptr) {
80+ PF_LOGD("GetPlatFormInfos succeeded: source=%s, path=%s.", instance_name, source.c_str());
81+ return true;
82+ }
83+ 
84+ PF_LOGE("Failed to obtain PlatFormInfos via Instance/GeInstance device[0] or OptionalInfos.");
85+ return false;
86+}
87+ 
88+const std::vector<std::pair<std::string, std::string>> kDevInfoTable = {
89+ /* 0: ACL_PLATFORM_AICORE_CNT */ {"SoCInfo", "ai_core_cnt"},
90+ /* 1: ACL_PLATFORM_AICORE_UB_SIZE */ {"AICoreSpec", "ub_size"},
91+ /* 2: ACL_PLATFORM_CUBE_CORE_CNT */ {"SoCInfo", "cube_core_cnt"},
92+ /* 3: ACL_PLATFORM_VECTOR_CORE_CNT */ {"SoCInfo", "vector_core_cnt"},
93+ /* 4: ACL_PLATFORM_L2_SIZE */ {"SoCInfo", "l2_size"},
94+ /* 5: ACL_PLATFORM_MEMORY_SIZE */ {"SoCInfo", "memory_size"},
95+ /* 6: ACL_PLATFORM_CUBE_FREQ */ {"AICoreSpec", "cube_freq"},
96+ /* 7: ACL_PLATFORM_VEC_FREQ */ {"VectorCoreSpec", "vec_freq"},
97+ /* 8: ACL_PLATFORM_BT_SIZE */ {"AICoreSpec", "bt_size"},
98+ /* 9: ACL_PLATFORM_L0_A_SIZE */ {"AICoreSpec", "l0_a_size"},
99+ /* 10: ACL_PLATFORM_L0_B_SIZE */ {"AICoreSpec", "l0_b_size"},
100+ /* 11: ACL_PLATFORM_L0_C_SIZE */ {"AICoreSpec", "l0_c_size"},
101+ /* 12: ACL_PLATFORM_L1_SIZE */ {"AICoreSpec", "l1_size"},
102+ /* 13: ACL_PLATFORM_SHORT_SOC_VERSION */ {"version", "Short_SoC_version"},
103+ /* 14: ACL_PLATFORM_SOC_VERSION */ {"version", "SoC_version"},
104+ /* 15: ACL_PLATFORM_AIC_VERSION */ {"version", "AIC_version"},
105+ /* 16: ACL_PLATFORM_NPU_ARCH */ {"version", "Arch_type"},
106+ /* 17: ACL_PLATFORM_MEMORY_TYPE */ {"SoCInfo", "memory_type"},
107+};
108+} // namespace
109+ 
110+aclError aclplatformGetDeviceInfo(aclplatformDevInfo infoType, char *value, uint32_t maxLen)
111+{
112+ // --- parameter validation ---
113+ if (value == nullptr) {
114+ PF_LOGE("aclplatformGetDeviceInfo: value is NULL.");
115+ return ACL_ERROR_INVALID_PARAM;
116+ }
117+ if (maxLen == 0U) {
118+ PF_LOGE("aclplatformGetDeviceInfo: maxLen is 0.");
119+ return ACL_ERROR_INVALID_PARAM;
120+ }
121+ const uint32_t info_idx = static_cast<uint32_t>(infoType);
122+ if (info_idx >= static_cast<uint32_t>(kDevInfoTable.size())) {
123+ PF_LOGE("aclplatformGetDeviceInfo: invalid info_type %u.", info_idx);
124+ return ACL_ERROR_INVALID_PARAM;
125+ }
126+ 
127+ // --- obtain platform info ---
128+ fe::PlatFormInfos platform_infos;
129+ if (!GetPlatFormInfos(platform_infos)) {
130+ return ACL_ERROR_OP_NOT_FOUND;
131+ }
132+ 
133+ // --- query the value ---
134+ const std::string &section = kDevInfoTable[info_idx].first;
135+ const std::string &key = kDevInfoTable[info_idx].second;
136+ std::string result;
137+ 
138+ if (!platform_infos.GetPlatformResWithLock(section, key, result)) {
139+ PF_LOGE("aclplatformGetDeviceInfo: key [%s/%s] not found.", section.c_str(), key.c_str());
140+ return ACL_ERROR_OP_NOT_FOUND;
141+ }
142+ if (result.empty()) {
143+ PF_LOGE("aclplatformGetDeviceInfo: empty result for key [%s/%s].", section.c_str(), key.c_str());
144+ return ACL_ERROR_OP_NOT_FOUND;
145+ }
146+ 
147+ PF_LOGI("aclplatformGetDeviceInfo: [%s, %s] = %s.", section.c_str(), key.c_str(), result.c_str());
148+ return CopyToBuffer(result, value, maxLen);
149+}
150+ 
151+aclError aclplatformGetInstructionInfo(aclplatformCoreType type,
152+ const char *instruction,
153+ char *value,
154+ uint32_t maxLen)
155+{
156+ // --- parameter validation ---
157+ if (instruction == nullptr) {
158+ PF_LOGE("aclplatformGetInstructionInfo: instruction is NULL.");
159+ return ACL_ERROR_INVALID_PARAM;
160+ }
161+ if (value == nullptr) {
162+ PF_LOGE("aclplatformGetInstructionInfo: value is NULL.");
163+ return ACL_ERROR_INVALID_PARAM;
164+ }
165+ if (maxLen == 0U) {
166+ PF_LOGE("aclplatformGetInstructionInfo: maxLen is 0.");
167+ return ACL_ERROR_INVALID_PARAM;
168+ }
169+ if (type != ACL_PLATFORM_CORE_TYPE_AI_CORE && type != ACL_PLATFORM_CORE_TYPE_VECTOR_CORE) {
170+ PF_LOGE("aclplatformGetInstructionInfo: invalid core type %d.", static_cast<int>(type));
171+ return ACL_ERROR_INVALID_PARAM;
172+ }
173+ 
174+ // --- obtain platform info ---
175+ fe::PlatFormInfos platform_infos;
176+ if (!GetPlatFormInfos(platform_infos)) {
177+ return ACL_ERROR_OP_NOT_FOUND;
178+ }
179+ 
180+ // --- query intrinsic dtype map ---
181+ const std::string instr_name(instruction);
182+ std::map<std::string, std::vector<std::string>> intrinsic_map;
183+ 
184+ if (type == ACL_PLATFORM_CORE_TYPE_AI_CORE) {
185+ intrinsic_map = platform_infos.GetAICoreIntrinsicDtype();
186+ } else {
187+ intrinsic_map = platform_infos.GetVectorCoreIntrinsicDtype();
188+ }
189+ 
190+ const auto it = intrinsic_map.find(instr_name);
191+ if (it == intrinsic_map.end() || it->second.empty()) {
192+ PF_LOGE("aclplatformGetInstructionInfo: instruction [%s] not found for core type %d.",
193+ instruction, static_cast<int>(type));
194+ return ACL_ERROR_OP_NOT_FOUND;
195+ }
196+ 
197+ // --- join dtypes with "," ---
198+ std::string result;
199+ const std::vector<std::string> &dtypes = it->second;
200+ for (size_t i = 0U; i < dtypes.size(); ++i) {
201+ if (i > 0U) {
202+ result += ',';
203+ }
204+ result += dtypes[i];
205+ }
206+ 
207+ PF_LOGI("aclplatformGetInstructionInfo: [%s], core[%d], result = %s.",
208+ instruction, static_cast<int>(type), result.c_str());
209+ return CopyToBuffer(result, value, maxLen);
210+}
@@ -89,7 +89,15 @@ map<string, vector<string>> PlatFormInfos::GetVectorCoreIntrinsicDtype() {
89 return platform_infos_impl_->GetVectorCoreIntrinsicDtype();89 return platform_infos_impl_->GetVectorCoreIntrinsicDtype();
90}90}
91 91 
92+bool PlatFormInfos::GetPlatformResWithOutLock(const string &label, const string &key, string &val) {
93+ if (platform_infos_impl_ == nullptr) {
94+ return true;
95+ }
96+ return platform_infos_impl_->GetPlatformRes(label, key, val);
97+}
98+ 
92bool PlatFormInfos::GetPlatformRes(const string &label, const string &key, string &val) {99bool PlatFormInfos::GetPlatformRes(const string &label, const string &key, string &val) {
100+ std::lock_guard<std::mutex> lock_guard(plt_info_mutex);
93 if (platform_infos_impl_ == nullptr) {101 if (platform_infos_impl_ == nullptr) {
94 return true;102 return true;
95 }103 }
@@ -105,6 +113,7 @@ bool PlatFormInfos::GetPlatformResWithLock(const string &label, const string &ke
105}113}
106 114 
107bool PlatFormInfos::GetPlatformRes(const std::string &label, std::map<std::string, std::string> &res) {115bool PlatFormInfos::GetPlatformRes(const std::string &label, std::map<std::string, std::string> &res) {
116+ std::lock_guard<std::mutex> lock_guard(plt_info_mutex);
108 if (platform_infos_impl_ == nullptr) {117 if (platform_infos_impl_ == nullptr) {
109 return true;118 return true;
110 }119 }
@@ -170,12 +179,12 @@ void PlatFormInfos::SetCoreNumByCoreType(const std::string &core_type) {
170 179 
171 std::lock_guard<std::mutex> lock_guard(plt_info_mutex);180 std::lock_guard<std::mutex> lock_guard(plt_info_mutex);
172 try {181 try {
173- (void)GetPlatformRes("SoCInfo", core_type_str, core_num_str);182+ (void)GetPlatformResWithOutLock("SoCInfo", core_type_str, core_num_str);
174 core_num_ = core_num_str.empty() ? 0 : std::stoi(core_num_str.c_str());183 core_num_ = core_num_str.empty() ? 0 : std::stoi(core_num_str.c_str());
175 if (customized_types.count(core_type) > 0) {184 if (customized_types.count(core_type) > 0) {
176 core_num_str.clear();185 core_num_str.clear();
177 core_type_str = "mix_vector_core_cnt";186 core_type_str = "mix_vector_core_cnt";
178- (void)GetPlatformRes("SoCInfo", core_type_str, core_num_str);187+ (void)GetPlatformResWithOutLock("SoCInfo", core_type_str, core_num_str);
179 core_num_ = core_num_str.empty() ? core_num_ : std::stoi(core_num_str.c_str());188 core_num_ = core_num_str.empty() ? core_num_ : std::stoi(core_num_str.c_str());
180 }189 }
181 } catch (...) {190 } catch (...) {
@@ -217,7 +226,7 @@ uint32_t PlatFormInfos::GetCoreNumByType(const std::string &core_type)
217 std::string core_num_str;226 std::string core_num_str;
218 uint32_t core_num = 0;227 uint32_t core_num = 0;
219 try {228 try {
220- (void)GetPlatformRes("SoCInfo", core_type_str, core_num_str);229+ (void)GetPlatformResWithOutLock("SoCInfo", core_type_str, core_num_str);
221 core_num = core_num_str.empty() ? 0 : std::stoi(core_num_str.c_str());230 core_num = core_num_str.empty() ? 0 : std::stoi(core_num_str.c_str());
222 } catch (...) {231 } catch (...) {
223 PF_LOGW("Unable to load core_num[%s].", core_num_str.c_str());232 PF_LOGW("Unable to load core_num[%s].", core_num_str.c_str());
@@ -281,7 +290,8 @@ std::map<std::string, std::vector<std::string>> PlatFormInfos::GetFixPipeDtypeM
281}290}
282 291 
283void PlatFormInfos::SetPlatformRes(const std::string &label, std::map<std::string, std::string> &res) {292void PlatFormInfos::SetPlatformRes(const std::string &label, std::map<std::string, std::string> &res) {
284- if (platform_infos_impl_ == nullptr) {293+ std::lock_guard<std::mutex> lock_guard(plt_info_mutex);
294+ if (platform_infos_impl_ == nullptr) {
285 return;295 return;
286 }296 }
287 platform_infos_impl_->SetPlatformRes(label, res);297 platform_infos_impl_->SetPlatformRes(label, res);
@@ -1,6 +1,7 @@
1set(CMAKE_CXX_STANDARD 14)1set(CMAKE_CXX_STANDARD 14)
2 2 
3file(GLOB FE_SRC_CPP_1 RELATIVE ${CMAKE_CURRENT_LIST_DIR}3file(GLOB FE_SRC_CPP_1 RELATIVE ${CMAKE_CURRENT_LIST_DIR}
4+ "${TOP_DIR}/src/platform/acl_platform.cpp"
4 "${TOP_DIR}/src/platform/platform_info.cpp"5 "${TOP_DIR}/src/platform/platform_info.cpp"
5 "${TOP_DIR}/src/platform/platform_infos_def.cpp"6 "${TOP_DIR}/src/platform/platform_infos_def.cpp"
6 "${TOP_DIR}/src/platform/platform_infos_impl.cpp"7 "${TOP_DIR}/src/platform/platform_infos_impl.cpp"
@@ -18,6 +19,7 @@ set_target_properties(platform_llt
18 19 
19target_include_directories(platform_llt PRIVATE20target_include_directories(platform_llt PRIVATE
20 ${TOP_DIR}/include/dfx/base21 ${TOP_DIR}/include/dfx/base
22+ ${TOP_DIR}/include/external
21 ${TOP_DIR}/pkg_inc23 ${TOP_DIR}/pkg_inc
22 ${TOP_DIR}/pkg_inc/base24 ${TOP_DIR}/pkg_inc/base
23 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto25 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto
@@ -82,6 +84,7 @@ set_target_properties(platform_llt_tiling
82 84 
83target_include_directories(platform_llt_tiling PRIVATE85target_include_directories(platform_llt_tiling PRIVATE
84 ${TOP_DIR}/include/dfx/base86 ${TOP_DIR}/include/dfx/base
87+ ${TOP_DIR}/include/external
85 ${TOP_DIR}/pkg_inc88 ${TOP_DIR}/pkg_inc
86 ${TOP_DIR}/pkg_inc/base89 ${TOP_DIR}/pkg_inc/base
87 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto90 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto
@@ -4,6 +4,7 @@ set(SLOG_STUB_FILES
4 ${CMAKE_CURRENT_LIST_DIR}/../depends/slog/slog_stub.cc)4 ${CMAKE_CURRENT_LIST_DIR}/../depends/slog/slog_stub.cc)
5 5 
6set (PLATFORM_SRC_FILES6set (PLATFORM_SRC_FILES
7+ ${TOP_DIR}/src/platform/acl_platform.cpp
7 ${TOP_DIR}/src/platform/platform_info.cpp8 ${TOP_DIR}/src/platform/platform_info.cpp
8 ${TOP_DIR}/src/platform/platform_infos_def.cpp9 ${TOP_DIR}/src/platform/platform_infos_def.cpp
9 ${TOP_DIR}/src/platform/platform_infos_impl.cpp10 ${TOP_DIR}/src/platform/platform_infos_impl.cpp
@@ -14,7 +15,8 @@ set (PLATFORM_SRC_FILES
14set(PLATFORM_UT_FILES15set(PLATFORM_UT_FILES
15 ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_instance_utest.cpp16 ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_instance_utest.cpp
16 ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_ge_instance_utest.cpp17 ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_ge_instance_utest.cpp
17- ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_v2_instance_utest.cpp)18+ ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_v2_instance_utest.cpp
19+ ${CMAKE_CURRENT_LIST_DIR}/testcase/platform_manager_acl_utest.cpp)
18 20 
19add_executable(platform_utest21add_executable(platform_utest
20 ${SLOG_STUB_FILES}22 ${SLOG_STUB_FILES}
@@ -39,6 +41,7 @@ target_include_directories(platform_utest PRIVATE
39 ${TOP_DIR}/src/runtime/inc41 ${TOP_DIR}/src/runtime/inc
40 ${TOP_DIR}/pkg_inc42 ${TOP_DIR}/pkg_inc
41 ${TOP_DIR}/pkg_inc/platform43 ${TOP_DIR}/pkg_inc/platform
44+ ${TOP_DIR}/include/external
42 ${TOP_DIR}/abl/slog/inc45 ${TOP_DIR}/abl/slog/inc
43 ${TOP_DIR}/metadef/inc/external46 ${TOP_DIR}/metadef/inc/external
44 ${TOP_DIR}/metadef/inc/external/platform47 ${TOP_DIR}/metadef/inc/external/platform
@@ -47,6 +50,7 @@ target_include_directories(platform_utest PRIVATE
47 ${CMAKE_CURRENT_LIST_DIR}/../depends/proto50 ${CMAKE_CURRENT_LIST_DIR}/../depends/proto
48 ${TOP_DIR}/src/platform/proto/platform_infos_proto/51 ${TOP_DIR}/src/platform/proto/platform_infos_proto/
49 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto/52 ${CMAKE_BINARY_DIR}/proto/platform_infos_proto/
53+ ${CMAKE_BINARY_DIR}/libc_sec/source/include
50 )54 )
51 55 
52target_include_directories(platform_stub_ut PRIVATE56target_include_directories(platform_stub_ut PRIVATE
@@ -90,11 +94,13 @@ target_link_libraries(platform_utest PRIVATE
90 GTestShared::gtest_main94 GTestShared::gtest_main
91 GTestShared::gmock95 GTestShared::gmock
92 GTestShared::gmock_main96 GTestShared::gmock_main
97+ c_sec
93 -lrt98 -lrt
94 -ldl99 -ldl
95 -lgcov100 -lgcov
96 ascend_protobuf101 ascend_protobuf
97 mockcpp102 mockcpp
103+ $<BUILD_INTERFACE:c_sec_headers>
98 $<BUILD_INTERFACE:intf_ut_pub>104 $<BUILD_INTERFACE:intf_ut_pub>
99 $<BUILD_INTERFACE:slog_headers>105 $<BUILD_INTERFACE:slog_headers>
100)106)
@@ -105,11 +111,13 @@ target_link_libraries(platform_stub_ut PRIVATE
105 GTestShared::gtest_main111 GTestShared::gtest_main
106 GTestShared::gmock112 GTestShared::gmock
107 GTestShared::gmock_main113 GTestShared::gmock_main
114+ c_sec
108 -lrt115 -lrt
109 -ldl116 -ldl
110 -lgcov117 -lgcov
111 ascend_protobuf118 ascend_protobuf
112 mockcpp119 mockcpp
120+ $<BUILD_INTERFACE:c_sec_headers>
113 $<BUILD_INTERFACE:intf_ut_pub>121 $<BUILD_INTERFACE:intf_ut_pub>
114 $<BUILD_INTERFACE:slog_headers>122 $<BUILD_INTERFACE:slog_headers>
115)123)
@@ -0,0 +1,464 @@
1+/**
2+ * Copyright (c) 2026 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+#include <gtest/gtest.h>
11+#include <mockcpp/mockcpp.hpp>
12+ 
13+#include <cstring>
14+#include <iostream>
15+#include <string>
16+#include <vector>
17+ 
18+#include "acl/acl_platform.h"
19+ 
20+#define protected public
21+#define private public
22+#include "platform_info.h"
23+#undef protected
24+#undef private
25+ 
26+namespace fe {
27+class PlatformManagerAclUTest : public testing::Test {
28+protected:
29+ void SetUp()
30+ {
31+ PlatformInfoManager::Instance().platform_infos_map_.clear();
32+ PlatformInfoManager::Instance().platform_info_map_.clear();
33+ PlatformInfoManager::Instance().device_platform_infos_map_.clear();
34+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear();
35+ PlatformInfoManager::Instance().loaded_ini_files_.clear();
36+ PlatformInfoManager::Instance().cfg_file_real_path_.clear();
37+ PlatformInfoManager::Instance().opti_compilation_info_ = OptionalInfo();
38+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
39+ PlatformInfoManager::Instance().init_flag_ = false;
40+ PlatformInfoManager::Instance().runtime_init_flag_ = false;
41+ 
42+ uint32_t ret = PlatformInfoManager::Instance().InitializePlatformInfo();
43+ ASSERT_EQ(ret, 0U);
44+ 
45+ // Bind soc_version via OptionalInfos so GetPlatformInfoWithOutSocVersion succeeds
46+ PlatFormInfos pf;
47+ OptionalInfos opti;
48+ ret = PlatformInfoManager::Instance().GetPlatformInfos("Ascend910B1", pf, opti);
49+ ASSERT_EQ(ret, 0U);
50+ opti.SetSocVersion("Ascend910B1");
51+ opti.SetCoreType("AiCore");
52+ opti.SetL1FusionFlag("false");
53+ opti.SetAICoreNum(24);
54+ PlatformInfoManager::Instance().SetOptionalCompilationInfo(opti);
55+ }
56+ 
57+ void TearDown()
58+ {
59+ PlatformInfoManager::Instance().Finalize();
60+ GlobalMockObject::verify();
61+ }
62+};
63+ 
64+// ============================================================================
65+// aclplatformGetDeviceInfo — normal path
66+// ============================================================================
67+ 
68+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_AICORE_CNT)
69+{
70+ char buf[64] = {0};
71+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
72+ EXPECT_EQ(ret, ACL_SUCCESS);
73+ EXPECT_STREQ(buf, "24");
74+}
75+ 
76+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_AICORE_UB_SIZE)
77+{
78+ char buf[64] = {0};
79+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_UB_SIZE, buf, sizeof(buf));
80+ EXPECT_EQ(ret, ACL_SUCCESS);
81+ EXPECT_STREQ(buf, "196608");
82+}
83+ 
84+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_CUBE_CORE_CNT)
85+{
86+ char buf[64] = {0};
87+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_CUBE_CORE_CNT, buf, sizeof(buf));
88+ EXPECT_EQ(ret, ACL_SUCCESS);
89+ EXPECT_STREQ(buf, "24");
90+}
91+ 
92+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_VECTOR_CORE_CNT)
93+{
94+ char buf[64] = {0};
95+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_VECTOR_CORE_CNT, buf, sizeof(buf));
96+ EXPECT_EQ(ret, ACL_SUCCESS);
97+ EXPECT_STREQ(buf, "48");
98+}
99+ 
100+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_L2_SIZE)
101+{
102+ char buf[64] = {0};
103+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_L2_SIZE, buf, sizeof(buf));
104+ EXPECT_EQ(ret, ACL_SUCCESS);
105+ EXPECT_STREQ(buf, "201326592");
106+}
107+ 
108+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_MEMORY_SIZE)
109+{
110+ char buf[64] = {0};
111+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_MEMORY_SIZE, buf, sizeof(buf));
112+ EXPECT_EQ(ret, ACL_SUCCESS);
113+ EXPECT_STREQ(buf, "68719476736");
114+}
115+ 
116+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_CUBE_FREQ)
117+{
118+ char buf[64] = {0};
119+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_CUBE_FREQ, buf, sizeof(buf));
120+ EXPECT_EQ(ret, ACL_SUCCESS);
121+ EXPECT_STREQ(buf, "1850");
122+}
123+ 
124+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_VEC_FREQ)
125+{
126+ // Ascend910B1 has no independent VectorCoreSpec section → vec_freq not found
127+ char buf[64] = {0};
128+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_VEC_FREQ, buf, sizeof(buf));
129+ EXPECT_EQ(ret, ACL_ERROR_OP_NOT_FOUND);
130+}
131+ 
132+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_BT_SIZE)
133+{
134+ char buf[64] = {0};
135+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_BT_SIZE, buf, sizeof(buf));
136+ EXPECT_EQ(ret, ACL_SUCCESS);
137+ EXPECT_STREQ(buf, "1024");
138+}
139+ 
140+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_L0_A_SIZE)
141+{
142+ char buf[64] = {0};
143+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_L0_A_SIZE, buf, sizeof(buf));
144+ EXPECT_EQ(ret, ACL_SUCCESS);
145+ EXPECT_STREQ(buf, "65536");
146+}
147+ 
148+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_L0_B_SIZE)
149+{
150+ char buf[64] = {0};
151+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_L0_B_SIZE, buf, sizeof(buf));
152+ EXPECT_EQ(ret, ACL_SUCCESS);
153+ EXPECT_STREQ(buf, "65536");
154+}
155+ 
156+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_L0_C_SIZE)
157+{
158+ char buf[64] = {0};
159+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_L0_C_SIZE, buf, sizeof(buf));
160+ EXPECT_EQ(ret, ACL_SUCCESS);
161+ EXPECT_STREQ(buf, "131072");
162+}
163+ 
164+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_L1_SIZE)
165+{
166+ char buf[64] = {0};
167+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_L1_SIZE, buf, sizeof(buf));
168+ EXPECT_EQ(ret, ACL_SUCCESS);
169+ EXPECT_STREQ(buf, "524288");
170+}
171+ 
172+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_SHORT_SOC_VERSION)
173+{
174+ char buf[64] = {0};
175+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_SHORT_SOC_VERSION, buf, sizeof(buf));
176+ EXPECT_EQ(ret, ACL_SUCCESS);
177+ EXPECT_STREQ(buf, "Ascend910B");
178+}
179+ 
180+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_SOC_VERSION)
181+{
182+ char buf[64] = {0};
183+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_SOC_VERSION, buf, sizeof(buf));
184+ EXPECT_EQ(ret, ACL_SUCCESS);
185+ EXPECT_STREQ(buf, "Ascend910B1");
186+}
187+ 
188+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_AIC_VERSION)
189+{
190+ char buf[64] = {0};
191+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AIC_VERSION, buf, sizeof(buf));
192+ EXPECT_EQ(ret, ACL_SUCCESS);
193+ EXPECT_STREQ(buf, "AIC-C-220");
194+}
195+ 
196+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_NPU_ARCH)
197+{
198+ char buf[64] = {0};
199+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_NPU_ARCH, buf, sizeof(buf));
200+ EXPECT_EQ(ret, ACL_SUCCESS);
201+ EXPECT_STREQ(buf, "4");
202+}
203+ 
204+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_MEMORY_TYPE)
205+{
206+ // Ascend910B1.ini has empty memory_type → returns not found
207+ char buf[64] = {0};
208+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_MEMORY_TYPE, buf, sizeof(buf));
209+ EXPECT_EQ(ret, ACL_ERROR_OP_NOT_FOUND);
210+}
211+ 
212+// ============================================================================
213+// aclplatformGetDeviceInfo — error paths
214+// ============================================================================
215+ 
216+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_null_value)
217+{
218+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, nullptr, 64);
219+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
220+}
221+ 
222+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_zero_maxLen)
223+{
224+ char buf[64] = {0};
225+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, 0U);
226+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
227+}
228+ 
229+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_buffer_too_small)
230+{
231+ char buf[2] = {0};
232+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_SOC_VERSION, buf, sizeof(buf));
233+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
234+}
235+ 
236+TEST_F(PlatformManagerAclUTest, acl_platform_GetDeviceInfo_invalid_enum)
237+{
238+ char buf[64] = {0};
239+ // Cast a value beyond the last valid enum
240+ aclError ret = aclplatformGetDeviceInfo(static_cast<aclplatformDevInfo>(999), buf, sizeof(buf));
241+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
242+}
243+ 
244+// ============================================================================
245+// aclplatformGetInstructionInfo — normal path
246+// ============================================================================
247+ 
248+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_AI_CORE_vadd)
249+{
250+ char buf[256] = {0};
251+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
252+ "Intrinsic_vadd", buf, sizeof(buf));
253+ EXPECT_EQ(ret, ACL_SUCCESS);
254+ EXPECT_STREQ(buf, "float16,float32,int32,int16");
255+}
256+ 
257+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_AI_CORE_vmul)
258+{
259+ char buf[256] = {0};
260+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
261+ "Intrinsic_vmul", buf, sizeof(buf));
262+ EXPECT_EQ(ret, ACL_SUCCESS);
263+ EXPECT_STREQ(buf, "float16,float32,int32,int16");
264+}
265+ 
266+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_AI_CORE_vrec)
267+{
268+ char buf[256] = {0};
269+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
270+ "Intrinsic_vrec", buf, sizeof(buf));
271+ EXPECT_EQ(ret, ACL_SUCCESS);
272+ EXPECT_STREQ(buf, "float16,float32");
273+}
274+ 
275+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_VECTOR_CORE_vadd)
276+{
277+ char buf[256] = {0};
278+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_VECTOR_CORE,
279+ "Intrinsic_vadd", buf, sizeof(buf));
280+ EXPECT_EQ(ret, ACL_SUCCESS);
281+ EXPECT_STREQ(buf, "float16,float32,int32,int16");
282+}
283+ 
284+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_VECTOR_CORE_vmul)
285+{
286+ char buf[256] = {0};
287+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_VECTOR_CORE,
288+ "Intrinsic_vmul", buf, sizeof(buf));
289+ EXPECT_EQ(ret, ACL_SUCCESS);
290+ EXPECT_STREQ(buf, "float16,float32,int32,int16");
291+}
292+ 
293+// ============================================================================
294+// aclplatformGetInstructionInfo — error paths
295+// ============================================================================
296+ 
297+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_null_instruction)
298+{
299+ char buf[256] = {0};
300+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
301+ nullptr, buf, sizeof(buf));
302+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
303+}
304+ 
305+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_null_value)
306+{
307+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
308+ "Intrinsic_vadd", nullptr, 256);
309+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
310+}
311+ 
312+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_zero_maxLen)
313+{
314+ char buf[256] = {0};
315+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
316+ "Intrinsic_vadd", buf, 0U);
317+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
318+}
319+ 
320+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_invalid_core_type)
321+{
322+ char buf[256] = {0};
323+ aclError ret = aclplatformGetInstructionInfo(static_cast<aclplatformCoreType>(99),
324+ "Intrinsic_vadd", buf, sizeof(buf));
325+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
326+}
327+ 
328+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_not_found)
329+{
330+ char buf[256] = {0};
331+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
332+ "Intrinsic_NotExist", buf, sizeof(buf));
333+ EXPECT_EQ(ret, ACL_ERROR_OP_NOT_FOUND);
334+}
335+ 
336+TEST_F(PlatformManagerAclUTest, acl_platform_GetInstructionInfo_buffer_too_small)
337+{
338+ char buf[4] = {0};
339+ aclError ret = aclplatformGetInstructionInfo(ACL_PLATFORM_CORE_TYPE_AI_CORE,
340+ "Intrinsic_vadd", buf, sizeof(buf));
341+ EXPECT_EQ(ret, ACL_ERROR_INVALID_PARAM);
342+}
343+ 
344+// ============================================================================
345+// GetPlatFormInfos — fallback chain coverage
346+// ============================================================================
347+// Query order:
348+// Step 1: Instance – GetRuntimePlatformInfosByDevice(0)
349+// Step 2: Instance – GetPlatformInfoWithOutSocVersion
350+// Step 3: GeInstance – GetRuntimePlatformInfosByDevice(0)
351+// Step 4: GeInstance – GetPlatformInfoWithOutSocVersion
352+ 
353+// ---- Step 1: Instance GetRuntimePlatformInfosByDevice succeeds ----
354+TEST_F(PlatformManagerAclUTest, GetPlatFormInfos_Step1_Instance_RuntimeDevice)
355+{
356+ // Wipe OptionalInfos so step 2 won't accidentally succeed
357+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
358+ 
359+ // Load valid PlatFormInfos and inject into runtime_device_platform_infos_map_
360+ fe::PlatFormInfos pf;
361+ fe::OptionalInfos opti;
362+ ASSERT_EQ(PlatformInfoManager::Instance().GetPlatformInfos("Ascend910B1", pf, opti), 0U);
363+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_[0] = pf;
364+ 
365+ char buf[64] = {0};
366+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
367+ EXPECT_EQ(ret, ACL_SUCCESS);
368+ EXPECT_STREQ(buf, "24");
369+}
370+ 
371+// ---- Step 2: Instance GetPlatformInfoWithOutSocVersion succeeds ----
372+// (all existing normal-path tests exercise this path implicitly)
373+ 
374+// ---- Steps 1-2 fail, Step 3: GeInstance GetRuntimePlatformInfosByDevice succeeds ----
375+TEST_F(PlatformManagerAclUTest, GetPlatFormInfos_Step3_GeInstance_RuntimeDevice)
376+{
377+ // Wipe Instance completely so steps 1-2 fail
378+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
379+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear();
380+ 
381+ // Initialize GeInstance and inject runtime device data
382+ PlatformInfoManager::GeInstance().InitializePlatformInfo();
383+ fe::PlatFormInfos pf;
384+ fe::OptionalInfos opti;
385+ ASSERT_EQ(PlatformInfoManager::GeInstance().GetPlatformInfos("Ascend910B1", pf, opti), 0U);
386+ PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_[0] = pf;
387+ 
388+ char buf[64] = {0};
389+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
390+ EXPECT_EQ(ret, ACL_SUCCESS);
391+ EXPECT_STREQ(buf, "24");
392+ 
393+ PlatformInfoManager::GeInstance().Finalize();
394+}
395+ 
396+// ---- Steps 1-3 fail, Step 4: GeInstance GetPlatformInfoWithOutSocVersion succeeds ----
397+TEST_F(PlatformManagerAclUTest, GetPlatFormInfos_Step4_GeInstance_OptionalInfos)
398+{
399+ // Wipe Instance completely
400+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
401+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear();
402+ PlatformInfoManager::GeInstance().opti_compilation_infos_ = OptionalInfos();
403+ fe::PlatFormInfos pf;
404+ pf.Init();
405+ PlatformInfoManager::GeInstance().runtime_platform_infos_ = pf;
406+ PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_.clear();
407+ 
408+ // Initialize GeInstance with OptionalInfos
409+ PlatformInfoManager::GeInstance().InitializePlatformInfo();
410+ fe::OptionalInfos opti;
411+ ASSERT_EQ(PlatformInfoManager::GeInstance().GetPlatformInfos("Ascend910B1", pf, opti), 0U);
412+ opti.SetSocVersion("Ascend910B1");
413+ opti.SetCoreType("AiCore");
414+ opti.SetL1FusionFlag("false");
415+ opti.SetAICoreNum(24);
416+ PlatformInfoManager::GeInstance().SetOptionalCompilationInfo(opti);
417+ 
418+ char buf[64] = {0};
419+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
420+ EXPECT_EQ(ret, ACL_SUCCESS);
421+ EXPECT_STREQ(buf, "24");
422+ 
423+ PlatformInfoManager::GeInstance().Finalize();
424+}
425+ 
426+// ---- All 4 steps fail: returns ACL_ERROR_OP_NOT_FOUND ----
427+TEST_F(PlatformManagerAclUTest, GetPlatFormInfos_AllFail)
428+{
429+ // Wipe Instance completely
430+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
431+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear();
432+ PlatformInfoManager::Instance().platform_infos_map_.clear();
433+ PlatformInfoManager::Instance().loaded_ini_files_.clear();
434+ PlatformInfoManager::GeInstance().opti_compilation_infos_ = OptionalInfos();
435+ fe::PlatFormInfos pf;
436+ pf.Init();
437+ PlatformInfoManager::GeInstance().runtime_platform_infos_ = pf;
438+ PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_.clear();
439+ // GeInstance is uninitialized → all 4 steps fail
440+ char buf[64] = {0};
441+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
442+ EXPECT_EQ(ret, ACL_ERROR_OP_NOT_FOUND);
443+}
444+ 
445+// ---- Instance OptionalInfos cleared, only GeInstance OptionalInfos set ----
446+// Ensures proper fallthrough when Instance env is clean.
447+TEST_F(PlatformManagerAclUTest, GetPlatFormInfos_FallbackToGeInstance_OnlyOptional)
448+{
449+ // Clear Instance OptionalInfos but keep platform_infos_map_ loaded
450+ PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos();
451+ PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear();
452+ PlatformInfoManager::GeInstance().opti_compilation_infos_ = OptionalInfos();
453+ fe::PlatFormInfos pf;
454+ pf.Init();
455+ PlatformInfoManager::GeInstance().runtime_platform_infos_ = pf;
456+ PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_.clear();
457+ 
458+ // GeInstance not set up → steps 1-4 all fail
459+ char buf[64] = {0};
460+ aclError ret = aclplatformGetDeviceInfo(ACL_PLATFORM_AICORE_CNT, buf, sizeof(buf));
461+ EXPECT_EQ(ret, ACL_ERROR_OP_NOT_FOUND);
462+}
463+ 
464+} // namespace fe