Skip to content

Commit

Permalink
[DRAFT][compiler] Introduce FuseGRUPass
Browse files Browse the repository at this point in the history
This pr introduces FuseGRUPass for fusing gru pattern into single CircleGRU op.

ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
  • Loading branch information
Artem Balyshev committed Aug 6, 2024
1 parent 1a558ac commit 36c7317
Show file tree
Hide file tree
Showing 6 changed files with 1,140 additions and 0 deletions.
3 changes: 3 additions & 0 deletions compiler/circle2circle/src/Circle2Circle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ int entry(int argc, char **argv)
"This will fuse BatchNorm operators of pre-activations to Convolution operator");
add_switch(arser, "--fuse_prelu", "This will fuse operators to PReLU operator");
add_switch(arser, "--fuse_gelu", "This will fuse operators to GeLU operator");
add_switch(arser, "--fuse_gru", "This will fuse operators to GRU operator");
add_switch(arser, "--fuse_rsqrt", "This will fuse operators to Rsqrt operator");
add_switch(arser, "--remove_duplicate_const", "This will remove all duplicate constant nodes");
add_switch(arser, "--remove_fakequant", "This will remove FakeQuant operators");
Expand Down Expand Up @@ -334,6 +335,8 @@ int entry(int argc, char **argv)
options->enable(Algorithms::FusePRelu);
if (arser.get<bool>("--fuse_gelu"))
options->enable(Algorithms::FuseGelu);
if (arser.get<bool>("--fuse_gru"))
options->enable(Algorithms::FuseGRU);
if (arser.get<bool>("--fuse_rsqrt"))
options->enable(Algorithms::FuseRsqrt);
if (arser.get<bool>("--fuse_transpose_with_mean"))
Expand Down
1 change: 1 addition & 0 deletions compiler/luci/pass/include/luci/CircleOptimizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CircleOptimizer final
FuseActivationFunction,
FusePRelu,
FuseGelu,
FuseGRU,
FuseRsqrt,
ShuffleWeightTo16x1Float32,
RemoveRedundantTranspose,
Expand Down
39 changes: 39 additions & 0 deletions compiler/luci/pass/include/luci/Pass/FuseGRUPass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef __LUCI_FUSE_GRU_PASS_H__
#define __LUCI_FUSE_GRU_PASS_H__

#include <logo/Pass.h>

namespace luci
{

/**
* @brief Class to fuse certain pattern of subgraph into CircleGRU
*
* For detailed subgraph pattern to be fused, please check its implementation.
*/
struct FuseGRUPass final : public logo::Pass
{
const char *name(void) const final { return "luci::FuseGRUPass"; }

bool run(loco::Graph *g) final;
};

} // namespace luci

#endif // __LUCI_FUSE_GRU_PASS_H__
5 changes: 5 additions & 0 deletions compiler/luci/pass/src/CircleOptimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "luci/Pass/FusePreActivationBatchNormPass.h"
#include "luci/Pass/FusePReluPass.h"
#include "luci/Pass/FuseGeluPass.h"
#include "luci/Pass/FuseGRUPass.h"
#include "luci/Pass/FuseRsqrtPass.h"
#include "luci/Pass/FuseSliceWithTConvPass.h"
#include "luci/Pass/FuseHorizontalFullyConnectedPass.h"
Expand Down Expand Up @@ -370,6 +371,10 @@ void CircleOptimizer::optimize(loco::Graph *g) const
{
phase.emplace_back(std::make_unique<FuseGeluPass>());
}
if (_options->query(Options::Algorithm::FuseGRU))
{
phase.emplace_back(std::make_unique<FuseGRUPass>());
}
if (_options->query(Options::Algorithm::FuseRsqrt))
{
phase.emplace_back(std::make_unique<FuseRsqrtPass>());
Expand Down
Loading

0 comments on commit 36c7317

Please sign in to comment.