George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 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" |
| 29 | #include "src/core/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 | */ |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 42 | class CpuElementwiseUnaryKernel : public ICpuKernel |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 43 | { |
| 44 | public: |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 45 | CpuElementwiseUnaryKernel() = default; |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 46 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuElementwiseUnaryKernel); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 47 | |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 48 | /** Function to configure the @ref CpuElementwiseUnaryKernel |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 49 | * |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 50 | * @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 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 | void configure(ElementWiseUnary op, const ITensorInfo &src, ITensorInfo &dst); |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 55 | /** 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] | 56 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 57 | * Similar to CpuElementwiseUnaryKernel::configure() |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 58 | * |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 59 | * @return a status |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 60 | */ |
Sang-Hoon Park | 668ccdc | 2021-02-03 10:32:59 +0000 | [diff] [blame] | 61 | static Status validate(ElementWiseUnary op, const ITensorInfo &src, const ITensorInfo &dst); |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 62 | |
| 63 | // Inherited methods overridden: |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 64 | void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | 2eb5d16 | 2021-07-02 09:01:49 +0100 | [diff] [blame] | 65 | const char *name() const override; |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 66 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 67 | /** Common signature for all the specialised elementwise unary micro-kernels |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 68 | * |
Michalis Spyrou | 18e20ff | 2020-05-06 17:03:59 +0100 | [diff] [blame] | 69 | * @param[in] window Region on which to execute the kernel. |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 70 | */ |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 71 | using ElementwiseUnaryUkernelPtr = std::add_pointer<void(const ITensor *, ITensor *, const Window &, ElementWiseUnary)>::type; |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 72 | |
Sang-Hoon Park | af1870b | 2020-12-08 18:50:56 +0000 | [diff] [blame] | 73 | private: |
Georgios Pinitas | 5ee0d95 | 2021-07-05 07:21:28 +0100 | [diff] [blame^] | 74 | ElementWiseUnary _op{}; |
| 75 | ElementwiseUnaryUkernelPtr _run_method{ nullptr }; |
| 76 | std::string _name{}; |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 77 | }; |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 78 | } // namespace kernels |
| 79 | } // namespace cpu |
George Wort | 5a97b28 | 2018-12-21 16:21:04 +0000 | [diff] [blame] | 80 | } // namespace arm_compute |
Sang-Hoon Park | 7249f15 | 2021-01-22 11:55:03 +0000 | [diff] [blame] | 81 | #endif /* ARM_COMPUTE_CPU_ELEMENTWISE_UNARY_KERNEL_H */ |