Compute Library
 20.08
KernelDescriptors.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-2020 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"
29 
30 namespace arm_compute
31 {
32 /** Descriptor for FFT scale kernels */
34 {
35  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 */
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 */
48 {
49  unsigned int axis{ 0 }; /**< Axis to run the kernel on. */
50  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 };
54 
55 /** Descriptor used by the GEMM kernels */
57 {
58  GEMMKernelInfo() = default;
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,
67  ActivationLayerInfo iactivation_info,
68  int inmult_transpose1xW_width,
69  int imult_interleave4x4_height,
70  GEMMLHSMatrixInfo ilhs_info,
71  GEMMRHSMatrixInfo irhs_info,
72  int32_t ina_offset,
73  int32_t inb_offset)
74  : 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),
75  activation_info(iactivation_info), mult_transpose1xW_width(inmult_transpose1xW_width), mult_interleave4x4_height(imult_interleave4x4_height), lhs_info(ilhs_info), rhs_info(irhs_info),
76  a_offset(ina_offset), b_offset(inb_offset)
77  {
78  }
79 
80  unsigned int m{ 0 }; /**< Number of LHS rows*/
81  unsigned int n{ 0 }; /**< Number of RHS columns*/
82  unsigned int k{ 0 }; /**< Number of LHS columns or RHS rows */
83  unsigned int depth_output_gemm3d{ 0 }; /**< Depth of the output tensor in case is reinterpreted as 3D */
84  bool reinterpret_input_as_3d{ false }; /**< Flag used to reinterpret the input as 3D */
85  bool broadcast_bias{ false }; /**< Flag used to broadcast the bias addition */
86  bool fp_mixed_precision{ false }; /**< Flag used to indicate wider accumulators (32 bit instead of 16 for FP16). */
87  ActivationLayerInfo activation_info{}; /**< Activation function to perform after the matrix multiplication */
88  int mult_transpose1xW_width{ 1 }; /**< Multiplication factor for the width of the 1xW transposed block */
89  int mult_interleave4x4_height{ 1 }; /**< Multiplication factor for the height of the 4x4 interleaved block */
90  GEMMLHSMatrixInfo lhs_info{}; /**< LHS matrix information used to retrieve the number of rows processed by each thread */
91  GEMMRHSMatrixInfo rhs_info{}; /**< RHS matrix information used for reshaping the RHS matrix */
92  int32_t a_offset{ 0 }; /**< Offset to be added to each element of the matrix A */
93  int32_t b_offset{ 0 }; /**< Offset to be added to each element of the matrix B */
94  GEMMLowpOutputStageInfo output_stage{}; /**< GEMMLowp output stage information */
95 };
96 
97 /** Descriptor used by the depthwise convolution kernels */
99 {
100  ActivationLayerInfo activation_info{}; /**< Activation function to perform after the depthwise convolution */
101 };
102 
103 /** Descriptor used by the depthwise convolution kernels to retrieve the number of output elements processed by each thread */
105 {
106  unsigned int n0{ 0 }; /**< Number of columns processed by each thread */
107 };
108 
109 /** Descriptor used by the softmax kernels */
111 {
112  float beta{ 1.f }; /**< A scaling factor for the exponent with default value 1.0 */
113  bool is_log{ false }; /**< Flag used to perform Log Softmax operation */
114  DataType input_data_type{ DataType::UNKNOWN }; /**< Input tensor data type */
115 };
116 
117 /** Descriptor used by the direct convolution layer output stage kernels */
119 {
120  int32_t result_fixedpoint_multiplier{ 0 }; /**< Result output stage multiplier used for quantizing */
121  int32_t result_shift{ 0 }; /**< Result output stage shift used for quantizing */
122  int32_t result_offset_after_shift{ 0 }; /**< Result offset used for quantizing */
123  DataType output_data_type{ DataType::UNKNOWN }; /**< Output tensor data type to use if the output is not initialized */
124 };
125 
127 {
128  /** Default constructor */
130  : InstanceNormalizationLayerKernelInfo(1.f, 0.f, 1e-12, true)
131  {
132  }
133  /** Constructor
134  *
135  * @param[in] gamma The scale scalar value applied to the normalized tensor.
136  * @param[in] beta The offset scalar value applied to the normalized tensor
137  * @param[in] epsilon Lower bound value for the normalization.
138  * @param[in] use_mixed_precision Use mixed precision in case of FP16 execution.
139  */
142  {
143  }
144 
145  float gamma; /**< The scale scalar value applied to the normalized tensor. Defaults to 1.0 */
146  float beta; /**< The offset scalar value applied to the normalized tensor. Defaults to 0.0 */
147  float epsilon; /**< Lower bound value for the normalization. Defaults to 1e-12 */
148  bool use_mixed_precision; /**< Use mixed precision in case of FP16 execution. Defaults to true */
149 };
150 
152 {
153  /** Default constructor */
154  GEMMLowpReductionKernelInfo() = default;
155  /** Constructor
156  *
157  * @param[in] k Number of matrix columns/rows.
158  * @param[in] is_reshaped True if the input tensor has been reshaped.
159  * @param[in] scalar Scalar value to multiply each reduced column/row by.
160  * @param[in] mul_by_scalar True if each column/row reduction has to be multiplied by a scalar value.
161  */
164  {
165  }
166 
167  int32_t k{ 0 }; /**< Number of matrix columns/rows */
168  bool is_reshaped{ false }; /**< True if the input tensor has been reshaped */
169  int32_t scalar{ 0 }; /**< Scalar value to multiply each reduced column/row by */
170  bool mul_by_scalar{ false }; /**< True if each column/row reduction has to be multiplied by a scalar value */
171 };
172 
174 {
175  /** Constructor
176  *
177  * @param[in] interpolation_policy Interpolation type to use
178  * @param[in] border_mode Border mode policy
179  * @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
180  * @param[in] sampling_policy (Optional) Sampling policy used by the interpolation. Defaults to @ref SamplingPolicy::CENTER
181  * @param[in] use_padding (Optional) Is padding in use or not. Defaults to true.
182  * @param[in] align_corners (Optional) Align corners of input and output, only affecting bilinear policy with TOP_LEFT sampling policy. Defaults to false.
183  */
188  bool use_padding = true,
189  bool align_corners = false)
196  {
197  }
198 
199  InterpolationPolicy interpolation_policy; /**< Interpolation type to use */
200  BorderMode border_mode; /**< Border mode policy */
201  PixelValue constant_border_value; /**< Constant value to use for constant border mode policy */
202  SamplingPolicy sampling_policy; /**< Sampling policy used by the interpolation. */
203  bool use_padding; /**< Indication of using padding */
204  bool align_corners; /**< Align corners of input and output */
205 };
206 
208 {
209  /** Default constructor */
210  ThresholdKernelInfo() = default;
211  /** Constructor
212  *
213  * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
214  * @param[in] false_value value to set when the condition is not respected.
215  * @param[in] true_value value to set when the condition is respected.
216  * @param[in] type Thresholding type. Either RANGE or BINARY.
217  * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
218  */
221  {
222  }
223 
224  uint8_t threshold{ 0 };
225  uint8_t false_value{ 0 };
226  uint8_t true_value{ 0 };
228  uint8_t upper{ 0 };
229 };
230 } // namespace arm_compute
231 #endif /* ARM_COMPUTE_CORE_KERNEL_DESCRIPTORS_H */
BorderMode
Methods available to handle borders.
Definition: Types.h:264
int32_t result_fixedpoint_multiplier
Result output stage multiplier used for quantizing.
BorderMode border_mode
Border mode policy.
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
bool broadcast_bias
Flag used to broadcast the bias addition.
InterpolationPolicy
Interpolation method.
Definition: Types.h:369
int mult_interleave4x4_height
Multiplication factor for the height of the 4x4 interleaved block.
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)
Constructor.
bool fp_mixed_precision
Flag used to indicate wider accumulators (32 bit instead of 16 for FP16).
Descriptor used by the GEMM kernels.
InterpolationPolicy interpolation_policy
Interpolation type to use.
int32_t result_offset_after_shift
Result offset used for quantizing.
unsigned int n0
Number of columns processed by each thread.
float beta
A scaling factor for the exponent with default value 1.0.
unsigned int depth_output_gemm3d
Depth of the output tensor in case is reinterpreted as 3D.
InstanceNormalizationLayerKernelInfo(float gamma, float beta, float epsilon, bool use_mixed_precision)
Constructor.
ThresholdKernelInfo(uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper)
Constructor.
bool align_corners
Align corners of input and output.
GEMM LHS (Left Hand Side) matrix information.
Definition: Types.h:1897
ActivationLayerInfo activation_info
Activation function to perform after the depthwise convolution.
ThresholdType
Threshold mode.
Definition: Types.h:384
bool use_padding
Indication of using padding.
unsigned int axis
Axis to run the kernel on.
int32_t scalar
Scalar value to multiply each reduced column/row by.
ActivationLayerInfo activation_info
Activation function to perform after the matrix multiplication.
Activation Layer Information class.
Definition: Types.h:1517
GEMMLHSMatrixInfo lhs_info
LHS matrix information used to retrieve the number of rows processed by each thread.
Copyright (c) 2017-2020 Arm Limited.
Samples are taken at pixel center.
bool use_mixed_precision
Use mixed precision in case of FP16 execution.
unsigned int m
Number of LHS rows.
unsigned int n
Number of RHS columns.
GEMMLowpReductionKernelInfo(int32_t k, bool is_reshaped, int32_t scalar, bool mul_by_scalar)
Constructor.
int32_t k
Number of matrix columns/rows.
SamplingPolicy sampling_policy
Sampling policy used by the interpolation.
GEMM RHS (Right Hand Side) matrix information.
Definition: Types.h:1912
int32_t b_offset
Offset to be added to each element of the matrix B.
bool conjugate
Flag to conjugate the output/.
DataType input_data_type
Input tensor data type.
bool is_log
Flag used to perform Log Softmax operation.
Descriptor used by the depthwise convolution kernels.
GEMMLowpOutputStageInfo output_stage
GEMMLowp output stage information.
Descriptor used by the FFT core kernels.
bool reinterpret_input_as_3d
Flag used to reinterpret the input as 3D.
Descriptor for FFT scale kernels.
GEMMLowp output stage info.
Definition: Types.h:1881
Descriptor used by the depthwise convolution kernels to retrieve the number of output elements proces...
unsigned int axis
Axis to perform the kernel on.
int32_t a_offset
Offset to be added to each element of the matrix A.
float epsilon
Lower bound value for the normalization.
GEMMRHSMatrixInfo rhs_info
RHS matrix information used for reshaping the RHS matrix.
bool is_first_stage
Flags if the FFT kernels is the first stage of a decomposed FFT.
Descriptor for FFT digit reverse kernels.
unsigned int Nx
Nx coefficient.
float gamma
The scale scalar value applied to the normalized tensor.
DataType output_data_type
Output tensor data type to use if the output is not initialized.
GEMMLowpReductionKernelInfo()=default
Default constructor.
unsigned int k
Number of LHS columns or RHS rows.
bool is_reshaped
True if the input tensor has been reshaped.
PixelValue constant_border_value
Constant value to use for constant border mode policy.
float scale
Axis to perform the kernel on.
Threshold with one value.
ThresholdKernelInfo()=default
Default constructor.
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, 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)
Descriptor used by the softmax kernels.
int mult_transpose1xW_width
Multiplication factor for the width of the 1xW transposed block.
DataType
Available data types.
Definition: Types.h:77
bool mul_by_scalar
True if each column/row reduction has to be multiplied by a scalar value.
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:102
int32_t result_shift
Result output stage shift used for quantizing.