Compute Library
 21.11
KernelDescriptors.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2021 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_CORE_KERNEL_DESCRIPTORS_H
25 #define ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H
26 
28 #include "arm_compute/core/Types.h"
30 
31 namespace arm_compute
32 {
33 /** Descriptor for FFT scale kernels */
35 {
36  float scale{ 0.f }; /**< Axis to perform the kernel on. */
37  bool conjugate{ true }; /**< Flag to conjugate the output/ */
38 };
39 
40 /** Descriptor for FFT digit reverse kernels */
42 {
43  unsigned int axis{ 0 }; /**< Axis to perform the kernel on. */
44  bool conjugate{ false }; /**< Flag to conjugate the output/ */
45 };
46 
47 /** Descriptor used by the FFT core kernels */
49 {
50  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. */
54 };
55 
56 class ITensorInfo;
57 /** Descriptor used by the GEMM kernels */
59 {
60  GEMMKernelInfo() = default;
62  unsigned int im,
63  unsigned int in,
64  unsigned int ik,
65  unsigned int idepth_output_gemm3d,
66  bool ireinterpret_input_as_3d,
67  bool ibroadcast_bias,
68  bool ifp_mixed_precision,
69  bool ihas_pad_y,
70  ActivationLayerInfo iactivation_info,
71  int inmult_transpose1xW_width,
72  int imult_interleave4x4_height,
73  GEMMLHSMatrixInfo ilhs_info,
74  GEMMRHSMatrixInfo irhs_info,
75  int32_t ina_offset,
76  int32_t inb_offset,
78  : 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),
79  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),
80  rhs_info(irhs_info), a_offset(ina_offset), b_offset(inb_offset), post_ops(ipost_ops)
81  {
82  }
83 
84  unsigned int m{ 0 }; /**< Number of LHS rows*/
85  unsigned int n{ 0 }; /**< Number of RHS columns*/
86  unsigned int k{ 0 }; /**< Number of LHS columns or RHS rows */
87  unsigned int depth_output_gemm3d{ 0 }; /**< Depth of the output tensor in case is reinterpreted as 3D */
88  bool reinterpret_input_as_3d{ false }; /**< Flag used to reinterpret the input as 3D */
89  bool broadcast_bias{ false }; /**< Flag used to broadcast the bias addition */
90  bool fp_mixed_precision{ false }; /**< Flag used to indicate wider accumulators (32 bit instead of 16 for FP16). */
91  bool has_pad_y{ false }; /**< Flag used to indicate if the input/output tensors have internal pad on the y direction */
92  ActivationLayerInfo activation_info{}; /**< Activation function to perform after the matrix multiplication */
93  int mult_transpose1xW_width{ 1 }; /**< Multiplication factor for the width of the 1xW transposed block */
94  int mult_interleave4x4_height{ 1 }; /**< Multiplication factor for the height of the 4x4 interleaved block */
95  GEMMLHSMatrixInfo lhs_info{}; /**< LHS matrix information used to retrieve the number of rows processed by each thread */
96  GEMMRHSMatrixInfo rhs_info{}; /**< RHS matrix information used for reshaping the RHS matrix */
97  int32_t a_offset{ 0 }; /**< Offset to be added to each element of the matrix A */
98  int32_t b_offset{ 0 }; /**< Offset to be added to each element of the matrix B */
99  GEMMLowpOutputStageInfo output_stage{}; /**< GEMMLowp output stage information */
100  experimental::PostOpList<ITensorInfo *> post_ops{}; /**< (EXPERIMENTAL_POST_OPS) Specifies a list of post ops to be fused after the main op. Note unsupported post ops would not be executed.
101  * If specified, automatically disable the @ref activation_info */
102 };
103 
104 /** Compute descriptor used by the depthwise convolution native kernel */
106 {
107  unsigned int n0{ 0 }; /**< Number of columns processed by each thread */
108  unsigned int m0{ 0 }; /**< Number of rows processed by each thread */
109  bool export_weights_to_cl_image{ false }; /**< Export the weights to cl_image */
110 };
111 
112 /** Descriptor used by the softmax kernels */
114 {
115  float beta{ 1.f }; /**< A scaling factor for the exponent with default value 1.0 */
116  bool is_log{ false }; /**< Flag used to perform Log Softmax operation */
117  DataType input_data_type{ DataType::UNKNOWN }; /**< Input tensor data type */
118  int32_t axis{ 0 }; /**< The dimension in which to apply softmax. */
119 };
120 
121 /** Descriptor used by the direct convolution layer output stage kernels */
123 {
124  int32_t result_fixedpoint_multiplier{ 0 }; /**< Result output stage multiplier used for quantizing */
125  int32_t result_shift{ 0 }; /**< Result output stage shift used for quantizing */
126  int32_t result_offset_after_shift{ 0 }; /**< Result offset used for quantizing */
127  DataType output_data_type{ DataType::UNKNOWN }; /**< Output tensor data type to use if the output is not initialized */
128 };
129 
131 {
132  /** Default constructor */
134  : InstanceNormalizationLayerKernelInfo(1.f, 0.f, 1e-12, true)
135  {
136  }
137  /** Constructor
138  *
139  * @param[in] gamma The scale scalar value applied to the normalized tensor.
140  * @param[in] beta The offset scalar value applied to the normalized tensor
141  * @param[in] epsilon Lower bound value for the normalization.
142  * @param[in] use_mixed_precision Use mixed precision in case of FP16 execution.
143  */
144  InstanceNormalizationLayerKernelInfo(float gamma, float beta, float epsilon, bool use_mixed_precision)
145  : gamma(gamma), beta(beta), epsilon(epsilon), use_mixed_precision(use_mixed_precision)
146  {
147  }
148 
149  float gamma; /**< The scale scalar value applied to the normalized tensor. Defaults to 1.0 */
150  float beta; /**< The offset scalar value applied to the normalized tensor. Defaults to 0.0 */
151  float epsilon; /**< Lower bound value for the normalization. Defaults to 1e-12 */
152  bool use_mixed_precision; /**< Use mixed precision in case of FP16 execution. Defaults to true */
153 };
154 
156 {
157  /** Default constructor */
158  GEMMLowpReductionKernelInfo() = default;
159  /** Constructor
160  *
161  * @param[in] k Number of matrix columns/rows.
162  * @param[in] is_reshaped True if the input tensor has been reshaped.
163  * @param[in] scalar Scalar value to multiply each reduced column/row by.
164  * @param[in] mul_by_scalar True if each column/row reduction has to be multiplied by a scalar value.
165  */
166  GEMMLowpReductionKernelInfo(int32_t k, bool is_reshaped, int32_t scalar, bool mul_by_scalar)
167  : k(k), is_reshaped(is_reshaped), scalar(scalar), mul_by_scalar(mul_by_scalar)
168  {
169  }
170 
171  int32_t k{ 0 }; /**< Number of matrix columns/rows */
172  bool is_reshaped{ false }; /**< True if the input tensor has been reshaped */
173  int32_t scalar{ 0 }; /**< Scalar value to multiply each reduced column/row by */
174  bool mul_by_scalar{ false }; /**< True if each column/row reduction has to be multiplied by a scalar value */
175 };
176 
178 {
179  /** Constructor
180  *
181  * @param[in] interpolation_policy Interpolation type to use
182  * @param[in] border_mode Border mode policy
183  * @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
184  * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
185  * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
186  * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false.
187  * @param[in] data_layout (Optional) Data layout used by the layer. Defaults to @ref DataLayout::UNKNOWN
188  */
190  BorderMode border_mode,
191  PixelValue constant_border_value = PixelValue(),
193  bool use_padding = true,
194  bool align_corners = false,
196  : interpolation_policy{ interpolation_policy },
197  border_mode{ border_mode },
198  constant_border_value{ constant_border_value },
200  use_padding{ use_padding },
201  align_corners{ align_corners },
203  {
204  }
205 
206  InterpolationPolicy interpolation_policy; /**< Interpolation type to use */
207  BorderMode border_mode; /**< Border mode policy */
208  PixelValue constant_border_value; /**< Constant value to use for constant border mode policy */
209  SamplingPolicy sampling_policy; /**< Sampling policy used by the interpolation. */
210  bool use_padding; /**< Indication of using padding */
211  bool align_corners; /**< Align corners of input and output */
212  DataLayout data_layout; /**< Data layout to use */
213 };
214 
215 struct RemapInfo
216 {
217  RemapInfo() = default;
218  RemapInfo(InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value)
219  : policy(policy), border_mode(border_mode), constant_border_value(constant_border_value)
220  {
221  }
225 };
226 } // namespace arm_compute
227 #endif /* ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H */
BorderMode
Methods available to handle borders.
Definition: Types.h:261
BorderMode border_mode
Border mode policy.
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
InterpolationPolicy
Interpolation method.
Definition: Types.h:398
experimental::PostOpList< ITensorInfo * > post_ops
bool export_weights_to_cl_image(const ITensorInfo *tensor)
Definition: CLHelpers.cpp:431
Descriptor used by the GEMM kernels.
InterpolationPolicy interpolation_policy
Interpolation type to use.
GEMMKernelInfo(unsigned int im, unsigned int in, unsigned int ik, unsigned int idepth_output_gemm3d, bool ireinterpret_input_as_3d, bool ibroadcast_bias, bool ifp_mixed_precision, bool ihas_pad_y, ActivationLayerInfo iactivation_info, int inmult_transpose1xW_width, int imult_interleave4x4_height, GEMMLHSMatrixInfo ilhs_info, GEMMRHSMatrixInfo irhs_info, int32_t ina_offset, int32_t inb_offset, const experimental::PostOpList< ITensorInfo *> &ipost_ops=experimental::PostOpList< ITensorInfo *> {})
InstanceNormalizationLayerKernelInfo(float gamma, float beta, float epsilon, bool use_mixed_precision)
Constructor.
bool align_corners
Align corners of input and output.
GEMM LHS (Left Hand Side) matrix information.
Definition: Types.h:1938
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
bool use_padding
Indication of using padding.
Activation Layer Information class.
Definition: Types.h:1509
Copyright (c) 2017-2021 Arm Limited.
Samples are taken at pixel center.
bool use_mixed_precision
Use mixed precision in case of FP16 execution.
GEMMLowpReductionKernelInfo(int32_t k, bool is_reshaped, int32_t scalar, bool mul_by_scalar)
Constructor.
InterpolationPolicy policy
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
GEMM RHS (Right Hand Side) matrix information.
Definition: Types.h:1953
Descriptor used by the FFT core kernels.
Descriptor for FFT scale kernels.
GEMMLowp output stage info.
Definition: Types.h:1922
Compute descriptor used by the depthwise convolution native kernel.
ScaleKernelInfo(InterpolationPolicy interpolation_policy, BorderMode border_mode, PixelValue constant_border_value=PixelValue(), SamplingPolicy sampling_policy=SamplingPolicy::CENTER, bool use_padding=true, bool align_corners=false, DataLayout data_layout=DataLayout::UNKNOWN) noexcept
Constructor.
float epsilon
Lower bound value for the normalization.
Descriptor for FFT digit reverse kernels.
float gamma
The scale scalar value applied to the normalized tensor.
PixelValue constant_border_value
Constant value to use for constant border mode policy.
float scale
Axis to perform the kernel on.
Descriptor used by the softmax kernels.
DataLayout data_layout
Data layout to use.
DataType
Available data types.
Definition: Types.h:79
RemapInfo(InterpolationPolicy policy, BorderMode border_mode, PixelValue constant_border_value)
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
A sequence of PostOps that can be appended to the end of other operators.
Definition: IPostOp.h:119
float beta
The offset scalar value applied to the normalized tensor.
Descriptor used by the direct convolution layer output stage kernels.
bool conjugate
Flag to conjugate the output/.
SamplingPolicy
Available Sampling Policies.
Definition: Types.h:104