diff --git a/binaries/benchmark_helper.cc b/binaries/benchmark_helper.cc index c88b785b04a..7a706985086 100644 --- a/binaries/benchmark_helper.cc +++ b/binaries/benchmark_helper.cc @@ -179,6 +179,7 @@ void loadInput( void runNetwork( shared_ptr workspace, caffe2::NetDef& net_def, + const bool wipe_cache, const bool run_individual, const int warmup, const int iter) { @@ -196,7 +197,9 @@ void runNetwork( CAFFE_ENFORCE(net->Run(), "Warmup run ", i, " has failed."); } - caffe2::wipe_cache(); + if (wipe_cache) { + caffe2::wipe_cache(); + } LOG(INFO) << "Main runs."; CAFFE_ENFORCE( iter >= 0, @@ -206,11 +209,15 @@ void runNetwork( for (int i = 0; i < iter; ++i) { caffe2::ObserverConfig::initSampleRate(1, 1, 1, 0, warmup); CAFFE_ENFORCE(net->Run(), "Main run ", i, " has failed."); - caffe2::wipe_cache(); + if (wipe_cache) { + caffe2::wipe_cache(); + } if (run_individual) { caffe2::ObserverConfig::initSampleRate(1, 1, 1, 1, warmup); CAFFE_ENFORCE(net->Run(), "Main run ", i, " with operator has failed."); - caffe2::wipe_cache(); + if (wipe_cache) { + caffe2::wipe_cache(); + } } } } diff --git a/binaries/benchmark_helper.h b/binaries/benchmark_helper.h index fa4a2bcebbe..4ee32dba219 100644 --- a/binaries/benchmark_helper.h +++ b/binaries/benchmark_helper.h @@ -87,5 +87,6 @@ void runNetwork( shared_ptr, caffe2::NetDef&, const bool, + const bool, const int, const int); diff --git a/binaries/caffe2_benchmark.cc b/binaries/caffe2_benchmark.cc index b6f8ce6193c..16c1173d0ff 100644 --- a/binaries/caffe2_benchmark.cc +++ b/binaries/caffe2_benchmark.cc @@ -66,6 +66,10 @@ CAFFE2_DEFINE_bool( false, "Whether to write out output in text format for regression purpose."); CAFFE2_DEFINE_int(warmup, 0, "The number of iterations to warm up."); +CAFFE2_DEFINE_bool( + wipe_cache, + false, + "Whether to evict the cache before running network."); int main(int argc, char** argv) { caffe2::GlobalInit(&argc, &argv); @@ -103,6 +107,7 @@ int main(int argc, char** argv) { runNetwork( workspace, net_def, + caffe2::FLAGS_wipe_cache, caffe2::FLAGS_run_individual, caffe2::FLAGS_warmup, caffe2::FLAGS_iter);