• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef TENSORFLOW_CORE_GRAPH_VALIDATE_H_
17 #define TENSORFLOW_CORE_GRAPH_VALIDATE_H_
18 
19 #include "tensorflow/core/framework/graph.pb.h"
20 #include "tensorflow/core/framework/op.h"
21 #include "tensorflow/core/graph/graph.h"
22 #include "tensorflow/core/lib/core/status.h"
23 
24 namespace tensorflow {
25 namespace graph {
26 
27 // Returns OK if every NodeDef in `graph_def` is valid with respect to
28 // its corresponding OpDef (as defined by ValidateNodeDef()) as
29 // registered in `op_registry`.  Also checks for deprecated ops.
30 //
31 // REQUIRES:
32 //  * `op_registry` is not nullptr.
33 //  * `graph_def` has default attrs filled in (see AddDefaultAttrsToGraphDef()).
34 Status ValidateGraphDef(const GraphDef& graph_def,
35                         const OpRegistryInterface& op_registry);
36 
37 // Like ValidateGraphDef() except it makes a copy of `graph_def` and calls
38 // AddDefaultAttrsToGraphDef() on the copy, removing that requirement from the
39 // caller.
40 Status ValidateGraphDefAgainstOpRegistry(
41     const GraphDef& graph_def, const OpRegistryInterface& op_registry);
42 
43 // Like ValidateGraphDefAgainstOpRegistry() except it takes an OpList
44 // instead of an OpRegistryInterface.  Note that the OpList need not
45 // have descriptions, which can be a big space savings, see
46 // GetOpListForValidation() below.
47 Status ValidateGraphDefAgainstOpList(const GraphDef& graph_def,
48                                      const OpList& op_list);
49 
50 // Get an OpList from `*op_registry` with all the descriptions removed.
51 void GetOpListForValidation(
52     OpList* op_list, const OpRegistry& op_registry = *OpRegistry::Global());
53 
54 // Validate that the graph has no cycle except for legal while loop cycles.
55 // This traverses the specified nodes in topological order to verify there are
56 // no cycles. Starting with inputless nodes, it visits nodes whose inputs have
57 // all been visited, and counts the total number of visited nodes. If there is a
58 // cycle, nodes in the cycle will never be visited, and the visited count will
59 // be less than the total node count.
60 Status ValidateGraphHasNoCycle(const Graph& graph);
61 
62 // Returns OK if the graph has no duplicate node names.
63 Status VerifyNoDuplicateNodeNames(const GraphDef& graph);
64 
65 }  // namespace graph
66 }  // namespace tensorflow
67 
68 #endif  // TENSORFLOW_CORE_GRAPH_VALIDATE_H_
69