diff --git a/lite/load_and_run/src/options/strategy_options.cpp b/lite/load_and_run/src/options/strategy_options.cpp index cb9f783c85fb997665b6f6f332dd397fbe6d3c5b..d5348acb47d0eb41a30cb5096c39b411408f9f92 100644 --- a/lite/load_and_run/src/options/strategy_options.cpp +++ b/lite/load_and_run/src/options/strategy_options.cpp @@ -1,6 +1,7 @@ #include "strategy_options.h" +#include "megbrain/utils/persistent_cache.h" +#include "megdnn/algorithm_cache.h" #include "models/model_mdl.h" - using namespace lar; DECLARE_bool(c_opr_lib_with_param); @@ -47,6 +48,15 @@ void StrategyOption::config_model( //! make output specification model_ptr->make_output_spec(); } + } else if (runtime_param.stage == RunStage::AFTER_MODEL_RUNNING) { + mgb_log_debug("clear cache"); +#if LITE_WITH_OPENCL + megcoreOpenCLClearGlobalData(); +#else + megdnn::AlgorithmCache::instance().clear(); + //! WARNING:this is used to clean the profile result cache + //! auto profile_cache = mgb::PersistentCache::inst().get_cache(); +#endif } } diff --git a/lite/test/test_lar_fast_run_options.cpp b/lite/test/test_lar_fast_run_options.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71763423c5eb8ccd570d9de18d1ca0ec04243e67 --- /dev/null +++ b/lite/test/test_lar_fast_run_options.cpp @@ -0,0 +1,59 @@ +#include +#include +#include +#include "./test_common.h" +#include "test_options.h" +using namespace lar; +DECLARE_bool(lite); +DECLARE_int32(iter); +DECLARE_bool(fast_run); +namespace { +BOOL_OPTION_WRAP(fast_run); +BOOL_OPTION_WRAP(lite); +INT32_OPTION_WRAP(iter, 10); +} // anonymous namespace + +TEST(TestLarFastRun, FAST_RUN) { + double heristic_time = 0, fast_run_time = 0; + lite::Timer timer("profile"); + { + std::string model_path = "./shufflenet.mge"; + timer.reset_start(); + TEST_INT32_OPTION(iter, 1); + heristic_time = timer.get_used_time(); + } + + { + std::string model_path = "./shufflenet.mge"; + timer.reset_start(); + DEFINE_INT32_WRAP(iter, 1); + TEST_BOOL_OPTION(fast_run); + fast_run_time = timer.get_used_time(); + } + //! profile time is longer than excute time + ASSERT_LT(heristic_time, fast_run_time); +} + +TEST(TestLarFastRun, FAST_RUN_LITE) { + double heristic_time = 0, fast_run_time = 0; + lite::Timer timer("profile"); + //! clear profile cache + auto profile_cache = mgb::PersistentCache::inst().get_cache(); + DEFINE_BOOL_WRAP(lite); + { + std::string model_path = "./shufflenet.mge"; + timer.reset_start(); + TEST_INT32_OPTION(iter, 1); + heristic_time = timer.get_used_time(); + } + + { + std::string model_path = "./shufflenet.mge"; + timer.reset_start(); + DEFINE_INT32_WRAP(iter, 1); + TEST_BOOL_OPTION(fast_run); + fast_run_time = timer.get_used_time(); + } + //! profile time is longer than excute time + ASSERT_LT(heristic_time, fast_run_time); +} \ No newline at end of file