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_GRAPPLER_GRAPPLER_ITEM_BUILDER_H_
17#define TENSORFLOW_CORE_GRAPPLER_GRAPPLER_ITEM_BUILDER_H_
18
19#include <memory>
20#include <set>
21#include <string>
22
23#include "tensorflow/core/framework/attr_value.pb.h"
24#include "tensorflow/core/grappler/grappler_item.h"
25
26namespace tensorflow {
27
28class MetaGraphDef;
29
30namespace grappler {
31
32struct ItemConfig {
33 ItemConfig() {}
34
35 // If true, ignore all user specified node placement.
36 bool ignore_user_placement = true;
37 // If true, ignore all user specified colocation attributes.
38 bool ignore_colocation = true;
39 // Dimension to use if a placeholder node has an _output_shapes attribute with
40 // a dimension of -1.
41 int placeholder_unknown_output_shape_dim = -1;
42 // If true, erases all "_noinline" attributes from user-defined functions.
43 // Has no effect if "inline_functions" is disabled.
44 bool erase_noinline_attributes = false;
45 // If non-empty, override the directory of asset paths.
46 string assets_directory_override;
47 // If true, runs ModelPruner on the graph.
48 bool prune_graph = false;
49 // Override feed nodes list.
50 std::set<string> feed_nodes;
51 // Override fetch nodes list.
52 std::set<string> fetch_nodes;
53
54 // Configs for graph optimizations from common_runtime. This is NOT Grappler
55 // function optimizer. When Grappler is invoked at runtime, it is typically
56 // running after common_runtime pass.
57 //
58 // If true, does L1 optimizations.
59 bool apply_optimizations = false;
60 // If true, does function inlining.
61 bool inline_functions = false;
62};
63
64// Method for optimizing the graph def (including function inlining and other
65// optimizations). This is optimizations from common_runtime, NOT Grappler
66// function optimizer.
67Status RuntimeGraphOptimizer(const GraphDef& graph_def_arg,
68 GraphDef* output_graph_def, const ItemConfig& cfg);
69
70// Factory method for creating a GrapplerItem from a MetaGraphDef.
71// Returns nullptr if the given meta_graph cannot be converted.
72std::unique_ptr<GrapplerItem> GrapplerItemFromMetaGraphDef(
73 const string& id, const MetaGraphDef& meta_graph, const ItemConfig& cfg);
74
75// Factory method for creating a GrapplerItem from a file
76// containing a MetaGraphDef in either binary or text format.
77// Returns nullptr if the given meta_graph cannot be converted.
78std::unique_ptr<GrapplerItem> GrapplerItemFromMetaGraphDefFile(
79 const string& id, const string& meta_graph_file, const ItemConfig& cfg);
80
81} // end namespace grappler
82} // end namespace tensorflow
83
84#endif // TENSORFLOW_CORE_GRAPPLER_GRAPPLER_ITEM_BUILDER_H_
85