| 343 | REGISTER_OP("Op").Input("i: float").Output("o: float"); |
| 344 | |
| 345 | static void BM_SubgraphHelper(int iters, int num_nodes, |
| 346 | bool use_function_convention) { |
| 347 | DeviceAttributes device_info; |
| 348 | device_info.set_name("/job:a/replica:0/task:0/cpu:0"); |
| 349 | device_info.set_device_type(DeviceType(DEVICE_CPU).type()); |
| 350 | device_info.set_incarnation(0); |
| 351 | |
| 352 | testing::StopTiming(); |
| 353 | Graph g(OpRegistry::Global()); |
| 354 | { // Scope for temporary variables used to construct g. |
| 355 | GraphDefBuilder b(GraphDefBuilder::kFailImmediately); |
| 356 | Node* last_node = nullptr; |
| 357 | for (int i = 0; i < num_nodes; i++) { |
| 358 | string name = strings::StrCat("N", i); |
| 359 | if (i > 0) { |
| 360 | last_node = ops::UnaryOp("Op", last_node, b.opts().WithName(name)); |
| 361 | } else { |
| 362 | last_node = ops::SourceOp("In", b.opts().WithName(name)); |
| 363 | } |
| 364 | } |
| 365 | TF_CHECK_OK(GraphDefBuilderToGraph(b, &g)); |
| 366 | } |
| 367 | |
| 368 | std::vector<string> fed; |
| 369 | if (num_nodes > 1000) { |
| 370 | fed.push_back(strings::StrCat("N", num_nodes - 1000)); |
| 371 | } |
| 372 | std::vector<string> fetch; |
| 373 | std::vector<string> targets = {strings::StrCat("N", num_nodes - 1)}; |
| 374 | testing::StartTiming(); |
| 375 | while (--iters > 0) { |
| 376 | Graph* subgraph = new Graph(OpRegistry::Global()); |
| 377 | CopyGraph(g, subgraph); |
| 378 | subgraph::RewriteGraphMetadata metadata; |
| 379 | TF_CHECK_OK(subgraph::RewriteGraphForExecution( |
| 380 | subgraph, fed, fetch, targets, device_info, use_function_convention, |
| 381 | &metadata)); |
| 382 | delete subgraph; |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | static void BM_Subgraph(int iters, int num_nodes) { |
| 387 | BM_SubgraphHelper(iters, num_nodes, false /* use_function_convention */); |
no test coverage detected