activation_kernel.cpp 3.1 KB
Newer Older
E
eclipsess 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2018 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. */

15
#include "operators/kernel/activation_kernel.h"
16
#include "common/types.h"
17
#include "operators/kernel/central-arm-func/activation_arm_func.h"
18
#include "operators/math/activation.h"
19 20 21
#if defined(__ARM_NEON__) || defined(__ARM_NEON)
#include <arm_neon.h>
#endif
E
eclipsess 已提交
22 23 24 25

namespace paddle_mobile {
namespace operators {

26
#ifdef RELU_OP
L
liuruilong 已提交
27
template <>
N
nhzlx 已提交
28
bool ReluKernel<CPU, float>::Init(ReluParam<CPU> *param) {
L
liuruilong 已提交
29 30 31
  return true;
}

E
eclipsess 已提交
32
template <>
L
liuruilong 已提交
33
void ReluKernel<CPU, float>::Compute(const ReluParam<CPU> &param) {
H
hjchen2 已提交
34 35
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
36
  ActivationCompute<float, RELU>()(input, output);
H
hjchen2 已提交
37
  output->set_lod(input->lod());
38 39 40 41 42 43 44 45 46
}

template <>
bool Relu6Kernel<CPU, float>::Init(ReluParam<CPU> *param) {
  return true;
}

template <>
void Relu6Kernel<CPU, float>::Compute(const ReluParam<CPU> &param) {
H
hjchen2 已提交
47 48
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
49
  ActivationCompute<float, RELU6>()(input, output);
H
hjchen2 已提交
50
  output->set_lod(input->lod());
E
eclipsess 已提交
51
}
52
#endif
E
eclipsess 已提交
53

54 55 56 57 58 59 60 61
#ifdef SIGMOID_OP
template <>
bool SigmoidKernel<CPU, float>::Init(SigmoidParam<CPU> *param) {
  return true;
}

template <>
void SigmoidKernel<CPU, float>::Compute(const SigmoidParam<CPU> &param) {
H
hjchen2 已提交
62 63
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
64
  ActivationCompute<float, SIGMOID>()(input, output);
H
hjchen2 已提交
65
  output->set_lod(input->lod());
66 67
}
#endif
L
liuruilong 已提交
68

69 70
#ifdef TANH_OP
template <>
71
bool TanhKernel<CPU, float>::Init(TanhParam<CPU> *param) {
72 73 74 75 76
  return true;
}

template <>
void TanhKernel<CPU, float>::Compute(const TanhParam<CPU> &param) {
H
hjchen2 已提交
77 78
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
79
  ActivationCompute<float, TANH>()(input, output);
H
hjchen2 已提交
80
  output->set_lod(input->lod());
81
}
L
liuruilong 已提交
82
#endif
83

84 85 86 87 88 89 90 91
#ifdef LOG_OP
template <>
bool LogKernel<CPU, float>::Init(ReluParam<CPU> *param) {
  return true;
}

template <>
void LogKernel<CPU, float>::Compute(const ReluParam<CPU> &param) {
H
hjchen2 已提交
92 93
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
94
  ActivationCompute<float, LOG>()(input, output);
H
hjchen2 已提交
95
  output->set_lod(input->lod());
96 97 98
}
#endif

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
#ifdef LEAKY_RELU_OP
template <>
bool LeakyReluKernel<CPU, float>::Init(LeakyReluParam<CPU> *param) {
  return true;
}

template <>
void LeakyReluKernel<CPU, float>::Compute(const LeakyReluParam<CPU> &param) {
  const LoDTensor *input = param.InputX();
  LoDTensor *output = param.Out();
  ActivationCompute<float, LEAKY_RELU>()(input, output, param.Alpha());
  output->set_lod(input->lod());
}
#endif

114 115
}  // namespace operators
}  // namespace paddle_mobile