Merged
Support builtin AICPU json package loading #666
jialimin1Add on Jul 21
Support builtin AICPU json package loading #666
Merged
Total: 3 files changed+126-48
| @@ -8,6 +8,7 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | +#include <algorithm> | ||
| 11 | #include <set> | 12 | #include <set> |
| 12 | #include "aicpu_json_load_manager.h" | 13 | #include "aicpu_json_load_manager.h" |
| 13 | #include <fstream> | 14 | #include <fstream> |
| @@ -25,11 +26,20 @@ const std::string kAicpuOpsFileEnvPath = "/built-in/op_impl/aicpu/aicpu_kernel/c | |||
| 25 | const std::string kTfOpsFileEnvPath = "/built-in/op_impl/aicpu/tf_kernel/config/tf_kernel.json"; | 26 | const std::string kTfOpsFileEnvPath = "/built-in/op_impl/aicpu/tf_kernel/config/tf_kernel.json"; |
| 26 | const std::string kAicpuCustJsonFilePath = "/op_impl/cpu/config/cust_aicpu_kernel.json"; | 27 | const std::string kAicpuCustJsonFilePath = "/op_impl/cpu/config/cust_aicpu_kernel.json"; |
| 27 | const std::string kAicpuCustOpsFilePath = "/op_impl/cpu/aicpu_kernel/impl/"; | 28 | const std::string kAicpuCustOpsFilePath = "/op_impl/cpu/aicpu_kernel/impl/"; |
| 29 | +const std::string kAicpuBuiltinJsonDir = "/built-in/op_impl/aicpu/config"; | ||
| 30 | +const std::string kAicpuBuiltinOpsFilePath = "/built-in/op_impl/aicpu/kernel/"; | ||
| 28 | constexpr size_t SOC_VERSION_LEN = 128U; | 31 | constexpr size_t SOC_VERSION_LEN = 128U; |
| 29 | constexpr int kMaxFileSizeLimit = INT_MAX; | 32 | constexpr int kMaxFileSizeLimit = INT_MAX; |
| 30 | const std::string kSplitSeparator = ":"; | 33 | const std::string kSplitSeparator = ":"; |
| 31 | const std::string kCustOpsBlacklistVendorName = "custom_aicpu_ops"; | 34 | const std::string kCustOpsBlacklistVendorName = "custom_aicpu_ops"; |
| 32 | const std::string kCustOpsBlacklistSoName = "libcust_cpu_kernels.so"; | 35 | const std::string kCustOpsBlacklistSoName = "libcust_cpu_kernels.so"; |
| 36 | + | ||
| 37 | +const std::string& GetKernelSoDir(const JsonLoadManger::OpPackageType packageType) | ||
| 38 | +{ | ||
| 39 | + static const std::string kCustomKernelSoDir = kAicpuCustOpsFilePath; | ||
| 40 | + static const std::string kBuiltinKernelSoDir = kAicpuBuiltinOpsFilePath; | ||
| 41 | + return (packageType == JsonLoadManger::OpPackageType::BUILTIN) ? kBuiltinKernelSoDir : kCustomKernelSoDir; | ||
| 42 | +} | ||
| 33 | } // namespace | 43 | } // namespace |
| 34 | 44 | ||
| 35 | bool JsonLoadManger::hasAicpuLoadBin_ = false; | 45 | bool JsonLoadManger::hasAicpuLoadBin_ = false; |
| @@ -45,9 +55,9 @@ std::mutex JsonLoadManger::custMutex_ = std::mutex(); | |||
| 45 | bool JsonLoadManger::aicpuCustLoadFlag_ = false; | 55 | bool JsonLoadManger::aicpuCustLoadFlag_ = false; |
| 46 | std::mutex JsonLoadManger::aicpuCustBinLoadMutex_ = std::mutex(); | 56 | std::mutex JsonLoadManger::aicpuCustBinLoadMutex_ = std::mutex(); |
| 47 | std::mutex JsonLoadManger::bufferCacheMutex_ = std::mutex(); | 57 | std::mutex JsonLoadManger::bufferCacheMutex_ = std::mutex(); |
| 48 | -std::vector<std::pair<std::string, nlohmann::json>> JsonLoadManger::custOpJsonInfo_ = {}; | 58 | +std::vector<JsonLoadManger::OpJsonFileInfo> JsonLoadManger::custOpJsonInfo_ = {}; |
| 49 | std::map<std::string, OpFullInfo> JsonLoadManger::customOpsInfos_ = {}; | 59 | std::map<std::string, OpFullInfo> JsonLoadManger::customOpsInfos_ = {}; |
| 50 | -std::map<std::string, std::string> JsonLoadManger::custRegisterInfos_ = {}; | 60 | +std::map<std::string, JsonLoadManger::OpRegisterInfo> JsonLoadManger::custRegisterInfos_ = {}; |
| 51 | std::map<std::string, JsonLoadManger::CustomBinManager> JsonLoadManger::customBinhandleInfos_ = {}; | 61 | std::map<std::string, JsonLoadManger::CustomBinManager> JsonLoadManger::customBinhandleInfos_ = {}; |
| 52 | std::map<std::string, std::shared_ptr<std::vector<char>>> JsonLoadManger::bufferCache_ = {}; | 62 | std::map<std::string, std::shared_ptr<std::vector<char>>> JsonLoadManger::bufferCache_ = {}; |
| 53 | 63 | ||
| @@ -151,33 +161,40 @@ aclnnStatus JsonLoadManger::LoadAicpuCustBinaryFromJson(const std::string& opTyp | |||
| 151 | std::string& kernelSoPath) | 161 | std::string& kernelSoPath) |
| 152 | { | 162 | { |
| 153 | std::unique_lock<std::mutex> lk(aicpuCustBinLoadMutex_); | 163 | std::unique_lock<std::mutex> lk(aicpuCustBinLoadMutex_); |
| 154 | - const std::string custRegisterPath = custRegisterInfos_[opType]; | 164 | + auto iter = custRegisterInfos_.find(opType); |
| 155 | - kernelSoPath = custRegisterPath + kAicpuCustOpsFilePath + kernelSoName; | 165 | + if (iter == custRegisterInfos_.end()) { |
| 166 | + OP_LOGE(ACLNN_ERR_INNER, "The operator %s not found in package registry.", opType.c_str()); | ||
| 167 | + return ACLNN_ERR_INNER; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + const auto& registerInfo = iter->second; | ||
| 171 | + kernelSoPath = registerInfo.opsRootPath + GetKernelSoDir(registerInfo.packageType) + kernelSoName; | ||
| 156 | if (customBinhandleInfos_[kernelSoPath].hasLoad) { | 172 | if (customBinhandleInfos_[kernelSoPath].hasLoad) { |
| 157 | - OP_LOGI("The custom kernel so %s has loaded, no need to reload.", kernelSoPath.c_str()); | 173 | + OP_LOGI("The package kernel so %s has loaded, no need to reload.", kernelSoPath.c_str()); |
| 158 | return ACLNN_SUCCESS; | 174 | return ACLNN_SUCCESS; |
| 159 | } | 175 | } |
| 160 | AICPU_ASSERT_OK_RETVAL(LoadBinaryFromJson(kernelSoPath, customBinhandleInfos_[kernelSoPath].binHandle, true)); | 176 | AICPU_ASSERT_OK_RETVAL(LoadBinaryFromJson(kernelSoPath, customBinhandleInfos_[kernelSoPath].binHandle, true)); |
| 161 | customBinhandleInfos_[kernelSoPath].hasLoad = true; | 177 | customBinhandleInfos_[kernelSoPath].hasLoad = true; |
| 162 | - OP_LOGI("The custom kernel so %s load successfully.", kernelSoPath.c_str()); | 178 | + OP_LOGI("The package kernel so %s load successfully.", kernelSoPath.c_str()); |
| 163 | return ACLNN_SUCCESS; | 179 | return ACLNN_SUCCESS; |
| 164 | } | 180 | } |
| 165 | 181 | ||
| 166 | -bool JsonLoadManger::ReadCustJsonFile(const std::string& opsRegisterName, const std::string& customJsonPath) | 182 | +bool JsonLoadManger::ReadCustJsonFile(const std::string& opsRegisterName, const std::string& customJsonPath, |
| 183 | + const OpPackageType packageType) | ||
| 167 | { | 184 | { |
| 168 | std::ifstream ifs(customJsonPath); | 185 | std::ifstream ifs(customJsonPath); |
| 169 | if (!ifs.is_open()) { | 186 | if (!ifs.is_open()) { |
| 170 | - OP_LOGW("Open custom op impl %s failed, do next operator repository.", customJsonPath.c_str()); | 187 | + OP_LOGW("Open operator impl %s failed, do next operator repository.", customJsonPath.c_str()); |
| 171 | return false; | 188 | return false; |
| 172 | } | 189 | } |
| 173 | nlohmann::json custOpInfoFile; | 190 | nlohmann::json custOpInfoFile; |
| 174 | if (OpsJsonFile::Instance().ParseUnderPath(customJsonPath, custOpInfoFile) != ACLNN_SUCCESS) { | 191 | if (OpsJsonFile::Instance().ParseUnderPath(customJsonPath, custOpInfoFile) != ACLNN_SUCCESS) { |
| 175 | - OP_LOGW("Parse custom json file[%s] failed.", customJsonPath.c_str()); | 192 | + OP_LOGW("Parse operator json file[%s] failed.", customJsonPath.c_str()); |
| 176 | return false; | 193 | return false; |
| 177 | } | 194 | } |
| 178 | - OP_LOGI("Custom operator repository name is %s, custom operator info file = %s", opsRegisterName.c_str(), | 195 | + OP_LOGI("Operator repository name is %s, operator info file = %s", opsRegisterName.c_str(), |
| 179 | custOpInfoFile.dump().c_str()); | 196 | custOpInfoFile.dump().c_str()); |
| 180 | - custOpJsonInfo_.emplace_back(std::pair<std::string, nlohmann::json>(opsRegisterName, custOpInfoFile)); | 197 | + custOpJsonInfo_.emplace_back(OpJsonFileInfo{opsRegisterName, custOpInfoFile, packageType}); |
| 181 | return true; | 198 | return true; |
| 182 | } | 199 | } |
| 183 | 200 | ||
| @@ -213,7 +230,7 @@ bool JsonLoadManger::ReadCustOpInfoFromJsonFile(const std::string& path) | |||
| 213 | for (size_t i = 0; i < customPathSize; i++) { | 230 | for (size_t i = 0; i < customPathSize; i++) { |
| 214 | customJsonPath = customOppPath[i] + kAicpuCustJsonFilePath; | 231 | customJsonPath = customOppPath[i] + kAicpuCustJsonFilePath; |
| 215 | OP_LOGI("Custom operator repository json path is %s.", customJsonPath.c_str()); | 232 | OP_LOGI("Custom operator repository json path is %s.", customJsonPath.c_str()); |
| 216 | - if (!ReadCustJsonFile(customOppPath[i], customJsonPath)) { | 233 | + if (!ReadCustJsonFile(customOppPath[i], customJsonPath, OpPackageType::CUSTOM)) { |
| 217 | continue; | 234 | continue; |
| 218 | } | 235 | } |
| 219 | } | 236 | } |
| @@ -221,51 +238,80 @@ bool JsonLoadManger::ReadCustOpInfoFromJsonFile(const std::string& path) | |||
| 221 | return true; | 238 | return true; |
| 222 | } | 239 | } |
| 223 | 240 | ||
| 241 | +bool JsonLoadManger::ReadBuiltinOpInfoFromJsonFile(const std::string& oppPath) | ||
| 242 | +{ | ||
| 243 | + const std::string configDir = oppPath + kAicpuBuiltinJsonDir; | ||
| 244 | + std::vector<std::string> jsonFilePaths; | ||
| 245 | + GetFilesWithSuffix(configDir, ".json", jsonFilePaths); | ||
| 246 | + if (jsonFilePaths.empty()) { | ||
| 247 | + OP_LOGI("Builtin operator config dir %s is empty.", configDir.c_str()); | ||
| 248 | + return false; | ||
| 249 | + } | ||
| 250 | + std::sort(jsonFilePaths.begin(), jsonFilePaths.end()); | ||
| 251 | + | ||
| 252 | + for (const auto& jsonPath : jsonFilePaths) { | ||
| 253 | + OP_LOGI("Builtin operator repository json path is %s.", jsonPath.c_str()); | ||
| 254 | + if (!ReadCustJsonFile(oppPath, jsonPath, OpPackageType::BUILTIN)) { | ||
| 255 | + continue; | ||
| 256 | + } | ||
| 257 | + } | ||
| 258 | + OP_LOGI("Builtin operator repository file size is %zu.", custOpJsonInfo_.size()); | ||
| 259 | + return true; | ||
| 260 | +} | ||
| 261 | + | ||
| 224 | // Read custom operator json file and store it | 262 | // Read custom operator json file and store it |
| 225 | aclnnStatus JsonLoadManger::CustJsonLoadAndParse() | 263 | aclnnStatus JsonLoadManger::CustJsonLoadAndParse() |
| 226 | { | 264 | { |
| 227 | std::unique_lock<std::mutex> lk(custMutex_); | 265 | std::unique_lock<std::mutex> lk(custMutex_); |
| 228 | if (aicpuCustLoadFlag_) { | 266 | if (aicpuCustLoadFlag_) { |
| 229 | - OP_LOGI("The custom operator repository has already been loaded."); | 267 | + OP_LOGI("The operator repository has already been loaded."); |
| 230 | return ACLNN_SUCCESS; | 268 | return ACLNN_SUCCESS; |
| 231 | } | 269 | } |
| 232 | - aicpuCustLoadFlag_ = true; | ||
| 233 | const char* customPathEnv = nullptr; | 270 | const char* customPathEnv = nullptr; |
| 234 | MM_SYS_GET_ENV(MM_ENV_ASCEND_CUSTOM_OPP_PATH, customPathEnv); | 271 | MM_SYS_GET_ENV(MM_ENV_ASCEND_CUSTOM_OPP_PATH, customPathEnv); |
| 235 | - // If ASCEND_CUSTOM_OPP_PATH is not set, it indicates there are no custom operators, return directly. | ||
| 236 | if (customPathEnv == nullptr) { | 272 | if (customPathEnv == nullptr) { |
| 237 | OP_LOGI("Custom operator environment variable ASCEND_CUSTOM_OPP_PATH is not set."); | 273 | OP_LOGI("Custom operator environment variable ASCEND_CUSTOM_OPP_PATH is not set."); |
| 238 | - return ACLNN_SUCCESS; | 274 | + } else { |
| 275 | + std::string pathEnv = std::string(customPathEnv); | ||
| 276 | + if (!ReadCustOpInfoFromJsonFile(pathEnv)) { | ||
| 277 | + OP_LOGW("Failed to read custom operator info from json file."); | ||
| 278 | + } | ||
| 239 | } | 279 | } |
| 240 | - std::string pathEnv = std::string(customPathEnv); | 280 | + const char* oppPathEnv = nullptr; |
| 241 | - // Failed to read custom operator json | 281 | + MM_SYS_GET_ENV(MM_ENV_ASCEND_OPP_PATH, oppPathEnv); |
| 242 | - if (!ReadCustOpInfoFromJsonFile(pathEnv)) { | 282 | + if (oppPathEnv == nullptr) { |
| 243 | - OP_LOGW("Failed to read custom operator info from json file."); | 283 | + OP_LOGI("Builtin operator environment variable ASCEND_OPP_PATH is not set."); |
| 244 | - return ACLNN_SUCCESS; | 284 | + } else { |
| 285 | + std::string oppPath = std::string(oppPathEnv); | ||
| 286 | + if (!ReadBuiltinOpInfoFromJsonFile(oppPath)) { | ||
| 287 | + OP_LOGW("Failed to read builtin operator info from json file."); | ||
| 288 | + } | ||
| 245 | } | 289 | } |
| 246 | - // Parse custom operator information | 290 | + (void)ParseCustOpInfo(); |
| 247 | - return ParseCustOpInfo(); | 291 | + aicpuCustLoadFlag_ = true; |
| 292 | + return ACLNN_SUCCESS; | ||
| 248 | } | 293 | } |
| 249 | 294 | ||
| 250 | aclnnStatus JsonLoadManger::ParseCustOpInfo() | 295 | aclnnStatus JsonLoadManger::ParseCustOpInfo() |
| 251 | { | 296 | { |
| 252 | for (auto iter = custOpJsonInfo_.cbegin(); iter != custOpJsonInfo_.cend(); ++iter) { | 297 | for (auto iter = custOpJsonInfo_.cbegin(); iter != custOpJsonInfo_.cend(); ++iter) { |
| 253 | - if (iter->second.find(kConfigOpInfos) == iter->second.end()) { | 298 | + if (iter->opJson.find(kConfigOpInfos) == iter->opJson.end()) { |
| 254 | - OP_LOGW("The custom operator json file does not contain 'op_infos'."); | 299 | + OP_LOGW("The operator json file does not contain 'op_infos'."); |
| 255 | - return ACLNN_SUCCESS; | 300 | + continue; |
| 256 | } | 301 | } |
| 257 | try { | 302 | try { |
| 258 | - OpInfoDescs infoDesc = iter->second; | 303 | + OpInfoDescs infoDesc = iter->opJson; |
| 259 | - FillCustOpInfos(iter->first, infoDesc); | 304 | + FillCustOpInfos(iter->opsRegisterName, infoDesc, iter->packageType); |
| 260 | } catch (const nlohmann::json::exception& e) { | 305 | } catch (const nlohmann::json::exception& e) { |
| 261 | - OP_LOGW("Failed to parse custom operator json file %s : %s.", iter->second.dump().c_str(), e.what()); | 306 | + OP_LOGW("Failed to parse operator json file %s : %s.", iter->opJson.dump().c_str(), e.what()); |
| 262 | - return ACLNN_SUCCESS; | 307 | + continue; |
| 263 | } | 308 | } |
| 264 | } | 309 | } |
| 265 | return ACLNN_SUCCESS; | 310 | return ACLNN_SUCCESS; |
| 266 | } | 311 | } |
| 267 | 312 | ||
| 268 | -void JsonLoadManger::FillCustOpInfos(std::string opsRegisterName, const OpInfoDescs& infoDesc) | 313 | +void JsonLoadManger::FillCustOpInfos(std::string opsRegisterName, const OpInfoDescs& infoDesc, |
| 314 | + const OpPackageType packageType) | ||
| 269 | { | 315 | { |
| 270 | if (!opsRegisterName.empty() && opsRegisterName.back() == '/') { | 316 | if (!opsRegisterName.empty() && opsRegisterName.back() == '/') { |
| 271 | opsRegisterName.pop_back(); | 317 | opsRegisterName.pop_back(); |
| @@ -281,13 +327,27 @@ void JsonLoadManger::FillCustOpInfos(std::string opsRegisterName, const OpInfoDe | |||
| 281 | continue; | 327 | continue; |
| 282 | } | 328 | } |
| 283 | 329 | ||
| 284 | - if (dirName == kCustOpsBlacklistVendorName && opDesc.opInfo.kernelSo == kCustOpsBlacklistSoName) { | 330 | + if ((packageType == OpPackageType::CUSTOM) && (dirName == kCustOpsBlacklistVendorName) && |
| 331 | + (opDesc.opInfo.kernelSo == kCustOpsBlacklistSoName)) { | ||
| 285 | OP_LOGI("vendor name[%s] and so name[%s] are in blacklist, skip to insert customer ops info. " | 332 | OP_LOGI("vendor name[%s] and so name[%s] are in blacklist, skip to insert customer ops info. " |
| 286 | "ops register name is %s, op type is %s.", | 333 | "ops register name is %s, op type is %s.", |
| 287 | dirName.c_str(), opDesc.opInfo.kernelSo.c_str(), opsRegisterName.c_str(), opDesc.opType.c_str()); | 334 | dirName.c_str(), opDesc.opInfo.kernelSo.c_str(), opsRegisterName.c_str(), opDesc.opType.c_str()); |
| 288 | continue; | 335 | continue; |
| 289 | } | 336 | } |
| 290 | 337 | ||
| 338 | + if (packageType == OpPackageType::BUILTIN) { | ||
| 339 | + if (opDesc.opInfo.kernelSo.empty()) { | ||
| 340 | + OP_LOGW("Builtin operator kernel so name is empty, skip op type %s.", opDesc.opType.c_str()); | ||
| 341 | + continue; | ||
| 342 | + } | ||
| 343 | + const std::string kernelSoPath = opsRegisterName + kAicpuBuiltinOpsFilePath + opDesc.opInfo.kernelSo; | ||
| 344 | + if (RealPath(kernelSoPath).empty()) { | ||
| 345 | + OP_LOGW("Builtin operator so path %s is invalid, skip op type %s.", kernelSoPath.c_str(), | ||
| 346 | + opDesc.opType.c_str()); | ||
| 347 | + continue; | ||
| 348 | + } | ||
| 349 | + } | ||
| 350 | + | ||
| 291 | if (customOpsInfos_.find(opDesc.opType) != customOpsInfos_.end()) { | 351 | if (customOpsInfos_.find(opDesc.opType) != customOpsInfos_.end()) { |
| 292 | OP_LOGW("[%s] of operator [%s] is duplicated; discarding in favor of existing entry.", | 352 | OP_LOGW("[%s] of operator [%s] is duplicated; discarding in favor of existing entry.", |
| 293 | opDesc.opType.c_str(), opsRegisterName.c_str()); | 353 | opDesc.opType.c_str(), opsRegisterName.c_str()); |
| @@ -296,12 +356,14 @@ void JsonLoadManger::FillCustOpInfos(std::string opsRegisterName, const OpInfoDe | |||
| 296 | if (!ret.second) { | 356 | if (!ret.second) { |
| 297 | OP_LOGW("Failed to insert operator [%s] and its information.", opDesc.opType.c_str()); | 357 | OP_LOGW("Failed to insert operator [%s] and its information.", opDesc.opType.c_str()); |
| 298 | } | 358 | } |
| 299 | - custRegisterInfos_.emplace(std::pair<std::string, std::string>(opDesc.opType, opsRegisterName)); | 359 | + custRegisterInfos_.emplace( |
| 300 | - OP_LOGI("Reading custom operator json file: operator type is %s, operator register name is %s.", | 360 | + std::pair<std::string, OpRegisterInfo>(opDesc.opType, OpRegisterInfo{opsRegisterName, packageType})); |
| 301 | - opDesc.opType.c_str(), opsRegisterName.c_str()); | 361 | + OP_LOGI( |
| 362 | + "Reading operator json file: operator type is %s, operator register name is %s, package type is %u.", | ||
| 363 | + opDesc.opType.c_str(), opsRegisterName.c_str(), static_cast<uint32_t>(packageType)); | ||
| 302 | } | 364 | } |
| 303 | } | 365 | } |
| 304 | - OP_LOGI("The number of elements in the custom operator registry container is %zu.", custRegisterInfos_.size()); | 366 | + OP_LOGI("The number of elements in the operator registry container is %zu.", custRegisterInfos_.size()); |
| 305 | return; | 367 | return; |
| 306 | } | 368 | } |
| 307 | 369 | ||
| @@ -310,13 +372,13 @@ bool JsonLoadManger::FindAndGetInCustomRegistry(const std::string& opType, std:: | |||
| 310 | { | 372 | { |
| 311 | auto iter = customOpsInfos_.find(opType); | 373 | auto iter = customOpsInfos_.find(opType); |
| 312 | if (iter == customOpsInfos_.end()) { | 374 | if (iter == customOpsInfos_.end()) { |
| 313 | - OP_LOGI("The operator %s not found in custom registry.", opType.c_str()); | 375 | + OP_LOGI("The operator %s not found in operator registry.", opType.c_str()); |
| 314 | return false; | 376 | return false; |
| 315 | } | 377 | } |
| 316 | kernelSo = iter->second.kernelSo; | 378 | kernelSo = iter->second.kernelSo; |
| 317 | functionName = iter->second.functionName; | 379 | functionName = iter->second.functionName; |
| 318 | - OP_LOGI("Found custom operator %s from the custom operator information library %s with function name %s.", | 380 | + OP_LOGI("Found operator %s from the operator information library %s with function name %s.", opType.c_str(), |
| 319 | - opType.c_str(), kernelSo.c_str(), functionName.c_str()); | 381 | + kernelSo.c_str(), functionName.c_str()); |
| 320 | return true; | 382 | return true; |
| 321 | } | 383 | } |
| 322 | 384 | ||
| @@ -381,4 +443,4 @@ std::shared_ptr<std::vector<char>> JsonLoadManger::GetOrCreateBuffer(const std:: | |||
| 381 | return buffer; | 443 | return buffer; |
| 382 | } | 444 | } |
| 383 | } // namespace internal | 445 | } // namespace internal |
| 384 | -} // namespace op | 446 | +} // namespace op |
| @@ -34,6 +34,19 @@ public: | |||
| 34 | bool hasLoad; | 34 | bool hasLoad; |
| 35 | aclrtBinHandle binHandle; | 35 | aclrtBinHandle binHandle; |
| 36 | } CustomBinManager; | 36 | } CustomBinManager; |
| 37 | + enum class OpPackageType { | ||
| 38 | + CUSTOM = 0, | ||
| 39 | + BUILTIN = 1, | ||
| 40 | + }; | ||
| 41 | + struct OpJsonFileInfo { | ||
| 42 | + std::string opsRegisterName; | ||
| 43 | + nlohmann::json opJson; | ||
| 44 | + OpPackageType packageType; | ||
| 45 | + }; | ||
| 46 | + struct OpRegisterInfo { | ||
| 47 | + std::string opsRootPath; | ||
| 48 | + OpPackageType packageType; | ||
| 49 | + }; | ||
| 37 | 50 | ||
| 38 | static aclrtBinHandle GetAicpuCustBinaryHandle(const std::string& kernelSoPath) | 51 | static aclrtBinHandle GetAicpuCustBinaryHandle(const std::string& kernelSoPath) |
| 39 | { | 52 | { |
| @@ -53,9 +66,12 @@ private: | |||
| 53 | JsonLoadManger& operator=(JsonLoadManger&&) = delete; | 66 | JsonLoadManger& operator=(JsonLoadManger&&) = delete; |
| 54 | static aclnnStatus LoadBinaryFromJson(const std::string& opsPath, aclrtBinHandle& binHandle, | 67 | static aclnnStatus LoadBinaryFromJson(const std::string& opsPath, aclrtBinHandle& binHandle, |
| 55 | const bool isCust = false); | 68 | const bool isCust = false); |
| 56 | - static bool ReadCustJsonFile(const std::string& opsRegisterName, const std::string& customJsonPath); | 69 | + static bool ReadCustJsonFile(const std::string& opsRegisterName, const std::string& customJsonPath, |
| 70 | + const OpPackageType packageType); | ||
| 57 | static bool ReadCustOpInfoFromJsonFile(const std::string& path); | 71 | static bool ReadCustOpInfoFromJsonFile(const std::string& path); |
| 58 | - static void FillCustOpInfos(std::string opsRegisterName, const OpInfoDescs& infoDesc); | 72 | + static bool ReadBuiltinOpInfoFromJsonFile(const std::string& oppPath); |
| 73 | + static void FillCustOpInfos(std::string opsRegisterName, const OpInfoDescs& infoDesc, | ||
| 74 | + const OpPackageType packageType); | ||
| 59 | static aclnnStatus ParseCustOpInfo(); | 75 | static aclnnStatus ParseCustOpInfo(); |
| 60 | static bool ReadBytesFromBinaryFile(const std::string& fileName, std::vector<char>& buffer); | 76 | static bool ReadBytesFromBinaryFile(const std::string& fileName, std::vector<char>& buffer); |
| 61 | static std::shared_ptr<std::vector<char>> GetOrCreateBuffer(const std::string& filePath); | 77 | static std::shared_ptr<std::vector<char>> GetOrCreateBuffer(const std::string& filePath); |
| @@ -72,16 +88,16 @@ private: | |||
| 72 | static std::mutex custMutex_; | 88 | static std::mutex custMutex_; |
| 73 | static std::mutex aicpuCustBinLoadMutex_; | 89 | static std::mutex aicpuCustBinLoadMutex_; |
| 74 | static std::mutex bufferCacheMutex_; | 90 | static std::mutex bufferCacheMutex_; |
| 75 | - // Custom operator package repository | 91 | + // AICPU package repository, including custom and builtin json packages. |
| 76 | - static std::vector<std::pair<std::string, nlohmann::json>> custOpJsonInfo_; | 92 | + static std::vector<OpJsonFileInfo> custOpJsonInfo_; |
| 77 | // store operator's name and detailed information | 93 | // store operator's name and detailed information |
| 78 | static std::map<std::string, OpFullInfo> customOpsInfos_; | 94 | static std::map<std::string, OpFullInfo> customOpsInfos_; |
| 79 | // store operator's name and operator's register | 95 | // store operator's name and operator's register |
| 80 | - static std::map<std::string, std::string> custRegisterInfos_; | 96 | + static std::map<std::string, OpRegisterInfo> custRegisterInfos_; |
| 81 | static std::map<std::string, CustomBinManager> customBinhandleInfos_; | 97 | static std::map<std::string, CustomBinManager> customBinhandleInfos_; |
| 82 | static std::map<std::string, std::shared_ptr<std::vector<char>>> bufferCache_; // 文件路径到buffer的映射 | 98 | static std::map<std::string, std::shared_ptr<std::vector<char>>> bufferCache_; // 文件路径到buffer的映射 |
| 83 | }; | 99 | }; |
| 84 | 100 | ||
| 85 | } // namespace internal | 101 | } // namespace internal |
| 86 | } // namespace op | 102 | } // namespace op |
| 87 | -#endif // OP_API_COMMON_INC_OPDEV_AICPU_JSON_LOAD_MANAGER_H_ | 103 | +#endif // OP_API_COMMON_INC_OPDEV_AICPU_JSON_LOAD_MANAGER_H_ |
| @@ -228,8 +228,8 @@ aclnnStatus AicpuTfTask::Run(aclOpExecutor* executor, aclrtStream stream) | |||
| 228 | aclnnStatus AicpuCCTask::GetKernelNameAndSoName(std::string& kernelSoName) | 228 | aclnnStatus AicpuCCTask::GetKernelNameAndSoName(std::string& kernelSoName) |
| 229 | { | 229 | { |
| 230 | if (JsonLoadManger::FindAndGetInCustomRegistry(opType_, kernelSoName, functionName_)) { | 230 | if (JsonLoadManger::FindAndGetInCustomRegistry(opType_, kernelSoName, functionName_)) { |
| 231 | - OP_LOGI("The Operator %s found in custom registry: kernel so name is %s, function name is %s.", opType_.c_str(), | 231 | + OP_LOGI("The Operator %s found in package registry: kernel so name is %s, function name is %s.", |
| 232 | - kernelSoName.c_str(), functionName_.c_str()); | 232 | + opType_.c_str(), kernelSoName.c_str(), functionName_.c_str()); |
| 233 | std::string kernelSoPath = ""; | 233 | std::string kernelSoPath = ""; |
| 234 | AICPU_ASSERT_OK_RETVAL(JsonLoadManger::LoadAicpuCustBinaryFromJson(opType_, kernelSoName, kernelSoPath)); | 234 | AICPU_ASSERT_OK_RETVAL(JsonLoadManger::LoadAicpuCustBinaryFromJson(opType_, kernelSoName, kernelSoPath)); |
| 235 | aicpuBinHandle_ = JsonLoadManger::GetAicpuCustBinaryHandle(kernelSoPath); | 235 | aicpuBinHandle_ = JsonLoadManger::GetAicpuCustBinaryHandle(kernelSoPath); |