blob: 84743508df399dec239d7fb21028e2ab0d9bea0e [file] [log] [blame]
giuros011e6e1b82019-05-14 16:12:53 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
giuros011e6e1b82019-05-14 16:12:53 +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_CLPRELULAYER_H
25#define ARM_COMPUTE_CLPRELULAYER_H
giuros011e6e1b82019-05-14 16:12:53 +010026
Michalis Spyrouad7515d2020-07-24 00:02:23 +010027#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h"
28#include "arm_compute/runtime/CL/ICLOperator.h"
29#include "arm_compute/runtime/IFunction.h"
giuros011e6e1b82019-05-14 16:12:53 +010030
31namespace arm_compute
32{
33class ICLTensor;
34
Michalis Spyrouad7515d2020-07-24 00:02:23 +010035namespace experimental
36{
giuros011e6e1b82019-05-14 16:12:53 +010037/** Basic function to run @ref CLArithmeticOperationKernel for PRELU
38 *
39 * @note The function implements an activation layer with the PRELU activation function.
40 */
Michalis Spyrouad7515d2020-07-24 00:02:23 +010041class CLPReluLayer : public ICLOperator
giuros011e6e1b82019-05-14 16:12:53 +010042{
43public:
Michalis Spyrouad7515d2020-07-24 00:02:23 +010044 /** Default Constructor */
45 CLPReluLayer();
46 /** Set the input and output tensor.
47 *
48 * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
49 *
50 * @param[in] compile_context The compile context to be used.
51 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
52 * @param[in] alpha PRelu layer parameters. Data types supported: same of @p input.
53 * @param[out] output Destination tensor. Data type supported: same as @p input
54 */
55 void configure(const CLCompileContext &compile_context, ITensorInfo *input, ITensorInfo *alpha, ITensorInfo *output);
56 /** Static function to check if given info will lead to a valid configuration of @ref CLPReluLayer
57 *
58 * @param[in] input Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
59 * @param[in] alpha PRelu layer parameters. Data types supported: same of @p input.
60 * @param[in] output Destination tensor info. Data type supported: same as @p input
61 *
62 * @return a status
63 */
64 static Status validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output);
65
66 // Inherited methods overridden:
Georgios Pinitas0499dff2020-07-31 22:21:38 +010067 void run(ITensorPack &tensors) override;
Michalis Spyrouad7515d2020-07-24 00:02:23 +010068
69private:
70 CLFillBorderKernel _border_handler;
71};
72} // namespace experimental
73
74/** Basic function to run @ref CLArithmeticOperationKernel for PRELU
75 *
76 * @note The function implements an activation layer with the PRELU activation function.
77 */
78class CLPReluLayer : public IFunction
79{
80public:
81 /** Default Constructor */
82 CLPReluLayer();
83 /** Default Destructor */
84 ~CLPReluLayer();
85 /** Prevent instances of this class from being copied (As this class contains pointers) */
86 CLPReluLayer(const CLPReluLayer &) = delete;
87 /** Default move constructor */
88 CLPReluLayer(CLPReluLayer &&);
89 /** Prevent instances of this class from being copied (As this class contains pointers) */
90 CLPReluLayer &operator=(const CLPReluLayer &) = delete;
91 /** Default move assignment operator */
92 CLPReluLayer &operator=(CLPReluLayer &&);
giuros011e6e1b82019-05-14 16:12:53 +010093 /** Set the input and output tensor.
94 *
95 * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
96 *
Michele Di Giorgiocbbed282019-12-20 13:26:08 +000097 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
giuros011e6e1b82019-05-14 16:12:53 +010098 * @param[in] alpha PRelu layer parameters. Data types supported: same of @p input.
99 * @param[out] output Destination tensor. Data type supported: same as @p input
100 */
101 void configure(ICLTensor *input, ICLTensor *alpha, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +0100102 /** Set the input and output tensor.
103 *
104 * @note If the output tensor is a nullptr or is equal to the input, the activation function will be performed in-place
105 *
106 * @param[in] compile_context The compile context to be used.
107 * @param[in] input Source tensor. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
108 * @param[in] alpha PRelu layer parameters. Data types supported: same of @p input.
109 * @param[out] output Destination tensor. Data type supported: same as @p input
110 */
111 void configure(const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *alpha, ICLTensor *output);
giuros011e6e1b82019-05-14 16:12:53 +0100112 /** Static function to check if given info will lead to a valid configuration of @ref CLPReluLayer
113 *
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000114 * @param[in] input Source tensor info. Data types supported: QASYMM8/QASYMM8_SIGNED/F16/F32.
giuros011e6e1b82019-05-14 16:12:53 +0100115 * @param[in] alpha PRelu layer parameters. Data types supported: same of @p input.
116 * @param[in] output Destination tensor info. Data type supported: same as @p input
117 *
118 * @return a status
119 */
120 static Status validate(const ITensorInfo *input, const ITensorInfo *alpha, const ITensorInfo *output);
Michalis Spyrouad7515d2020-07-24 00:02:23 +0100121
122 // Inherited methods overridden:
123 void run() override;
124
125private:
126 struct Impl;
127 std::unique_ptr<Impl> _impl;
giuros011e6e1b82019-05-14 16:12:53 +0100128};
129} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000130#endif /* ARM_COMPUTE_CLPRELULAYER_H */