blob: bda65a35e03d786a47b75efc308518ee16d994df [file] [log] [blame]
George Wort5a97b282018-12-21 16:21:04 +00001/*
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +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 */
Sang-Hoon Park7249f152021-01-22 11:55:03 +000024#ifndef ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H
25#define ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H
George Wort5a97b282018-12-21 16:21:04 +000026
George Wort5a97b282018-12-21 16:21:04 +000027#include "arm_compute/core/Types.h"
Sang-Hoon Park7249f152021-01-22 11:55:03 +000028#include "src/core/common/Macros.h"
29#include "src/core/cpu/ICpuKernel.h"
George Wort5a97b282018-12-21 16:21:04 +000030
31namespace arm_compute
32{
Sang-Hoon Park7249f152021-01-22 11:55:03 +000033namespace cpu
34{
35namespace kernels
36{
George Wort5a97b282018-12-21 16:21:04 +000037/** Interface for an element-wise unary operation kernel
38 *
39 * Element-wise operation is computed by:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000040 * @f[ dst(x) = OP(src(x))@f]
George Wort5a97b282018-12-21 16:21:04 +000041 */
Sang-Hoon Park7249f152021-01-22 11:55:03 +000042class CpuElementwiseUnaryKernel : public ICpuKernel
George Wort5a97b282018-12-21 16:21:04 +000043{
44public:
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010045 CpuElementwiseUnaryKernel() = default;
Sang-Hoon Park7249f152021-01-22 11:55:03 +000046 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseUnaryKernel);
George Wort5a97b282018-12-21 16:21:04 +000047
Sang-Hoon Park7249f152021-01-22 11:55:03 +000048 /** Function to configure the @ref CpuElementwiseUnaryKernel
George Wort5a97b282018-12-21 16:21:04 +000049 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000050 * @param[in] op Arithmetic operation to be executed.
51 * @param[in] src First tensor input. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
52 * @param[out] dst Output tensor. Data types supported: Same as @p src.
George Wort5a97b282018-12-21 16:21:04 +000053 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000054 void configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010055 /** Static function to check if given info will lead to a valid configuration
George Wort5a97b282018-12-21 16:21:04 +000056 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010057 * Similar to CpuElementwiseUnaryKernel::configure()
George Wort5a97b282018-12-21 16:21:04 +000058 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010059 * @return a status
George Wort5a97b282018-12-21 16:21:04 +000060 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000061 static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst);
George Wort5a97b282018-12-21 16:21:04 +000062
63 // Inherited methods overridden:
Sang-Hoon Park7249f152021-01-22 11:55:03 +000064 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010065 const char *name() const override;
George Wort5a97b282018-12-21 16:21:04 +000066
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000067 /** Common signature for all the specialised elementwise unary micro-kernels
George Wort5a97b282018-12-21 16:21:04 +000068 *
Michalis Spyrou18e20ff2020-05-06 17:03:59 +010069 * @param[in] window Region on which to execute the kernel.
George Wort5a97b282018-12-21 16:21:04 +000070 */
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000071 using ElementwiseUnaryUkernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const Window &, ElementWiseUnary)>::type;
George Wort5a97b282018-12-21 16:21:04 +000072
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000073private:
Georgios Pinitas5ee0d952021-07-05 07:21:28 +010074 ElementWiseUnary _op{};
75 ElementwiseUnaryUkernelPtr _run_method{ nullptr };
76 std::string _name{};
George Wort5a97b282018-12-21 16:21:04 +000077};
Sang-Hoon Park7249f152021-01-22 11:55:03 +000078} // namespace kernels
79} // namespace cpu
George Wort5a97b282018-12-21 16:21:04 +000080} // namespace arm_compute
Sang-Hoon Park7249f152021-01-22 11:55:03 +000081#endif /* ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H */