Merged
【PR】: 简要描述 延迟加载配置文件 #1880
jiang-mingming01Add on Apr 28
【PR】: 简要描述 延迟加载配置文件 #1880
Merged
Total: 4 files changed+555-80
| @@ -14,6 +14,7 @@ | |||
| 14 | #include <map> | 14 | #include <map> |
| 15 | #include <string> | 15 | #include <string> |
| 16 | #include <array> | 16 | #include <array> |
| 17 | +#include <unordered_set> | ||
| 17 | #include "platform_info_def.h" | 18 | #include "platform_info_def.h" |
| 18 | #include "platform_infos_def.h" | 19 | #include "platform_infos_def.h" |
| 19 | 20 | ||
| @@ -71,8 +72,6 @@ class PlatformInfoManager { | |||
| 71 | 72 | ||
| 72 | void Trim(std::string &str); | 73 | void Trim(std::string &str); |
| 73 | 74 | ||
| 74 | - uint32_t LoadConfigFile(std::string real_path); | ||
| 75 | - | ||
| 76 | void ParseVersion(std::map<std::string, std::string> &version_map, | 75 | void ParseVersion(std::map<std::string, std::string> &version_map, |
| 77 | std::string &soc_version, | 76 | std::string &soc_version, |
| 78 | PlatformInfo &platform_info_temp); | 77 | PlatformInfo &platform_info_temp); |
| @@ -142,6 +141,8 @@ class PlatformInfoManager { | |||
| 142 | uint32_t AssemblePlatformInfoVector(std::map<std::string, std::map<std::string, std::string>> &content_info_map); | 141 | uint32_t AssemblePlatformInfoVector(std::map<std::string, std::map<std::string, std::string>> &content_info_map); |
| 143 | void FillupFixPipeInfo(PlatFormInfos &platform_infos); | 142 | void FillupFixPipeInfo(PlatFormInfos &platform_infos); |
| 144 | 143 | ||
| 144 | + uint32_t EnsureSocVersionLoaded(const std::string &soc_version); | ||
| 145 | + | ||
| 145 | bool init_flag_; | 146 | bool init_flag_; |
| 146 | bool runtime_init_flag_; | 147 | bool runtime_init_flag_; |
| 147 | std::map<std::string, PlatformInfo> platform_info_map_; | 148 | std::map<std::string, PlatformInfo> platform_info_map_; |
| @@ -152,6 +153,10 @@ class PlatformInfoManager { | |||
| 152 | 153 | ||
| 153 | OptionalInfos opti_compilation_infos_; | 154 | OptionalInfos opti_compilation_infos_; |
| 154 | 155 | ||
| 156 | + std::string cfg_file_real_path_; | ||
| 157 | + | ||
| 158 | + std::unordered_set<std::string> loaded_ini_files_; | ||
| 159 | + | ||
| 155 | std::map<uint32_t, PlatFormInfos> device_platform_infos_map_; | 160 | std::map<uint32_t, PlatFormInfos> device_platform_infos_map_; |
| 156 | 161 | ||
| 157 | PlatFormInfos runtime_platform_infos_; | 162 | PlatFormInfos runtime_platform_infos_; |
| @@ -95,8 +95,8 @@ void PlatformInfoManager::Trim(std::string &str) { | |||
| 95 | if (str.empty()) { | 95 | if (str.empty()) { |
| 96 | return; | 96 | return; |
| 97 | } | 97 | } |
| 98 | - size_t start_pos = str.find_first_not_of(" \t"); | 98 | + size_t start_pos = str.find_first_not_of(" \t\r\n"); |
| 99 | - size_t end_pos = str.find_last_not_of(" \t"); | 99 | + size_t end_pos = str.find_last_not_of(" \t\r\n"); |
| 100 | if (start_pos == std::string::npos || start_pos > end_pos) { | 100 | if (start_pos == std::string::npos || start_pos > end_pos) { |
| 101 | str.clear(); | 101 | str.clear(); |
| 102 | return; | 102 | return; |
| @@ -165,49 +165,20 @@ uint32_t PlatformInfoManager::LoadIniFile(std::string ini_file_real_path) { | |||
| 165 | return PLATFORM_SUCCESS; | 165 | return PLATFORM_SUCCESS; |
| 166 | } | 166 | } |
| 167 | 167 | ||
| 168 | -uint32_t PlatformInfoManager::LoadConfigFile(std::string real_path) { | 168 | +uint32_t PlatformInfoManager::EnsureSocVersionLoaded(const std::string &soc_version) { |
| 169 | - std::vector<std::string> ini_cfg_files; | 169 | + if (soc_version.empty()) { |
| 170 | - DIR *dir; | ||
| 171 | - struct dirent *dirp = nullptr; | ||
| 172 | - char *file_suffix = const_cast<char *>(".ini"); | ||
| 173 | - dir = opendir(real_path.c_str()); | ||
| 174 | - if (dir == nullptr) { | ||
| 175 | - PF_LOGE("Failed to open directory %s.", real_path.c_str()); | ||
| 176 | return PLATFORM_FAILED; | 170 | return PLATFORM_FAILED; |
| 177 | } | 171 | } |
| 178 | - | 172 | + if (loaded_ini_files_.count(soc_version) > 0) { |
| 179 | - while ((dirp = readdir(dir)) != nullptr) { | 173 | + return PLATFORM_SUCCESS; |
| 180 | - if (dirp->d_name[0] == '.') { | ||
| 181 | - continue; | ||
| 182 | - } | ||
| 183 | - std::string file_name = dirp->d_name; | ||
| 184 | - if (strlen(dirp->d_name) <= strlen(file_suffix)) { | ||
| 185 | - continue; | ||
| 186 | - } | ||
| 187 | - size_t pos = file_name.rfind('.'); | ||
| 188 | - if (pos == std::string::npos) { | ||
| 189 | - continue; | ||
| 190 | - } | ||
| 191 | - if (file_name.substr(pos + 1) != INI_FILE_SUFFIX) { | ||
| 192 | - continue; | ||
| 193 | - } | ||
| 194 | - if (strcmp(&(dirp->d_name)[strlen(dirp->d_name) - strlen(file_suffix)], file_suffix) == 0) { | ||
| 195 | - ini_cfg_files.push_back(real_path + "/" + dirp->d_name); | ||
| 196 | - } | ||
| 197 | } | 174 | } |
| 198 | - closedir(dir); | 175 | + std::string ini_file_path = cfg_file_real_path_ + "/" + soc_version + ".ini"; |
| 199 | - | 176 | + PF_LOGD("Begin to load ini file[%s].", ini_file_path.c_str()); |
| 200 | - if (ini_cfg_files.empty()) { | 177 | + if (LoadIniFile(ini_file_path) != PLATFORM_SUCCESS) { |
| 201 | - PF_LOGE("There is no ini file in path %s.", real_path.c_str()); | 178 | + PF_LOGE("Failed to load ini file[%s].", ini_file_path.c_str()); |
| 202 | return PLATFORM_FAILED; | 179 | return PLATFORM_FAILED; |
| 203 | } | 180 | } |
| 204 | - | 181 | + loaded_ini_files_.insert(soc_version); |
| 205 | - for (std::string ini_file_path : ini_cfg_files) { | ||
| 206 | - if (LoadIniFile(ini_file_path) != PLATFORM_SUCCESS) { | ||
| 207 | - PF_LOGE("Failed to load ini file[%s].", ini_file_path.c_str()); | ||
| 208 | - return PLATFORM_FAILED; | ||
| 209 | - } | ||
| 210 | - } | ||
| 211 | return PLATFORM_SUCCESS; | 182 | return PLATFORM_SUCCESS; |
| 212 | } | 183 | } |
| 213 | 184 | ||
| @@ -932,17 +903,12 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::InitializeP | |||
| 932 | if (init_flag_) { | 903 | if (init_flag_) { |
| 933 | return PLATFORM_SUCCESS; | 904 | return PLATFORM_SUCCESS; |
| 934 | } | 905 | } |
| 935 | - std::string cfg_file_real_path = fe::GetConfigFilePath<PlatformInfoManager>(); | 906 | + cfg_file_real_path_ = fe::GetConfigFilePath<PlatformInfoManager>(); |
| 936 | - if (cfg_file_real_path.empty()) { | 907 | + if (cfg_file_real_path_.empty()) { |
| 937 | - PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); | 908 | + PF_LOGE("File path[%s] is not valid.", cfg_file_real_path_.c_str()); |
| 938 | return PLATFORM_FAILED; | 909 | return PLATFORM_FAILED; |
| 939 | } | 910 | } |
| 940 | 911 | ||
| 941 | - uint32_t ret = LoadConfigFile(cfg_file_real_path); | ||
| 942 | - if (ret != PLATFORM_SUCCESS) { | ||
| 943 | - PF_LOGE("Failed to load configuration file, path: %s.", cfg_file_real_path.c_str()); | ||
| 944 | - return PLATFORM_FAILED; | ||
| 945 | - } | ||
| 946 | if (!opti_compilation_infos_.Init()) { | 912 | if (!opti_compilation_infos_.Init()) { |
| 947 | PF_LOGE("Failed to initialize optional information."); | 913 | PF_LOGE("Failed to initialize optional information."); |
| 948 | return PLATFORM_FAILED; | 914 | return PLATFORM_FAILED; |
| @@ -962,8 +928,15 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatform | |||
| 962 | std::lock_guard<std::mutex> lock_guard(pc_lock_); | 928 | std::lock_guard<std::mutex> lock_guard(pc_lock_); |
| 963 | auto iter = platform_info_map_.find(realSocVersion); | 929 | auto iter = platform_info_map_.find(realSocVersion); |
| 964 | if (iter == platform_info_map_.end()) { | 930 | if (iter == platform_info_map_.end()) { |
| 965 | - PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); | 931 | + if (EnsureSocVersionLoaded(realSocVersion) != PLATFORM_SUCCESS) { |
| 966 | - return PLATFORM_FAILED; | 932 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); |
| 933 | + return PLATFORM_FAILED; | ||
| 934 | + } | ||
| 935 | + iter = platform_info_map_.find(realSocVersion); | ||
| 936 | + if (iter == platform_info_map_.end()) { | ||
| 937 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); | ||
| 938 | + return PLATFORM_FAILED; | ||
| 939 | + } | ||
| 967 | } | 940 | } |
| 968 | platform_info = iter->second; | 941 | platform_info = iter->second; |
| 969 | opti_compilation_info = opti_compilation_info_; | 942 | opti_compilation_info = opti_compilation_info_; |
| @@ -979,8 +952,15 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatform | |||
| 979 | } | 952 | } |
| 980 | auto iter = platform_info_map_.find(opti_compilation_info_.soc_version); | 953 | auto iter = platform_info_map_.find(opti_compilation_info_.soc_version); |
| 981 | if (iter == platform_info_map_.end()) { | 954 | if (iter == platform_info_map_.end()) { |
| 982 | - PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_info_.soc_version.c_str()); | 955 | + if (EnsureSocVersionLoaded(opti_compilation_info_.soc_version) != PLATFORM_SUCCESS) { |
| 983 | - return PLATFORM_FAILED; | 956 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_info_.soc_version.c_str()); |
| 957 | + return PLATFORM_FAILED; | ||
| 958 | + } | ||
| 959 | + iter = platform_info_map_.find(opti_compilation_info_.soc_version); | ||
| 960 | + if (iter == platform_info_map_.end()) { | ||
| 961 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_info_.soc_version.c_str()); | ||
| 962 | + return PLATFORM_FAILED; | ||
| 963 | + } | ||
| 984 | } | 964 | } |
| 985 | platform_info = iter->second; | 965 | platform_info = iter->second; |
| 986 | opti_compilation_info = opti_compilation_info_; | 966 | opti_compilation_info = opti_compilation_info_; |
| @@ -1005,8 +985,15 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatform | |||
| 1005 | std::lock_guard<std::mutex> lock_guard(pc_lock_); | 985 | std::lock_guard<std::mutex> lock_guard(pc_lock_); |
| 1006 | auto iter = platform_infos_map_.find(realSocVersion); | 986 | auto iter = platform_infos_map_.find(realSocVersion); |
| 1007 | if (iter == platform_infos_map_.end()) { | 987 | if (iter == platform_infos_map_.end()) { |
| 1008 | - PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); | 988 | + if (EnsureSocVersionLoaded(realSocVersion) != PLATFORM_SUCCESS) { |
| 1009 | - return PLATFORM_FAILED; | 989 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); |
| 990 | + return PLATFORM_FAILED; | ||
| 991 | + } | ||
| 992 | + iter = platform_infos_map_.find(realSocVersion); | ||
| 993 | + if (iter == platform_infos_map_.end()) { | ||
| 994 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", realSocVersion.c_str()); | ||
| 995 | + return PLATFORM_FAILED; | ||
| 996 | + } | ||
| 1010 | } | 997 | } |
| 1011 | platform_info = iter->second; | 998 | platform_info = iter->second; |
| 1012 | opti_compilation_info = opti_compilation_infos_; | 999 | opti_compilation_info = opti_compilation_infos_; |
| @@ -1017,14 +1004,22 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatform | |||
| 1017 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInfoWithOutSocVersion( | 1004 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInfoWithOutSocVersion( |
| 1018 | PlatFormInfos &platform_info, OptionalInfos &opti_compilation_info) { | 1005 | PlatFormInfos &platform_info, OptionalInfos &opti_compilation_info) { |
| 1019 | std::lock_guard<std::mutex> lock_guard(pc_lock_); | 1006 | std::lock_guard<std::mutex> lock_guard(pc_lock_); |
| 1020 | - if (opti_compilation_infos_.GetSocVersion().empty()) { | 1007 | + std::string real_soc = opti_compilation_infos_.GetSocVersion(); |
| 1008 | + if (real_soc.empty()) { | ||
| 1021 | PF_LOGW("Cannot find platform_info."); | 1009 | PF_LOGW("Cannot find platform_info."); |
| 1022 | return PLATFORM_FAILED; | 1010 | return PLATFORM_FAILED; |
| 1023 | } | 1011 | } |
| 1024 | - auto iter = platform_infos_map_.find(opti_compilation_infos_.GetSocVersion()); | 1012 | + auto iter = platform_infos_map_.find(real_soc); |
| 1025 | if (iter == platform_infos_map_.end()) { | 1013 | if (iter == platform_infos_map_.end()) { |
| 1026 | - PF_LOGE("Cannot find platform_info by SoCVersion %s.", opti_compilation_infos_.GetSocVersion().c_str()); | 1014 | + if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) { |
| 1027 | - return PLATFORM_FAILED; | 1015 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", real_soc.c_str()); |
| 1016 | + return PLATFORM_FAILED; | ||
| 1017 | + } | ||
| 1018 | + iter = platform_infos_map_.find(real_soc); | ||
| 1019 | + if (iter == platform_infos_map_.end()) { | ||
| 1020 | + PF_LOGE("Cannot find platform_info by SoCVersion %s.", real_soc.c_str()); | ||
| 1021 | + return PLATFORM_FAILED; | ||
| 1022 | + } | ||
| 1028 | } | 1023 | } |
| 1029 | platform_info = iter->second; | 1024 | platform_info = iter->second; |
| 1030 | if (!platform_info.GetFixPipeDtypeMap().empty()) { | 1025 | if (!platform_info.GetFixPipeDtypeMap().empty()) { |
| @@ -1037,17 +1032,24 @@ __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatform | |||
| 1037 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInstanceByDevice( | 1032 | __attribute__((visibility("default"))) uint32_t PlatformInfoManager::GetPlatformInstanceByDevice( |
| 1038 | const uint32_t &device_id, PlatFormInfos &platform_info) { | 1033 | const uint32_t &device_id, PlatFormInfos &platform_info) { |
| 1039 | std::lock_guard<std::mutex> lock_guard(pc_lock_); | 1034 | std::lock_guard<std::mutex> lock_guard(pc_lock_); |
| 1035 | + std::string real_soc = opti_compilation_infos_.GetSocVersion(); | ||
| 1040 | auto iter = device_platform_infos_map_.find(device_id); | 1036 | auto iter = device_platform_infos_map_.find(device_id); |
| 1041 | if (iter == device_platform_infos_map_.end()) { | 1037 | if (iter == device_platform_infos_map_.end()) { |
| 1042 | - if (opti_compilation_infos_.GetSocVersion().empty()) { | 1038 | + if (real_soc.empty()) { |
| 1043 | PF_LOGW("Not initialize soc_version of optional_infos."); | 1039 | PF_LOGW("Not initialize soc_version of optional_infos."); |
| 1044 | return PLATFORM_FAILED; | 1040 | return PLATFORM_FAILED; |
| 1045 | } | 1041 | } |
| 1046 | - if (platform_infos_map_.find(opti_compilation_infos_.GetSocVersion()) == platform_infos_map_.end()) { | 1042 | + if (platform_infos_map_.find(real_soc) == platform_infos_map_.end()) { |
| 1047 | - PF_LOGW("Failed to initialize platform info map."); | 1043 | + if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) { |
| 1048 | - return PLATFORM_FAILED; | 1044 | + PF_LOGW("Failed to initialize platform info map."); |
| 1045 | + return PLATFORM_FAILED; | ||
| 1046 | + } | ||
| 1047 | + if (platform_infos_map_.find(real_soc) == platform_infos_map_.end()) { | ||
| 1048 | + PF_LOGW("Failed to initialize platform info map."); | ||
| 1049 | + return PLATFORM_FAILED; | ||
| 1050 | + } | ||
| 1049 | } | 1051 | } |
| 1050 | - device_platform_infos_map_[device_id] = platform_infos_map_[opti_compilation_infos_.GetSocVersion()]; | 1052 | + device_platform_infos_map_[device_id] = platform_infos_map_[real_soc]; |
| 1051 | } | 1053 | } |
| 1052 | platform_info = device_platform_infos_map_[device_id]; | 1054 | platform_info = device_platform_infos_map_[device_id]; |
| 1053 | return PLATFORM_SUCCESS; | 1055 | return PLATFORM_SUCCESS; |
| @@ -1069,9 +1071,17 @@ uint32_t PlatformInfoManager::UpdatePlatformInfos(fe::PlatFormInfos &platform_in | |||
| 1069 | PF_LOGE("Soc_version in the optional information is empty."); | 1071 | PF_LOGE("Soc_version in the optional information is empty."); |
| 1070 | return PLATFORM_FAILED; | 1072 | return PLATFORM_FAILED; |
| 1071 | } | 1073 | } |
| 1072 | - if (platform_infos_map_.find(opti_compilation_infos_.GetSocVersion()) == platform_infos_map_.end()) { | 1074 | + auto iter = platform_infos_map_.find(opti_compilation_infos_.GetSocVersion()); |
| 1073 | - PF_LOGE("Platform info for soc_version [%s] is not initialized.", opti_compilation_infos_.GetSocVersion().c_str()); | 1075 | + if (iter == platform_infos_map_.end()) { |
| 1074 | - return PLATFORM_FAILED; | 1076 | + if (EnsureSocVersionLoaded(opti_compilation_infos_.GetSocVersion()) != PLATFORM_SUCCESS) { |
| 1077 | + PF_LOGE("Platform info for soc_version [%s] is not initialized.", opti_compilation_infos_.GetSocVersion().c_str()); | ||
| 1078 | + return PLATFORM_FAILED; | ||
| 1079 | + } | ||
| 1080 | + iter = platform_infos_map_.find(opti_compilation_infos_.GetSocVersion()); | ||
| 1081 | + if (iter == platform_infos_map_.end()) { | ||
| 1082 | + PF_LOGE("Platform info for soc_version [%s] is not initialized.", opti_compilation_infos_.GetSocVersion().c_str()); | ||
| 1083 | + return PLATFORM_FAILED; | ||
| 1084 | + } | ||
| 1075 | } | 1085 | } |
| 1076 | platform_infos_map_[opti_compilation_infos_.GetSocVersion()] = platform_info; | 1086 | platform_infos_map_[opti_compilation_infos_.GetSocVersion()] = platform_info; |
| 1077 | return PLATFORM_SUCCESS; | 1087 | return PLATFORM_SUCCESS; |
| @@ -1088,9 +1098,17 @@ uint32_t PlatformInfoManager::UpdatePlatformInfos(const std::string &soc_version | |||
| 1088 | if (real_soc == SOC_VERSION_ASCEND910) { | 1098 | if (real_soc == SOC_VERSION_ASCEND910) { |
| 1089 | real_soc = SOC_VERSION_ASCEND910A; | 1099 | real_soc = SOC_VERSION_ASCEND910A; |
| 1090 | } | 1100 | } |
| 1091 | - if (platform_infos_map_.find(real_soc) == platform_infos_map_.end()) { | 1101 | + auto iter = platform_infos_map_.find(real_soc); |
| 1092 | - PF_LOGE("Platform info for soc_version [%s] is not initialized.", real_soc.c_str()); | 1102 | + if (iter == platform_infos_map_.end()) { |
| 1093 | - return PLATFORM_FAILED; | 1103 | + if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) { |
| 1104 | + PF_LOGE("Platform info for soc_version [%s] is not initialized.", real_soc.c_str()); | ||
| 1105 | + return PLATFORM_FAILED; | ||
| 1106 | + } | ||
| 1107 | + iter = platform_infos_map_.find(real_soc); | ||
| 1108 | + if (iter == platform_infos_map_.end()) { | ||
| 1109 | + PF_LOGE("Platform info for soc_version [%s] is not initialized.", real_soc.c_str()); | ||
| 1110 | + return PLATFORM_FAILED; | ||
| 1111 | + } | ||
| 1094 | } | 1112 | } |
| 1095 | opti_compilation_infos_.SetSocVersionWithLock(real_soc); | 1113 | opti_compilation_infos_.SetSocVersionWithLock(real_soc); |
| 1096 | platform_infos_map_[real_soc] = platform_info; | 1114 | platform_infos_map_[real_soc] = platform_info; |
| @@ -1112,6 +1130,10 @@ uint32_t PlatformInfoManager::Finalize() { | |||
| 1112 | 1130 | ||
| 1113 | runtime_device_platform_infos_map_.clear(); | 1131 | runtime_device_platform_infos_map_.clear(); |
| 1114 | 1132 | ||
| 1133 | + loaded_ini_files_.clear(); | ||
| 1134 | + | ||
| 1135 | + cfg_file_real_path_.clear(); | ||
| 1136 | + | ||
| 1115 | init_flag_ = false; | 1137 | init_flag_ = false; |
| 1116 | 1138 | ||
| 1117 | return PLATFORM_SUCCESS; | 1139 | return PLATFORM_SUCCESS; |
| @@ -1154,10 +1176,12 @@ uint32_t PlatformInfoManager::InitRuntimePlatformInfos(const std::string &SoCVer | |||
| 1154 | return PLATFORM_SUCCESS; | 1176 | return PLATFORM_SUCCESS; |
| 1155 | } | 1177 | } |
| 1156 | 1178 | ||
| 1157 | - std::string cfg_file_real_path = fe::GetConfigFilePath<PlatformInfoManager>(); | 1179 | + if (cfg_file_real_path_.empty()) { |
| 1158 | - if (cfg_file_real_path.empty()) { | 1180 | + cfg_file_real_path_ = fe::GetConfigFilePath<PlatformInfoManager>(); |
| 1159 | - PF_LOGE("File path[%s] is not valid.", cfg_file_real_path.c_str()); | 1181 | + if (cfg_file_real_path_.empty()) { |
| 1160 | - return PLATFORM_FAILED; | 1182 | + PF_LOGE("File path[%s] is not valid.", cfg_file_real_path_.c_str()); |
| 1183 | + return PLATFORM_FAILED; | ||
| 1184 | + } | ||
| 1161 | } | 1185 | } |
| 1162 | 1186 | ||
| 1163 | std::string real_soc = SoCVersion; | 1187 | std::string real_soc = SoCVersion; |
| @@ -1165,13 +1189,12 @@ uint32_t PlatformInfoManager::InitRuntimePlatformInfos(const std::string &SoCVer | |||
| 1165 | real_soc = SOC_VERSION_ASCEND910A; | 1189 | real_soc = SOC_VERSION_ASCEND910A; |
| 1166 | } | 1190 | } |
| 1167 | 1191 | ||
| 1168 | - std::string ini_file_path = cfg_file_real_path + "/" + real_soc + ".ini"; | 1192 | + if (EnsureSocVersionLoaded(real_soc) != PLATFORM_SUCCESS) { |
| 1169 | - if (LoadIniFile(ini_file_path) != PLATFORM_SUCCESS) { | 1193 | + PF_LOGE("Failed to load ini file for soc[%s].", real_soc.c_str()); |
| 1170 | - PF_LOGE("Failed to load ini file[%s].", ini_file_path.c_str()); | 1194 | + return PLATFORM_FAILED; |
| 1171 | - return PLATFORM_FAILED; | ||
| 1172 | } | 1195 | } |
| 1173 | 1196 | ||
| 1174 | - const auto it = platform_infos_map_.find(SoCVersion); | 1197 | + const auto it = platform_infos_map_.find(real_soc); |
| 1175 | if (it == platform_infos_map_.end()) { | 1198 | if (it == platform_infos_map_.end()) { |
| 1176 | std::string errLevel = "E20101"; | 1199 | std::string errLevel = "E20101"; |
| 1177 | std::vector<const char*> args_keys; | 1200 | std::vector<const char*> args_keys; |
| @@ -27,6 +27,10 @@ protected: | |||
| 27 | PlatformInfoManager::GeInstance().platform_info_map_.clear(); | 27 | PlatformInfoManager::GeInstance().platform_info_map_.clear(); |
| 28 | PlatformInfoManager::GeInstance().device_platform_infos_map_.clear(); | 28 | PlatformInfoManager::GeInstance().device_platform_infos_map_.clear(); |
| 29 | PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_.clear(); | 29 | PlatformInfoManager::GeInstance().runtime_device_platform_infos_map_.clear(); |
| 30 | + PlatformInfoManager::GeInstance().loaded_ini_files_.clear(); | ||
| 31 | + PlatformInfoManager::GeInstance().cfg_file_real_path_.clear(); | ||
| 32 | + PlatformInfoManager::GeInstance().opti_compilation_info_ = OptionalInfo(); | ||
| 33 | + PlatformInfoManager::GeInstance().opti_compilation_infos_ = OptionalInfos(); | ||
| 30 | PlatformInfoManager::GeInstance().init_flag_ = false; | 34 | PlatformInfoManager::GeInstance().init_flag_ = false; |
| 31 | PlatformInfoManager::GeInstance().runtime_init_flag_ = false; | 35 | PlatformInfoManager::GeInstance().runtime_init_flag_ = false; |
| 32 | } | 36 | } |
| @@ -78,4 +82,47 @@ TEST_F(PlatformManagerGeUTest, platform_ge_instance_kirin9030) { | |||
| 78 | uint32_t ret3 = ge_instance.UpdateRuntimePlatformInfosByDevice(0, platform_infos); | 82 | uint32_t ret3 = ge_instance.UpdateRuntimePlatformInfosByDevice(0, platform_infos); |
| 79 | EXPECT_EQ(ret3, 0U); | 83 | EXPECT_EQ(ret3, 0U); |
| 80 | } | 84 | } |
| 85 | + | ||
| 86 | +TEST_F(PlatformManagerGeUTest, platform_ge_instance_InitRuntimePlatformInfos_success) { | ||
| 87 | + PlatformInfoManager &ge_instance = PlatformInfoManager::GeInstance(); | ||
| 88 | + std::string soc_version = "Ascend910B1"; | ||
| 89 | + uint32_t ret = ge_instance.InitRuntimePlatformInfos(soc_version); | ||
| 90 | + EXPECT_EQ(ret, 0U); | ||
| 91 | + EXPECT_EQ(ge_instance.loaded_ini_files_.count(soc_version), 1U); | ||
| 92 | + EXPECT_TRUE(ge_instance.runtime_init_flag_); | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +TEST_F(PlatformManagerGeUTest, platform_ge_instance_InitRuntimePlatformInfos_repeat) { | ||
| 96 | + PlatformInfoManager &ge_instance = PlatformInfoManager::GeInstance(); | ||
| 97 | + std::string soc_version = "Ascend910B1"; | ||
| 98 | + uint32_t ret = ge_instance.InitRuntimePlatformInfos(soc_version); | ||
| 99 | + EXPECT_EQ(ret, 0U); | ||
| 100 | + ret = ge_instance.InitRuntimePlatformInfos(soc_version); | ||
| 101 | + EXPECT_EQ(ret, 0U); | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +TEST_F(PlatformManagerGeUTest, platform_ge_instance_InitRuntimePlatformInfos_Ascend910_mapping) { | ||
| 105 | + PlatformInfoManager &ge_instance = PlatformInfoManager::GeInstance(); | ||
| 106 | + std::string soc_version = "Ascend910"; | ||
| 107 | + uint32_t ret = ge_instance.InitRuntimePlatformInfos(soc_version); | ||
| 108 | + EXPECT_EQ(ret, 0U); | ||
| 109 | + EXPECT_EQ(ge_instance.loaded_ini_files_.count("Ascend910A"), 1U); | ||
| 110 | + EXPECT_EQ(ge_instance.loaded_ini_files_.count("Ascend910"), 0U); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +TEST_F(PlatformManagerGeUTest, platform_ge_instance_InitRuntimePlatformInfos_fail) { | ||
| 114 | + PlatformInfoManager &ge_instance = PlatformInfoManager::GeInstance(); | ||
| 115 | + std::string soc_version = "NonExistentSoC"; | ||
| 116 | + uint32_t ret = ge_instance.InitRuntimePlatformInfos(soc_version); | ||
| 117 | + EXPECT_NE(ret, 0U); | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +TEST_F(PlatformManagerGeUTest, platform_ge_instance_GetPlatformInfos_fail) { | ||
| 121 | + PlatformInfoManager &ge_instance = PlatformInfoManager::GeInstance(); | ||
| 122 | + std::string soc_version = "NonExistentSoC"; | ||
| 123 | + PlatFormInfos platform_infos; | ||
| 124 | + OptionalInfos optional_infos; | ||
| 125 | + uint32_t ret = ge_instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 126 | + EXPECT_NE(ret, 0U); | ||
| 127 | +} | ||
| 81 | } | 128 | } |
| @@ -27,6 +27,10 @@ protected: | |||
| 27 | PlatformInfoManager::Instance().platform_info_map_.clear(); | 27 | PlatformInfoManager::Instance().platform_info_map_.clear(); |
| 28 | PlatformInfoManager::Instance().device_platform_infos_map_.clear(); | 28 | PlatformInfoManager::Instance().device_platform_infos_map_.clear(); |
| 29 | PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear(); | 29 | PlatformInfoManager::Instance().runtime_device_platform_infos_map_.clear(); |
| 30 | + PlatformInfoManager::Instance().loaded_ini_files_.clear(); | ||
| 31 | + PlatformInfoManager::Instance().cfg_file_real_path_.clear(); | ||
| 32 | + PlatformInfoManager::Instance().opti_compilation_info_ = OptionalInfo(); | ||
| 33 | + PlatformInfoManager::Instance().opti_compilation_infos_ = OptionalInfos(); | ||
| 30 | PlatformInfoManager::Instance().init_flag_ = false; | 34 | PlatformInfoManager::Instance().init_flag_ = false; |
| 31 | PlatformInfoManager::Instance().runtime_init_flag_ = false; | 35 | PlatformInfoManager::Instance().runtime_init_flag_ = false; |
| 32 | } | 36 | } |
| @@ -244,4 +248,400 @@ TEST_F(PlatformManagerUTest, platform_instance_InitByInstance_already_initialize | |||
| 244 | EXPECT_EQ(platform_infos.platform_infos_impl_, first_impl); | 248 | EXPECT_EQ(platform_infos.platform_infos_impl_, first_impl); |
| 245 | } | 249 | } |
| 246 | 250 | ||
| 251 | +TEST_F(PlatformManagerUTest, platform_instance_lazy_load_success) { | ||
| 252 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 253 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 254 | + EXPECT_EQ(ret, 0U); | ||
| 255 | + std::string soc_version = "Ascend910B1"; | ||
| 256 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 0U); | ||
| 257 | + PlatFormInfos platform_infos; | ||
| 258 | + OptionalInfos optional_infos; | ||
| 259 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 260 | + EXPECT_EQ(ret, 0U); | ||
| 261 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 1U); | ||
| 262 | + EXPECT_EQ(instance.loaded_ini_files_.count(soc_version), 1U); | ||
| 263 | +} | ||
| 264 | + | ||
| 265 | +TEST_F(PlatformManagerUTest, platform_instance_lazy_load_no_repeat) { | ||
| 266 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 267 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 268 | + EXPECT_EQ(ret, 0U); | ||
| 269 | + std::string soc_version = "Ascend910B1"; | ||
| 270 | + PlatFormInfos platform_infos; | ||
| 271 | + OptionalInfos optional_infos; | ||
| 272 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 273 | + EXPECT_EQ(ret, 0U); | ||
| 274 | + size_t loaded_count = instance.loaded_ini_files_.size(); | ||
| 275 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 276 | + EXPECT_EQ(ret, 0U); | ||
| 277 | + EXPECT_EQ(instance.loaded_ini_files_.size(), loaded_count); | ||
| 278 | +} | ||
| 279 | + | ||
| 280 | +TEST_F(PlatformManagerUTest, platform_instance_lazy_load_fail) { | ||
| 281 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 282 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 283 | + EXPECT_EQ(ret, 0U); | ||
| 284 | + std::string soc_version = "NonExistentSoC"; | ||
| 285 | + PlatFormInfos platform_infos; | ||
| 286 | + OptionalInfos optional_infos; | ||
| 287 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 288 | + EXPECT_NE(ret, 0U); | ||
| 289 | +} | ||
| 290 | + | ||
| 291 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfo_lazy_load) { | ||
| 292 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 293 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 294 | + EXPECT_EQ(ret, 0U); | ||
| 295 | + std::string soc_version = "Ascend910B1"; | ||
| 296 | + PlatformInfo platform_info; | ||
| 297 | + OptionalInfo optional_info; | ||
| 298 | + ret = instance.GetPlatformInfo(soc_version, platform_info, optional_info); | ||
| 299 | + EXPECT_EQ(ret, 0U); | ||
| 300 | + EXPECT_EQ(instance.platform_info_map_.count(soc_version), 1U); | ||
| 301 | +} | ||
| 302 | + | ||
| 303 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_lazy_load) { | ||
| 304 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 305 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 306 | + EXPECT_EQ(ret, 0U); | ||
| 307 | + std::string soc_version = "Ascend910B1"; | ||
| 308 | + OptionalInfo optional_info; | ||
| 309 | + optional_info.soc_version = soc_version; | ||
| 310 | + instance.SetOptionalCompilationInfo(optional_info); | ||
| 311 | + PlatformInfo platform_info; | ||
| 312 | + OptionalInfo out_optional_info; | ||
| 313 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_info, out_optional_info); | ||
| 314 | + EXPECT_EQ(ret, 0U); | ||
| 315 | +} | ||
| 316 | + | ||
| 317 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInstanceByDevice_lazy_load) { | ||
| 318 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 319 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 320 | + EXPECT_EQ(ret, 0U); | ||
| 321 | + std::string soc_version = "Ascend910B1"; | ||
| 322 | + OptionalInfos optional_infos; | ||
| 323 | + optional_infos.Init(); | ||
| 324 | + optional_infos.SetSocVersion(soc_version); | ||
| 325 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 326 | + PlatFormInfos platform_infos; | ||
| 327 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 328 | + EXPECT_EQ(ret, 0U); | ||
| 329 | + EXPECT_EQ(instance.device_platform_infos_map_.count(0), 1U); | ||
| 330 | +} | ||
| 331 | + | ||
| 332 | +TEST_F(PlatformManagerUTest, platform_instance_EnsureSocVersionLoaded_empty) { | ||
| 333 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 334 | + uint32_t ret = instance.EnsureSocVersionLoaded(""); | ||
| 335 | + EXPECT_NE(ret, 0U); | ||
| 336 | +} | ||
| 337 | + | ||
| 338 | +TEST_F(PlatformManagerUTest, platform_instance_Finalize_clears_loaded) { | ||
| 339 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 340 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 341 | + EXPECT_EQ(ret, 0U); | ||
| 342 | + std::string soc_version = "Ascend910B1"; | ||
| 343 | + PlatFormInfos platform_infos; | ||
| 344 | + OptionalInfos optional_infos; | ||
| 345 | + (void)instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 346 | + EXPECT_FALSE(instance.loaded_ini_files_.empty()); | ||
| 347 | + EXPECT_FALSE(instance.cfg_file_real_path_.empty()); | ||
| 348 | + ret = instance.Finalize(); | ||
| 349 | + EXPECT_EQ(ret, 0U); | ||
| 350 | + EXPECT_TRUE(instance.loaded_ini_files_.empty()); | ||
| 351 | + EXPECT_TRUE(instance.cfg_file_real_path_.empty()); | ||
| 352 | +} | ||
| 353 | + | ||
| 354 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfo_lazy_load_fail) { | ||
| 355 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 356 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 357 | + EXPECT_EQ(ret, 0U); | ||
| 358 | + std::string soc_version = "NonExistentSoC"; | ||
| 359 | + PlatformInfo platform_info; | ||
| 360 | + OptionalInfo optional_info; | ||
| 361 | + ret = instance.GetPlatformInfo(soc_version, platform_info, optional_info); | ||
| 362 | + EXPECT_NE(ret, 0U); | ||
| 363 | +} | ||
| 364 | + | ||
| 365 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_empty_fail) { | ||
| 366 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 367 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 368 | + EXPECT_EQ(ret, 0U); | ||
| 369 | + PlatformInfo platform_info; | ||
| 370 | + OptionalInfo optional_info; | ||
| 371 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_info, optional_info); | ||
| 372 | + EXPECT_NE(ret, 0U); | ||
| 373 | +} | ||
| 374 | + | ||
| 375 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_lazy_load_fail) { | ||
| 376 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 377 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 378 | + EXPECT_EQ(ret, 0U); | ||
| 379 | + OptionalInfo optional_info; | ||
| 380 | + optional_info.soc_version = "NonExistentSoC"; | ||
| 381 | + instance.SetOptionalCompilationInfo(optional_info); | ||
| 382 | + PlatformInfo platform_info; | ||
| 383 | + OptionalInfo out_optional_info; | ||
| 384 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_info, out_optional_info); | ||
| 385 | + EXPECT_NE(ret, 0U); | ||
| 386 | +} | ||
| 387 | + | ||
| 388 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_PlatformInfos_empty_fail) { | ||
| 389 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 390 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 391 | + EXPECT_EQ(ret, 0U); | ||
| 392 | + PlatFormInfos platform_infos; | ||
| 393 | + OptionalInfos optional_infos; | ||
| 394 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_infos, optional_infos); | ||
| 395 | + EXPECT_NE(ret, 0U); | ||
| 396 | +} | ||
| 397 | + | ||
| 398 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_PlatformInfos_lazy_load_fail) { | ||
| 399 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 400 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 401 | + EXPECT_EQ(ret, 0U); | ||
| 402 | + OptionalInfos optional_infos; | ||
| 403 | + optional_infos.Init(); | ||
| 404 | + optional_infos.SetSocVersion("NonExistentSoC"); | ||
| 405 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 406 | + PlatFormInfos platform_infos; | ||
| 407 | + OptionalInfos out_optional_infos; | ||
| 408 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_infos, out_optional_infos); | ||
| 409 | + EXPECT_NE(ret, 0U); | ||
| 410 | +} | ||
| 411 | + | ||
| 412 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInstanceByDevice_empty_soc_fail) { | ||
| 413 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 414 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 415 | + EXPECT_EQ(ret, 0U); | ||
| 416 | + PlatFormInfos platform_infos; | ||
| 417 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 418 | + EXPECT_NE(ret, 0U); | ||
| 419 | +} | ||
| 420 | + | ||
| 421 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInstanceByDevice_lazy_load_fail) { | ||
| 422 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 423 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 424 | + EXPECT_EQ(ret, 0U); | ||
| 425 | + OptionalInfos optional_infos; | ||
| 426 | + optional_infos.Init(); | ||
| 427 | + optional_infos.SetSocVersion("NonExistentSoC"); | ||
| 428 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 429 | + PlatFormInfos platform_infos; | ||
| 430 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 431 | + EXPECT_NE(ret, 0U); | ||
| 432 | +} | ||
| 433 | + | ||
| 434 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInstanceByDevice_Ascend910_mapping) { | ||
| 435 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 436 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 437 | + EXPECT_EQ(ret, 0U); | ||
| 438 | + OptionalInfos optional_infos; | ||
| 439 | + optional_infos.Init(); | ||
| 440 | + optional_infos.SetSocVersion("Ascend910"); | ||
| 441 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 442 | + PlatFormInfos platform_infos; | ||
| 443 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 444 | + EXPECT_EQ(ret, 0U); | ||
| 445 | + EXPECT_EQ(instance.loaded_ini_files_.count("Ascend910A"), 1U); | ||
| 446 | + EXPECT_EQ(instance.device_platform_infos_map_.count(0), 1U); | ||
| 447 | +} | ||
| 448 | + | ||
| 449 | +TEST_F(PlatformManagerUTest, platform_instance_InitializePlatformInfo_repeat) { | ||
| 450 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 451 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 452 | + EXPECT_EQ(ret, 0U); | ||
| 453 | + ret = instance.InitializePlatformInfo(); | ||
| 454 | + EXPECT_EQ(ret, 0U); | ||
| 455 | +} | ||
| 456 | + | ||
| 457 | +TEST_F(PlatformManagerUTest, platform_instance_Trim_empty) { | ||
| 458 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 459 | + std::string str = ""; | ||
| 460 | + instance.Trim(str); | ||
| 461 | + EXPECT_EQ(str, ""); | ||
| 462 | +} | ||
| 463 | + | ||
| 464 | +TEST_F(PlatformManagerUTest, platform_instance_EnsureSocVersionLoaded_repeat) { | ||
| 465 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 466 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 467 | + EXPECT_EQ(ret, 0U); | ||
| 468 | + ret = instance.EnsureSocVersionLoaded("Ascend910B1"); | ||
| 469 | + EXPECT_EQ(ret, 0U); | ||
| 470 | + ret = instance.EnsureSocVersionLoaded("Ascend910B1"); | ||
| 471 | + EXPECT_EQ(ret, 0U); | ||
| 472 | +} | ||
| 473 | + | ||
| 474 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfo_Ascend910_mapping) { | ||
| 475 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 476 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 477 | + EXPECT_EQ(ret, 0U); | ||
| 478 | + PlatformInfo platform_info; | ||
| 479 | + OptionalInfo optional_info; | ||
| 480 | + ret = instance.GetPlatformInfo("Ascend910", platform_info, optional_info); | ||
| 481 | + EXPECT_EQ(ret, 0U); | ||
| 482 | + EXPECT_EQ(instance.loaded_ini_files_.count("Ascend910A"), 1U); | ||
| 483 | +} | ||
| 484 | + | ||
| 485 | +TEST_F(PlatformManagerUTest, platform_instance_SetOptionalCompilationInfo_Ascend910_mapping) { | ||
| 486 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 487 | + OptionalInfo optional_info; | ||
| 488 | + optional_info.soc_version = "Ascend910"; | ||
| 489 | + instance.SetOptionalCompilationInfo(optional_info); | ||
| 490 | + EXPECT_EQ(instance.opti_compilation_info_.soc_version, "Ascend910A"); | ||
| 491 | +} | ||
| 492 | + | ||
| 493 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfos_Ascend910_mapping) { | ||
| 494 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 495 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 496 | + EXPECT_EQ(ret, 0U); | ||
| 497 | + PlatFormInfos platform_infos; | ||
| 498 | + OptionalInfos optional_infos; | ||
| 499 | + ret = instance.GetPlatformInfos("Ascend910", platform_infos, optional_infos); | ||
| 500 | + EXPECT_EQ(ret, 0U); | ||
| 501 | + EXPECT_EQ(instance.loaded_ini_files_.count("Ascend910A"), 1U); | ||
| 502 | +} | ||
| 503 | + | ||
| 504 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfo_defensive) { | ||
| 505 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 506 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 507 | + EXPECT_EQ(ret, 0U); | ||
| 508 | + std::string soc_version = "Ascend910B1"; | ||
| 509 | + PlatformInfo platform_info; | ||
| 510 | + OptionalInfo optional_info; | ||
| 511 | + ret = instance.GetPlatformInfo(soc_version, platform_info, optional_info); | ||
| 512 | + EXPECT_EQ(ret, 0U); | ||
| 513 | + instance.platform_info_map_.erase(soc_version); | ||
| 514 | + ret = instance.GetPlatformInfo(soc_version, platform_info, optional_info); | ||
| 515 | + EXPECT_NE(ret, 0U); | ||
| 516 | +} | ||
| 517 | + | ||
| 518 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfos_defensive) { | ||
| 519 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 520 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 521 | + EXPECT_EQ(ret, 0U); | ||
| 522 | + std::string soc_version = "Ascend910B1"; | ||
| 523 | + PlatFormInfos platform_infos; | ||
| 524 | + OptionalInfos optional_infos; | ||
| 525 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 526 | + EXPECT_EQ(ret, 0U); | ||
| 527 | + instance.platform_infos_map_.erase(soc_version); | ||
| 528 | + ret = instance.GetPlatformInfos(soc_version, platform_infos, optional_infos); | ||
| 529 | + EXPECT_NE(ret, 0U); | ||
| 530 | +} | ||
| 531 | + | ||
| 532 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInfoWithOutSocVersion_PlatformInfos_defensive) { | ||
| 533 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 534 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 535 | + EXPECT_EQ(ret, 0U); | ||
| 536 | + OptionalInfos optional_infos; | ||
| 537 | + optional_infos.Init(); | ||
| 538 | + optional_infos.SetSocVersion("Ascend910B1"); | ||
| 539 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 540 | + PlatFormInfos platform_infos; | ||
| 541 | + OptionalInfos out_optional_infos; | ||
| 542 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_infos, out_optional_infos); | ||
| 543 | + EXPECT_EQ(ret, 0U); | ||
| 544 | + instance.platform_infos_map_.erase("Ascend910B1"); | ||
| 545 | + ret = instance.GetPlatformInfoWithOutSocVersion(platform_infos, out_optional_infos); | ||
| 546 | + EXPECT_NE(ret, 0U); | ||
| 547 | +} | ||
| 548 | + | ||
| 549 | +TEST_F(PlatformManagerUTest, platform_instance_GetPlatformInstanceByDevice_defensive) { | ||
| 550 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 551 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 552 | + EXPECT_EQ(ret, 0U); | ||
| 553 | + OptionalInfos optional_infos; | ||
| 554 | + optional_infos.Init(); | ||
| 555 | + optional_infos.SetSocVersion("Ascend910B1"); | ||
| 556 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 557 | + PlatFormInfos platform_infos; | ||
| 558 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 559 | + EXPECT_EQ(ret, 0U); | ||
| 560 | + instance.platform_infos_map_.erase("Ascend910B1"); | ||
| 561 | + instance.device_platform_infos_map_.clear(); | ||
| 562 | + ret = instance.GetPlatformInstanceByDevice(0, platform_infos); | ||
| 563 | + EXPECT_NE(ret, 0U); | ||
| 564 | +} | ||
| 565 | + | ||
| 566 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_with_soc_lazy_load_success) { | ||
| 567 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 568 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 569 | + EXPECT_EQ(ret, 0U); | ||
| 570 | + std::string soc_version = "Ascend910B1"; | ||
| 571 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 0U); | ||
| 572 | + PlatFormInfos new_platform_infos; | ||
| 573 | + ret = instance.UpdatePlatformInfos(soc_version, new_platform_infos); | ||
| 574 | + EXPECT_EQ(ret, 0U); | ||
| 575 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 1U); | ||
| 576 | + EXPECT_EQ(instance.loaded_ini_files_.count(soc_version), 1U); | ||
| 577 | +} | ||
| 578 | + | ||
| 579 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_with_soc_lazy_load_fail) { | ||
| 580 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 581 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 582 | + EXPECT_EQ(ret, 0U); | ||
| 583 | + std::string soc_version = "NonExistentSoC"; | ||
| 584 | + PlatFormInfos new_platform_infos; | ||
| 585 | + ret = instance.UpdatePlatformInfos(soc_version, new_platform_infos); | ||
| 586 | + EXPECT_NE(ret, 0U); | ||
| 587 | +} | ||
| 588 | + | ||
| 589 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_with_soc_Ascend910_mapping) { | ||
| 590 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 591 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 592 | + EXPECT_EQ(ret, 0U); | ||
| 593 | + PlatFormInfos new_platform_infos; | ||
| 594 | + ret = instance.UpdatePlatformInfos("Ascend910", new_platform_infos); | ||
| 595 | + EXPECT_EQ(ret, 0U); | ||
| 596 | + EXPECT_EQ(instance.loaded_ini_files_.count("Ascend910A"), 1U); | ||
| 597 | + EXPECT_EQ(instance.platform_infos_map_.count("Ascend910A"), 1U); | ||
| 598 | +} | ||
| 599 | + | ||
| 600 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_with_soc_empty_fail) { | ||
| 601 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 602 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 603 | + EXPECT_EQ(ret, 0U); | ||
| 604 | + PlatFormInfos new_platform_infos; | ||
| 605 | + ret = instance.UpdatePlatformInfos("", new_platform_infos); | ||
| 606 | + EXPECT_NE(ret, 0U); | ||
| 607 | +} | ||
| 608 | + | ||
| 609 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_no_soc_lazy_load_success) { | ||
| 610 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 611 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 612 | + EXPECT_EQ(ret, 0U); | ||
| 613 | + std::string soc_version = "Ascend910B1"; | ||
| 614 | + OptionalInfos optional_infos; | ||
| 615 | + optional_infos.Init(); | ||
| 616 | + optional_infos.SetSocVersion(soc_version); | ||
| 617 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 618 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 0U); | ||
| 619 | + PlatFormInfos new_platform_infos; | ||
| 620 | + ret = instance.UpdatePlatformInfos(new_platform_infos); | ||
| 621 | + EXPECT_EQ(ret, 0U); | ||
| 622 | + EXPECT_EQ(instance.platform_infos_map_.count(soc_version), 1U); | ||
| 623 | + EXPECT_EQ(instance.loaded_ini_files_.count(soc_version), 1U); | ||
| 624 | +} | ||
| 625 | + | ||
| 626 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_no_soc_lazy_load_fail) { | ||
| 627 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 628 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 629 | + EXPECT_EQ(ret, 0U); | ||
| 630 | + OptionalInfos optional_infos; | ||
| 631 | + optional_infos.Init(); | ||
| 632 | + optional_infos.SetSocVersion("NonExistentSoC"); | ||
| 633 | + instance.SetOptionalCompilationInfo(optional_infos); | ||
| 634 | + PlatFormInfos new_platform_infos; | ||
| 635 | + ret = instance.UpdatePlatformInfos(new_platform_infos); | ||
| 636 | + EXPECT_NE(ret, 0U); | ||
| 637 | +} | ||
| 638 | + | ||
| 639 | +TEST_F(PlatformManagerUTest, platform_instance_UpdatePlatformInfos_no_soc_empty_fail) { | ||
| 640 | + PlatformInfoManager &instance = PlatformInfoManager::Instance(); | ||
| 641 | + uint32_t ret = instance.InitializePlatformInfo(); | ||
| 642 | + EXPECT_EQ(ret, 0U); | ||
| 643 | + PlatFormInfos new_platform_infos; | ||
| 644 | + ret = instance.UpdatePlatformInfos(new_platform_infos); | ||
| 645 | + EXPECT_NE(ret, 0U); | ||
| 646 | +} | ||
| 247 | } | 647 | } |