Browse Source

fix(lite/load_and_run): fix fast-run invalid in fitting mode

GitOrigin-RevId: a6761c1a35
master
Megvii Engine Team 2 years ago
parent
commit
1886ebc3a0
2 changed files with 70 additions and 1 deletions
  1. +11
    -1
      lite/load_and_run/src/options/strategy_options.cpp
  2. +59
    -0
      lite/test/test_lar_fast_run_options.cpp

+ 11
- 1
lite/load_and_run/src/options/strategy_options.cpp View File

@@ -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
}
}



+ 59
- 0
lite/test/test_lar_fast_run_options.cpp View File

@@ -0,0 +1,59 @@
#include <gtest/gtest.h>
#include <string.h>
#include <memory>
#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);
}

Loading…
Cancel
Save