- Added optimizer_options field to GraphOptions, moved graph optmization

options there.
- Deprecated the existing skip_common_subexpression_elimination field.
Change: 113194182
This commit is contained in:
Manjunath Kudlur 2016-01-27 13:24:50 -08:00 committed by Vijay Vasudevan
parent 697084c97b
commit c2722a1fc6
5 changed files with 78 additions and 15 deletions

View File

@ -25,7 +25,9 @@
* For C++ API users: `TensorShape::ShortDebugString` has been renamed to
`DebugString`, and the previous `DebugString` behavior is gone (it was
needlessly verbose and produced a confusing empty string for scalars).
* `GraphOptions.skip_common_subexpression_elimination` has been removed. All
graph optimizer options are now specified via
`GraphOptions.OptimizerOptions`.
## Bug fixes

View File

@ -476,15 +476,8 @@ Status DirectSession::CreateGraphs(
std::unordered_map<string, Graph*>* outputs) {
std::unique_ptr<FunctionLibraryDefinition> fdefs;
std::unique_ptr<Graph> graph;
GraphConstructorOptions opts;
if (options_.config.has_graph_options()) {
opts.optimizer_do_cse = !options_.config.graph_options()
.skip_common_subexpression_elimination();
opts.optimizer_do_constant_folding =
options_.config.graph_options().do_constant_folding();
} else {
opts.optimizer_do_cse = true;
}
GraphConstructorOptions opts{
options_.config.graph_options().optimizer_options()};
std::unordered_set<StringPiece, StringPiece::Hasher> keep_nodes;
for (const string& feed : feeds) {

View File

@ -27,16 +27,40 @@ message GPUOptions {
};
message GraphOptions {
// If true, do not attempt to optimize the graph using common
// subexpression elimination.
bool skip_common_subexpression_elimination = 1;
// Removed, use optimizer_options below.
reserved "skip_common_subexpression_elimination";
reserved 1;
// If true, use control flow to schedule the activation of Recv nodes.
// (Currently ignored.)
bool enable_recv_scheduling = 2;
// If true, perform constant folding optimization on the graph.
bool do_constant_folding = 3;
// Options passed to the graph optimizer
message OptimizerOptions {
// If true, optimize the graph using common subexpression elimination.
bool do_common_subexpression_elimination = 1;
// If true, perform constant folding optimization on the graph.
bool do_constant_folding = 2;
// Optimization level
enum Level {
// L1 is the default level.
// Optimization performed at L1 :
// 1. Common subexpression elimination
L1 = 0;
// Optimization performed at L2 :
// 1. Common subexpression elimination
// 2. Constant folding
L2 = 2;
// No optimizations
L0 = -1;
}
Level opt_level = 3;
}
OptimizerOptions optimizer_options = 3;
};
// Session configuration parameters.

View File

@ -382,8 +382,42 @@ bool GraphConstructor::TypeValidateEdge(const Edge* edge) {
return true;
}
static void SetDoCSE(const GraphOptions::OptimizerOptions& optimizer_opt,
bool force, GraphConstructorOptions* graph_opt) {
graph_opt->optimizer_do_cse =
force || optimizer_opt.do_common_subexpression_elimination();
}
static void SetDoConstantFolding(
const GraphOptions::OptimizerOptions& optimizer_opt, bool force,
GraphConstructorOptions* graph_opt) {
graph_opt->optimizer_do_constant_folding =
force || optimizer_opt.do_constant_folding();
}
} // namespace
// ----------------------------------------------------------------------------
// GraphConstructorOptions functions
// ----------------------------------------------------------------------------
GraphConstructorOptions::GraphConstructorOptions(
const GraphOptions::OptimizerOptions& opts) {
// Set the individually specified options first.
SetDoCSE(opts, false, this);
SetDoConstantFolding(opts, false, this);
// Set options that the level signifies
if (opts.opt_level() == GraphOptions::OptimizerOptions::L0) {
// No optimizations performed.
} else if (opts.opt_level() == GraphOptions::OptimizerOptions::L1) {
SetDoCSE(opts, true, this);
} else if (opts.opt_level() == GraphOptions::OptimizerOptions::L2) {
SetDoCSE(opts, true, this);
SetDoConstantFolding(opts, true, this);
}
}
// ----------------------------------------------------------------------------
// ConvertGraphDefToGraph
// ----------------------------------------------------------------------------

View File

@ -16,6 +16,7 @@ limitations under the License.
#ifndef TENSORFLOW_GRAPH_GRAPH_CONSTRUCTOR_H_
#define TENSORFLOW_GRAPH_GRAPH_CONSTRUCTOR_H_
#include "tensorflow/core/framework/config.pb.h"
#include "tensorflow/core/framework/graph.pb.h"
#include "tensorflow/core/graph/graph.h"
#include "tensorflow/core/lib/core/status.h"
@ -32,6 +33,9 @@ struct ConstantFoldingOptions {
// Construct a graph *g out of a GraphDef gdef. Returns non-OK on
// error, in which case *g is left in an incomplete state.
struct GraphConstructorOptions {
explicit GraphConstructorOptions(
const GraphOptions::OptimizerOptions& opts = Level0());
// If true, allows internal ops in the GraphDef.
bool allow_internal_ops = false;
@ -55,6 +59,12 @@ struct GraphConstructorOptions {
bool optimizer_do_constant_folding = false;
ConstantFoldingOptions constant_folding_opts;
static GraphOptions::OptimizerOptions Level0() {
GraphOptions::OptimizerOptions ret;
ret.set_opt_level(GraphOptions::OptimizerOptions::L0);
return ret;
}
};
extern Status ConvertGraphDefToGraph(const GraphConstructorOptions& opts,
const GraphDef& gdef, Graph* g);