George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 1 | /* |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2023 Arm Limited. |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 3 | * |
| 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 Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H |
| 25 | #define ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 26 | |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 28 | #include "src/core/common/Macros.h" |
Georgios Pinitas | 7891a73 | 2021-08-20 21:39:25 +0100 | [diff] [blame] | 29 | #include "src/cpu/ICpuKernel.h" |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 30 | |
| 31 | namespace arm_compute |
| 32 | { |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 33 | namespace cpu |
| 34 | { |
| 35 | namespace kernels |
| 36 | { |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 37 | /** Interface for an element-wise unary operation kernel |
| 38 | * |
| 39 | * Element-wise operation is computed by: |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 40 | * @f[ dst(x) = OP(src(x))@f] |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 41 | */ |
Yair Schwarzbaum | 46d44d2 | 2022-01-12 16:38:58 +0200 | [diff] [blame] | 42 | class CpuElementwiseUnaryKernel : public ICpuKernel<CpuElementwiseUnaryKernel> |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 43 | { |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 44 | private: |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 45 | 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 Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 47 | |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 48 | public: |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 49 | CpuElementwiseUnaryKernel() = default; |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 50 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseUnaryKernel); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 51 | |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 52 | /** Function to configure the @ref CpuElementwiseUnaryKernel |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 53 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 54 | * @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 Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 57 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 58 | void configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 59 | /** Static function to check if given info will lead to a valid configuration |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 60 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 61 | * Similar to CpuElementwiseUnaryKernel::configure() |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 62 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 63 | * @return a status |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 64 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 65 | static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 66 | |
| 67 | // Inherited methods overridden: |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 68 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 69 | const char *name() const override; |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 70 | |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 71 | struct ElementwiseUnaryKernel |
| 72 | { |
| 73 | const char *name; |
| 74 | const DataTypeISASelectorPtr is_selected; |
| 75 | ElementwiseUnaryUkernelPtr ukernel; |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 76 | ElementwiseUnaryPreparePtr prepare_func; |
Giorgio Arena | 5ae8d80 | 2021-11-18 18:02:13 +0000 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | static const std::vector<ElementwiseUnaryKernel> &get_available_kernels(); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 80 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 81 | private: |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame] | 82 | ElementWiseUnary _op{}; |
| 83 | ElementwiseUnaryUkernelPtr _run_method{ nullptr }; |
| 84 | std::string _name{}; |
Viet-Hoa Do | fd472f0 | 2023-03-15 14:05:06 +0000 | [diff] [blame] | 85 | std::unique_ptr<uint8_t[]> _lut{}; |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 86 | }; |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 87 | } // namespace kernels |
| 88 | } // namespace cpu |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 89 | } // namespace arm_compute |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 90 | #endif /* ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H */ |