blob: ceb90dcf702cc75b748fbdf87c6fd5bbb74519cd [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{
33class ITensor;
Sang-Hoon Park7249f152021-01-22 11:55:03 +000034namespace cpu
35{
36namespace kernels
37{
George Wort5a97b282018-12-21 16:21:04 +000038/** Interface for an element-wise unary operation kernel
39 *
40 * Element-wise operation is computed by:
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000041 * @f[ dst(x) = OP(src(x))@f]
George Wort5a97b282018-12-21 16:21:04 +000042 *
43 */
Sang-Hoon Park7249f152021-01-22 11:55:03 +000044class CpuElementwiseUnaryKernel : public ICpuKernel
George Wort5a97b282018-12-21 16:21:04 +000045{
46public:
47 const char *name() const override
48 {
Sang-Hoon Park7249f152021-01-22 11:55:03 +000049 return "CpuElementwiseUnaryKernel";
George Wort5a97b282018-12-21 16:21:04 +000050 }
51 /** Default constructor */
Sang-Hoon Park7249f152021-01-22 11:55:03 +000052 CpuElementwiseUnaryKernel();
George Wort5a97b282018-12-21 16:21:04 +000053 /** Default destructor */
Sang-Hoon Park7249f152021-01-22 11:55:03 +000054 ~CpuElementwiseUnaryKernel() = default;
55 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseUnaryKernel);
George Wort5a97b282018-12-21 16:21:04 +000056
Sang-Hoon Park7249f152021-01-22 11:55:03 +000057 /** Function to configure the @ref CpuElementwiseUnaryKernel
George Wort5a97b282018-12-21 16:21:04 +000058 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000059 * @param[in] op Arithmetic operation to be executed.
60 * @param[in] src First tensor input. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
61 * @param[out] dst Output tensor. Data types supported: Same as @p src.
George Wort5a97b282018-12-21 16:21:04 +000062 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000063 void configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst);
George Wort5a97b282018-12-21 16:21:04 +000064
Sang-Hoon Park7249f152021-01-22 11:55:03 +000065 /** Static function to check if given info will lead to a valid configuration of @ref CpuElementwiseUnaryKernel
George Wort5a97b282018-12-21 16:21:04 +000066 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000067 * @param[in] op Arithmetic operation to be executed.
68 * @param[in] src First tensor input info. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
69 * @param[in] dst Output tensor info. Data types supported: Same as @p src.
George Wort5a97b282018-12-21 16:21:04 +000070 *
71 * @return a Status
72 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000073 static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst);
George Wort5a97b282018-12-21 16:21:04 +000074
75 // Inherited methods overridden:
Sang-Hoon Park7249f152021-01-22 11:55:03 +000076 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
George Wort5a97b282018-12-21 16:21:04 +000077
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000078 /** Common signature for all the specialised elementwise unary micro-kernels
George Wort5a97b282018-12-21 16:21:04 +000079 *
Michalis Spyrou18e20ff2020-05-06 17:03:59 +010080 * @param[in] window Region on which to execute the kernel.
George Wort5a97b282018-12-21 16:21:04 +000081 */
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000082 using ElementwiseUnaryUkernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const Window &, ElementWiseUnary)>::type;
George Wort5a97b282018-12-21 16:21:04 +000083
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000084private:
Sang-Hoon Park7249f152021-01-22 11:55:03 +000085 ElementWiseUnary _op;
George Wort5a97b282018-12-21 16:21:04 +000086};
Sang-Hoon Park7249f152021-01-22 11:55:03 +000087} // namespace kernels
88} // namespace cpu
George Wort5a97b282018-12-21 16:21:04 +000089} // namespace arm_compute
Sang-Hoon Park7249f152021-01-22 11:55:03 +000090#endif /* ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H */