1 | /* Copyright 2020 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 | #ifndef TENSORFLOW_CORE_GRAPH_GRAPH_NODE_UTIL_H_ |
16 | #define TENSORFLOW_CORE_GRAPH_GRAPH_NODE_UTIL_H_ |
17 | |
18 | #include "tensorflow/core/framework/node_def_util.h" |
19 | #include "tensorflow/core/lib/core/stringpiece.h" |
20 | #include "tensorflow/core/platform/status.h" |
21 | |
22 | namespace tensorflow { |
23 | class Node; |
24 | struct NodeDebugInfo; |
25 | |
26 | // We forward declare protos so that kernels don't need to depend on them |
27 | class NodeDef; |
28 | class OpDef; |
29 | |
30 | // Produce a human-readable version of a Node or NodeDef that is more concise |
31 | // than a text-format proto. |
32 | string SummarizeNode(const Node& node); |
33 | |
34 | // Produces a formatted string pattern from the node which can uniquely identify |
35 | // this node upstream to produce an informative error message. The pattern |
36 | // followed is: {{node <node_name>}} |
37 | string FormatNodeForError(const Node& node); |
38 | |
39 | // Merges the original node names from the debug information of 'from' to the |
40 | // debug information of 'to'. |
41 | void MergeDebugInfo(const NodeDebugInfo& from, Node* to); |
42 | void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to); |
43 | void MergeDebugInfo(const NodeDef& from, NodeDef* to); |
44 | |
45 | // Computes the mapping from input/output argument name to the |
46 | // corresponding input/output index range. For example, |
47 | // input "foo" corresponds to input indices |
48 | // [ (*inputs)["foo"].first, (*inputs)["foo"].second ). |
49 | // NOTE(mrry): To reduce allocations when the map is used and save |
50 | // space, the returned `NameRangeMap` objects borrow the input/output |
51 | // argument names from `op_def`. The `op_def` must outlive the |
52 | // returned `NameRangeMap` objects. |
53 | Status NameRangesForNode(const Node& node, const OpDef& op_def, |
54 | NameRangeMap* inputs, NameRangeMap* outputs); |
55 | |
56 | // Returns "status" with formatted Node attached as additional text |
57 | // in the error message. If 'allow_multiple_formatted_node' is false and there |
58 | // is already a formatted Node present in 'status', we simply attach the name |
59 | // of the Node instead of the formatted string. |
60 | Status AttachDef(const Status& status, const Node& node, |
61 | bool allow_multiple_formatted_node = false); |
62 | } // namespace tensorflow |
63 | |
64 | #endif // TENSORFLOW_CORE_GRAPH_GRAPH_NODE_UTIL_H_ |
65 | |