1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations 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
22namespace tensorflow {
23class Node;
24struct NodeDebugInfo;
25
26// We forward declare protos so that kernels don't need to depend on them
27class NodeDef;
28class OpDef;
29
30// Produce a human-readable version of a Node or NodeDef that is more concise
31// than a text-format proto.
32string 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>}}
37string FormatNodeForError(const Node& node);
38
39// Merges the original node names from the debug information of 'from' to the
40// debug information of 'to'.
41void MergeDebugInfo(const NodeDebugInfo& from, Node* to);
42void MergeDebugInfo(const NodeDebugInfo& from, NodeDef* to);
43void 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.
53Status 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.
60Status 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