From d49bd42cecea2ade511884977b2d2f6580cc50d4 Mon Sep 17 00:00:00 2001 From: zhupengyang <1165938320@qq.com> Date: Fri, 15 May 2020 21:18:49 +0800 Subject: [PATCH] [NPU] refine subgraph name (#3624) --- lite/core/mir/subgraph/subgraph_pass_test.cc | 3 ++- lite/kernels/npu/subgraph_compute.cc | 18 +++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/lite/core/mir/subgraph/subgraph_pass_test.cc b/lite/core/mir/subgraph/subgraph_pass_test.cc index 0fa69df8b5..8fd3751f9c 100644 --- a/lite/core/mir/subgraph/subgraph_pass_test.cc +++ b/lite/core/mir/subgraph/subgraph_pass_test.cc @@ -25,6 +25,7 @@ DEFINE_string(optimized_model_dir, "", "path of optimized naive buffer model"); DEFINE_string(input_tensor_shape, "1,3,224,224", "shape of input tensors"); DEFINE_string(input_tensor_type, "float32", "data type of input tensors"); DEFINE_string(output_tensor_type, "float32", "data type of output tensors"); +DEFINE_string(subgraph_model_cache_dir, "", "dir of subgraph model cache"); namespace paddle { namespace lite { @@ -132,7 +133,7 @@ std::shared_ptr TestModel( mobile_config.set_model_from_file(optimized_model_dir + ".nb"); mobile_config.set_power_mode(lite_api::PowerMode::LITE_POWER_HIGH); mobile_config.set_threads(1); - // mobile_config.set_subgraph_model_cache_dir("/data/local/tmp"); + mobile_config.set_subgraph_model_cache_dir(FLAGS_subgraph_model_cache_dir); predictor = lite_api::CreatePaddlePredictor(mobile_config); FillInputTensors(predictor, input_tensor_shape, input_tensor_type, 1); // Run optimized model diff --git a/lite/kernels/npu/subgraph_compute.cc b/lite/kernels/npu/subgraph_compute.cc index d2609ff61e..101cd65e8b 100644 --- a/lite/kernels/npu/subgraph_compute.cc +++ b/lite/kernels/npu/subgraph_compute.cc @@ -34,24 +34,16 @@ std::string SubgraphEngine::GenerateModelCacheName() const { auto inames = device_inames_; auto onames = device_onames_; std::sort(inames.begin(), inames.end()); - std::sort(onames.begin(), onames.end()); - std::string model_cache_name = ""; + std::string model_cache_name = "subgraph_" + std::to_string(block_idx_); for (auto iname : inames) { + model_cache_name += "_"; auto itensor = scope_->FindTensor(iname); - std::replace(iname.begin(), iname.end(), '/', '_'); - model_cache_name += "_" + iname; + int tmp = 0; for (auto i : itensor->dims().Vectorize()) { - model_cache_name += "_" + std::to_string(i); - } - } - for (auto oname : onames) { - auto otensor = scope_->FindTensor(oname); - std::replace(oname.begin(), oname.end(), '/', '_'); - model_cache_name += "_" + oname; - for (auto i : otensor->dims().Vectorize()) { - model_cache_name += "_" + std::to_string(i); + tmp += i * i; } + model_cache_name += std::to_string(tmp % 1999); } model_cache_name += "_.om"; -- GitLab