Skip to content

Commit

Permalink
[luci] Fuse Gelu before convert_nchw_to_nhwc (Samsung#10763)
Browse files Browse the repository at this point in the history
This fuses Gelu Op before convert_ncwh_to_nhwc.

ONE-DCO-1.0-Signed-off-by: Hyukjin Jeong <[email protected]>
  • Loading branch information
jinevening authored May 8, 2023
1 parent d0ae3b4 commit e4957ba
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions compiler/luci/pass/src/CircleOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ bool OptimizeOptionsImpl::query(Algorithm algo)
}

// TODO Make a struct for args
void convert_nchw_to_nhwc(loco::Graph *g, bool preserve_input, bool preserve_output, bool fuse_fc)
void convert_nchw_to_nhwc(loco::Graph *g, bool preserve_input, bool preserve_output, bool fuse_fc,
bool fuse_gelu)
{
logo::Phase phase;

Expand All @@ -161,6 +162,12 @@ void convert_nchw_to_nhwc(loco::Graph *g, bool preserve_input, bool preserve_out
if (fuse_fc)
phase.emplace_back(std::make_unique<luci::FuseAddWithFullyConnectedPass>());

// Fuse decomposed ops to Gelu Op
// Why here? ConverNCHWToNHWCPass inserts additional Ops, so it is better to fuse
// Gelu in advance.
if (fuse_gelu)
phase.emplace_back(std::make_unique<luci::FuseGeluPass>());

phase.emplace_back(
std::make_unique<luci::ConvertNCHWToNHWCPass>(preserve_input, preserve_output));

Expand Down Expand Up @@ -217,8 +224,9 @@ void CircleOptimizer::optimize(loco::Graph *g) const
_options->param(Options::AlgorithmParameters::NCHW_to_NHWC_output_shape) != "true";

bool fuse_fc = _options->query(Options::Algorithm::FuseAddWithFullyConnected);
bool fuse_gelu = _options->query(Options::Algorithm::FuseGelu);

convert_nchw_to_nhwc(g, preserve_input, preserve_output, fuse_fc);
convert_nchw_to_nhwc(g, preserve_input, preserve_output, fuse_fc, fuse_gelu);
}

/* TRANSFORM DECLARATION BEGIN */
Expand Down

0 comments on commit e4957ba

Please sign in to comment.