47 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *weights,
const ITensorInfo *biases,
const ITensorInfo *output,
48 const PadStrideInfo &
conv_info,
unsigned int depth_multiplier,
const ActivationLayerInfo &act_info,
const Size2D dilation,
49 const ITensorInfo *output_multipliers,
const ITensorInfo *output_shifts)
58 "For QASYMM8 only logistic, relu, lower bounded relu and lower-upper bounded relu are supported");
76 ARM_COMPUTE_RETURN_ERROR_ON((biases->dimension(0) != weights->dimension(2)) && (weights->dimension(2) != 1 || biases->dimension(0) != weights->dimension(3)));
106 if(output->total_size() != 0)
108 const ConvolutionInfo
info{
conv_info, depth_multiplier, ActivationLayerInfo(), dilation };
116 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *
input, ITensorInfo *weights, ITensorInfo *output,
const PadStrideInfo &
conv_info,
117 unsigned int depth_multiplier, std::string &
kernel_name,
const Size2D dilation)
120 const ConvolutionInfo
info 122 conv_info, depth_multiplier, ActivationLayerInfo(), dilation
132 unsigned int num_elems_read_per_iteration_x = 0;
133 unsigned int num_elems_read_per_iteration_y = 0;
134 unsigned int num_elems_written_per_iteration_x = 0;
135 unsigned int num_elems_written_per_iteration_y = 0;
141 num_elems_written_per_iteration_y = 1;
142 num_elems_read_per_iteration_y = 3;
146 num_elems_read_per_iteration_x = 8;
149 num_elems_read_per_iteration_x = 9;
152 num_elems_read_per_iteration_x = 16;
155 num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) *
conv_stride_x;
160 kernel_name =
"depthwise_convolution_3x3_stridex1_stridey1_f16";
161 num_elems_read_per_iteration_x = 8;
162 num_elems_written_per_iteration_x = 4;
163 num_elems_read_per_iteration_y = 6;
164 num_elems_written_per_iteration_y = 4;
168 kernel_name =
"depthwise_convolution_3x3_stridex2_stridey2_f16";
169 num_elems_read_per_iteration_x = 10;
170 num_elems_written_per_iteration_x = 4;
171 num_elems_read_per_iteration_y = 5;
172 num_elems_written_per_iteration_y = 2;
179 kernel_name =
"depthwise_convolution_3x3_stridex1_stridey1_f32";
180 num_elems_read_per_iteration_x = 4;
181 num_elems_read_per_iteration_y = 6;
182 num_elems_written_per_iteration_x = 2;
183 num_elems_written_per_iteration_y = 4;
187 kernel_name =
"depthwise_convolution_3x3_stridex2_stridey2_f32";
188 num_elems_read_per_iteration_x = 6;
189 num_elems_read_per_iteration_y = 5;
190 num_elems_written_per_iteration_x = 2;
191 num_elems_written_per_iteration_y = 2;
197 num_elems_written_per_iteration_y = 1;
198 num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) *
conv_stride_x;
199 num_elems_read_per_iteration_y = 3;
206 kernel_name = is_qasymm ?
"dwc_3x3_native_quantized8" :
"depthwise_convolution_3x3";
207 kernel_name += (is_qasymm && is_dot8_supported ?
"_dot8" :
"");
211 num_elems_written_per_iteration_y = (is_qasymm &&
conv_stride_y == 1 && dilation.y() == 1) ? 2 : 1;
213 num_elems_read_per_iteration_y = num_elems_written_per_iteration_y + 2;
218 num_elems_read_per_iteration_x += 2 * dilation.x();
219 num_elems_read_per_iteration_y += 2 * dilation.y();
222 Window win =
calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y));
225 num_elems_read_per_iteration_x, num_elems_read_per_iteration_y,
227 AccessWindowStatic weights_access(weights, 0, 0, 3, 3);
228 AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y);
233 return std::make_pair(err, win);
238 : _border_size(0), _input(), _output(), _weights(), _biases(), _conv_stride_y(1), _output_multipliers(), _output_shifts(), _is_quantized(false), _conv_stride_x(0), _conv_pad_top(0), _conv_pad_left(0)
251 configure(
CLKernelLibrary::get().get_compile_context(),
input, weights, biases, output,
conv_info, depth_multiplier, act_info, dilation, output_multipliers, output_shifts);
260 conv_info, depth_multiplier, act_info, dilation,
261 (output_multipliers !=
nullptr) ? output_multipliers->
info() :
nullptr,
262 (output_shifts !=
nullptr) ? output_shifts->
info() :
nullptr));
268 _conv_stride_x =
conv_info.stride().first;
269 _conv_stride_y =
conv_info.stride().second;
272 _output_multipliers = output_multipliers;
273 _output_shifts = output_shifts;
281 ICLKernel::configure_internal(win_config.second);
293 build_opts.add_option_if(_biases !=
nullptr,
"-DHAS_BIAS");
308 build_opts.add_option_if(is_quantized_per_channel,
"-DPER_CHANNEL_QUANTIZATION");
309 build_opts.add_option_if(is_dot8_supported,
"-DIS_DOT8");
313 int output_multiplier = 0;
314 int output_shift = 0;
319 if(act_info.enabled())
325 const int o1 = oq_info.
offset;
331 const float s1 = iq_info.
scale;
390 Window collapsed_in = collapsed;
414 if(_biases !=
nullptr)
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
const Window & window() const
The maximum window the kernel can be executed on.
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
Calculate the depthwise convolution output shape of a tensor.
bool dot8_supported(const cl::Device &device)
Helper function to check whether the cl_arm_integer_dot_product_int8 extension is supported.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
const size_t conv_stride_x
constexpr int step() const
Return the step of the dimension.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
const size_t conv_stride_y
std::string lower_string(const std::string &val)
Lower a given string.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Activation Layer Information class.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
void add_option(std::string option)
Adds option to the existing build option list.
CLDepthwiseConvolutionLayer3x3NCHWKernel()
Default constructor.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
std::pair< int32_t, int32_t > get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info)
Returns a pair of minimum and maximum values for a quantized activation.
void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier=1, ActivationLayerInfo act_info=ActivationLayerInfo(), const Size2D &dilation=Size2D(1U, 1U), const ICLTensor *output_multipliers=nullptr, const ICLTensor *output_shifts=nullptr)
Initialize the function's source, destination, conv and border_size.
quantized, asymmetric fixed-point 8-bit number unsigned
T z() const
Alias to access the size of the third dimension.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
size_t data_size_from_type(DataType data_type)
The size in bytes of the data type.
Padding and stride information class.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
quantized, symmetric per channel fixed-point 8-bit number
std::string get_cl_promoted_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL promoted type.
Lower and Upper Bounded Rectifier ( )
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Interface for OpenCL tensor.
Upper Bounded Rectifier ( )
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
Class for specifying the size of an image or rectangle.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
quantized, asymmetric fixed-point 8-bit number signed
void adjust(size_t dimension, int adjust_value, bool is_at_start)
Adjust the start or end of a given dimension by the given value.
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
Window first_slice_window_3D() const
First 3D slice of the window.
Describe a multidimensional execution window.
BorderSize border_size() const override
The size of the border for that kernel.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier=1, ActivationLayerInfo act_info=ActivationLayerInfo(), const Size2D &dilation=Size2D(1U, 1U), const ITensorInfo *output_multipliers=nullptr, const ITensorInfo *output_shifts=nullptr)
Static function to check if given info will lead to a valid configuration of CLDepthwiseConvolutionLa...