xref: /aosp_15_r20/external/tensorflow/tensorflow/core/grappler/utils/transitive_fanin.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2019 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_GRAPPLER_UTILS_TRANSITIVE_FANIN_H_
16 #define TENSORFLOW_CORE_GRAPPLER_UTILS_TRANSITIVE_FANIN_H_
17 
18 #include <unordered_map>
19 #include <vector>
20 
21 #include "tensorflow/core/framework/graph.pb.h"
22 #include "tensorflow/core/lib/core/status.h"
23 
24 namespace tensorflow {
25 namespace grappler {
26 
27 // Computes the transitive fanin of the graph based on reachability from the
28 // specified terminal nodes. Returns the set of nodes comprising the
29 // transitive fanin into fanin_nodes. Optionally returns a map of name->node
30 // for that graph into name_to_fanin_node if that is not set to nullptr.
31 Status ComputeTransitiveFanin(
32     const GraphDef& graph, const std::vector<string>& terminal_nodes,
33     std::unordered_map<string, const NodeDef*>* name_to_fanin_node,
34     std::vector<const NodeDef*>* fanin_nodes);
35 
36 Status ComputeTransitiveFanin(const GraphDef& graph,
37                               const std::vector<string>& terminal_nodes,
38                               std::vector<const NodeDef*>* fanin_nodes);
39 
40 // Creates output_graph from input_graph using the transitive fanin from the
41 // specified terminal nodes. Returns error if the input_graph is deemed
42 // structurally invalid.
43 Status SetTransitiveFaninGraph(const GraphDef& input_graph,
44                                GraphDef* output_graph,
45                                const std::vector<string>& terminal_nodes);
46 
47 }  // namespace grappler
48 }  // namespace tensorflow
49 
50 #endif  // TENSORFLOW_CORE_GRAPPLER_UTILS_TRANSITIVE_FANIN_H_
51