Elffuss BraidHub

kikocis/ncnn public

master · 7.0 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2022 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 "pass_ncnn.h"
16
17namespace pnnx {
18
19namespace ncnn {
20
21class F_conv_transpose1d_4 : 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
29pnnx.Input weight 0 1 weight
30F.conv_transpose1d op_0 2 1 input weight out bias=None stride=%stride output_padding=%output_padding padding=%padding dilation=%dilation groups=1
31pnnx.Output output 1 0 out
32)PNNXIR";
33 }
34
35 const char* type_str() const
36 {
37 return "Deconvolution1D";
38 }
39
40 const char* name_str() const
41 {
42 return "deconv1d";
43 }
44
45 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
46 {
47 std::vector<int> weight_shape = op->inputs[1]->shape;
48 if (weight_shape.empty())
49 {
50 weight_shape = {0, 0, 0};
51 }
52
53 op->params["0"] = weight_shape[1];
54 op->params["1"] = weight_shape[2];
55 op->params["2"] = captured_params.at("dilation").ai[0];
56 op->params["3"] = captured_params.at("stride").ai[0];
57 op->params["4"] = captured_params.at("padding").ai[0];
58 op->params["18"] = captured_params.at("output_padding").ai[0];
59 op->params["5"] = 0;
60 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
61 op->params["28"] = 1; // dynamic weight
62 }
63};
64
65REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv_transpose1d_4, 22)
66
67class F_conv_transpose1d_5 : public GraphRewriterPass
68{
69public:
70 const char* match_pattern_graph() const
71 {
72 return R"PNNXIR(7767517
735 4
74pnnx.Input input 0 1 input
75pnnx.Input weight 0 1 weight
76pnnx.Input bias 0 1 bias
77F.conv_transpose1d op_0 3 1 input weight bias out stride=%stride output_padding=%output_padding padding=%padding dilation=%dilation groups=1
78pnnx.Output output 1 0 out
79)PNNXIR";
80 }
81
82 const char* type_str() const
83 {
84 return "Deconvolution1D";
85 }
86
87 const char* name_str() const
88 {
89 return "deconv1d";
90 }
91
92 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
93 {
94 std::vector<int> weight_shape = op->inputs[1]->shape;
95 if (weight_shape.empty())
96 {
97 weight_shape = {0, 0, 0};
98 }
99
100 op->params["0"] = weight_shape[1];
101 op->params["1"] = weight_shape[2];
102 op->params["2"] = captured_params.at("dilation").ai[0];
103 op->params["3"] = captured_params.at("stride").ai[0];
104 op->params["4"] = captured_params.at("padding").ai[0];
105 op->params["18"] = captured_params.at("output_padding").ai[0];
106 op->params["5"] = 1;
107 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
108 op->params["28"] = 1; // dynamic weight
109 }
110};
111
112REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv_transpose1d_5, 22)
113
114class F_conv_transpose1d_6 : public GraphRewriterPass
115{
116public:
117 const char* match_pattern_graph() const
118 {
119 return R"PNNXIR(7767517
1204 3
121pnnx.Input input 0 1 input
122pnnx.Input weight 0 1 weight
123F.conv_transpose1d op_0 2 1 input weight out bias=None stride=%stride output_padding=%output_padding padding=%padding dilation=%dilation groups=%groups
124pnnx.Output output 1 0 out
125)PNNXIR";
126 }
127
128 const char* type_str() const
129 {
130 return "DeconvolutionDepthWise1D";
131 }
132
133 const char* name_str() const
134 {
135 return "deconvdw1d";
136 }
137
138 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
139 {
140 std::vector<int> weight_shape = op->inputs[1]->shape;
141 if (weight_shape.empty())
142 {
143 weight_shape = {0, 0, 0};
144 }
145
146 op->params["0"] = weight_shape[1] * captured_params.at("groups").i;
147 op->params["1"] = weight_shape[2];
148 op->params["2"] = captured_params.at("dilation").ai[0];
149 op->params["3"] = captured_params.at("stride").ai[0];
150 op->params["4"] = captured_params.at("padding").ai[0];
151 op->params["18"] = captured_params.at("output_padding").ai[0];
152 op->params["5"] = 0;
153 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
154 op->params["7"] = captured_params.at("groups");
155 op->params["28"] = 1; // dynamic weight
156 }
157};
158
159REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv_transpose1d_6, 23)
160
161class F_conv_transpose1d_7 : public GraphRewriterPass
162{
163public:
164 const char* match_pattern_graph() const
165 {
166 return R"PNNXIR(7767517
1675 4
168pnnx.Input input 0 1 input
169pnnx.Input weight 0 1 weight
170pnnx.Input bias 0 1 bias
171F.conv_transpose1d op_0 3 1 input weight bias out stride=%stride output_padding=%output_padding padding=%padding dilation=%dilation groups=%groups
172pnnx.Output output 1 0 out
173)PNNXIR";
174 }
175
176 const char* type_str() const
177 {
178 return "DeconvolutionDepthWise1D";
179 }
180
181 const char* name_str() const
182 {
183 return "deconvdw1d";
184 }
185
186 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
187 {
188 std::vector<int> weight_shape = op->inputs[1]->shape;
189 if (weight_shape.empty())
190 {
191 weight_shape = {0, 0, 0};
192 }
193
194 op->params["0"] = weight_shape[1] * captured_params.at("groups").i;
195 op->params["1"] = weight_shape[2];
196 op->params["2"] = captured_params.at("dilation").ai[0];
197 op->params["3"] = captured_params.at("stride").ai[0];
198 op->params["4"] = captured_params.at("padding").ai[0];
199 op->params["18"] = captured_params.at("output_padding").ai[0];
200 op->params["5"] = 1;
201 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
202 op->params["7"] = captured_params.at("groups");
203 op->params["28"] = 1; // dynamic weight
204 }
205};
206
207REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv_transpose1d_7, 23)
208
209} // namespace ncnn
210
211} // namespace pnnx