1/* Copyright 2017 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
16#ifndef TENSORFLOW_CORE_FRAMEWORK_GRAPH_TO_FUNCTIONDEF_H_
17#define TENSORFLOW_CORE_FRAMEWORK_GRAPH_TO_FUNCTIONDEF_H_
18
19#include <string>
20#include <vector>
21
22#include "tensorflow/core/framework/function.pb.h"
23#include "tensorflow/core/graph/graph.h"
24#include "tensorflow/core/lib/core/status.h"
25
26namespace tensorflow {
27
28// Graph to FunctionDef conversion. This code is closely modeled on the Python
29// function graph_to_function_def(), which is located in
30// tensorflow/python/framework/graph_to_function_def.py.
31Status GraphToFunctionDef(const Graph& fn_body, const string& fn_name,
32 bool append_hash_to_fn_name,
33 bool set_stateful_from_nodes,
34 bool copy_placeholder_attrs_from_nodes,
35 const std::vector<const Node*>& body_nodes,
36 const std::vector<OutputTensor>& inputs,
37 const std::vector<OutputTensor>& outputs,
38 const std::vector<string>& output_names,
39 const std::vector<const Node*>& control_outputs,
40 const std::vector<string>& control_output_names,
41 const char* description, FunctionDef* fdef);
42
43// Converts 'graph' to a FunctionDef 'fdef', with name 'name':
44//
45// (1) 'node->IsArg()' nodes converted to function inputs.
46// (2) 'node->IsRetval()' nodes converted to function output.
47// (3) 'control_ret' returns an optional with a control output name, that will
48// be added to the function `control_ret` map (see FunctionDef) and
49// `control_output` in Op definition (see OpDef). Control output name must
50// be unique for all control output nodes.
51Status GraphToFunctionDef(
52 const Graph& graph, const string& name,
53 const std::function<absl::optional<string>(const Node*)>& control_ret,
54 FunctionDef* fdef);
55
56Status GraphToFunctionDef(const Graph& graph, const string& name,
57 FunctionDef* fdef);
58
59Status GraphToFunctionDef(const Graph& graph, const string& name,
60 const std::vector<std::string>& output_names,
61 FunctionDef* fdef);
62
63Status GetGraphAndArgRets(
64 const string& function_name, AttrSlice attrs, const FunctionDef* fdef,
65 const FunctionLibraryDefinition* lib_def, std::unique_ptr<Graph>* graph,
66 std::vector<Node*>* arg_nodes, std::vector<Node*>* ret_nodes,
67 std::vector<string>* ret_node_names, DataTypeVector* ret_types,
68 std::vector<string>* control_ret_node_names);
69
70} // namespace tensorflow
71
72#endif // TENSORFLOW_CORE_FRAMEWORK_GRAPH_TO_FUNCTIONDEF_H_
73