add sleep time between runs (#12347)

Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12347

add sleep time between net and operator runs, and between each iteration.

Reviewed By: sf-wind

Differential Revision: D10209308

fbshipit-source-id: 9a42b47e1fdc14b42dba6bb3ff048fe8e2934615
This commit is contained in:
Huamin Li
2018-11-01 00:23:19 -07:00
committed by Facebook Github Bot
parent 86e1009497
commit 8444ed951d
3 changed files with 43 additions and 3 deletions

View File

@ -234,7 +234,9 @@ void runNetwork(
const bool run_individual,
const int warmup,
const int iter,
const int sleep_before_run) {
const int sleep_before_run,
const int sleep_between_iteration,
const int sleep_between_net_and_operator) {
if (!net_def.has_name()) {
net_def.set_name("benchmark");
}
@ -262,6 +264,7 @@ void runNetwork(
"Number of main runs should be non negative, provided ",
iter,
".");
LOG(INFO) << "net runs.";
for (int i = 0; i < iter; ++i) {
caffe2::ObserverConfig::initSampleRate(1, 1, 1, 0, warmup);
fillInputBlob(workspace, tensor_protos_map, i);
@ -272,9 +275,28 @@ void runNetwork(
if (wipe_cache) {
caffe2::wipe_cache();
}
if (run_individual) {
if (sleep_between_iteration > 0) {
std::this_thread::sleep_for(
std::chrono::seconds(sleep_between_iteration));
}
}
if (run_individual) {
LOG(INFO) << "operator runs.";
if (sleep_between_net_and_operator > 0) {
std::this_thread::sleep_for(
std::chrono::seconds(sleep_between_net_and_operator));
}
for (int i = 0; i < iter; ++i) {
caffe2::ObserverConfig::initSampleRate(1, 1, 1, 1, warmup);
fillInputBlob(workspace, tensor_protos_map, i);
CAFFE_ENFORCE(net->Run(), "Main run ", i, " with operator has failed.");
if (wipe_cache) {
caffe2::wipe_cache();
}
if (sleep_between_iteration > 0) {
std::this_thread::sleep_for(
std::chrono::seconds(sleep_between_iteration));
}
}
}
}
@ -336,6 +358,8 @@ int benchmark(
const string& FLAGS_output_folder,
bool FLAGS_run_individual,
int FLAGS_sleep_before_run,
int FLAGS_sleep_between_iteration,
int FLAGS_sleep_between_net_and_operator,
bool FLAGS_text_output,
int FLAGS_warmup,
bool FLAGS_wipe_cache) {
@ -396,7 +420,9 @@ int benchmark(
FLAGS_run_individual,
FLAGS_warmup,
FLAGS_iter,
FLAGS_sleep_before_run);
FLAGS_sleep_before_run,
FLAGS_sleep_between_iteration,
FLAGS_sleep_between_net_and_operator);
writeOutput(
workspace,

View File

@ -112,6 +112,8 @@ void runNetwork(
const bool,
const int,
const int,
const int,
const int,
const int);
int benchmark(
int argc,
@ -128,6 +130,8 @@ int benchmark(
const string& FLAGS_output_folder,
bool FLAGS_run_individual,
int FLAGS_sleep_before_run,
int FLAGS_sleep_between_iteration,
int FLAGS_sleep_between_net_and_operator,
bool FLAGS_text_output,
int FLAGS_warmup,
bool FLAGS_wipe_cache);

View File

@ -63,6 +63,14 @@ C10_DEFINE_int(
sleep_before_run,
0,
"The seconds to sleep before starting the benchmarking.");
C10_DEFINE_int(
sleep_between_iteration,
0,
"The seconds to sleep between the individual iterations.");
C10_DEFINE_int(
sleep_between_net_and_operator,
0,
"The seconds to sleep between net and operator runs.");
C10_DEFINE_bool(
text_output,
false,
@ -90,6 +98,8 @@ int main(int argc, char** argv) {
FLAGS_output_folder,
FLAGS_run_individual,
FLAGS_sleep_before_run,
FLAGS_sleep_between_iteration,
FLAGS_sleep_between_net_and_operator,
FLAGS_text_output,
FLAGS_warmup,
FLAGS_wipe_cache);