未验证 提交 624fa8d4 编写于 作者: X xiebaiyuan 提交者: GitHub

add mem opt option for high api ,test = develop (#2319)

* add mem opt option for high api ,test = develop

* fix is_lod params && test-performance ,test=develop
上级 92179da1
......@@ -41,6 +41,10 @@ bool PaddleMobilePredictor<Device, T>::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<Device, T>(configInternal));
#ifdef PADDLE_MOBILE_CL
paddle_mobile_->SetCLPath(config.cl_path);
......
......@@ -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;
};
......
......@@ -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;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册