Don't do anything in benchmarks if iters == 0.
Change: 122740998
This commit is contained in:
parent
e55e45aef7
commit
7584aa60a4
@ -115,50 +115,51 @@ string GetRendezvousKey(const Node* node) {
|
|||||||
void Benchmark::RunWithArgs(
|
void Benchmark::RunWithArgs(
|
||||||
const std::vector<std::pair<const Node*, Tensor>>& inputs,
|
const std::vector<std::pair<const Node*, Tensor>>& inputs,
|
||||||
const std::vector<const Node*>& outputs, int iters) {
|
const std::vector<const Node*>& outputs, int iters) {
|
||||||
if (device_) {
|
if (!device_ || iters == 0) {
|
||||||
// Gets inputs' and outputs' rendezvous keys.
|
return;
|
||||||
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);
|
|
||||||
}
|
|
||||||
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::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(device_->Sync());
|
|
||||||
testing::StopTiming();
|
|
||||||
}
|
}
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
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::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(device_->Sync());
|
||||||
|
testing::StopTiming();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // end namespace test
|
} // end namespace test
|
||||||
|
Loading…
Reference in New Issue
Block a user