From ba1508e33a7d0605369fc3801e248dd6cae987ab Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Fri, 1 Jul 2022 12:19:09 +0800 Subject: [PATCH] fix(lite): fix exception bug for load and run GitOrigin-RevId: 339a343a80d65a523b60b4c97360927970149e7f --- lite/load_and_run/BUILD | 1 + lite/load_and_run/src/models/model_mdl.cpp | 4 ++-- .../src/strategys/strategy_fitting.cpp | 25 +++++++++++----------- .../load_and_run/src/strategys/strategy_normal.cpp | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/lite/load_and_run/BUILD b/lite/load_and_run/BUILD index 1c865f9e..5940b300 100644 --- a/lite/load_and_run/BUILD +++ b/lite/load_and_run/BUILD @@ -5,6 +5,7 @@ cc_library( hdrs = glob(["src/**/*.h"]), includes = ["src"], features = if_opt([ + "no_exceptions", "no_rtti", ]), diff --git a/lite/load_and_run/src/models/model_mdl.cpp b/lite/load_and_run/src/models/model_mdl.cpp index 818e7410..804c6d63 100644 --- a/lite/load_and_run/src/models/model_mdl.cpp +++ b/lite/load_and_run/src/models/model_mdl.cpp @@ -7,7 +7,7 @@ DECLARE_bool(share_param_mem); using namespace lar; ModelMdl::ModelMdl(const std::string& path) : model_path(path) { - mgb_log_warn("creat mdl model use XPU as default comp node"); + mgb_log("creat mdl model use XPU as default comp node"); m_load_config.comp_graph = mgb::ComputingGraph::make(); m_load_config.comp_graph->options().graph_opt_level = 0; testcase_num = 0; @@ -16,7 +16,7 @@ ModelMdl::ModelMdl(const std::string& path) : model_path(path) { void ModelMdl::load_model() { //! read dump file if (share_model_mem) { - mgb_log_warn("enable share model memory"); + mgb_log("enable share model memory"); FILE* fin = fopen(model_path.c_str(), "rb"); mgb_assert(fin, "failed to open %s: %s", model_path.c_str(), strerror(errno)); fseek(fin, 0, SEEK_END); diff --git a/lite/load_and_run/src/strategys/strategy_fitting.cpp b/lite/load_and_run/src/strategys/strategy_fitting.cpp index d7d1dc1c..3c750d65 100644 --- a/lite/load_and_run/src/strategys/strategy_fitting.cpp +++ b/lite/load_and_run/src/strategys/strategy_fitting.cpp @@ -170,7 +170,7 @@ void OptionsTimeProfiler::profile_with_given_options( auto start = timer.get_msecs(); model->run_model(); model->wait(); - mgb_log_warn("warm up %ld time %f ms", i, timer.get_msecs() - start); + mgb_log("warm up %ld time %f ms", i, timer.get_msecs() - start); } }; double inference_time = 0.0; @@ -180,7 +180,7 @@ void OptionsTimeProfiler::profile_with_given_options( model->run_model(); model->wait(); auto end = timer.get_msecs(); - mgb_log_warn("run iter %ld time %f ms", i, end - start); + mgb_log("run iter %ld time %f ms", i, end - start); inference_time += end - start; mgb_throw_if( inference_time > TIME_OUT, mgb::TimeoutError, @@ -213,7 +213,7 @@ void OptionsTimeProfiler::profile_with_given_options( auto start = timer.get_msecs(); config_model_before_runing(); auto end = timer.get_msecs(); - mgb_log_warn("config model time %f ms", end - start); + mgb_log("config model time %f ms", end - start); warm_up(); run_iter(); } @@ -228,9 +228,10 @@ void OptionsTimeProfiler::profile_with_given_options( auto average = inference_time / runtime_param.run_iter; if (exception_state) { average = TIME_OUT; - printf("out of time (this may be caused by some exception, please checkout the " - "log) when profile option:\n%s\n", - option_code.c_str()); + mgb_log_error( + "out of time (this may be caused by some exception, please checkout " + "the log) when profile option:\n%s\n", + option_code.c_str()); } else { printf("profile option:\n%s\naverage time = %.2f\n", option_code.c_str(), average); @@ -369,7 +370,7 @@ void UserInfoParser::parse_info(std::shared_ptr& manager) { FittingStrategy::FittingStrategy(std::string model_path) { m_manager = std::make_shared(); m_dumped_model = FLAGS_dump_fitting_model; - mgb::set_log_level(mgb::LogLevel::WARN); + mgb::set_log_level(mgb::LogLevel::INFO); m_options = std::make_shared(); m_model_path = model_path; auto option_creator_map = OptionFactory::get_Instance().get_option_creator_map(); @@ -458,10 +459,10 @@ void FittingStrategy::dump_best_options_with_model() { model->run_model(); model->wait(); std::vector model_data = model->get_model_data(); - mgb_log_warn("model_data size=%zu", model_data.size()); - mgb_log_warn("json_info size=%zu", json_info.size()); - mgb_log_warn("info_algo_policy_data size=%zu", info_algo_policy_data.size()); - mgb_log_warn("info_binary_cache_data size=%zu", info_binary_cache_data.size()); + mgb_log("model_data size=%zu", model_data.size()); + mgb_log("json_info size=%zu", json_info.size()); + mgb_log("info_algo_policy_data size=%zu", info_algo_policy_data.size()); + mgb_log("info_binary_cache_data size=%zu", info_binary_cache_data.size()); lite::ModelPacker packer( model_data, m_dumped_model, json_info, info_algo_policy_data, info_binary_cache_data); @@ -508,7 +509,7 @@ void FittingStrategy::AutoCleanFile::dump_model() { model->wait(); std::vector model_data = model->get_model_data(); - mgb_log_warn("dumped model_data size=%zu\n", model_data.size()); + mgb_log("dumped model_data size=%zu\n", model_data.size()); auto fp = fopen(m_filename.c_str(), "wb"); fwrite(model_data.data(), 1, model_data.size(), fp); fclose(fp); diff --git a/lite/load_and_run/src/strategys/strategy_normal.cpp b/lite/load_and_run/src/strategys/strategy_normal.cpp index 3743cf15..b7edf667 100644 --- a/lite/load_and_run/src/strategys/strategy_normal.cpp +++ b/lite/load_and_run/src/strategys/strategy_normal.cpp @@ -109,7 +109,7 @@ void NormalStrategy::run_subline() { //! config model config_after_load(); //! config when running model - mgb_log_warn("run testcase: %zu ", idx); + mgb_log("run testcase: %zu ", idx); m_runtime_param.stage = RunStage::MODEL_RUNNING; stage_config_model();