blob: b39a8d7701319c11873c4ab7bd03e3b6d2c10816 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitasf8f04422021-01-08 17:25:55 +00002 * Copyright (c) 2017-2021 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEACTIVATIONLAYER_H
25#define ARM_COMPUTE_NEACTIVATIONLAYER_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Georgios Pinitasf8f04422021-01-08 17:25:55 +000027#include "arm_compute/runtime/IFunction.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29#include "arm_compute/core/Types.h"
Georgios Pinitasf8f04422021-01-08 17:25:55 +000030#include "arm_compute/runtime/IRuntimeContext.h"
31
32#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
34namespace arm_compute
35{
Georgios Pinitas12833d02019-07-25 13:31:10 +010036// Forward declarations
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037class ITensor;
Georgios Pinitasf8f04422021-01-08 17:25:55 +000038class ITensorInfo;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010039
Michele Di Giorgiobd2c8e12021-01-19 15:29:02 +000040/** Basic function to run @ref cpu::kernels::CpuActivationKernel
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 *
42 * @note The function simulates an activation layer with the specified activation function.
43 */
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010044class NEActivationLayer : public IFunction
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045{
46public:
Georgios Pinitas12833d02019-07-25 13:31:10 +010047 /** 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 Pinitas1fd2c802020-06-16 17:44:46 +010055 NEActivationLayer(NEActivationLayer &&);
Georgios Pinitas12833d02019-07-25 13:31:10 +010056 /** 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 Pinitas1fd2c802020-06-16 17:44:46 +010059 NEActivationLayer &operator=(NEActivationLayer &&);
Michalis Spyrouebcebf12020-10-21 00:04:14 +010060 /** Destructor */
61 ~NEActivationLayer();
Michele Di Giorgio7b12bfb2019-10-25 16:34:28 +010062 /** [NEActivationLayer snippet] **/
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 /** Set the input and output tensor.
64 *
Sheri Zhanga47dcc22021-04-22 14:41:12 +010065 * 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 Giorgiodde9ec92018-02-13 15:24:04 +000077 * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
Gian Marco Iodiceb30dcc52017-06-20 09:07:21 +010078 *
79 * @param[in, out] input Source tensor. In case of @p output tensor = nullptr, this tensor will store the result
Michalis Spyrou8d4d1b82019-11-28 11:31:23 +000080 * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
Gian Marco Iodiceb30dcc52017-06-20 09:07:21 +010081 * @param[out] output Destination tensor. Data type supported: same as @p input
82 * @param[in] activation_info Activation layer parameters.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010083 */
Gian Marco Iodiceb30dcc52017-06-20 09:07:21 +010084 void configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info);
Michele Di Giorgio7b12bfb2019-10-25 16:34:28 +010085 /** [NEActivationLayer snippet] **/
Michalis Spyrouafa5d812017-11-30 14:25:57 +000086 /** 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 Spyrou8d4d1b82019-11-28 11:31:23 +000089 * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000090 * @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 Pinitas1fd2c802020-06-16 17:44:46 +010096
97 // Inherited methods overridden
98 void run() override;
99
100private:
101 struct Impl;
102 std::unique_ptr<Impl> _impl;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103};
Georgios Pinitasf8f04422021-01-08 17:25:55 +0000104} // namespace arm_computes
Michalis Spyrouf4643372019-11-29 16:17:13 +0000105#endif /* ARM_COMPUTE_NEACTIVATIONLAYER_H */