Elffuss BraidHub

kikocis/ncnn public

master · 1.8 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
4//
5// Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
6// in compliance with the License. You may obtain a copy of the License at
7//
8// https://opensource.org/licenses/BSD-3-Clause
9//
10// Unless required by applicable law or agreed to in writing, software distributed
11// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12// CONDITIONS OF ANY KIND, either express or implied. See the License for the
13// specific language governing permissions and limitations under the License.
14
15#include "fuse_silu.h"
16
17#include "pass_level2.h"
18
19namespace pnnx {
20
21class fuse_silu_pass : public GraphRewriterPass
22{
23public:
24 const char* match_pattern_graph() const
25 {
26 return R"PNNXIR(7767517
274 3
28pnnx.Input input 0 1 input
29F.sigmoid op_0 1 1 input a
30pnnx.Expression op_1 2 1 input a out expr=mul(@0,@1)
31pnnx.Output output 1 0 out
32)PNNXIR";
33 }
34
35 const char* type_str() const
36 {
37 return "F.silu";
38 }
39
40 const char* name_str() const
41 {
42 return "silu";
43 }
44};
45
46class fuse_silu_pass_1 : public fuse_silu_pass
47{
48public:
49 const char* match_pattern_graph() const
50 {
51 return R"PNNXIR(7767517
524 3
53pnnx.Input input 0 1 input
54nn.Sigmoid op_0 1 1 input a
55pnnx.Expression op_1 2 1 input a out expr=mul(@0,@1)
56pnnx.Output output 1 0 out
57)PNNXIR";
58 }
59};
60
61void fuse_silu(Graph& graph)
62{
63 fuse_silu_pass a;
64 fuse_silu_pass_1 b;
65 int opindex = 0;
66
67 pnnx_graph_rewrite(graph, &a, opindex);
68 pnnx_graph_rewrite(graph, &b, opindex);
69}
70
71} // namespace pnnx