| 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_level2.h" |
| 16 | |
| 17 | namespace pnnx { |
| 18 | |
| 19 | class F_upsample : public GraphRewriterPass |
| 20 | { |
| 21 | public: |
| 22 | const char* match_pattern_graph() const |
| 23 | { |
| 24 | return R"PNNXIR(7767517 |
| 25 | 5 4 |
| 26 | pnnx.Input input_0 0 1 input |
| 27 | pnnx.Input input_1 0 1 size |
| 28 | prim::Constant op_0 0 1 scale_factor value=None |
| 29 | aten::upsample_nearest1d op_1 3 1 input size scale_factor out |
| 30 | pnnx.Output output 1 0 out |
| 31 | )PNNXIR"; |
| 32 | } |
| 33 | |
| 34 | const char* type_str() const |
| 35 | { |
| 36 | return "F.upsample"; |
| 37 | } |
| 38 | |
| 39 | void write(Operator* op, const std::map<std::string, Parameter>& /*captured_params*/) const |
| 40 | { |
| 41 | op->params["mode"] = "nearest"; |
| 42 | } |
| 43 | }; |
| 44 | |
| 45 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample, 11) |
| 46 | |
| 47 | class F_upsample_1 : public GraphRewriterPass |
| 48 | { |
| 49 | public: |
| 50 | const char* match_pattern_graph() const |
| 51 | { |
| 52 | return R"PNNXIR(7767517 |
| 53 | 5 4 |
| 54 | pnnx.Input input_0 0 1 input |
| 55 | pnnx.Input input_1 0 1 scale_factor |
| 56 | prim::Constant op_0 0 1 size value=None |
| 57 | aten::upsample_nearest1d op_1 3 1 input size scale_factor out |
| 58 | pnnx.Output output 1 0 out |
| 59 | )PNNXIR"; |
| 60 | } |
| 61 | |
| 62 | const char* type_str() const |
| 63 | { |
| 64 | return "F.upsample"; |
| 65 | } |
| 66 | |
| 67 | void write(Operator* op, const std::map<std::string, Parameter>& /*captured_params*/) const |
| 68 | { |
| 69 | op->params["mode"] = "nearest"; |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_1, 11) |
| 74 | |
| 75 | class F_upsample_2 : public GraphRewriterPass |
| 76 | { |
| 77 | public: |
| 78 | const char* match_pattern_graph() const |
| 79 | { |
| 80 | return R"PNNXIR(7767517 |
| 81 | 6 5 |
| 82 | pnnx.Input input_0 0 1 input |
| 83 | pnnx.Input input_1 0 1 size |
| 84 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 85 | prim::Constant op_1 0 1 scale_factor value=None |
| 86 | aten::upsample_linear1d op_2 4 1 input size align_corners scale_factor out |
| 87 | pnnx.Output output 1 0 out |
| 88 | )PNNXIR"; |
| 89 | } |
| 90 | |
| 91 | const char* type_str() const |
| 92 | { |
| 93 | return "F.upsample"; |
| 94 | } |
| 95 | |
| 96 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 97 | { |
| 98 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 99 | op->params["mode"] = "linear"; |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_2, 11) |
| 104 | |
| 105 | class F_upsample_3 : public GraphRewriterPass |
| 106 | { |
| 107 | public: |
| 108 | const char* match_pattern_graph() const |
| 109 | { |
| 110 | return R"PNNXIR(7767517 |
| 111 | 6 5 |
| 112 | pnnx.Input input_0 0 1 input |
| 113 | pnnx.Input input_1 0 1 scale_factor |
| 114 | prim::Constant op_0 0 1 size value=None |
| 115 | prim::Constant op_1 0 1 align_corners value=%align_corners |
| 116 | aten::upsample_linear1d op_2 4 1 input size align_corners scale_factor out |
| 117 | pnnx.Output output 1 0 out |
| 118 | )PNNXIR"; |
| 119 | } |
| 120 | |
| 121 | const char* type_str() const |
| 122 | { |
| 123 | return "F.upsample"; |
| 124 | } |
| 125 | |
| 126 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 127 | { |
| 128 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 129 | op->params["mode"] = "linear"; |
| 130 | } |
| 131 | }; |
| 132 | |
| 133 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_3, 11) |
| 134 | |
| 135 | class F_upsample_4 : public GraphRewriterPass |
| 136 | { |
| 137 | public: |
| 138 | const char* match_pattern_graph() const |
| 139 | { |
| 140 | return R"PNNXIR(7767517 |
| 141 | 7 6 |
| 142 | pnnx.Input input_0 0 1 input |
| 143 | pnnx.Input input_1 0 1 size |
| 144 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 145 | prim::Constant op_1 0 1 scale_h value=None |
| 146 | prim::Constant op_2 0 1 scale_w value=None |
| 147 | aten::upsample_bilinear2d op_3 5 1 input size align_corners scale_h scale_w out |
| 148 | pnnx.Output output 1 0 out |
| 149 | )PNNXIR"; |
| 150 | } |
| 151 | |
| 152 | const char* type_str() const |
| 153 | { |
| 154 | return "F.upsample"; |
| 155 | } |
| 156 | |
| 157 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 158 | { |
| 159 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 160 | op->params["mode"] = "bilinear"; |
| 161 | } |
| 162 | }; |
| 163 | |
| 164 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_4, 11) |
| 165 | |
| 166 | class F_upsample_4_1 : public GraphRewriterPass |
| 167 | { |
| 168 | public: |
| 169 | const char* match_pattern_graph() const |
| 170 | { |
| 171 | return R"PNNXIR(7767517 |
| 172 | 6 5 |
| 173 | pnnx.Input input_0 0 1 input |
| 174 | pnnx.Input input_1 0 1 size |
| 175 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 176 | prim::Constant op_1 0 1 scale_factor value=None |
| 177 | aten::upsample_bilinear2d op_2 4 1 input size align_corners scale_factor out |
| 178 | pnnx.Output output 1 0 out |
| 179 | )PNNXIR"; |
| 180 | } |
| 181 | |
| 182 | const char* type_str() const |
| 183 | { |
| 184 | return "F.upsample"; |
| 185 | } |
| 186 | |
| 187 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 188 | { |
| 189 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 190 | op->params["mode"] = "bilinear"; |
| 191 | } |
| 192 | }; |
| 193 | |
| 194 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_4_1, 11) |
| 195 | |
| 196 | class F_upsample_5 : public GraphRewriterPass |
| 197 | { |
| 198 | public: |
| 199 | const char* match_pattern_graph() const |
| 200 | { |
| 201 | return R"PNNXIR(7767517 |
| 202 | 6 5 |
| 203 | pnnx.Input input_0 0 1 input |
| 204 | pnnx.Input input_1 0 1 scale_factor |
| 205 | prim::Constant op_0 0 1 size value=None |
| 206 | prim::Constant op_1 0 1 align_corners value=%align_corners |
| 207 | aten::upsample_bilinear2d op_2 4 1 input size align_corners scale_factor out |
| 208 | pnnx.Output output 1 0 out |
| 209 | )PNNXIR"; |
| 210 | } |
| 211 | |
| 212 | const char* type_str() const |
| 213 | { |
| 214 | return "F.upsample"; |
| 215 | } |
| 216 | |
| 217 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 218 | { |
| 219 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 220 | op->params["mode"] = "bilinear"; |
| 221 | } |
| 222 | }; |
| 223 | |
| 224 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_5, 11) |
| 225 | |
| 226 | class F_upsample_6 : public GraphRewriterPass |
| 227 | { |
| 228 | public: |
| 229 | const char* match_pattern_graph() const |
| 230 | { |
| 231 | return R"PNNXIR(7767517 |
| 232 | 7 6 |
| 233 | pnnx.Input input_0 0 1 input |
| 234 | pnnx.Input input_1 0 1 size |
| 235 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 236 | prim::Constant op_1 0 1 scale_h value=None |
| 237 | prim::Constant op_2 0 1 scale_w value=None |
| 238 | aten::upsample_bicubic2d op_3 5 1 input size align_corners scale_h scale_w out |
| 239 | pnnx.Output output 1 0 out |
| 240 | )PNNXIR"; |
| 241 | } |
| 242 | |
| 243 | const char* type_str() const |
| 244 | { |
| 245 | return "F.upsample"; |
| 246 | } |
| 247 | |
| 248 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 249 | { |
| 250 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 251 | op->params["mode"] = "bicubic"; |
| 252 | } |
| 253 | }; |
| 254 | |
| 255 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_6, 11) |
| 256 | |
| 257 | class F_upsample_6_1 : public GraphRewriterPass |
| 258 | { |
| 259 | public: |
| 260 | const char* match_pattern_graph() const |
| 261 | { |
| 262 | return R"PNNXIR(7767517 |
| 263 | 6 5 |
| 264 | pnnx.Input input_0 0 1 input |
| 265 | pnnx.Input input_1 0 1 size |
| 266 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 267 | prim::Constant op_1 0 1 scale_factor value=None |
| 268 | aten::upsample_bicubic2d op_2 4 1 input size align_corners scale_factor out |
| 269 | pnnx.Output output 1 0 out |
| 270 | )PNNXIR"; |
| 271 | } |
| 272 | |
| 273 | const char* type_str() const |
| 274 | { |
| 275 | return "F.upsample"; |
| 276 | } |
| 277 | |
| 278 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 279 | { |
| 280 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 281 | op->params["mode"] = "bicubic"; |
| 282 | } |
| 283 | }; |
| 284 | |
| 285 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_6_1, 11) |
| 286 | |
| 287 | class F_upsample_7 : public GraphRewriterPass |
| 288 | { |
| 289 | public: |
| 290 | const char* match_pattern_graph() const |
| 291 | { |
| 292 | return R"PNNXIR(7767517 |
| 293 | 6 5 |
| 294 | pnnx.Input input_0 0 1 input |
| 295 | pnnx.Input input_1 0 1 scale_factor |
| 296 | prim::Constant op_0 0 1 size value=None |
| 297 | prim::Constant op_1 0 1 align_corners value=%align_corners |
| 298 | aten::upsample_bicubic2d op_2 4 1 input size align_corners scale_factor out |
| 299 | pnnx.Output output 1 0 out |
| 300 | )PNNXIR"; |
| 301 | } |
| 302 | |
| 303 | const char* type_str() const |
| 304 | { |
| 305 | return "F.upsample"; |
| 306 | } |
| 307 | |
| 308 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 309 | { |
| 310 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 311 | op->params["mode"] = "bicubic"; |
| 312 | } |
| 313 | }; |
| 314 | |
| 315 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_7, 11) |
| 316 | |
| 317 | class F_upsample_8 : public GraphRewriterPass |
| 318 | { |
| 319 | public: |
| 320 | const char* match_pattern_graph() const |
| 321 | { |
| 322 | return R"PNNXIR(7767517 |
| 323 | 8 7 |
| 324 | pnnx.Input input_0 0 1 input |
| 325 | pnnx.Input input_1 0 1 size |
| 326 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 327 | prim::Constant op_1 0 1 scale_d value=None |
| 328 | prim::Constant op_2 0 1 scale_h value=None |
| 329 | prim::Constant op_3 0 1 scale_w value=None |
| 330 | aten::upsample_trilinear3d op_4 6 1 input size align_corners scale_d scale_h scale_w out |
| 331 | pnnx.Output output 1 0 out |
| 332 | )PNNXIR"; |
| 333 | } |
| 334 | |
| 335 | const char* type_str() const |
| 336 | { |
| 337 | return "F.upsample"; |
| 338 | } |
| 339 | |
| 340 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 341 | { |
| 342 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 343 | op->params["mode"] = "trilinear"; |
| 344 | } |
| 345 | }; |
| 346 | |
| 347 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_8, 11) |
| 348 | |
| 349 | class F_upsample_8_1 : public GraphRewriterPass |
| 350 | { |
| 351 | public: |
| 352 | const char* match_pattern_graph() const |
| 353 | { |
| 354 | return R"PNNXIR(7767517 |
| 355 | 6 5 |
| 356 | pnnx.Input input_0 0 1 input |
| 357 | pnnx.Input input_1 0 1 size |
| 358 | prim::Constant op_0 0 1 align_corners value=%align_corners |
| 359 | prim::Constant op_1 0 1 scale_factor value=None |
| 360 | aten::upsample_trilinear3d op_2 4 1 input size align_corners scale_factor out |
| 361 | pnnx.Output output 1 0 out |
| 362 | )PNNXIR"; |
| 363 | } |
| 364 | |
| 365 | const char* type_str() const |
| 366 | { |
| 367 | return "F.upsample"; |
| 368 | } |
| 369 | |
| 370 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 371 | { |
| 372 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 373 | op->params["mode"] = "trilinear"; |
| 374 | } |
| 375 | }; |
| 376 | |
| 377 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_8_1, 11) |
| 378 | |
| 379 | class F_upsample_9 : public GraphRewriterPass |
| 380 | { |
| 381 | public: |
| 382 | const char* match_pattern_graph() const |
| 383 | { |
| 384 | return R"PNNXIR(7767517 |
| 385 | 6 5 |
| 386 | pnnx.Input input_0 0 1 input |
| 387 | pnnx.Input input_1 0 1 scale_factor |
| 388 | prim::Constant op_0 0 1 size value=None |
| 389 | prim::Constant op_1 0 1 align_corners value=%align_corners |
| 390 | aten::upsample_trilinear3d op_2 4 1 input size align_corners scale_factor out |
| 391 | pnnx.Output output 1 0 out |
| 392 | )PNNXIR"; |
| 393 | } |
| 394 | |
| 395 | const char* type_str() const |
| 396 | { |
| 397 | return "F.upsample"; |
| 398 | } |
| 399 | |
| 400 | void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const |
| 401 | { |
| 402 | op->params["align_corners"] = captured_params.at("align_corners"); |
| 403 | op->params["mode"] = "trilinear"; |
| 404 | } |
| 405 | }; |
| 406 | |
| 407 | REGISTER_GLOBAL_PNNX_GRAPH_REWRITER_PASS(F_upsample_9, 11) |
| 408 | |
| 409 | } // namespace pnnx |