| 362 | } |
| 363 | |
| 364 | void _getConstData(const Net* net, std::vector<MNN::Express::VARP> inputs, const std::set<int>& inputIndexes, |
| 365 | const std::set<int>& outputIndexes, |
| 366 | std::map<int, std::tuple<int, int, std::vector<int>, std::vector<char>>>& constTensorData, |
| 367 | std::string srcpath) { |
| 368 | // set a backend and context to run resize |
| 369 | ScheduleConfig config; |
| 370 | config.type = MNN_FORWARD_CPU; |
| 371 | BackendConfig backendConfig; |
| 372 | backendConfig.precision = BackendConfig::Precision_High; |
| 373 | config.backendConfig = &backendConfig; |
| 374 | Backend::Info compute; |
| 375 | compute.type = config.type; |
| 376 | compute.numThread = config.numThread; |
| 377 | compute.user = config.backendConfig; |
| 378 | const RuntimeCreator* runtimeCreator(MNNGetExtraRuntimeCreator(compute.type)); |
| 379 | std::unique_ptr<Runtime> runtime(runtimeCreator->onCreate(compute)); |
| 380 | std::shared_ptr<Backend> backend(runtime->onCreate()); |
| 381 | BackendConfig defaultConfig; |
| 382 | defaultConfig.flags = 4; |
| 383 | std::shared_ptr<Backend> defaultBackend(runtime->onCreate(&defaultConfig)); |
| 384 | std::vector<std::shared_ptr<Tensor>> allTensors; |
| 385 | allTensors.resize(net->tensorName()->size()); |
| 386 | ErrorCode code = NO_ERROR; |
| 387 | FileLoader loader((srcpath + ".weight").c_str()); |
| 388 | initConstTensors(allTensors, net, defaultBackend.get(), code, &loader); |
| 389 | if (NO_ERROR != code) { |
| 390 | MNN_ERROR("Init tensor error code = %d\n", code); |
| 391 | return; |
| 392 | } |
| 393 | bool valid = initTensors(allTensors, net); |
| 394 | // set tensors' shape by inputConfig |
| 395 | std::map<std::string, MNN::Express::VARP> inputsMap; |
| 396 | for (int i = 0; i < inputs.size(); i++) { |
| 397 | auto name = inputs[i]->name(); |
| 398 | inputsMap[name] = inputs[i]; |
| 399 | } |
| 400 | for (int i = 0; i < allTensors.size(); i++) { |
| 401 | auto name = net->tensorName()->GetAsString(i)->str(); |
| 402 | if (inputsMap.find(name) != inputsMap.end()) { |
| 403 | auto input = inputsMap[name]; |
| 404 | auto info = input->getInfo(); |
| 405 | auto& dims = info->dim; |
| 406 | allTensors[i]->buffer().dimensions = dims.size(); |
| 407 | for (int j = 0; j < dims.size(); j++) { |
| 408 | allTensors[i]->setLength(j, dims[j]); |
| 409 | } |
| 410 | allTensors[i]->buffer().host = |
| 411 | (uint8_t*)MNNMemoryAllocAlign(info->size * sizeof(float), MNN_MEMORY_ALIGN_DEFAULT); |
| 412 | auto ptr = input->readMap<float>(); |
| 413 | std::memcpy(allTensors[i]->buffer().host, ptr, info->size * sizeof(float)); |
| 414 | } |
| 415 | } |
| 416 | std::vector<Schedule::OpCacheInfo> infos; |
| 417 | auto selectOps = _collectNeededOps(net, inputIndexes, outputIndexes); |
| 418 | { |
| 419 | std::vector<const Op*> ops; |
| 420 | for (int i = 0; i < selectOps.size(); i++) { |
| 421 | auto op = net->oplists()->GetAs<Op>(selectOps[i]); |
no test coverage detected