depthwise_conv_arm_func.h 2.1 KB
Newer Older
L
liuruilong 已提交
1
/* Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
L
liuruilong 已提交
2

L
liuruilong 已提交
3 4 5
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
L
liuruilong 已提交
6

L
liuruilong 已提交
7 8 9 10 11 12 13 14
    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. */

15
#ifdef DEPTHWISECONV_OP
L
liuruilong 已提交
16 17

#pragma once
E
eclipsess 已提交
18
#include <operators/math/depthwise_conv_3x3.h>
19
#include <vector>
E
eclipsess 已提交
20
#include "operators/kernel/central-arm-func/conv_arm_func.h"
E
eclipsycn 已提交
21

L
liuruilong 已提交
22 23 24 25 26
#include "operators/op_param.h"

namespace paddle_mobile {
namespace operators {

L
liuruilong 已提交
27
template <typename P>
N
nhzlx 已提交
28
void DepthwiseConvCompute(const ConvParam<CPU> &param) {
E
eclipsess 已提交
29 30 31 32
  Tensor Bias;
  Bias.mutable_data<float>({param.Groups()});
  if (param.Groups() == param.Input()->dims()[1] &&
      param.Filter()->dims()[2] == param.Filter()->dims()[3] &&
E
eclipsess 已提交
33 34
      param.Filter()->dims()[2] == 3 && param.Strides()[0] == 1 &&
      param.Input()->dims()[2] == param.Input()->dims()[3]) {
E
eclipsess 已提交
35 36 37 38 39
    math::DepthwiseConv3x3s1p1(param.Input(), param.Filter(), param.Output(),
                               &Bias, false);
  } else if (param.Groups() == param.Input()->dims()[1] &&
             param.Input()->dims()[1] == param.Output()->dims()[1] &&
             param.Filter()->dims()[2] == param.Filter()->dims()[3] &&
E
eclipsess 已提交
40 41
             param.Filter()->dims()[2] == 3 && param.Strides()[0] == 2 &&
             param.Input()->dims()[2] == param.Input()->dims()[3]) {
E
eclipsess 已提交
42 43 44 45 46 47
    //    math::DepthwiseConv3x3(param.Input(), param.Strides(),
    //    param.Paddings(),
    //                           param.Filter(), &Bias, param.Output(), false);
    math::DepthwiseConv3x3s2p1v2(param.Input(), param.Filter(), param.Output(),
                                 Bias, false);

E
eclipsess 已提交
48
  } else {
49
    ConvBasic<float, float>(param);
L
liuruilong 已提交
50 51 52
  }
}

L
liuruilong 已提交
53 54
}  // namespace operators
}  // namespace paddle_mobile
L
liuruilong 已提交
55 56

#endif