| 337 | } |
| 338 | |
| 339 | StaticModule::StaticModule(std::vector<int> inputs, |
| 340 | std::vector<int> outputs, |
| 341 | std::vector<std::shared_ptr<BufferStorage>>&& buffer, |
| 342 | Schedule::ScheduleInfo&& scheduleInfo, |
| 343 | std::shared_ptr<Schedule::ScheduleInfo> sharedConst, |
| 344 | Session::ModeGroup&& mode, |
| 345 | std::shared_ptr<Executor::RuntimeManager> rtm, |
| 346 | const Module::Config& config |
| 347 | ) { |
| 348 | setType("StaticModule"); |
| 349 | mResource.reset(new Resource); |
| 350 | mRuntimeManager = rtm; |
| 351 | MNN_ASSERT(nullptr != rtm); |
| 352 | // Apply before createPipelineBackend creates Backends. |
| 353 | rtm->applyMetaToRuntime(); |
| 354 | auto rt = rtm->getInside()->mRuntime; |
| 355 | mResource->mSharedConst = sharedConst; |
| 356 | mResource->mModes = std::move(mode); |
| 357 | mResource->mBnInfo.user = &mResource->mBnConfig; |
| 358 | mResource->mModes.inputMode = config.shapeMutable ? Interpreter::Session_Input_User : Interpreter::Session_Input_Inside; |
| 359 | mResource->mModes.outputMode = Interpreter::Session_Output_User; |
| 360 | std::shared_ptr<BufferStorage> net_storage; |
| 361 | std::map<const Op*, std::pair<std::shared_ptr<Execution>, DataType>> exeCache; |
| 362 | MNN_ASSERT(1 == scheduleInfo.pipelineInfo.size()); |
| 363 | auto& bnCache = scheduleInfo.pipelineInfo[0].first; |
| 364 | // Create Backend for prearrange |
| 365 | Session::createPipelineBackend(scheduleInfo.pipelineInfo[0], rt); |
| 366 | if (nullptr == bnCache.cache.first || nullptr == bnCache.cache.second) { |
| 367 | MNN_ERROR("[MNN:Express] Create Backend Error\n"); |
| 368 | return; |
| 369 | } |
| 370 | bnCache.cache.first->pNPUModelDirPath = rtm->getInside()->mContent->mNpuDir; |
| 371 | bnCache.cache.second->pNPUModelDirPath = rtm->getInside()->mContent->mNpuDir; |
| 372 | if (config.rearrange) { |
| 373 | mResource->mBuffer = preRearrangeWeights(scheduleInfo, bnCache.cache.first.get(), bnCache.cache.second.get(), config.base); |
| 374 | } else { |
| 375 | mResource->mBuffer = std::move(buffer); |
| 376 | } |
| 377 | mResource->mOutputNumbers = (int)outputs.size(); |
| 378 | /** Compute: |
| 379 | std::vector<int, int> mOutputFromTensor; |
| 380 | std::vector<int, int> mOutputFromInput; |
| 381 | */ |
| 382 | for (int i = 0; i < outputs.size(); ++i) { |
| 383 | auto& t = outputs[i]; |
| 384 | bool fromInput = false; |
| 385 | for (int j = 0; j < inputs.size(); ++j) { |
| 386 | if (inputs[j] == t) { |
| 387 | fromInput = true; |
| 388 | mResource->mOutputFromInput.emplace_back(std::make_pair(i, j)); |
| 389 | break; |
| 390 | } |
| 391 | } |
| 392 | if (fromInput) { |
| 393 | continue; |
| 394 | } |
| 395 | mResource->mOutputFromTensor.emplace_back(i); |
| 396 | } |
nothing calls this directly
no test coverage detected