| 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_level5.h" |
| 16 | |
| 17 | #include "pass_level5/attribute_unpooling.h" |
| 18 | #include "pass_level5/fold_constants.h" |
| 19 | #include "pass_level5/eliminate_dropout.h" |
| 20 | #include "pass_level5/eliminate_identity_operator.h" |
| 21 | #include "pass_level5/eliminate_noop_cat.h" |
| 22 | #include "pass_level5/eliminate_noop_einsum.h" |
| 23 | #include "pass_level5/eliminate_noop_expand.h" |
| 24 | #include "pass_level5/eliminate_noop_expression.h" |
| 25 | #include "pass_level5/eliminate_noop_pad.h" |
| 26 | #include "pass_level5/eliminate_noop_upsample.h" |
| 27 | #include "pass_level5/eliminate_noop_slice.h" |
| 28 | #include "pass_level5/eliminate_noop_view_reshape.h" |
| 29 | #include "pass_level5/eliminate_reshape_shape_expression.h" |
| 30 | #include "pass_level5/eliminate_type_as.h" |
| 31 | #include "pass_level5/eval_expression.h" |
| 32 | #include "pass_level5/fuse_adjacent_reshape.h" |
| 33 | #include "pass_level5/fuse_channel_shuffle.h" |
| 34 | #include "pass_level5/fuse_constant_expression.h" |
| 35 | #include "pass_level5/fuse_conv1d_batchnorm1d.h" |
| 36 | #include "pass_level5/fuse_conv2d_batchnorm2d.h" |
| 37 | #include "pass_level5/fuse_conv3d_batchnorm3d.h" |
| 38 | #include "pass_level5/fuse_convtranspose1d_batchnorm1d.h" |
| 39 | #include "pass_level5/fuse_convtranspose2d_batchnorm2d.h" |
| 40 | #include "pass_level5/fuse_convtranspose3d_batchnorm3d.h" |
| 41 | #include "pass_level5/fuse_contiguous_view.h" |
| 42 | #include "pass_level5/fuse_layernorm.h" |
| 43 | #include "pass_level5/fuse_linear_batchnorm1d.h" |
| 44 | #include "pass_level5/fuse_multiheadattention.h" |
| 45 | #include "pass_level5/fuse_pad_conv1d.h" |
| 46 | #include "pass_level5/fuse_pad_conv2d.h" |
| 47 | #include "pass_level5/fuse_rmsnorm.h" |
| 48 | #include "pass_level5/fuse_scaled_dot_product_attention.h" |
| 49 | #include "pass_level5/fuse_select_to_unbind.h" |
| 50 | #include "pass_level5/fuse_silu.h" |
| 51 | #include "pass_level5/fuse_slice_copy.h" |
| 52 | #include "pass_level5/fuse_slice_indices.h" |
| 53 | #include "pass_level5/fuse_slice_to_tensor_split.h" |
| 54 | #include "pass_level5/fuse_slice_squeeze_to_select.h" |
| 55 | #include "pass_level5/fuse_static_batchnorm.h" |
| 56 | #include "pass_level5/fuse_static_conv.h" |
| 57 | #include "pass_level5/fuse_static_convtranspose.h" |
| 58 | #include "pass_level5/fuse_static_embedding.h" |
| 59 | #include "pass_level5/fuse_static_groupnorm.h" |
| 60 | #include "pass_level5/fuse_static_instancenorm.h" |
| 61 | #include "pass_level5/fuse_static_layernorm.h" |
| 62 | #include "pass_level5/fuse_static_linear.h" |
| 63 | #include "pass_level5/fuse_static_prelu.h" |
| 64 | #include "pass_level5/fuse_static_rmsnorm.h" |
| 65 | #include "pass_level5/normalize_einsum_equation.h" |
| 66 | #include "pass_level4/dead_code_elimination.h" |
| 67 | #include "pass_level4/canonicalize.h" |
| 68 | #include "pass_level3/fuse_index_expression.h" |
| 69 | #include "pass_level5/fuse_pixel_unshuffle.h" |
| 70 | |
| 71 | namespace pnnx { |
| 72 | |
| 73 | void pass_level5(Graph& g, const std::set<std::string>& foldable_constants, const std::string& foldable_constants_zippath) |
| 74 | { |
| 75 | eval_expression(g); |
| 76 | |
| 77 | fuse_constant_expression(g); |
| 78 | |
| 79 | fold_constants(g, foldable_constants, foldable_constants_zippath); |
| 80 | |
| 81 | eliminate_noop_expression(g); |
| 82 | |
| 83 | eliminate_noop_slice(g); |
| 84 | |
| 85 | fuse_slice_squeeze_to_select(g); |
| 86 | |
| 87 | fuse_slice_indices(g); |
| 88 | |
| 89 | normalize_einsum_equation(g); |
| 90 | |
| 91 | eliminate_noop_einsum(g); |
| 92 | |
| 93 | eliminate_identity_operator(g); |
| 94 | |
| 95 | fuse_select_to_unbind(g); |
| 96 | |
| 97 | fuse_slice_to_tensor_split(g); |
| 98 | |
| 99 | fuse_slice_copy(g); |
| 100 | |
| 101 | attribute_unpooling(g); |
| 102 | |
| 103 | fuse_static_batchnorm(g); |
| 104 | fuse_static_groupnorm(g); |
| 105 | fuse_static_instancenorm(g); |
| 106 | fuse_static_layernorm(g); |
| 107 | fuse_static_rmsnorm(g); |
| 108 | |
| 109 | fuse_static_conv(g); |
| 110 | fuse_static_convtranspose(g); |
| 111 | fuse_static_linear(g); |
| 112 | fuse_static_embedding(g); |
| 113 | fuse_static_prelu(g); |
| 114 | |
| 115 | fuse_conv1d_batchnorm1d(g); |
| 116 | fuse_conv2d_batchnorm2d(g); |
| 117 | fuse_conv3d_batchnorm3d(g); |
| 118 | fuse_convtranspose1d_batchnorm1d(g); |
| 119 | fuse_convtranspose2d_batchnorm2d(g); |
| 120 | fuse_convtranspose3d_batchnorm3d(g); |
| 121 | fuse_linear_batchnorm1d(g); |
| 122 | |
| 123 | fuse_pad_conv1d(g); |
| 124 | fuse_pad_conv2d(g); |
| 125 | |
| 126 | eliminate_noop_pad(g); |
| 127 | |
| 128 | eliminate_noop_cat(g); |
| 129 | |
| 130 | eliminate_dropout(g); |
| 131 | eliminate_type_as(g); |
| 132 | |
| 133 | eliminate_noop_upsample(g); |
| 134 | |
| 135 | fuse_contiguous_view(g); |
| 136 | |
| 137 | // need to execute before fuse_adjacent_reshape |
| 138 | fuse_pixel_unshuffle(g); |
| 139 | |
| 140 | fuse_adjacent_reshape(g); |
| 141 | |
| 142 | eliminate_noop_view_reshape(g); |
| 143 | |
| 144 | eliminate_reshape_shape_expression(g); |
| 145 | eliminate_noop_expand(g); |
| 146 | |
| 147 | fuse_channel_shuffle(g); |
| 148 | fuse_layernorm(g); |
| 149 | fuse_rmsnorm(g); |
| 150 | fuse_multiheadattention(g); |
| 151 | fuse_scaled_dot_product_attention(g); |
| 152 | |
| 153 | fuse_silu(g); |
| 154 | |
| 155 | fuse_index_expression(g); |
| 156 | |
| 157 | dead_code_elimination(g); |
| 158 | |
| 159 | canonicalize(g); |
| 160 | } |
| 161 | |
| 162 | } // namespace pnnx |