Skip to content

Commit

Permalink
[GraphOptimizer] Do transpose and reshape optimizations first
Browse files Browse the repository at this point in the history
  • Loading branch information
aturetsk authored and rdzhabarov committed Oct 16, 2018
1 parent ac49da6 commit f36eee8
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/Optimizer/GraphOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ static void optimizeArithmeticNodes(Function *F) {
}

/// Statically transpose Constants.
static void optimizeTranspose(Function *F) {
static void transposeConstants(Function *F) {
auto &nodes = F->getNodes();

for (auto &node : nodes) {
Expand Down Expand Up @@ -2092,6 +2092,13 @@ void glow::optimize(Function *F, CompilationMode mode) {
DCE(F);
}

// Reshapes and transposes can prevent other optimizations from triggering, so
// try to optimize them out first.
optimizeReshape(F);
if (mode == CompilationMode::Infer) {
transposeConstants(F);
}

// Optimize the pooling operation.
optimizePool(F);

Expand All @@ -2108,9 +2115,6 @@ void glow::optimize(Function *F, CompilationMode mode) {
DCE(F);

if (mode == CompilationMode::Infer) {
// Constant-fold transpose operations.
optimizeTranspose(F);

// Merge batch normalization operations.
// Do after transpose constant folding, as weight transposes can prevent
// the optimization from triggering.
Expand All @@ -2129,10 +2133,7 @@ void glow::optimize(Function *F, CompilationMode mode) {
// Optimize Tensor shape transformations.
optimizeSliceOfSplat(F);

optimizeReshape(F);

// Merge Transpose into MatMul.
// Run after optimizeReshape to ensure a single Reshapes precedes MatMul.
// Run DCE to ensure correct number of node users.
DCE(F);
mergeTransposeIntoMatMul(F);
Expand Down

0 comments on commit f36eee8

Please sign in to comment.