Elffuss BraidHub

kikocis/ncnn public

master · 7.7 KiBRawPermalink
1// Tencent is pleased to support the open source community by making ncnn available.
2//
3// Copyright (C) 2021 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_conv1d_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.conv1d op_0 2 1 input weight out bias=None stride=%stride 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 "Convolution1D";
38 }
39
40 const char* name_str() const
41 {
42 return "conv1d";
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, 0};
51 }
52
53 op->params["0"] = weight_shape[0];
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 if (captured_params.at("padding").type == 4)
58 {
59 if (captured_params.at("padding").s == "same")
60 op->params["4"] = -233;
61 else if (captured_params.at("padding").s == "valid")
62 op->params["4"] = 0;
63 }
64 else
65 {
66 op->params["4"] = captured_params.at("padding").ai[0];
67 }
68 op->params["5"] = 0;
69 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
70 op->params["19"] = 1; // dynamic weight
71 }
72};
73
74REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv1d_4, 22)
75
76class F_conv1d_5 : public GraphRewriterPass
77{
78public:
79 const char* match_pattern_graph() const
80 {
81 return R"PNNXIR(7767517
825 4
83pnnx.Input input 0 1 input
84pnnx.Input weight 0 1 weight
85pnnx.Input bias 0 1 bias
86F.conv1d op_0 3 1 input weight bias out stride=%stride padding=%padding dilation=%dilation groups=1
87pnnx.Output output 1 0 out
88)PNNXIR";
89 }
90
91 const char* type_str() const
92 {
93 return "Convolution1D";
94 }
95
96 const char* name_str() const
97 {
98 return "conv1d";
99 }
100
101 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
102 {
103 std::vector<int> weight_shape = op->inputs[1]->shape;
104 if (weight_shape.empty())
105 {
106 weight_shape = {0, 0, 0};
107 }
108
109 op->params["0"] = weight_shape[0];
110 op->params["1"] = weight_shape[2];
111 op->params["2"] = captured_params.at("dilation").ai[0];
112 op->params["3"] = captured_params.at("stride").ai[0];
113 if (captured_params.at("padding").type == 4)
114 {
115 if (captured_params.at("padding").s == "same")
116 op->params["4"] = -233;
117 else if (captured_params.at("padding").s == "valid")
118 op->params["4"] = 0;
119 }
120 else
121 {
122 op->params["4"] = captured_params.at("padding").ai[0];
123 }
124 op->params["5"] = 1;
125 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
126 op->params["19"] = 1; // dynamic weight
127 }
128};
129
130REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv1d_5, 22)
131
132class F_conv1d_6 : public GraphRewriterPass
133{
134public:
135 const char* match_pattern_graph() const
136 {
137 return R"PNNXIR(7767517
1384 3
139pnnx.Input input 0 1 input
140pnnx.Input weight 0 1 weight
141F.conv1d op_0 2 1 input weight out bias=None stride=%stride padding=%padding dilation=%dilation groups=%groups
142pnnx.Output output 1 0 out
143)PNNXIR";
144 }
145
146 const char* type_str() const
147 {
148 return "ConvolutionDepthWise1D";
149 }
150
151 const char* name_str() const
152 {
153 return "convdw1d";
154 }
155
156 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
157 {
158 std::vector<int> weight_shape = op->inputs[1]->shape;
159 if (weight_shape.empty())
160 {
161 weight_shape = {0, 0, 0};
162 }
163
164 op->params["0"] = weight_shape[0];
165 op->params["1"] = weight_shape[2];
166 op->params["2"] = captured_params.at("dilation").ai[0];
167 op->params["3"] = captured_params.at("stride").ai[0];
168 if (captured_params.at("padding").type == 4)
169 {
170 if (captured_params.at("padding").s == "same")
171 op->params["4"] = -233;
172 else if (captured_params.at("padding").s == "valid")
173 op->params["4"] = 0;
174 }
175 else
176 {
177 op->params["4"] = captured_params.at("padding").ai[0];
178 }
179 op->params["5"] = 0;
180 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
181 op->params["7"] = captured_params.at("groups");
182 op->params["19"] = 1; // dynamic weight
183 }
184};
185
186REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv1d_6, 23)
187
188class F_conv1d_7 : public GraphRewriterPass
189{
190public:
191 const char* match_pattern_graph() const
192 {
193 return R"PNNXIR(7767517
1945 4
195pnnx.Input input 0 1 input
196pnnx.Input weight 0 1 weight
197pnnx.Input bias 0 1 bias
198F.conv1d op_0 3 1 input weight bias out stride=%stride padding=%padding dilation=%dilation groups=%groups
199pnnx.Output output 1 0 out
200)PNNXIR";
201 }
202
203 const char* type_str() const
204 {
205 return "ConvolutionDepthWise1D";
206 }
207
208 const char* name_str() const
209 {
210 return "convdw1d";
211 }
212
213 void write(Operator* op, const std::map<std::string, Parameter>& captured_params, const std::map<std::string, Attribute>& /*captured_attrs*/) const
214 {
215 std::vector<int> weight_shape = op->inputs[1]->shape;
216 if (weight_shape.empty())
217 {
218 weight_shape = {0, 0, 0};
219 }
220
221 op->params["0"] = weight_shape[0];
222 op->params["1"] = weight_shape[2];
223 op->params["2"] = captured_params.at("dilation").ai[0];
224 op->params["3"] = captured_params.at("stride").ai[0];
225 if (captured_params.at("padding").type == 4)
226 {
227 if (captured_params.at("padding").s == "same")
228 op->params["4"] = -233;
229 else if (captured_params.at("padding").s == "valid")
230 op->params["4"] = 0;
231 }
232 else
233 {
234 op->params["4"] = captured_params.at("padding").ai[0];
235 }
236 op->params["5"] = 1;
237 op->params["6"] = (int)(weight_shape[0] * weight_shape[1] * weight_shape[2]);
238 op->params["7"] = captured_params.at("groups");
239 op->params["19"] = 1; // dynamic weight
240 }
241};
242
243REGISTER_GLOBAL_PNNX_NCNN_GRAPH_REWRITER_PASS(F_conv1d_7, 23)
244
245} // namespace ncnn
246
247} // namespace pnnx