From 7249f154c2ec029f9b8c91f2bb845abe6590f7ed Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Fri, 22 Jan 2021 11:55:03 +0000 Subject: Rename functions/classes for elementwise unary operations * Create CpuElementwiseUnary operator * Rename kernel classes * Make the kernels stateless Partially implements: COMPMID-4003 Change-Id: Ie0440cd01d4924847d6991b4df7ccaf311439297 Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/4912 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- .../NEON/functions/NEElementwiseUnaryLayer.cpp | 105 ++++++++------------- 1 file changed, 40 insertions(+), 65 deletions(-) (limited to 'src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp') diff --git a/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp b/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp index 5c779f1489..1a9e8839ca 100644 --- a/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp +++ b/src/runtime/NEON/functions/NEElementwiseUnaryLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Arm Limited. + * Copyright (c) 2018-2021 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -22,88 +22,63 @@ * SOFTWARE. */ #include "arm_compute/runtime/NEON/functions/NEElementwiseUnaryLayer.h" - -#include "src/core/NEON/kernels/NEElementwiseUnaryKernel.h" - +#include "src/runtime/cpu/operators/CpuElementwiseUnary.h" #include namespace arm_compute { -void NERsqrtLayer::configure(const ITensor *input, ITensor *output) -{ - auto k = std::make_unique(); - k->configure(ElementWiseUnary::RSQRT, input, output); - _kernel = std::move(k); -} -Status NERsqrtLayer::validate(const ITensorInfo *input, const ITensorInfo *output) -{ - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::RSQRT, input, output); -} +using OperatorType = cpu::CpuElementwiseUnary; -void NEExpLayer::configure(const ITensor *input, ITensor *output) +template +struct NEElementwiseUnaryLayer::Impl { - auto k = std::make_unique(); - k->configure(ElementWiseUnary::EXP, input, output); - _kernel = std::move(k); -} -Status NEExpLayer::validate(const ITensorInfo *input, const ITensorInfo *output) -{ - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::EXP, input, output); -} + const ITensor *src{ nullptr }; + ITensor *dst{ nullptr }; + std::unique_ptr cpu_op{ nullptr }; +}; -void NENegLayer::configure(const ITensor *input, ITensor *output) -{ - auto k = std::make_unique(); - k->configure(ElementWiseUnary::NEG, input, output); - _kernel = std::move(k); -} -Status NENegLayer::validate(const ITensorInfo *input, const ITensorInfo *output) +template +NEElementwiseUnaryLayer::NEElementwiseUnaryLayer() + : _impl(std::make_unique()) { - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::NEG, input, output); } +template +NEElementwiseUnaryLayer::~NEElementwiseUnaryLayer() = default; +template +NEElementwiseUnaryLayer::NEElementwiseUnaryLayer(NEElementwiseUnaryLayer &&) = default; +template +NEElementwiseUnaryLayer &NEElementwiseUnaryLayer::operator=(NEElementwiseUnaryLayer &&) = default; -void NELogLayer::configure(const ITensor *input, ITensor *output) +template +void NEElementwiseUnaryLayer::configure(const ITensor *input, ITensor *output) { - auto k = std::make_unique(); - k->configure(ElementWiseUnary::LOG, input, output); - _kernel = std::move(k); -} -Status NELogLayer::validate(const ITensorInfo *input, const ITensorInfo *output) -{ - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::LOG, input, output); + _impl->src = input; + _impl->dst = output; + _impl->cpu_op = std::make_unique(); + _impl->cpu_op->configure(op, *_impl->src->info(), *_impl->dst->info()); } -void NEAbsLayer::configure(const ITensor *input, ITensor *output) +template +Status NEElementwiseUnaryLayer::validate(const ITensorInfo *input, const ITensorInfo *output) { - auto k = std::make_unique(); - k->configure(ElementWiseUnary::ABS, input, output); - _kernel = std::move(k); -} -Status NEAbsLayer::validate(const ITensorInfo *input, const ITensorInfo *output) -{ - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::ABS, input, output); + return OperatorType::validate(op, *input, *output); } -void NERoundLayer::configure(const ITensor *input, ITensor *output) -{ - auto k = std::make_unique(); - k->configure(ElementWiseUnary::ROUND, input, output); - _kernel = std::move(k); -} -Status NERoundLayer::validate(const ITensorInfo *input, const ITensorInfo *output) +template +void NEElementwiseUnaryLayer::run() { - return NEElementwiseUnaryKernel::validate(ElementWiseUnary::ROUND, input, output); + ITensorPack pack; + pack.add_tensor(TensorType::ACL_SRC, _impl->src); + pack.add_tensor(TensorType::ACL_DST, _impl->dst); + _impl->cpu_op->run(pack); } -void NESinLayer::configure(const ITensor *input, ITensor *output) -{ - auto k = std::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); -} +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; +template class NEElementwiseUnaryLayer; } // namespace arm_compute -- cgit v1.2.1