add wipe_cache option (#8204)

as title
This commit is contained in:
llyfacebook 2018-06-06 13:08:39 -07:00 committed by Yinghai Lu
parent eaea0f4b82
commit 4d025a6a54
3 changed files with 16 additions and 3 deletions

View file

@ -179,6 +179,7 @@ void loadInput(
void runNetwork(
shared_ptr<caffe2::Workspace> 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();
}
}
}
}

View file

@ -87,5 +87,6 @@ void runNetwork(
shared_ptr<caffe2::Workspace>,
caffe2::NetDef&,
const bool,
const bool,
const int,
const int);

View file

@ -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);