提交 33521991 编写于 作者: H Huie 提交者: zp7

add exp cpu op (#1760)

* add exp cpu

* add exp cpu
上级 b1ba1065
......@@ -91,6 +91,7 @@ const char *G_OP_TYPE_WRITE_TO_ARRAY = "write_to_array";
const char *G_OP_TYPE_READ_FROM_ARRAY = "read_from_array";
const char *G_OP_TYPE_IS_EMPTY = "is_empty";
const char *G_OP_TYPE_INCREMENT = "increment";
const char *G_OP_TYPE_EXP = "exp";
const char *G_OP_TYPE_QUANTIZE = "quantize";
const char *G_OP_TYPE_DEQUANTIZE = "dequantize";
......@@ -169,6 +170,7 @@ std::unordered_map<
{G_OP_TYPE_FUSION_CONV_ADD_ADD_PRELU, {{"Input"}, {"Out"}}},
{G_OP_TYPE_IM2SEQUENCE, {{"X"}, {"Out"}}},
{G_OP_TYPE_DROPOUT, {{"X"}, {"Out"}}},
{G_OP_TYPE_EXP, {{"X"}, {"Out"}}},
{G_OP_TYPE_FUSION_CONV_ADD_BN, {{"Input"}, {"Y"}}},
{G_OP_TYPE_FUSION_POOL_BN, {{"X"}, {"Y"}}},
{G_OP_TYPE_FUSION_ELEMENTWISE_ADD_RELU, {{"X", "Y"}, {"Out"}}},
......
......@@ -345,3 +345,6 @@ LOAD_OP1(one_hot, CPU);
#ifdef ASSIGN_VALUE_OP
LOAD_OP1(assign_value, CPU);
#endif
#ifdef EXP_OP
LOAD_OP1(exp, CPU);
#endif
/* 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. */
#ifdef EXP_OP
#include "exp_op.h"
namespace paddle_mobile {
namespace operators {
template <typename DeviceType, typename T>
void EXPOp<DeviceType, T>::InferShape() const {
auto shape = this->param_.InputX()->dims();
this->param_.Out()->Resize(shape);
}
} // namespace operators
} // namespace paddle_mobile
namespace ops = paddle_mobile::operators;
#ifdef PADDLE_MOBILE_CPU
REGISTER_OPERATOR_CPU(exp, ops::EXPOp);
#endif
#ifdef PADDLE_MOBILE_CL
// REGISTER_OPERATOR_CL(exp, ops::EXPOp);
#endif
#endif
/* 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. */
#pragma once
#include <string>
#include "framework/operator.h"
#include "operators/kernel/exp_kernel.h"
#include "operators/op_param.h"
namespace paddle_mobile {
namespace operators {
#ifdef EXP_OP
DECLARE_OPERATOR(EXP, EXPParam, EXPKernel);
#endif
} // namespace operators
} // namespace paddle_mobile
/* 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. */
//
// Created by hujie09 on 2019-07-16.
//
#ifdef EXP_OP
#pragma once
#include <math.h>
#include <operators/kernel/exp_kernel.h>
namespace paddle_mobile {
namespace operators {
template <>
bool EXPKernel<CPU, float>::Init(
paddle_mobile::operators::EXPParam<paddle_mobile::CPU> *param) {
return true;
}
template <>
void EXPKernel<CPU, float>::Compute(
const paddle_mobile::operators::EXPParam<paddle_mobile::CPU> &param) {
const auto input_ = param.InputX();
auto output = param.Out();
float *output_data = output->mutable_data<float>();
const float *input_data = input_->data<float>();
for (int i = 0; i < output->numel(); ++i, output_data++, input_data++) {
*output_data = exp(*input_data);
}
}
} // namespace operators
} // namespace paddle_mobile
#endif // EXP_OP
/* 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. */
#ifdef EXP_OP
#include <operators/op_param.h>
#include "framework/operator.h"
namespace paddle_mobile {
namespace operators {
DECLARE_KERNEL(EXP, EXPParam)
}
} // namespace paddle_mobile
#endif // EXP_OP
......@@ -3431,6 +3431,26 @@ class Pad2dParam : public OpParam {
RType *out_;
};
#endif
#ifdef EXP_OP
template <typename Dtype>
class EXPParam : public OpParam {
typedef typename DtypeTensorTrait<Dtype>::gtype GType;
typedef typename DtypeTensorTrait<Dtype>::rtype RType;
public:
EXPParam(const VariableNameMap &inputs, const VariableNameMap &outputs,
const AttributeMap &attrs, Scope *scope)
: OpParam(inputs, outputs, attrs, scope) {
input_x_ = InputXFrom<GType>(inputs, *scope);
out_ = OutFrom<GType>(outputs, *scope);
}
const GType *InputX() const { return input_x_; }
GType *Out() const { return out_; }
private:
GType *input_x_;
GType *out_;
};
#endif
} // namespace operators
} // namespace paddle_mobile
......@@ -293,6 +293,7 @@ if(NOT FOUND_MATCH)
set(DENSITY_PRIORBOX_OP ON)
set(FUSION_CONVADD_OP ON)
set(FUSION_CONVADDPRELU_OP ON)
set(EXP_OP ON)
set(FUSION_CONVADDRELU_OP ON)
set(FUSION_FC_OP ON)
set(LRN_OP ON)
......@@ -709,3 +710,6 @@ endif()
if (DENSITY_PRIORBOX_OP)
add_definitions(-DDENSITY_PRIORBOX_OP)
endif()
if (EXP_OP)
add_definitions(-DEXP_OP)
endif ()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册