MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / BM_LargeTensorWrite

Function BM_LargeTensorWrite

tensorflow/core/kernels/save_op_test.cc:664–692  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

662// Benchmark-related code below.
663
664static 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}
693BENCHMARK(BM_LargeTensorWrite)->Arg((1 << 30) / 4 /* 1GB float tensor */);
694
695} // namespace

Callers

nothing calls this directly

Calls 12

StopTimingFunction · 0.85
TmpDirFunction · 0.85
SaveFunction · 0.85
StartTimingFunction · 0.85
ExitOnErrorMethod · 0.80
ToGraphMethod · 0.80
TensorShapeClass · 0.50
JoinPathFunction · 0.50
BenchmarkClass · 0.50
statusMethod · 0.45
num_nodesMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected