blob: 280efe11f8ffd46b57850ac2bb0616b8412a077f [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +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_GCSOFTMAXLAYERKERNEL_H
25#define ARM_COMPUTE_GCSOFTMAXLAYERKERNEL_H
Anthony Barbier7068f992017-10-26 15:23:08 +010026
27#include "arm_compute/core/GLES_COMPUTE/IGCSimple3DKernel.h"
28
29namespace arm_compute
30{
31class IGCTensor;
32
33/** Interface for the identifying the max value of 1D Logits */
34class GCLogits1DMaxKernel : public IGCSimple3DKernel
35{
36public:
37 /** Set the input and output tensors.
38 *
39 * @param[in] input Source tensor. Data types supported: F16/F32
40 * @param[out] output Destination tensor. Data types supported: same as @p input
41 */
42 void configure(const IGCTensor *input, IGCTensor *output);
Anthony Barbier7068f992017-10-26 15:23:08 +010043};
44
45/** Interface for shifting the logits values around the max value and exponentiating the result */
46class GCLogits1DShiftExpSumKernel : public IGCKernel
47{
48public:
49 /** Default constructor */
50 GCLogits1DShiftExpSumKernel();
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 GCLogits1DShiftExpSumKernel(const GCLogits1DShiftExpSumKernel &) = delete;
53 /** Prevent instances of this class from being copied (As this class contains pointers) */
54 GCLogits1DShiftExpSumKernel &operator=(const GCLogits1DShiftExpSumKernel &) = delete;
55 /** Allow instances of this class to be moved */
56 GCLogits1DShiftExpSumKernel(GCLogits1DShiftExpSumKernel &&) = default;
57 /** Allow instances of this class to be moved */
58 GCLogits1DShiftExpSumKernel &operator=(GCLogits1DShiftExpSumKernel &&) = default;
59 /** Set the input and output tensors.
60 *
61 * @param[in] input Source tensor. Data types supported: F16/F32
62 * @param[in] max Max values tensor. Data types supported: same as @p input
63 * @param[out] output Destination tensor. Data types supported: same as @p input
64 * @param[out] sum Sum of 1D logits tensor. Data types supported: same as @p input
65 */
66 void configure(const IGCTensor *input, const IGCTensor *max, IGCTensor *output, IGCTensor *sum);
67
68 // Inherited methods overridden:
69 void run(const Window &window) override;
70
71private:
72 const IGCTensor *_input;
73 const IGCTensor *_max;
74 IGCTensor *_output;
75 IGCTensor *_sum;
76};
77
78/** Interface for calculating the final step of the Softmax Layer where each logit value is multiplied by the inverse of the sum of the logits. */
79class GCLogits1DNormKernel : public IGCKernel
80{
81public:
82 /** Default constructor */
83 GCLogits1DNormKernel();
84 /** Prevent instances of this class from being copied (As this class contains pointers) */
85 GCLogits1DNormKernel(const GCLogits1DNormKernel &) = delete;
86 /** Prevent instances of this class from being copied (As this class contains pointers) */
87 GCLogits1DNormKernel &operator=(const GCLogits1DNormKernel &) = delete;
88 /** Allow instances of this class to be moved */
89 GCLogits1DNormKernel(GCLogits1DNormKernel &&) = default;
90 /** Allow instances of this class to be moved */
91 GCLogits1DNormKernel &operator=(GCLogits1DNormKernel &&) = default;
92 /** Set the input and output tensors.
93 *
94 * @param[in] input Source tensor. Data types supported: F16/F32
95 * @param[in] sum Sum tensor. Dimensions should be dim(input)-1. Data types supported: same as @p input
96 * @param[out] output Destination tensor. Data types supported: same as @p input
97 */
98 void configure(const IGCTensor *input, const IGCTensor *sum, IGCTensor *output);
99
100 // Inherited methods overridden:
101 void run(const Window &window) override;
102
103private:
104 const IGCTensor *_input;
105 const IGCTensor *_sum;
106 IGCTensor *_output;
107};
108} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000109#endif /*ARM_COMPUTE_GCSOFTMAXLAYERKERNEL_H */