1 | /* Copyright 2015 The TensorFlow Authors. All Rights Reserved. |
2 | |
3 | Licensed under the Apache License, Version 2.0 (the "License"); |
4 | you may not use this file except in compliance with the License. |
5 | You may obtain a copy of the License at |
6 | |
7 | http://www.apache.org/licenses/LICENSE-2.0 |
8 | |
9 | Unless required by applicable law or agreed to in writing, software |
10 | distributed under the License is distributed on an "AS IS" BASIS, |
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | See the License for the specific language governing permissions and |
13 | limitations under the License. |
14 | ==============================================================================*/ |
15 | |
16 | #include <memory> |
17 | |
18 | #include "absl/memory/memory.h" |
19 | #include "pybind11/pybind11.h" |
20 | #include "pybind11/pytypes.h" |
21 | #include "tensorflow/core/framework/graph.pb.h" |
22 | #include "tensorflow/core/framework/step_stats.pb.h" |
23 | #include "tensorflow/core/util/stat_summarizer.h" |
24 | |
25 | namespace py = pybind11; |
26 | |
27 | PYBIND11_MODULE(_pywrap_stat_summarizer, m) { |
28 | py::class_<tensorflow::StatSummarizer> stat_summ_class(m, "StatSummarizer" , |
29 | py::dynamic_attr()); |
30 | stat_summ_class |
31 | .def(py::init([](std::string graph_def_serialized) { |
32 | tensorflow::GraphDef proto; |
33 | proto.ParseFromString(graph_def_serialized); |
34 | return new tensorflow::StatSummarizer(proto); |
35 | })) |
36 | .def(py::init([]() { |
37 | return new tensorflow::StatSummarizer( |
38 | tensorflow::StatSummarizerOptions()); |
39 | })) |
40 | .def("ProcessStepStats" , &tensorflow::StatSummarizer::ProcessStepStats) |
41 | .def("GetOutputString" , &tensorflow::StatSummarizer::GetOutputString) |
42 | .def("PrintStepStats" , &tensorflow::StatSummarizer::PrintStepStats) |
43 | .def("ProcessStepStatsStr" , [](tensorflow::StatSummarizer& self, |
44 | const std::string& step_stats_str) { |
45 | tensorflow::StepStats step_stats; |
46 | step_stats.ParseFromString(step_stats_str); |
47 | self.ProcessStepStats(step_stats); |
48 | }); |
49 | }; |
50 | |