| 662 | // Benchmark-related code below. |
| 663 | |
| 664 | static void BM_LargeTensorWrite(int iters, int num_elements) { |
| 665 | testing::StopTiming(); |
| 666 | |
| 667 | // 4 * num_elements bytes total , since sizeof(float) == 4. |
| 668 | Tensor tensor(DT_FLOAT, TensorShape({num_elements})); |
| 669 | tensor.flat<float>().setZero(); |
| 670 | |
| 671 | // Builds the graph. |
| 672 | const tstring temp_filename = |
| 673 | io::JoinPath(testing::TmpDir(), "benchmark_checkpoint"); |
| 674 | auto root = Scope::NewRootScope().ExitOnError(); |
| 675 | const tstring tensor_name = "my_tensor"; |
| 676 | ops::Save(root, temp_filename, {tensor_name}, {{tensor}}); |
| 677 | |
| 678 | // Disables optimizations. |
| 679 | SessionOptions session_options; |
| 680 | session_options.config.mutable_graph_options() |
| 681 | ->mutable_optimizer_options() |
| 682 | ->set_opt_level(tensorflow::OptimizerOptions::L0); |
| 683 | |
| 684 | TF_CHECK_OK(root.status()); |
| 685 | Graph* g = new Graph(OpRegistry::Global()); |
| 686 | TF_CHECK_OK(root.ToGraph(g)); |
| 687 | VLOG(1) << "Save op's output path: " << temp_filename; |
| 688 | VLOG(1) << "# nodes in Graph: " << g->num_nodes(); |
| 689 | |
| 690 | testing::StartTiming(); |
| 691 | test::Benchmark("cpu", g, &session_options).Run(iters); |
| 692 | } |
| 693 | BENCHMARK(BM_LargeTensorWrite)->Arg((1 << 30) / 4 /* 1GB float tensor */); |
| 694 | |
| 695 | } // namespace |
nothing calls this directly
no test coverage detected