From ed753266948314922ee56b0d4a3e801264011a12 Mon Sep 17 00:00:00 2001 From: Manuel Bottini Date: Wed, 15 May 2019 15:30:47 +0100 Subject: COMPMID-2283: Implement SIN operator for NEON Change-Id: I31ee0e7c9a30540cfd2cad76993afb66abfccc4d Signed-off-by: Manuel Bottini Reviewed-on: https://review.mlplatform.org/c/1169 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: Michalis Spyrou --- src/core/NEON/kernels/NEElementwiseUnaryKernel.cpp | 14 +++++++++++--- src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp | 11 +++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/core/NEON/kernels/NEElementwiseUnaryKernel.cpp b/src/core/NEON/kernels/NEElementwiseUnaryKernel.cpp index 45f0fedebb..5d3af3b03d 100644 --- a/src/core/NEON/kernels/NEElementwiseUnaryKernel.cpp +++ b/src/core/NEON/kernels/NEElementwiseUnaryKernel.cpp @@ -65,13 +65,15 @@ inline ScalarType elementwise_op_scalar(const ScalarType &a) return std::abs(a); case ElementWiseUnary::ROUND: return support::cpp11::nearbyint(a); + case ElementWiseUnary::SIN: + return std::sin(a); default: ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); } } /* Elementwise operations that are supported for float */ -template ::type = 0> +template ::type = 0> inline VectorType elementwise_op(const VectorType &a) { switch(op) @@ -88,13 +90,15 @@ inline VectorType elementwise_op(const VectorType &a) return wrapper::vabs(a); case ElementWiseUnary::ROUND: return wrapper::vround(a); + case ElementWiseUnary::SIN: + return wrapper::vsin(a); default: ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); } } /* Elementwise operations that are supported for non floats */ -template < ElementWiseUnary op, bool is_float, typename VectorType, typename std::enable_if < !is_float, int >::type = 0 > +template < ElementWiseUnary op, typename ScalarType, bool is_float, typename VectorType, typename std::enable_if < !is_float, int >::type = 0 > inline VectorType elementwise_op(const VectorType &a) { switch(op) @@ -129,7 +133,7 @@ void elementwise_op(const ITensor *in, ITensor *out, const Window &window) int x = window_start_x; for(; x <= window_end_x - window_step_x; x += window_step_x) { - wrapper::vstore(output_ptr + x, elementwise_op(wrapper::vloadq(input_ptr + x))); + wrapper::vstore(output_ptr + x, elementwise_op(wrapper::vloadq(input_ptr + x))); } for(; x < window_end_x; ++x) { @@ -215,6 +219,9 @@ void NEElementwiseUnaryKernel::configure(ElementWiseUnary op, const ITensor *inp case ElementWiseUnary::ROUND: _function = configure_func(input, output); break; + case ElementWiseUnary::SIN: + _function = configure_func(input, output); + break; default: ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); } @@ -229,6 +236,7 @@ Status NEElementwiseUnaryKernel::validate_arguments(ElementWiseUnary op, const I case ElementWiseUnary::RSQRT: case ElementWiseUnary::LOG: case ElementWiseUnary::ROUND: + case ElementWiseUnary::SIN: ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(&input, 1, DataType::F16, DataType::F32); break; case ElementWiseUnary::NEG: diff --git a/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp b/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp index e4c9101274..4b44a05a64 100644 --- a/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp +++ b/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp @@ -96,4 +96,15 @@ Status NERoundLayer::validate(const ITensorInfo *input, const ITensorInfo *outpu return NEElementwiseUnaryKernel::validate(ElementWiseUnary::ROUND, input, output); } +void NESinLayer::configure(const ITensor *input, ITensor *output) +{ + auto k = arm_compute::support::cpp14::make_unique(); + k->configure(ElementWiseUnary::SIN, input, output); + _kernel = std::move(k); +} +Status NESinLayer::validate(const ITensorInfo *input, const ITensorInfo *output) +{ + return NEElementwiseUnaryKernel::validate(ElementWiseUnary::SIN, input, output); +} + } // namespace arm_compute -- cgit v1.2.1