blob: 8ac2dae911d982cc0161d3778a32d601fdb076b3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas1fd2c802020-06-16 17:44:46 +01002 * Copyright (c) 2017-2020 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
Michalis Spyrou95abfdd2018-11-28 14:59:47 +000027#include "arm_compute/runtime/NEON/INESimpleFunctionNoBorder.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29#include "arm_compute/core/Types.h"
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010030#include "arm_compute/runtime/NEON/INEOperator.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
32namespace arm_compute
33{
Georgios Pinitas12833d02019-07-25 13:31:10 +010034// Forward declarations
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035class ITensor;
36
37/** Basic function to run @ref NEActivationLayerKernel
38 *
39 * @note The function simulates an activation layer with the specified activation function.
40 */
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010041class NEActivationLayer : public IFunction
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042{
43public:
Georgios Pinitas12833d02019-07-25 13:31:10 +010044 /** Constructor
45 *
46 * @param[in] ctx Runtime context to be used by the function
47 */
48 NEActivationLayer(IRuntimeContext *ctx = nullptr);
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010049 /** Destructor */
50 ~NEActivationLayer();
Georgios Pinitas12833d02019-07-25 13:31:10 +010051 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NEActivationLayer(const NEActivationLayer &) = delete;
53 /** Default move constructor */
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010054 NEActivationLayer(NEActivationLayer &&);
Georgios Pinitas12833d02019-07-25 13:31:10 +010055 /** Prevent instances of this class from being copied (As this class contains pointers) */
56 NEActivationLayer &operator=(const NEActivationLayer &) = delete;
57 /** Default move assignment operator */
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010058 NEActivationLayer &operator=(NEActivationLayer &&);
Michele Di Giorgio7b12bfb2019-10-25 16:34:28 +010059 /** [NEActivationLayer snippet] **/
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 /** Set the input and output tensor.
61 *
Michele Di Giorgiodde9ec92018-02-13 15:24:04 +000062 * @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 +010063 *
64 * @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 +000065 * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
Gian Marco Iodiceb30dcc52017-06-20 09:07:21 +010066 * @param[out] output Destination tensor. Data type supported: same as @p input
67 * @param[in] activation_info Activation layer parameters.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068 */
Gian Marco Iodiceb30dcc52017-06-20 09:07:21 +010069 void configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info);
Michele Di Giorgio7b12bfb2019-10-25 16:34:28 +010070 /** [NEActivationLayer snippet] **/
Michalis Spyrouafa5d812017-11-30 14:25:57 +000071 /** Static function to check if given info will lead to a valid configuration of @ref NEActivationLayer
72 *
73 * @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 +000074 * of the activation function. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000075 * @param[in] output Destination tensor info. Data type supported: same as @p input
76 * @param[in] act_info Activation layer information.
77 *
78 * @return a status
79 */
80 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info);
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010081
82 // Inherited methods overridden
83 void run() override;
84
85private:
86 struct Impl;
87 std::unique_ptr<Impl> _impl;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088};
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010089
90namespace experimental
91{
92/** Basic function to run @ref NEActivationLayerKernel */
93class NEActivationLayer : public INEOperator
94{
95public:
96 /** Set the input and output tensor.
97 *
98 * @param[in] input Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
99 * @param[out] output Destination tensor info. Data type supported: same as @p input
100 * @param[in] activation_info Activation layer parameters.
101 */
102 void configure(const ITensorInfo *input, ITensorInfo *output, const ActivationLayerInfo &activation_info);
103 /** Static function to check if given info will lead to a valid configuration of @ref NEActivationLayer
104 *
105 * @param[in] input Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/QSYMM16/F16/F32.
106 * @param[in] output Destination tensor info. Data type supported: same as @p input
107 * @param[in] act_info Activation layer information.
108 *
109 * @return a status
110 */
111 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info);
112
113 // Inherited methods overridden:
114 MemoryRequirements workspace() const override;
115};
116} // namespace experimental
Michalis Spyrou95abfdd2018-11-28 14:59:47 +0000117} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000118#endif /* ARM_COMPUTE_NEACTIVATIONLAYER_H */