conv_impl.h 11.8 KB
Newer Older
Y
Yan Chunwei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include "lite/core/context.h"
#include "lite/core/target_wrapper.h"
#include "lite/operators/op_params.h"

namespace paddle {
namespace lite {
namespace arm {
namespace math {

void conv_3x3s1_direct_fp32(const float* din,
                            float* dout,
                            int num,
                            int chout,
                            int hout,
                            int wout,
                            int chin,
                            int hin,
                            int win,
                            const float* weights,
                            const float* bias,
                            const operators::ConvParam& param,
38
                            ARMContext* ctx);
Y
Yan Chunwei 已提交
39

40
template <typename Dtype>
Y
Yan Chunwei 已提交
41
void conv_3x3s1_direct_int8(const int8_t* din,
42
                            Dtype* dout,
Y
Yan Chunwei 已提交
43 44 45 46 47 48 49 50
                            int num,
                            int chout,
                            int hout,
                            int wout,
                            int chin,
                            int hin,
                            int win,
                            const int8_t* weights,
51
                            const float* bias,
Y
Yan Chunwei 已提交
52
                            const operators::ConvParam& param,
53
                            ARMContext* ctx,
Y
Yan Chunwei 已提交
54 55 56 57 58 59 60 61 62 63 64 65 66 67
                            const float* scale);

void conv_3x3s2_direct_fp32(const float* din,
                            float* dout,
                            int num,
                            int chout,
                            int hout,
                            int wout,
                            int chin,
                            int hin,
                            int win,
                            const float* weights,
                            const float* bias,
                            const operators::ConvParam& param,
68
                            ARMContext* ctx);
Y
Yan Chunwei 已提交
69 70 71

int conv_3x3s2_direct_int8_c_num();

72
template <typename Dtype>
Y
Yan Chunwei 已提交
73
void conv_3x3s2_direct_int8(const int8_t* din,
74
                            Dtype* dout,
Y
Yan Chunwei 已提交
75 76 77 78 79 80 81 82
                            int num,
                            int chout,
                            int hout,
                            int wout,
                            int chin,
                            int hin,
                            int win,
                            const int8_t* weights,
83
                            const float* bias,
Y
Yan Chunwei 已提交
84
                            const operators::ConvParam& param,
85
                            ARMContext* ctx,
Y
Yan Chunwei 已提交
86 87
                            const float* scale);

88 89
void conv_1x5s1_direct(const float* din,
                       float* dout,
Y
Yan Chunwei 已提交
90 91 92 93 94 95 96
                       int num,
                       int chout,
                       int hout,
                       int wout,
                       int chin,
                       int hin,
                       int win,
97 98
                       const float* weights,
                       const float* bias,
Y
Yan Chunwei 已提交
99 100 101 102 103 104 105 106 107 108 109
                       int group,
                       int kernel_w,
                       int kernel_h,
                       int stride_w,
                       int stride_h,
                       int dila_w,
                       int dila_h,
                       int pad_w,
                       int pad_h,
                       bool flag_bias,
                       bool flag_relu,
110
                       ARMContext& ctx);  // NOLINT
Y
Yan Chunwei 已提交
111

112 113
void conv_5x1s1_direct(const float* din,
                       float* dout,
Y
Yan Chunwei 已提交
114 115 116 117 118 119 120
                       int num,
                       int chout,
                       int hout,
                       int wout,
                       int chin,
                       int hin,
                       int win,
121 122
                       const float* weights,
                       const float* bias,
Y
Yan Chunwei 已提交
123 124 125 126 127 128 129 130 131 132 133
                       int group,
                       int kernel_w,
                       int kernel_h,
                       int stride_w,
                       int stride_h,
                       int dila_w,
                       int dila_h,
                       int pad_w,
                       int pad_h,
                       bool flag_bias,
                       bool flag_relu,
134
                       ARMContext& ctx);  // NOLINT
Y
Yan Chunwei 已提交
135 136 137 138 139 140 141 142 143 144 145 146 147

void conv1x1s1_gemm(const float* din,
                    float* dout,
                    int num,
                    int chout,
                    int hout,
                    int wout,
                    int chin,
                    int hin,
                    int win,
                    const float* weights,
                    const float* bias,
                    const operators::ConvParam& param,
148
                    ARMContext* ctx);
Y
Yan Chunwei 已提交
149

150
template <typename Dtype>
Y
Yan Chunwei 已提交
151
void conv1x1s1_gemm_int8(const int8_t* din,
152
                         Dtype* dout,
Y
Yan Chunwei 已提交
153 154 155 156 157 158 159 160
                         int num,
                         int chout,
                         int hout,
                         int wout,
                         int chin,
                         int hin,
                         int win,
                         const int8_t* weights,
161
                         const float* bias,
Y
Yan Chunwei 已提交
162
                         const operators::ConvParam& param,
163 164
                         ARMContext* ctx,
                         const float* scale);
Y
Yan Chunwei 已提交
165 166 167 168 169 170 171 172 173 174 175 176 177

void conv_im2col_gemm(const float* din,
                      float* dout,
                      int num,
                      int chout,
                      int hout,
                      int wout,
                      int chin,
                      int hin,
                      int win,
                      const float* weights,
                      const float* bias,
                      const operators::ConvParam& param,
178
                      ARMContext* ctx);
Y
Yan Chunwei 已提交
179

180
template <typename Dtype>
Y
Yan Chunwei 已提交
181
void conv_im2col_gemm_int8(const int8_t* din,
182
                           Dtype* dout,
Y
Yan Chunwei 已提交
183 184 185 186 187 188 189 190
                           int num,
                           int chout,
                           int hout,
                           int wout,
                           int chin,
                           int hin,
                           int win,
                           const int8_t* weights,
191
                           const float* bias,
Y
Yan Chunwei 已提交
192
                           const operators::ConvParam& param,
193 194
                           ARMContext* ctx,
                           const float* scale);
Y
Yan Chunwei 已提交
195

196 197 198
/// depthwise conv
void conv_depthwise_3x3_fp32(const void* din,
                             void* dout,
Y
Yan Chunwei 已提交
199
                             int num,
200 201 202 203 204 205 206 207
                             int ch_out,
                             int h_out,
                             int w_out,
                             int ch_in,
                             int h_in,
                             int w_in,
                             const void* weights,
                             const float* bias,
Y
Yan Chunwei 已提交
208
                             const operators::ConvParam& param,
209
                             ARMContext* ctx,
Y
Yan Chunwei 已提交
210 211
                             const float* scale);

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243
void conv_depthwise_3x3_int8_fp32(const void* din,
                                  void* dout,
                                  int num,
                                  int ch_out,
                                  int h_out,
                                  int w_out,
                                  int ch_in,
                                  int h_in,
                                  int w_in,
                                  const void* weights,
                                  const float* bias,
                                  const operators::ConvParam& param,
                                  ARMContext* ctx,
                                  const float* scale);

void conv_depthwise_3x3_int8_int8(const void* din,
                                  void* dout,
                                  int num,
                                  int ch_out,
                                  int h_out,
                                  int w_out,
                                  int ch_in,
                                  int h_in,
                                  int w_in,
                                  const void* weights,
                                  const float* bias,
                                  const operators::ConvParam& param,
                                  ARMContext* ctx,
                                  const float* scale);

void conv_depthwise_5x5_fp32(const void* din,
                             void* dout,
Y
Yan Chunwei 已提交
244
                             int num,
245 246 247 248 249 250 251 252
                             int ch_out,
                             int h_out,
                             int w_out,
                             int ch_in,
                             int h_in,
                             int w_in,
                             const void* weights,
                             const float* bias,
Y
Yan Chunwei 已提交
253
                             const operators::ConvParam& param,
254
                             ARMContext* ctx,
Y
Yan Chunwei 已提交
255 256
                             const float* scale);

257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
void conv_depthwise_5x5_int8_fp32(const void* din,
                                  void* dout,
                                  int num,
                                  int ch_out,
                                  int h_out,
                                  int w_out,
                                  int ch_in,
                                  int h_in,
                                  int w_in,
                                  const void* weights,
                                  const float* bias,
                                  const operators::ConvParam& param,
                                  ARMContext* ctx,
                                  const float* scale);

void conv_depthwise_5x5_int8_int8(const void* din,
                                  void* dout,
                                  int num,
                                  int ch_out,
                                  int h_out,
                                  int w_out,
                                  int ch_in,
                                  int h_in,
                                  int w_in,
                                  const void* weights,
                                  const float* bias,
                                  const operators::ConvParam& param,
                                  ARMContext* ctx,
                                  const float* scale);

/// winograd conv, only support 3x3s1
Y
Yan Chunwei 已提交
288 289 290 291 292 293 294 295 296 297 298 299
void conv_winograd3x3(const float* din,
                      float* dout,
                      int num,
                      int chout,
                      int hout,
                      int wout,
                      int chin,
                      int hin,
                      int win,
                      const float* weights,
                      const float* bias,
                      const operators::ConvParam& param,
300
                      ARMContext* ctx);
Y
Yan Chunwei 已提交
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315

void winograd_transform_weights(
    void* dout, const void* din, int ch_out, int ch_in, void* work_space);

void fill_bias(float* tensor, const float* bias, int channel, int channel_size);

void fill_bias_int8(int* tensor,
                    const int* bias,
                    int channel,
                    int channel_size);

}  // namespace math
}  // namespace arm
}  // namespace lite
}  // namespace paddle