TODO: Support sharding and depth.
| 167 | |
| 168 | // TODO: Support sharding and depth. |
| 169 | static void BM_Helper(int iters, int width, int num_stages, int tensor_size, |
| 170 | bool use_multiple_devices) { |
| 171 | testing::StopTiming(); |
| 172 | const Cluster* cluster = GetCluster(); |
| 173 | |
| 174 | // Creates a session. |
| 175 | std::unique_ptr<Session> session(NewSession(cluster->options)); |
| 176 | GraphDef def = CreateGraphDef(num_stages, width, tensor_size, |
| 177 | use_multiple_devices, cluster); |
| 178 | graph::SetDefaultDevice(cluster->devices[0].name(), &def); |
| 179 | |
| 180 | TF_CHECK_OK(session->Create(def)); |
| 181 | |
| 182 | // Randomly initialize the input. |
| 183 | Tensor x(DT_FLOAT, TensorShape({tensor_size, 1})); |
| 184 | |
| 185 | testing::SetLabel( |
| 186 | strings::StrCat(def.node_size(), " nodes; ", |
| 187 | use_multiple_devices ? "Multi device" : "Single device", |
| 188 | "; tensor bytes/send: ", tensor_size * sizeof(float))); |
| 189 | |
| 190 | std::vector<Tensor> outputs; |
| 191 | |
| 192 | // Do a few warmup iterations. |
| 193 | for (int i = 0; i < 3; i++) { |
| 194 | outputs.clear(); |
| 195 | TF_CHECK_OK(session->Run({{"x", x}}, {"y:0"}, {}, &outputs)); |
| 196 | CHECK_EQ(size_t{1}, outputs.size()); |
| 197 | |
| 198 | if (i == 0) { |
| 199 | // Print out x, and y. |
| 200 | const Tensor& y = outputs[0]; |
| 201 | VLOG(1) << DebugString(x, y, tensor_size); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // Iterations. |
| 206 | testing::StartTiming(); |
| 207 | for (int i = 0; i < iters; i++) { |
| 208 | outputs.clear(); |
| 209 | TF_CHECK_OK(session->Run({{"x", x}}, {"y:0"}, {}, &outputs)); |
| 210 | CHECK_EQ(size_t{1}, outputs.size()); |
| 211 | } |
| 212 | testing::StopTiming(); |
| 213 | TF_CHECK_OK(session->Close()); |
| 214 | } |
| 215 | static void BM_ShardedProgram(int iters, int width, int num_stages) { |
| 216 | BM_Helper(iters, width, num_stages, 2 /*tensor_size*/, true /*multi-device*/); |
| 217 | } |
no test coverage detected