blob: d9dc0a0702e94c36ee93768bd7f8d347e9bc6199 [file] [log] [blame]
Matthew Benthamf1aeab92023-05-30 13:35:34 +00001/*
2 * Copyright (c) 2016-2023 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_ACTIVATIONLAYERINFO_H
25#define ARM_COMPUTE_ACTIVATIONLAYERINFO_H
26
27#include "arm_compute/core/Coordinates.h"
28#include "arm_compute/core/QuantizationInfo.h"
29#include "arm_compute/core/Size2D.h"
30#include "arm_compute/core/Size3D.h"
31#include "arm_compute/core/Strides.h"
32#include "arm_compute/core/TensorShape.h"
33#include "arm_compute/core/Types.h"
34#include "arm_compute/core/experimental/IPostOp.h"
35#include "arm_compute/core/utils/misc/Macros.h"
36#include "support/Bfloat16.h"
37#include "support/Half.h"
38
39#include <cmath>
40#include <cstddef>
41#include <cstdint>
42#include <map>
43#include <string>
44#include <utility>
45
46namespace arm_compute
47{
48/** Activation Layer Information class */
49class ActivationLayerInfo
50{
51public:
52 typedef arm_compute::ActivationFunction ActivationFunction;
53
54 /** Lookup table */
55 using LookupTable256 = std::array<qasymm8_t, 256>;
56
57 ActivationLayerInfo() = default;
58 /** Default Constructor
59 *
60 * @param[in] f The activation function to use.
61 * @param[in] a (Optional) The alpha parameter used by some activation functions
62 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
63 * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH).
64 */
65 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
66 : _act(f), _a(a), _b(b), _enabled(true)
67 {
68 }
69 /** Get the type of activation function */
70 ActivationFunction activation() const
71 {
72 return _act;
73 }
74 /** Get the alpha value */
75 float a() const
76 {
77 return _a;
78 }
79 /** Get the beta value */
80 float b() const
81 {
82 return _b;
83 }
84 /** Check if initialised */
85 bool enabled() const
86 {
87 return _enabled;
88 }
89
90#ifdef __aarch64__
91 const LookupTable256 &lut() const
92 {
93 return _lut;
94 }
95 void setLookupTable256(LookupTable256 &lut)
96 {
97 _lut = std::move(lut);
98 }
99#endif // __aarch64__
100private:
101 ActivationFunction _act = { ActivationLayerInfo::ActivationFunction::IDENTITY };
102 float _a = {};
103 float _b = {};
104 bool _enabled = { false };
105
106#ifdef __aarch64__
107 LookupTable256 _lut = {};
108#endif // __aarch64__
109};
110} // namespace arm_compute
111#endif /* ARM_COMPUTE_ACTIVATIONLAYERINFO_H */