blob: 00188f0d492d728153be3e030085ce38e115d0dc [file] [log] [blame]
George Wort5a97b282018-12-21 16:21:04 +00001/*
Viet-Hoa Dofd472f02023-03-15 14:05:06 +00002 * Copyright (c) 2018-2023 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"
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/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 */
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020042class CpuElementwiseUnaryKernel : public ICpuKernel<CpuElementwiseUnaryKernel>
George Wort5a97b282018-12-21 16:21:04 +000043{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000044private:
Viet-Hoa Dofd472f02023-03-15 14:05:06 +000045 using ElementwiseUnaryUkernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const Window &, ElementWiseUnary, const uint8_t *)>::type;
46 using ElementwiseUnaryPreparePtr = std::add_pointer<std::unique_ptr<uint8_t[]>(ElementWiseUnary op, const ITensorInfo *, const ITensorInfo *)>::type;
Giorgio Arena5ae8d802021-11-18 18:02:13 +000047
George Wort5a97b282018-12-21 16:21:04 +000048public:
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010049 CpuElementwiseUnaryKernel() = default;
Sang-Hoon Park7249f152021-01-22 11:55:03 +000050 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseUnaryKernel);
George Wort5a97b282018-12-21 16:21:04 +000051
Sang-Hoon Park7249f152021-01-22 11:55:03 +000052 /** Function to configure the @ref CpuElementwiseUnaryKernel
George Wort5a97b282018-12-21 16:21:04 +000053 *
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000054 * @param[in] op Arithmetic operation to be executed.
55 * @param[in] src First tensor input. Data types supported: F16/F32, F16/F32/S32 for NEG/ABS operations.
56 * @param[out] dst Output tensor. Data types supported: Same as @p src.
George Wort5a97b282018-12-21 16:21:04 +000057 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000058 void configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst);
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010059 /** Static function to check if given info will lead to a valid configuration
George Wort5a97b282018-12-21 16:21:04 +000060 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010061 * Similar to CpuElementwiseUnaryKernel::configure()
George Wort5a97b282018-12-21 16:21:04 +000062 *
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010063 * @return a status
George Wort5a97b282018-12-21 16:21:04 +000064 */
Sang-Hoon Park668ccdc2021-02-03 10:32:59 +000065 static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst);
George Wort5a97b282018-12-21 16:21:04 +000066
67 // Inherited methods overridden:
Sang-Hoon Park7249f152021-01-22 11:55:03 +000068 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Georgios Pinitas2eb5d162021-07-02 09:01:49 +010069 const char *name() const override;
George Wort5a97b282018-12-21 16:21:04 +000070
Giorgio Arena5ae8d802021-11-18 18:02:13 +000071 struct ElementwiseUnaryKernel
72 {
73 const char *name;
74 const DataTypeISASelectorPtr is_selected;
75 ElementwiseUnaryUkernelPtr ukernel;
Viet-Hoa Dofd472f02023-03-15 14:05:06 +000076 ElementwiseUnaryPreparePtr prepare_func;
Giorgio Arena5ae8d802021-11-18 18:02:13 +000077 };
78
79 static const std::vector<ElementwiseUnaryKernel> &get_available_kernels();
George Wort5a97b282018-12-21 16:21:04 +000080
Sang-Hoon Parkaf1870b2020-12-08 18:50:56 +000081private:
Georgios Pinitas5ee0d952021-07-05 07:21:28 +010082 ElementWiseUnary _op{};
83 ElementwiseUnaryUkernelPtr _run_method{ nullptr };
84 std::string _name{};
Viet-Hoa Dofd472f02023-03-15 14:05:06 +000085 std::unique_ptr<uint8_t[]> _lut{};
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 */