blob: 168a06a55cfe15e788b606aa73ed7940cc3252fc [file] [log] [blame]
Georgios Pinitas0bc78492019-03-18 20:07:37 +00001/*
Gian Marco Iodice3cce35d2022-12-30 16:07:45 +00002 * Copyright (c) 2019-2023 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 */
Jakub Sujak0d27b2e2023-08-24 14:01:20 +010024#ifndef ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS_H
25#define ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS_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"
SiCong Li91295492023-07-21 18:16:13 +010029#include "arm_compute/function_info/ActivationLayerInfo.h"
Gian Marco Iodiceca1f4602019-07-16 15:46:48 +010030
Georgios Pinitas0bc78492019-03-18 20:07:37 +000031namespace arm_compute
32{
Georgios Pinitas8be91482019-03-26 17:23:28 +000033/** Descriptor for FFT scale kernels */
34struct FFTScaleKernelInfo
Georgios Pinitas0bc78492019-03-18 20:07:37 +000035{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010036 float scale{0.f}; /**< Axis to perform the kernel on. */
37 bool conjugate{true}; /**< Flag to conjugate the output/ */
Georgios Pinitas8be91482019-03-26 17:23:28 +000038};
39
40/** Descriptor for FFT digit reverse kernels */
41struct FFTDigitReverseKernelInfo
42{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043 unsigned int axis{0}; /**< Axis to perform the kernel on. */
44 bool conjugate{false}; /**< Flag to conjugate the output/ */
Georgios Pinitas8be91482019-03-26 17:23:28 +000045};
46
47/** Descriptor used by the FFT core kernels */
48struct FFTRadixStageKernelInfo
49{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050 unsigned int axis{0}; /**< Axis to run the kernel on. */
51 unsigned int radix{0}; /**< Radix to use. */
52 unsigned int Nx{0}; /**< Nx coefficient. */
53 bool is_first_stage{false}; /**< Flags if the FFT kernels is the first stage of a decomposed FFT. */
Georgios Pinitas0bc78492019-03-18 20:07:37 +000054};
Gian Marco Iodice7026b302019-06-26 17:18:11 +010055
SiCongLi1af54162021-10-06 15:25:57 +010056class ITensorInfo;
Gian Marco Iodice7026b302019-06-26 17:18:11 +010057/** Descriptor used by the GEMM kernels */
58struct GEMMKernelInfo
59{
morgolockaba2f912020-05-05 16:28:19 +010060 GEMMKernelInfo() = default;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061 GEMMKernelInfo(unsigned int im,
62 unsigned int in,
63 unsigned int ik,
64 unsigned int idepth_output_gemm3d,
65 bool ireinterpret_input_as_3d,
66 bool ibroadcast_bias,
67 bool ifp_mixed_precision,
68 bool ihas_pad_y,
69 ActivationLayerInfo iactivation_info,
70 int inmult_transpose1xW_width,
71 int imult_interleave4x4_height,
72 GEMMLHSMatrixInfo ilhs_info,
73 GEMMRHSMatrixInfo irhs_info,
74 int32_t ina_offset,
75 int32_t inb_offset)
76 : m(im),
77 n(in),
78 k(ik),
79 depth_output_gemm3d(idepth_output_gemm3d),
80 reinterpret_input_as_3d(ireinterpret_input_as_3d),
81 broadcast_bias(ibroadcast_bias),
82 fp_mixed_precision(ifp_mixed_precision),
83 has_pad_y(ihas_pad_y),
84 activation_info(iactivation_info),
85 mult_transpose1xW_width(inmult_transpose1xW_width),
86 mult_interleave4x4_height(imult_interleave4x4_height),
87 lhs_info(ilhs_info),
88 rhs_info(irhs_info),
89 a_offset(ina_offset),
90 b_offset(inb_offset)
morgolockaba2f912020-05-05 16:28:19 +010091 {
92 }
93
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010094 unsigned int m{0}; /**< Number of LHS rows*/
95 unsigned int n{0}; /**< Number of RHS columns*/
96 unsigned int k{0}; /**< Number of LHS columns or RHS rows */
97 unsigned int depth_output_gemm3d{0}; /**< Depth of the output tensor in case is reinterpreted as 3D */
98 bool reinterpret_input_as_3d{false}; /**< Flag used to reinterpret the input as 3D */
99 bool broadcast_bias{false}; /**< Flag used to broadcast the bias addition */
100 bool fp_mixed_precision{false}; /**< Flag used to indicate wider accumulators (32 bit instead of 16 for FP16). */
101 bool has_pad_y{
102 false}; /**< Flag used to indicate if the input/output tensors have internal pad on the y direction */
103 ActivationLayerInfo activation_info{}; /**< Activation function to perform after the matrix multiplication */
104 int mult_transpose1xW_width{1}; /**< Multiplication factor for the width of the 1xW transposed block */
105 int mult_interleave4x4_height{1}; /**< Multiplication factor for the height of the 4x4 interleaved block */
106 GEMMLHSMatrixInfo
107 lhs_info{}; /**< LHS matrix information used to retrieve the number of rows processed by each thread */
108 GEMMRHSMatrixInfo rhs_info{}; /**< RHS matrix information used for reshaping the RHS matrix */
109 int32_t a_offset{0}; /**< Offset to be added to each element of the matrix A */
110 int32_t b_offset{0}; /**< Offset to be added to each element of the matrix B */
111 GEMMLowpOutputStageInfo output_stage{}; /**< GEMMLowp output stage information */
Gian Marco Iodice7026b302019-06-26 17:18:11 +0100112};
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100113
Gian Marco Iodice8155c022021-04-16 15:08:59 +0100114/** Compute descriptor used by the depthwise convolution native kernel */
115struct DWCComputeKernelInfo
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100116{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100117 unsigned int n0{1}; /**< Number of columns processed by each thread */
118 unsigned int m0{1}; /**< Number of rows processed by each thread */
119 bool export_input_to_cl_image{false}; /**< Export input to cl_image */
120 bool export_weights_to_cl_image{false}; /**< Export the weights to cl_image */
Gian Marco Iodice9285adb2019-09-05 16:10:27 +0100121};
Sang-Hoon Park62eeb532019-10-29 13:13:19 +0000122
Gian Marco Iodice2cc50b32022-05-30 14:41:49 +0100123/** Compute descriptor used by the direct convolution kernel */
124struct DirectConvComputeKernelInfo
125{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100126 int32_t m0{1}; /**< Number of rows to be processed by the kernel */
127 int32_t n0{1}; /**< Number of columns to be processed by the kernel */
128 int32_t k0{1}; /**< Number of partial accumulations to be processed in a single iteration by the kernel */
129 bool export_weights_to_cl_image{false}; /**< Flag to export the weights to cl_image */
130 bool export_output_to_cl_image{false}; /**< Flag to export the output to cl_image */
131 bool export_input_to_cl_image{false}; /**< Flag to export the input to cl_image */
Gian Marco Iodice2cc50b32022-05-30 14:41:49 +0100132};
133
Sang-Hoon Park62eeb532019-10-29 13:13:19 +0000134/** Descriptor used by the softmax kernels */
135struct SoftmaxKernelInfo
136{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100137 float beta{1.f}; /**< A scaling factor for the exponent with default value 1.0 */
138 bool is_log{false}; /**< Flag used to perform Log Softmax operation */
139 DataType input_data_type{DataType::UNKNOWN}; /**< Input tensor data type */
140 int32_t axis{0}; /**< The dimension in which to apply softmax. */
Sang-Hoon Park62eeb532019-10-29 13:13:19 +0000141};
Michele Di Giorgio45361932019-12-19 13:53:44 +0000142
143/** Descriptor used by the direct convolution layer output stage kernels */
144struct DirectConvolutionLayerOutputStageKernelInfo
145{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100146 int32_t result_fixedpoint_multiplier{0}; /**< Result output stage multiplier used for quantizing */
147 int32_t result_shift{0}; /**< Result output stage shift used for quantizing */
148 int32_t result_offset_after_shift{0}; /**< Result offset used for quantizing */
149 DataType output_data_type{
150 DataType::UNKNOWN}; /**< Output tensor data type to use if the output is not initialized */
Michele Di Giorgio45361932019-12-19 13:53:44 +0000151};
Georgios Pinitas55a687d2020-01-30 12:00:23 +0000152
153struct InstanceNormalizationLayerKernelInfo
154{
155 /** Default constructor */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100156 InstanceNormalizationLayerKernelInfo() : InstanceNormalizationLayerKernelInfo(1.f, 0.f, 1e-12, true)
Georgios Pinitas55a687d2020-01-30 12:00:23 +0000157 {
158 }
159 /** Constructor
160 *
161 * @param[in] gamma The scale scalar value applied to the normalized tensor.
162 * @param[in] beta The offset scalar value applied to the normalized tensor
163 * @param[in] epsilon Lower bound value for the normalization.
164 * @param[in] use_mixed_precision Use mixed precision in case of FP16 execution.
165 */
166 InstanceNormalizationLayerKernelInfo(float gamma, float beta, float epsilon, bool use_mixed_precision)
167 : gamma(gamma), beta(beta), epsilon(epsilon), use_mixed_precision(use_mixed_precision)
168 {
169 }
170
171 float gamma; /**< The scale scalar value applied to the normalized tensor. Defaults to 1.0 */
172 float beta; /**< The offset scalar value applied to the normalized tensor. Defaults to 0.0 */
173 float epsilon; /**< Lower bound value for the normalization. Defaults to 1e-12 */
174 bool use_mixed_precision; /**< Use mixed precision in case of FP16 execution. Defaults to true */
175};
Michele Di Giorgioa602f032020-03-12 19:34:33 +0000176
177struct GEMMLowpReductionKernelInfo
178{
179 /** Default constructor */
180 GEMMLowpReductionKernelInfo() = default;
181 /** Constructor
182 *
183 * @param[in] k Number of matrix columns/rows.
184 * @param[in] is_reshaped True if the input tensor has been reshaped.
185 * @param[in] scalar Scalar value to multiply each reduced column/row by.
186 * @param[in] mul_by_scalar True if each column/row reduction has to be multiplied by a scalar value.
187 */
188 GEMMLowpReductionKernelInfo(int32_t k, bool is_reshaped, int32_t scalar, bool mul_by_scalar)
189 : k(k), is_reshaped(is_reshaped), scalar(scalar), mul_by_scalar(mul_by_scalar)
190 {
191 }
192
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100193 int32_t k{0}; /**< Number of matrix columns/rows */
194 bool is_reshaped{false}; /**< True if the input tensor has been reshaped */
195 int32_t scalar{0}; /**< Scalar value to multiply each reduced column/row by */
196 bool mul_by_scalar{false}; /**< True if each column/row reduction has to be multiplied by a scalar value */
Michele Di Giorgioa602f032020-03-12 19:34:33 +0000197};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100198
199struct ScaleKernelInfo
200{
201 /** Constructor
202 *
203 * @param[in] interpolation_policy Interpolation type to use
204 * @param[in] border_mode Border mode policy
205 * @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
206 * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
207 * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
208 * @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 +0000209 * @param[in] data_layout (Optional) Data layout used by the layer. Defaults to @ref DataLayout::UNKNOWN
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100210 */
211 ScaleKernelInfo(InterpolationPolicy interpolation_policy,
212 BorderMode border_mode,
213 PixelValue constant_border_value = PixelValue(),
214 SamplingPolicy sampling_policy = SamplingPolicy::CENTER,
215 bool use_padding = true,
Michele Di Giorgio655e8c62021-01-28 12:51:02 +0000216 bool align_corners = false,
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000217 DataLayout data_layout = DataLayout::UNKNOWN) noexcept
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100218 : interpolation_policy{interpolation_policy},
219 border_mode{border_mode},
220 constant_border_value{constant_border_value},
221 sampling_policy{sampling_policy},
222 use_padding{use_padding},
223 align_corners{align_corners},
224 data_layout{data_layout}
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100225 {
226 }
227
228 InterpolationPolicy interpolation_policy; /**< Interpolation type to use */
229 BorderMode border_mode; /**< Border mode policy */
230 PixelValue constant_border_value; /**< Constant value to use for constant border mode policy */
231 SamplingPolicy sampling_policy; /**< Sampling policy used by the interpolation. */
232 bool use_padding; /**< Indication of using padding */
233 bool align_corners; /**< Align corners of input and output */
Michele Di Giorgio655e8c62021-01-28 12:51:02 +0000234 DataLayout data_layout; /**< Data layout to use */
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100235};
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000236
237struct MatMulKernelInfo
238{
Gian Marco Iodice352c07d2023-05-03 12:21:38 +0100239 MatMulKernelInfo() = default;
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100240 MatMulKernelInfo(
241 bool adj_lhs, bool adj_rhs, int m0 = 1, int n0 = 1, int k0 = 1, bool export_rhs_to_cl_image = false)
242 : adj_lhs{adj_lhs}, adj_rhs{adj_rhs}, m0{m0}, n0{n0}, k0{k0}, export_rhs_to_cl_image{export_rhs_to_cl_image}
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000243 {
244 }
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100245 bool adj_lhs{false}; /**< Get Adjoint LHS flag value */
246 bool adj_rhs{false}; /**< Get Adjoint RHS flag value */
247 int m0{1}; /**< Number of output rows processed by each work-item*/
248 int n0{1}; /**< Number of output columns processed by each work-item*/
249 int k0{1}; /**< Number of inner accumulations */
250 bool export_rhs_to_cl_image{false}; /**< Flag to know whether the RHS tensor should be exported to cl_image*/
Ramy Elgammal2b6ebfe2023-03-09 21:15:37 +0000251};
Georgios Pinitas0bc78492019-03-18 20:07:37 +0000252} // namespace arm_compute
Jakub Sujak0d27b2e2023-08-24 14:01:20 +0100253#endif // ACL_ARM_COMPUTE_CORE_KERNELDESCRIPTORS_H