diff --git a/mobile/src/io/api_paddle_mobile.cc b/mobile/src/io/api_paddle_mobile.cc index 4c6acb2567a2e6a26048d006b2b2d6dce17ebd0c..8bfc91998f600726c1bcf8fe932372928928e334 100644 --- a/mobile/src/io/api_paddle_mobile.cc +++ b/mobile/src/io/api_paddle_mobile.cc @@ -41,6 +41,10 @@ bool PaddleMobilePredictor::Init(const PaddleMobileConfig &config) { if (config.pre_post_type == PaddleMobileConfig::UINT8_255) { configInternal.pre_post_type = PrePostType::UINT8_255; } + + configInternal.memory_optimization_level = + config.mem_opt ? MemoryOptimizationWithoutFeeds : NoMemoryOptimization; + paddle_mobile_.reset(new PaddleMobile(configInternal)); #ifdef PADDLE_MOBILE_CL paddle_mobile_->SetCLPath(config.cl_path); diff --git a/mobile/src/io/paddle_inference_api.h b/mobile/src/io/paddle_inference_api.h index 001b2c9bf02d2484f5fb8839802531f863535f84..c89b998144badcf7b88dbbfcaa631a25df7892d5 100644 --- a/mobile/src/io/paddle_inference_api.h +++ b/mobile/src/io/paddle_inference_api.h @@ -221,6 +221,7 @@ struct PaddleMobileConfig : public PaddlePredictor::Config { bool lod_mode = false; int thread_num = 1; bool load_when_predict = false; + bool mem_opt = true; std::string cl_path; struct PaddleModelMemoryPack memory_pack; }; diff --git a/mobile/test/net/test_net_performance.cpp b/mobile/test/net/test_net_performance.cpp index 678558d602e2926e6a1f6786bb95281828ff3677..95e72ea7a77d38f07abd391326120b136b4cc499 100644 --- a/mobile/test/net/test_net_performance.cpp +++ b/mobile/test/net/test_net_performance.cpp @@ -156,22 +156,41 @@ void test(int argc, char *argv[]) { } // 测速 - auto time5 = time(); + auto max_time = -1; + auto min_time = 100000; + auto all_time = 0; if (is_lod) { for (int i = 0; i < run_times; i++) { + auto time7 = time(); paddle_mobile.Predict(input_lod_tensor); + auto time8 = time(); + const double diff_time_single = time_diff(time7, time8); + max_time = fmax(diff_time_single, max_time); + min_time = fmin(diff_time_single, min_time); + all_time += diff_time_single; } } else { paddle_mobile.Feed(var_names[0], input_tensor); for (int i = 0; i < run_times; i++) { + auto time7 = time(); paddle_mobile.Predict(); + auto time8 = time(); + const double diff_time_single = time_diff(time7, time8); + max_time = fmax(diff_time_single, max_time); + min_time = fmin(diff_time_single, min_time); + all_time += diff_time_single; } } - auto time6 = time(); std::cout << "auto-test" - << " predict-time-cost " << time_diff(time5, time6) / run_times + << " predict-time-cost-avg " << all_time * 1.0f / run_times << "ms" << std::endl; + std::cout << "auto-test" + << " predict-time-cost-max " << double(max_time) << "ms" + << std::endl; + std::cout << "auto-test" + << " predict-time-cost-min " << double(min_time) << "ms" + << std::endl; std::cout << std::endl; }