blob: 0025301e480603f00f4e7a458ee99f3e7456dd5c [file] [log] [blame]
Georgios Pinitas0bc78492019-03-18 20:07:37 +00001/*
Michele Di Giorgio655e8c62021-01-28 12:51:02 +00002 * Copyright (c) 2019-2021 Arm Limited.
Georgios Pinitas0bc78492019-03-18 20:07:37 +00003 *
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_CORE_KERNEL_DESCRIPTORS_H
25#define ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H
Georgios Pinitas0bc78492019-03-18 20:07:37 +000026
Sang-Hoon Parkc2617982020-05-20 22:13:47 +010027#include "arm_compute/core/PixelValue.h"
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010028#include "arm_compute/core/Types.h"
29
Georgios Pinitas0bc78492019-03-18 20:07:37 +000030namespace arm_compute
31{
Georgios Pinitas8be91482019-03-26 17:23:28 +000032/** Descriptor for FFT scale kernels */
33struct FFTScaleKernelInfo
Georgios Pinitas0bc78492019-03-18 20:07:37 +000034{
Georgios Pinitas8be91482019-03-26 17:23:28 +000035 float scale{ 0.f }; /**< Axis to perform the kernel on. */
36 bool conjugate{ true }; /**< Flag to conjugate the output/ */
37};
38
39/** Descriptor for FFT digit reverse kernels */
40struct FFTDigitReverseKernelInfo
41{
42 unsigned int axis{ 0 }; /**< Axis to perform the kernel on. */
43 bool conjugate{ false }; /**< Flag to conjugate the output/ */
44};
45
46/** Descriptor used by the FFT core kernels */
47struct FFTRadixStageKernelInfo
48{
49 unsigned int axis{ 0 }; /**< Axis to run the kernel on. */
Georgios Pinitas0bc78492019-03-18 20:07:37 +000050 unsigned int radix{ 0 }; /**< Radix to use. */
51 unsigned int Nx{ 0 }; /**< Nx coefficient. */
52 bool is_first_stage{ false }; /**< Flags if the FFT kernels is the first stage of a decomposed FFT. */
53};
Gian Marco Iodice7026b302019-06-26 17:18:11 +010054
55/** Descriptor used by the GEMM kernels */
56struct GEMMKernelInfo
57{
morgolockaba2f912020-05-05 16:28:19 +010058 GEMMKernelInfo() = default;
59 GEMMKernelInfo(
60 unsigned int im,
61 unsigned int in,
62 unsigned int ik,
63 unsigned int idepth_output_gemm3d,
64 bool ireinterpret_input_as_3d,
65 bool ibroadcast_bias,
66 bool ifp_mixed_precision,
Gian Marco Iodice9ae06d42020-10-22 16:37:12 +010067 bool ihas_pad_y,
morgolockaba2f912020-05-05 16:28:19 +010068 ActivationLayerInfo iactivation_info,
69 int inmult_transpose1xW_width,
70 int imult_interleave4x4_height,
71 GEMMLHSMatrixInfo ilhs_info,
72 GEMMRHSMatrixInfo irhs_info,
73 int32_t ina_offset,
74 int32_t inb_offset)
75 : m(im), n(in), k(ik), depth_output_gemm3d(idepth_output_gemm3d), reinterpret_input_as_3d(ireinterpret_input_as_3d), broadcast_bias(ibroadcast_bias), fp_mixed_precision(ifp_mixed_precision),
Michele Di Giorgio655e8c62021-01-28 12:51:02 +000076 has_pad_y(ihas_pad_y), activation_info(iactivation_info), mult_transpose1xW_width(inmult_transpose1xW_width), mult_interleave4x4_height(imult_interleave4x4_height), lhs_info(ilhs_info),
77 rhs_info(irhs_info), a_offset(ina_offset), b_offset(inb_offset)
morgolockaba2f912020-05-05 16:28:19 +010078 {
79 }
80
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000081 unsigned int m{ 0 }; /**< Number of LHS rows*/
82 unsigned int n{ 0 }; /**< Number of RHS columns*/
83 unsigned int k{ 0 }; /**< Number of LHS columns or RHS rows */
84 unsigned int depth_output_gemm3d{ 0 }; /**< Depth of the output tensor in case is reinterpreted as 3D */
85 bool reinterpret_input_as_3d{ false }; /**< Flag used to reinterpret the input as 3D */
86 bool broadcast_bias{ false }; /**< Flag used to broadcast the bias addition */
87 bool fp_mixed_precision{ false }; /**< Flag used to indicate wider accumulators (32 bit instead of 16 for FP16). */
Gian Marco Iodice9ae06d42020-10-22 16:37:12 +010088 bool has_pad_y{ false }; /**< Flag used to indicate if the input/output tensors have internal pad on the y direction */
Michele Di Giorgiob54ba282020-01-14 15:31:55 +000089 ActivationLayerInfo activation_info{}; /**< Activation function to perform after the matrix multiplication */
90 int mult_transpose1xW_width{ 1 }; /**< Multiplication factor for the width of the 1xW transposed block */
91 int mult_interleave4x4_height{ 1 }; /**< Multiplication factor for the height of the 4x4 interleaved block */
92 GEMMLHSMatrixInfo lhs_info{}; /**< LHS matrix information used to retrieve the number of rows processed by each thread */
93 GEMMRHSMatrixInfo rhs_info{}; /**< RHS matrix information used for reshaping the RHS matrix */
94 int32_t a_offset{ 0 }; /**< Offset to be added to each element of the matrix A */
95 int32_t b_offset{ 0 }; /**< Offset to be added to each element of the matrix B */
96 GEMMLowpOutputStageInfo output_stage{}; /**< GEMMLowp output stage information */
Gian Marco Iodice7026b302019-06-26 17:18:11 +010097};
Gian Marco Iodice9285adb2019-09-05 16:10:27 +010098
99/** Descriptor used by the depthwise convolution kernels */
100struct DWCKernelInfo
101{
102 ActivationLayerInfo activation_info{}; /**< Activation function to perform after the depthwise convolution */
103};
104
105/** Descriptor used by the depthwise convolution kernels to retrieve the number of output elements processed by each thread */
106struct DWCWeightsKernelInfo
107{
108 unsigned int n0{ 0 }; /**< Number of columns processed by each thread */
109};
Sang-Hoon Park62eeb532019-10-29 13:13:19 +0000110
111/** Descriptor used by the softmax kernels */
112struct SoftmaxKernelInfo
113{
Sang-Hoon Park0779fec2019-11-13 17:08:12 +0000114 float beta{ 1.f }; /**< A scaling factor for the exponent with default value 1.0 */
115 bool is_log{ false }; /**< Flag used to perform Log Softmax operation */
116 DataType input_data_type{ DataType::UNKNOWN }; /**< Input tensor data type */
Sang-Hoon Park201e0fe2021-01-27 13:14:56 +0000117 int32_t axis{ 0 }; /**< The dimension in which to apply softmax. */
Sang-Hoon Park62eeb532019-10-29 13:13:19 +0000118};
Michele Di Giorgio45361932019-12-19 13:53:44 +0000119
120/** Descriptor used by the direct convolution layer output stage kernels */
121struct DirectConvolutionLayerOutputStageKernelInfo
122{
123 int32_t result_fixedpoint_multiplier{ 0 }; /**< Result output stage multiplier used for quantizing */
124 int32_t result_shift{ 0 }; /**< Result output stage shift used for quantizing */
125 int32_t result_offset_after_shift{ 0 }; /**< Result offset used for quantizing */
126 DataType output_data_type{ DataType::UNKNOWN }; /**< Output tensor data type to use if the output is not initialized */
127};
Georgios Pinitas55a687d2020-01-30 12:00:23 +0000128
129struct InstanceNormalizationLayerKernelInfo
130{
131 /** Default constructor */
132 InstanceNormalizationLayerKernelInfo()
133 : InstanceNormalizationLayerKernelInfo(1.f, 0.f, 1e-12, true)
134 {
135 }
136 /** Constructor
137 *
138 * @param[in] gamma The scale scalar value applied to the normalized tensor.
139 * @param[in] beta The offset scalar value applied to the normalized tensor
140 * @param[in] epsilon Lower bound value for the normalization.
141 * @param[in] use_mixed_precision Use mixed precision in case of FP16 execution.
142 */
143 InstanceNormalizationLayerKernelInfo(float gamma, float beta, float epsilon, bool use_mixed_precision)
144 : gamma(gamma), beta(beta), epsilon(epsilon), use_mixed_precision(use_mixed_precision)
145 {
146 }
147
148 float gamma; /**< The scale scalar value applied to the normalized tensor. Defaults to 1.0 */
149 float beta; /**< The offset scalar value applied to the normalized tensor. Defaults to 0.0 */
150 float epsilon; /**< Lower bound value for the normalization. Defaults to 1e-12 */
151 bool use_mixed_precision; /**< Use mixed precision in case of FP16 execution. Defaults to true */
152};
Michele Di Giorgioa602f032020-03-12 19:34:33 +0000153
154struct GEMMLowpReductionKernelInfo
155{
156 /** Default constructor */
157 GEMMLowpReductionKernelInfo() = default;
158 /** Constructor
159 *
160 * @param[in] k Number of matrix columns/rows.
161 * @param[in] is_reshaped True if the input tensor has been reshaped.
162 * @param[in] scalar Scalar value to multiply each reduced column/row by.
163 * @param[in] mul_by_scalar True if each column/row reduction has to be multiplied by a scalar value.
164 */
165 GEMMLowpReductionKernelInfo(int32_t k, bool is_reshaped, int32_t scalar, bool mul_by_scalar)
166 : k(k), is_reshaped(is_reshaped), scalar(scalar), mul_by_scalar(mul_by_scalar)
167 {
168 }
169
170 int32_t k{ 0 }; /**< Number of matrix columns/rows */
171 bool is_reshaped{ false }; /**< True if the input tensor has been reshaped */
172 int32_t scalar{ 0 }; /**< Scalar value to multiply each reduced column/row by */
173 bool mul_by_scalar{ false }; /**< True if each column/row reduction has to be multiplied by a scalar value */
174};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100175
176struct ScaleKernelInfo
177{
178 /** Constructor
179 *
180 * @param[in] interpolation_policy Interpolation type to use
181 * @param[in] border_mode Border mode policy
182 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT and use_padding is set to false. Defaults to default @ref PixelValue
183 * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
184 * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
185 * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false.
Michele Di Giorgio655e8c62021-01-28 12:51:02 +0000186 * @param[in] data_layout (Optional) Data layout used by the layer. Defaults to @ref DataLayout::UNKNOWN
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100187 */
188 ScaleKernelInfo(InterpolationPolicy interpolation_policy,
189 BorderMode border_mode,
190 PixelValue constant_border_value = PixelValue(),
191 SamplingPolicy sampling_policy = SamplingPolicy::CENTER,
192 bool use_padding = true,
Michele Di Giorgio655e8c62021-01-28 12:51:02 +0000193 bool align_corners = false,
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000194 DataLayout data_layout = DataLayout::UNKNOWN) noexcept
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100195 : interpolation_policy{ interpolation_policy },
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000196 border_mode{ border_mode },
197 constant_border_value{ constant_border_value },
198 sampling_policy{ sampling_policy },
199 use_padding{ use_padding },
200 align_corners{ align_corners },
201 data_layout{ data_layout }
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100202 {
203 }
204
205 InterpolationPolicy interpolation_policy; /**< Interpolation type to use */
206 BorderMode border_mode; /**< Border mode policy */
207 PixelValue constant_border_value; /**< Constant value to use for constant border mode policy */
208 SamplingPolicy sampling_policy; /**< Sampling policy used by the interpolation. */
209 bool use_padding; /**< Indication of using padding */
210 bool align_corners; /**< Align corners of input and output */
Michele Di Giorgio655e8c62021-01-28 12:51:02 +0000211 DataLayout data_layout; /**< Data layout to use */
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100212};
Georgios Pinitas25ef7212020-06-02 23:00:41 +0100213
214struct ThresholdKernelInfo
215{
216 /** Default constructor */
217 ThresholdKernelInfo() = default;
218 /** Constructor
219 *
220 * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
221 * @param[in] false_value value to set when the condition is not respected.
222 * @param[in] true_value value to set when the condition is respected.
223 * @param[in] type Thresholding type. Either RANGE or BINARY.
224 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
225 */
226 ThresholdKernelInfo(uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper)
227 : threshold(threshold), false_value(false_value), true_value(true_value), type(type), upper(upper)
228 {
229 }
230
231 uint8_t threshold{ 0 };
232 uint8_t false_value{ 0 };
233 uint8_t true_value{ 0 };
234 ThresholdType type{ ThresholdType::BINARY };
235 uint8_t upper{ 0 };
236};
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000237} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000238#endif /* ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H */