Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEACTIVATIONLAYER_H |
| 25 | #define ARM_COMPUTE_NEACTIVATIONLAYER_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 27 | #include "arm_compute/runtime/IFunction.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
| 29 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/IRuntimeContext.h" |
| 31 | |
| 32 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 33 | |
| 34 | namespace arm_compute |
| 35 | { |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 36 | // Forward declarations |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 37 | class ITensor; |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 38 | class ITensorInfo; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | |
Michele Di Giorgio | bd2c8e1 | 2021-01-19 15:29:02 +0000 | [diff] [blame] | 40 | /** Basic function to run @ref cpu::kernels::CpuActivationKernel |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | * |
| 42 | * @note The function simulates an activation layer with the specified activation function. |
| 43 | */ |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 44 | class NEActivationLayer : public IFunction |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 45 | { |
| 46 | public: |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 47 | /** Constructor |
| 48 | * |
| 49 | * @param[in] ctx Runtime context to be used by the function |
| 50 | */ |
| 51 | NEActivationLayer(IRuntimeContext *ctx = nullptr); |
| 52 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 53 | NEActivationLayer(const NEActivationLayer &) = delete; |
| 54 | /** Default move constructor */ |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 55 | NEActivationLayer(NEActivationLayer &&); |
Georgios Pinitas | 12833d0 | 2019-07-25 13:31:10 +0100 | [diff] [blame] | 56 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 57 | NEActivationLayer &operator=(const NEActivationLayer &) = delete; |
| 58 | /** Default move assignment operator */ |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 59 | NEActivationLayer &operator=(NEActivationLayer &&); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 60 | /** Destructor */ |
| 61 | ~NEActivationLayer(); |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 62 | /** [NEActivationLayer snippet] **/ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 63 | /** Set the input and output tensor. |
| 64 | * |
Sheri Zhang | a47dcc2 | 2021-04-22 14:41:12 +0100 | [diff] [blame] | 65 | * Valid data layouts: |
| 66 | * - All |
| 67 | * |
| 68 | * Valid data type configurations: |
| 69 | * |src |dst | |
| 70 | * |:--------------|:--------------| |
| 71 | * |QASYMM8 |QASYMM8 | |
| 72 | * |QASYMM8_SIGNED |QASYMM8_SIGNED | |
| 73 | * |QSYMM16 |QSYMM16 | |
| 74 | * |F16 |F16 | |
| 75 | * |F32 |F32 | |
| 76 | * |
Michele Di Giorgio | dde9ec9 | 2018-02-13 15:24:04 +0000 | [diff] [blame] | 77 | * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 78 | * |
| 79 | * @param[in, out] input Source tensor. In case of @p output tensor = nullptr, this tensor will store the result |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 80 | * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32. |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 81 | * @param[out] output Destination tensor. Data type supported: same as @p input |
| 82 | * @param[in] activation_info Activation layer parameters. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | */ |
Gian Marco Iodice | b30dcc5 | 2017-06-20 09:07:21 +0100 | [diff] [blame] | 84 | void configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info); |
Michele Di Giorgio | 7b12bfb | 2019-10-25 16:34:28 +0100 | [diff] [blame] | 85 | /** [NEActivationLayer snippet] **/ |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 86 | /** Static function to check if given info will lead to a valid configuration of @ref NEActivationLayer |
| 87 | * |
| 88 | * @param[in] input Source tensor info. In case of @p output tensor info = nullptr, this tensor will store the result |
Michalis Spyrou | 8d4d1b8 | 2019-11-28 11:31:23 +0000 | [diff] [blame] | 89 | * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 90 | * @param[in] output Destination tensor info. Data type supported: same as @p input |
| 91 | * @param[in] act_info Activation layer information. |
| 92 | * |
| 93 | * @return a status |
| 94 | */ |
| 95 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info); |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 96 | |
| 97 | // Inherited methods overridden |
| 98 | void run() override; |
| 99 | |
| 100 | private: |
| 101 | struct Impl; |
| 102 | std::unique_ptr<Impl> _impl; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 103 | }; |
Georgios Pinitas | f8f0442 | 2021-01-08 17:25:55 +0000 | [diff] [blame] | 104 | } // namespace arm_computes |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 105 | #endif /* ARM_COMPUTE_NEACTIVATIONLAYER_H */ |