MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Optimize

Method Optimize

tensorflow/core/common_runtime/graph_optimizer.cc:37–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35GraphOptimizer::~GraphOptimizer() {}
36
37void GraphOptimizer::Optimize(
38 FunctionLibraryRuntime* runtime, Env* env, const Device* device,
39 std::unique_ptr<Graph>* graph,
40 const std::unordered_map<string, std::vector<PartialTensorShape>>*
41 shape_map,
42 const NodePredicate& cse_consider_fn, const NodePredicate& cf_consider_fn,
43 bool inline_multi_device_functions,
44 bool inline_impl_selection_group_functions) {
45 Graph* g = graph->get();
46 DumpGraph("Initial", g);
47
48 bool changed = true;
49 const int kMaxRounds = 10;
50 for (int rounds = 0; rounds < kMaxRounds; ++rounds) {
51 changed = false;
52 if (RemoveListArrayConverter(g)) {
53 DumpGraph("RemoveListArrayConverter", g);
54 changed = true;
55 }
56 if (opts_.do_function_inlining() && RemoveDeadNodes(g)) {
57 DumpGraph("RemoveDeadNodes", g);
58 changed = true;
59 }
60 if (opts_.do_function_inlining() && RemoveIdentityNodes(g)) {
61 DumpGraph("RemoveIdentityNodes", g);
62 changed = true;
63 }
64 if (opts_.do_op_fusion() && OptimizeFusion(g)) {
65 RemoveDeadNodes(g);
66 DumpGraph("OptimizeFusionEngine", g);
67 changed = true;
68 }
69 if (opts_.do_constant_folding()) {
70 ConstantFoldingOptions cf_opts;
71 cf_opts.shape_map = shape_map;
72 cf_opts.consider = cf_consider_fn;
73 if (opts_.max_folded_constant_in_bytes() > 0) {
74 cf_opts.max_constant_size_in_bytes =
75 opts_.max_folded_constant_in_bytes();
76 }
77 bool was_mutated;
78 ConstantFold(cf_opts, runtime, env, device, g, &was_mutated)
79 .IgnoreError();
80 if (was_mutated) {
81 RemoveDeadNodes(g);
82 DumpGraph("ConstFolding", g);
83 changed = true;
84 }
85 }
86
87 if (opts_.do_function_inlining() && FixupSourceAndSinkEdges(g)) {
88 DumpGraph("FixupSourceAndSinkEdges", g);
89 changed = true;
90 }
91 if (opts_.do_common_subexpression_elimination() &&
92 OptimizeCSE(g, cse_consider_fn)) {
93 DumpGraph("OptimizeCSE", g);
94 changed = true;

Callers 4

CreateExecutorsMethod · 0.45
OptimizeGraphFunction · 0.45
CreateItemMethod · 0.45
InitBaseGraphMethod · 0.45

Calls 15

DumpGraphFunction · 0.85
RemoveListArrayConverterFunction · 0.85
RemoveDeadNodesFunction · 0.85
RemoveIdentityNodesFunction · 0.85
OptimizeFusionFunction · 0.85
ConstantFoldFunction · 0.85
FixupSourceAndSinkEdgesFunction · 0.85
OptimizeCSEFunction · 0.85
SingleDeviceClass · 0.85
ExpandInlineFunctionsFunction · 0.70
OptimizeFunction · 0.70
CopyGraphFunction · 0.50

Tested by

no test coverage detected