diff --git a/src/common/types.cpp b/src/common/types.cpp index 63b834c703621725f949c098ce7a4dc0e9f082f7..56f9ec91445e72bfd886c3e97c28b4cf6c4ce956 100644 --- a/src/common/types.cpp +++ b/src/common/types.cpp @@ -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"}}}, diff --git a/src/framework/load_ops.h b/src/framework/load_ops.h index 16b0eb87cfc424164fbdb2e0c86473e75140be45..3beae9eddd322b2df33090268c9c4fd1b38fa57b 100644 --- a/src/framework/load_ops.h +++ b/src/framework/load_ops.h @@ -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 diff --git a/src/operators/exp_op.cpp b/src/operators/exp_op.cpp new file mode 100644 index 0000000000000000000000000000000000000000..72ec69ce52eea85bc0ebc9ad53b9ad240f0f9da1 --- /dev/null +++ b/src/operators/exp_op.cpp @@ -0,0 +1,36 @@ +/* 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 +void EXPOp::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 diff --git a/src/operators/exp_op.h b/src/operators/exp_op.h new file mode 100644 index 0000000000000000000000000000000000000000..6f8cd099b7246963678a5cb98b8d4d73d26ba5ff --- /dev/null +++ b/src/operators/exp_op.h @@ -0,0 +1,30 @@ +/* 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 +#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 diff --git a/src/operators/kernel/arm/exp_kernel.cpp b/src/operators/kernel/arm/exp_kernel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0323a2b0455128e3e1c3e727fabaa13978ca3b38 --- /dev/null +++ b/src/operators/kernel/arm/exp_kernel.cpp @@ -0,0 +1,47 @@ +/* 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 +#include +namespace paddle_mobile { +namespace operators { +template <> +bool EXPKernel::Init( + paddle_mobile::operators::EXPParam *param) { + return true; +} + +template <> +void EXPKernel::Compute( + const paddle_mobile::operators::EXPParam ¶m) { + const auto input_ = param.InputX(); + auto output = param.Out(); + float *output_data = output->mutable_data(); + const float *input_data = input_->data(); + 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 diff --git a/src/operators/kernel/exp_kernel.h b/src/operators/kernel/exp_kernel.h new file mode 100644 index 0000000000000000000000000000000000000000..ed7c4296f8750b0ec87569f73eb70c4aed3cbb54 --- /dev/null +++ b/src/operators/kernel/exp_kernel.h @@ -0,0 +1,24 @@ +/* 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 +#include "framework/operator.h" +namespace paddle_mobile { +namespace operators { +DECLARE_KERNEL(EXP, EXPParam) +} +} // namespace paddle_mobile +#endif // EXP_OP diff --git a/src/operators/op_param.h b/src/operators/op_param.h index 4df7b5b173f49e79607ee23c816acfea90f5ea15..b8068b8d0d8e69fb65012beff3e98f0525ae6cae 100644 --- a/src/operators/op_param.h +++ b/src/operators/op_param.h @@ -3431,6 +3431,26 @@ class Pad2dParam : public OpParam { RType *out_; }; #endif +#ifdef EXP_OP +template +class EXPParam : public OpParam { + typedef typename DtypeTensorTrait::gtype GType; + typedef typename DtypeTensorTrait::rtype RType; + public: + EXPParam(const VariableNameMap &inputs, const VariableNameMap &outputs, + const AttributeMap &attrs, Scope *scope) + : OpParam(inputs, outputs, attrs, scope) { + input_x_ = InputXFrom(inputs, *scope); + out_ = OutFrom(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 diff --git a/tools/op.cmake b/tools/op.cmake index 13b6cbdd18fa957f7a67d170d9f7019ca9635a78..b8ea4cb7b72efa7ab041a9c5cb87a452cffbb01a 100755 --- a/tools/op.cmake +++ b/tools/op.cmake @@ -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 ()