• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2018 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 // Helper functions for dumping Graphs, GraphDefs, and FunctionDefs to files for
17 // debugging.
18 
19 #ifndef TENSORFLOW_CORE_UTIL_DUMP_GRAPH_H_
20 #define TENSORFLOW_CORE_UTIL_DUMP_GRAPH_H_
21 
22 #include <string>
23 
24 #include "tensorflow/core/framework/cost_graph.pb.h"
25 #include "tensorflow/core/framework/function.h"
26 #include "tensorflow/core/framework/graph.pb.h"
27 #include "tensorflow/core/graph/graph.h"
28 
29 namespace tensorflow {
30 
31 // Dumps 'graph_def' to a file, as a GraphDef text proto. Returns the file name
32 // chosen.
33 //
34 // If the TF_DUMP_GRAPH_PREFIX environment variable is "-", then instead the
35 // GraphDef will be logged (using the LOG() macro).
36 //
37 // Automatically picks a file name. Prefixes 'name' with the value of the
38 // TF_DUMP_GRAPH_PREFIX environment variable if 'dirname' is empty, and suffixes
39 // 'name' with ".pbtxt" to form a name. If a graph has already been dumped by
40 // this process with the same name, suffixes with "_n.pbtxt", where 'n' is a
41 // sequence number.
42 string DumpGraphDefToFile(const string& name, GraphDef const& graph_def,
43                           const string& dirname = "");
44 
45 // Similar to DumpGraphDefToFile, use CostGraphDef instead of GraphDef.
46 string DumpCostGraphDefToFile(const string& name, CostGraphDef const& graph_def,
47                               const string& dirname = "");
48 
49 // Similar to DumpGraphDefToFile, but builds the GraphDef to dump from a 'graph'
50 // and an optional function library 'flib_def'. Returns the file name chosen.
51 string DumpGraphToFile(const string& name, Graph const& graph,
52                        const FunctionLibraryDefinition* flib_def = nullptr,
53                        const string& dirname = "");
54 
55 // Similar to DumpGraphDefToFile, but dumps a function as a FunctionDef text
56 // proto. Returns the file name chosen.
57 string DumpFunctionDefToFile(const string& name, FunctionDef const& fdef,
58                              const string& dirname = "");
59 
60 // Sets a custom Graph dumper. If set, this dumper will be used to dump graphs
61 // instead via DumpGraphToFile. As the custom dumper may not produce protobufs,
62 // allow specifying a file suffix/extension too.
63 void SetGraphDumper(
64     std::function<Status(const Graph& graph,
65                          const FunctionLibraryDefinition* flib_def,
66                          WritableFile*)>
67         dumper,
68     string suffix = ".pbtxt");
69 
70 }  // namespace tensorflow
71 
72 #endif  // TENSORFLOW_CORE_UTIL_DUMP_GRAPH_H_
73