| 398 | } |
| 399 | |
| 400 | static Module* loadInternal(const std::vector<std::string>& inputs, const std::vector<std::string>& outputs, const uint8_t* buffer, size_t length, const std::shared_ptr<MNN::Express::Executor::RuntimeManager> _rtMgr, const Module::Config* config) { |
| 401 | // Check if runtime is valid |
| 402 | if (nullptr == _rtMgr || _rtMgr->getInside()->mRuntime.first.empty()) { |
| 403 | MNN_ERROR("Invalid runtime\n"); |
| 404 | return nullptr; |
| 405 | } |
| 406 | bool checkMNNBuffer = true; |
| 407 | if (nullptr != _rtMgr) { |
| 408 | checkMNNBuffer = _rtMgr->getInside()->mContent->modes.checkNetBuffer; |
| 409 | } |
| 410 | bool valid = true; |
| 411 | if (checkMNNBuffer) { |
| 412 | valid = OpCommonUtils::checkNet(buffer, length); |
| 413 | } |
| 414 | if (!valid) { |
| 415 | return nullptr; |
| 416 | } |
| 417 | auto net = GetNet(buffer); |
| 418 | Timer _time; |
| 419 | std::shared_ptr<Module::Info> info(new Module::Info); |
| 420 | if (net->mnn_uuid()) { |
| 421 | info->uuid = net->mnn_uuid()->str(); |
| 422 | } |
| 423 | if (net->extraInfo()) { |
| 424 | if (net->extraInfo()->version()) { |
| 425 | info->version = net->extraInfo()->version()->str(); |
| 426 | } |
| 427 | // Get Meta |
| 428 | if (net->extraInfo()->buffer()) { |
| 429 | auto extra = flatbuffers::GetRoot<Extra>(net->extraInfo()->buffer()->data()); |
| 430 | if (nullptr != extra->attr()) { |
| 431 | for (int i=0; i<extra->attr()->size(); ++i) { |
| 432 | auto attr = extra->attr()->GetAs<Attribute>(i); |
| 433 | if (nullptr != attr->key() && nullptr != attr->s()) { |
| 434 | // The model may be incomplete, avoid crash |
| 435 | info->metaData.insert(std::make_pair(attr->key()->str(), attr->s()->str())); |
| 436 | } |
| 437 | } |
| 438 | } |
| 439 | } |
| 440 | } |
| 441 | if (net->bizCode()) { |
| 442 | info->bizCode = net->bizCode()->str(); |
| 443 | } |
| 444 | auto rtMgr = _rtMgr; |
| 445 | Module::Config defaultConfig; |
| 446 | if (nullptr == config) { |
| 447 | config = &defaultConfig; |
| 448 | } |
| 449 | info->inputNames = inputs; |
| 450 | info->outputNames = outputs; |
| 451 | if ((!inputs.empty()) && (!outputs.empty())) { |
| 452 | _loadInputs(info.get(), inputs, net); |
| 453 | info->runTimeManager = rtMgr; |
| 454 | std::shared_ptr<Module> m(PipelineModule::load(inputs, outputs, buffer, length, rtMgr, config)); |
| 455 | if (nullptr == m) { |
| 456 | return nullptr; |
| 457 | } |
no test coverage detected