blob: 97f92d6a1e094d3ece54a359d5a4c56d944b7a5d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 ARM Limited.
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 */
24#ifndef __ARM_COMPUTE_NEACTIVATIONLAYERKERNEL_H__
25#define __ARM_COMPUTE_NEACTIVATIONLAYERKERNEL_H__
26
27#include "arm_compute/core/FixedPoint.h"
28#include "arm_compute/core/NEON/INESimpleKernel.h"
29
30namespace arm_compute
31{
32class ITensor;
33
34/** Interface for the activation layer kernel. */
35class NEActivationLayerKernel : public INESimpleKernel
36{
37public:
38 /** Constructor */
39 NEActivationLayerKernel();
40 /** Prevent instances of this class from being copied (As this class contains pointers) */
41 NEActivationLayerKernel(const NEActivationLayerKernel &) = delete;
42 /** Default move constructor */
43 NEActivationLayerKernel(NEActivationLayerKernel &&) = default;
44 /** Prevent instances of this class from being copied (As this class contains pointers) */
45 NEActivationLayerKernel &operator=(const NEActivationLayerKernel &) = delete;
46 /** Default move assignment operator */
47 NEActivationLayerKernel &operator=(NEActivationLayerKernel &&) = default;
48 /** Set the input and output tensor.
49 *
50 * @param[in] input Source tensor. Data types supported: QS8/F32.
51 * @param[out] output Destination tensor. Data type supported: same as @p input
52 * @param[in] activation_info Activation layer information.
53 */
54 void configure(const ITensor *input, ITensor *output, ActivationLayerInfo activation_info);
55
56 // Inherited methods overridden:
57 void run(const Window &window) override;
58
59private:
60 using ActivationFunction = ActivationLayerInfo::ActivationFunction;
61 /** Common signature for all the specialised @ref NEActivationLayerKernel functions
62 *
63 * @param[in] window Region on which to execute the kernel.
64 */
65 using ActivationFunctionExecutorPtr = void (NEActivationLayerKernel::*)(const Window &window);
66 /** Function to apply an activation function on a tensor.
67 *
68 * @param[in] window Region on which to execute the kernel
69 */
70 template <ActivationLayerInfo::ActivationFunction F, typename T>
71 typename std::enable_if<std::is_same<T, float>::value, void>::type activation(const Window &window);
72 /** Function to apply an activation function on a tensor.
73 *
74 * @param[in] window Region on which to execute the kernel
75 */
76 template <ActivationLayerInfo::ActivationFunction F, typename T>
77 typename std::enable_if<std::is_same<T, qint8_t>::value, void>::type activation(const Window &window);
78
79private:
80 ActivationFunctionExecutorPtr _func;
81 ActivationLayerInfo _act_info;
82};
83}
84#endif /*__ARM_COMPUTE_NEACTIVATIONLAYERKERNEL_H__ */