Elffuss BraidHub

kikocis/ncnn public

master · 2.1 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 "fuse_contiguous_view.h"
16
17#include "pass_level2.h"
18
19namespace pnnx {
20
21class fuse_contiguous_view_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
29Tensor.contiguous op_0 1 1 input a memory_format=*
30Tensor.view op_1 1 1 a out shape=%shape
31pnnx.Output output 1 0 out
32)PNNXIR";
33 }
34
35 const char* type_str() const
36 {
37 return "Tensor.reshape";
38 }
39
40 const char* name_str() const
41 {
42 return "view_shape";
43 }
44};
45
46class fuse_contiguous_view_pass_1 : public GraphRewriterPass
47{
48public:
49 const char* match_pattern_graph() const
50 {
51 return R"PNNXIR(7767517
525 4
53pnnx.Input input_1 0 1 input
54pnnx.Input input_2 0 1 shape
55Tensor.contiguous op_0 1 1 input a memory_format=*
56Tensor.view op_1 2 1 a shape out
57pnnx.Output output 1 0 out
58)PNNXIR";
59 }
60
61 const char* type_str() const
62 {
63 return "Tensor.reshape";
64 }
65
66 const char* name_str() const
67 {
68 return "view_shape";
69 }
70};
71
72void fuse_contiguous_view(Graph& graph)
73{
74 fuse_contiguous_view_pass a;
75 fuse_contiguous_view_pass_1 b;
76 int opindex = 0;
77
78 pnnx_graph_rewrite(graph, &a, opindex);
79 pnnx_graph_rewrite(graph, &b, opindex);
80}
81
82} // namespace pnnx