blob: 23a092c4076ee96f16b5af14dfae1f885d8f0c2b [file] [log] [blame]
George Wort5a97b282018-12-21 16:21:04 +00001/*
Sang-Hoon Park7249f152021-01-22 11:55:03 +00002 * Copyright (c) 2018-2021 Arm Limited.
George Wort5a97b282018-12-21 16:21:04 +00003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "arm_compute/runtime/NEON/functions/NEElementwiseUnaryLayer.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010025
Georgios Pinitas7891a732021-08-20 21:39:25 +010026#include "src/cpu/operators/CpuElementwiseUnary.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010027
George Wort5a97b282018-12-21 16:21:04 +000028#include <utility>
29
30namespace arm_compute
31{
Sang-Hoon Park7249f152021-01-22 11:55:03 +000032using OperatorType = cpu::CpuElementwiseUnary;
33
34template <ElementWiseUnary op>
35struct NEElementwiseUnaryLayer<op>::Impl
George Wort5a97b282018-12-21 16:21:04 +000036{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010037 const ITensor *src{nullptr};
38 ITensor *dst{nullptr};
39 std::unique_ptr<OperatorType> cpu_op{nullptr};
Sang-Hoon Park7249f152021-01-22 11:55:03 +000040};
41
42template <ElementWiseUnary op>
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043NEElementwiseUnaryLayer<op>::NEElementwiseUnaryLayer() : _impl(std::make_unique<Impl>())
Sang-Hoon Park7249f152021-01-22 11:55:03 +000044{
George Wort5a97b282018-12-21 16:21:04 +000045}
Sang-Hoon Park7249f152021-01-22 11:55:03 +000046template <ElementWiseUnary op>
47NEElementwiseUnaryLayer<op>::~NEElementwiseUnaryLayer() = default;
48template <ElementWiseUnary op>
49NEElementwiseUnaryLayer<op>::NEElementwiseUnaryLayer(NEElementwiseUnaryLayer &&) = default;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050template <ElementWiseUnary op>
Sang-Hoon Park7249f152021-01-22 11:55:03 +000051NEElementwiseUnaryLayer<op> &NEElementwiseUnaryLayer<op>::operator=(NEElementwiseUnaryLayer &&) = default;
52
53template <ElementWiseUnary op>
54void NEElementwiseUnaryLayer<op>::configure(const ITensor *input, ITensor *output)
George Wort5a97b282018-12-21 16:21:04 +000055{
Sang-Hoon Park7249f152021-01-22 11:55:03 +000056 _impl->src = input;
57 _impl->dst = output;
58 _impl->cpu_op = std::make_unique<OperatorType>();
59 _impl->cpu_op->configure(op, *_impl->src->info(), *_impl->dst->info());
George Wort5a97b282018-12-21 16:21:04 +000060}
61
Sang-Hoon Park7249f152021-01-22 11:55:03 +000062template <ElementWiseUnary op>
63Status NEElementwiseUnaryLayer<op>::validate(const ITensorInfo *input, const ITensorInfo *output)
George Wort5a97b282018-12-21 16:21:04 +000064{
Sang-Hoon Park7249f152021-01-22 11:55:03 +000065 return OperatorType::validate(op, *input, *output);
George Wort5a97b282018-12-21 16:21:04 +000066}
Usama Ariff6e475c2019-05-10 12:06:28 +010067
Sang-Hoon Park7249f152021-01-22 11:55:03 +000068template <ElementWiseUnary op>
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010069void NEElementwiseUnaryLayer<op>::run()
Usama Ariff6e475c2019-05-10 12:06:28 +010070{
Sang-Hoon Park7249f152021-01-22 11:55:03 +000071 ITensorPack pack;
72 pack.add_tensor(TensorType::ACL_SRC, _impl->src);
73 pack.add_tensor(TensorType::ACL_DST, _impl->dst);
74 _impl->cpu_op->run(pack);
Usama Ariff6e475c2019-05-10 12:06:28 +010075}
76
Sang-Hoon Park7249f152021-01-22 11:55:03 +000077template class NEElementwiseUnaryLayer<ElementWiseUnary::RSQRT>;
78template class NEElementwiseUnaryLayer<ElementWiseUnary::EXP>;
79template class NEElementwiseUnaryLayer<ElementWiseUnary::NEG>;
80template class NEElementwiseUnaryLayer<ElementWiseUnary::LOG>;
81template class NEElementwiseUnaryLayer<ElementWiseUnary::ABS>;
82template class NEElementwiseUnaryLayer<ElementWiseUnary::ROUND>;
83template class NEElementwiseUnaryLayer<ElementWiseUnary::SIN>;
Manuel Bottinied753262019-05-15 15:30:47 +010084
George Wort5a97b282018-12-21 16:21:04 +000085} // namespace arm_compute