Skip to content

Commit

Permalink
Don't do anything in benchmarks if iters == 0.
Browse files Browse the repository at this point in the history
Change: 122740998
  • Loading branch information
A. Unique TensorFlower authored and tensorflower-gardener committed May 19, 2016
1 parent e55e45a commit 7584aa6
Showing 1 changed file with 39 additions and 38 deletions.
77 changes: 39 additions & 38 deletions tensorflow/core/common_runtime/kernel_benchmark_testlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,50 +115,51 @@ string GetRendezvousKey(const Node* node) {
void Benchmark::RunWithArgs(
const std::vector<std::pair<const Node*, Tensor>>& inputs,
const std::vector<const Node*>& outputs, int iters) {
if (device_) {
// Gets inputs' and outputs' rendezvous keys.
std::vector<std::pair<string, Tensor>> in;
for (const auto& p : inputs) {
in.push_back({GetRendezvousKey(p.first), p.second});
if (!device_ || iters == 0) {
return;
}
// Gets inputs' and outputs' rendezvous keys.
std::vector<std::pair<string, Tensor>> in;
for (const auto& p : inputs) {
in.push_back({GetRendezvousKey(p.first), p.second});
}
std::vector<string> out;
for (const auto& n : outputs) {
out.push_back(GetRendezvousKey(n));
}
Tensor unused; // In benchmark, we don't care the return value.
bool is_dead;

// Warm up
Executor::Args args;
args.rendezvous = rendez_;
args.runner = [this](std::function<void()> closure) {
pool_->Schedule(closure);
};
for (int i = 0; i < 3; ++i) {
for (const auto& p : in) {
rendez_->Send(p.first, Rendezvous::Args(), p.second, false);
}
std::vector<string> out;
for (const auto& n : outputs) {
out.push_back(GetRendezvousKey(n));
TF_CHECK_OK(exec_->Run(args));
for (const string& key : out) {
rendez_->Recv(key, Rendezvous::Args(), &unused, &is_dead);
}
Tensor unused; // In benchmark, we don't care the return value.
bool is_dead;
}
TF_CHECK_OK(device_->Sync());

// Warm up
Executor::Args args;
args.rendezvous = rendez_;
args.runner = [this](std::function<void()> closure) {
pool_->Schedule(closure);
};
for (int i = 0; i < 3; ++i) {
for (const auto& p : in) {
rendez_->Send(p.first, Rendezvous::Args(), p.second, false);
}
TF_CHECK_OK(exec_->Run(args));
for (const string& key : out) {
rendez_->Recv(key, Rendezvous::Args(), &unused, &is_dead);
}
testing::StartTiming();
while (iters-- > 0) {
for (const auto& p : in) {
rendez_->Send(p.first, Rendezvous::Args(), p.second, false);
}
TF_CHECK_OK(device_->Sync());

testing::StartTiming();
while (iters-- > 0) {
for (const auto& p : in) {
rendez_->Send(p.first, Rendezvous::Args(), p.second, false);
}
TF_CHECK_OK(exec_->Run(args));
for (const string& key : out) {
rendez_->Recv(key, Rendezvous::Args(), &unused, &is_dead);
}
TF_CHECK_OK(exec_->Run(args));
for (const string& key : out) {
rendez_->Recv(key, Rendezvous::Args(), &unused, &is_dead);
}

TF_CHECK_OK(device_->Sync());
testing::StopTiming();
}

TF_CHECK_OK(device_->Sync());
testing::StopTiming();
}

} // end namespace test
Expand Down

0 comments on commit 7584aa6

Please sign in to comment.