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)
115 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *output,
const PadStrideInfo &conv_info,
116 unsigned int depth_multiplier,
GPUTarget gpu_target, std::string &
kernel_name,
const Size2D dilation)
120 auto_init_if_empty(*output, input->clone()->set_tensor_shape(output_shape).set_quantization_info(output->quantization_info()));
123 const unsigned int conv_stride_y = conv_info.stride().second;
128 unsigned int num_elems_read_per_iteration_x = 0;
129 unsigned int num_elems_read_per_iteration_y = 0;
130 unsigned int num_elems_written_per_iteration_x = 0;
131 unsigned int num_elems_written_per_iteration_y = 0;
135 kernel_name =
"depthwise_convolution_3x3_f16";
137 num_elems_written_per_iteration_y = 1;
138 num_elems_read_per_iteration_y = 3;
139 switch(conv_stride_x)
142 num_elems_read_per_iteration_x = 8;
145 num_elems_read_per_iteration_x = 9;
148 num_elems_read_per_iteration_x = 16;
151 num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x;
156 if(conv_stride_x == 1 && conv_stride_y == 1)
158 kernel_name =
"depthwise_convolution_3x3_stridex1_stridey1_bifrost_f16";
159 num_elems_read_per_iteration_x = 8;
160 num_elems_written_per_iteration_x = 4;
161 num_elems_read_per_iteration_y = 6;
162 num_elems_written_per_iteration_y = 4;
164 else if(conv_stride_x == 2 && conv_stride_y == 2)
166 kernel_name =
"depthwise_convolution_3x3_stridex2_stridey2_bifrost_f16";
167 num_elems_read_per_iteration_x = 10;
168 num_elems_written_per_iteration_x = 4;
169 num_elems_read_per_iteration_y = 5;
170 num_elems_written_per_iteration_y = 2;
176 if(conv_stride_x == 1 && conv_stride_y == 1)
178 kernel_name =
"depthwise_convolution_3x3_stridex1_stridey1_bifrost_f32";
179 num_elems_read_per_iteration_x = 4;
180 num_elems_read_per_iteration_y = 6;
181 num_elems_written_per_iteration_x = 2;
182 num_elems_written_per_iteration_y = 4;
184 else if(conv_stride_x == 2 && conv_stride_y == 2)
186 kernel_name =
"depthwise_convolution_3x3_stridex2_stridey2_bifrost_f32";
187 num_elems_read_per_iteration_x = 6;
188 num_elems_read_per_iteration_y = 5;
189 num_elems_written_per_iteration_x = 2;
190 num_elems_written_per_iteration_y = 2;
194 kernel_name =
"depthwise_convolution_3x3";
196 num_elems_written_per_iteration_y = 1;
197 num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x;
198 num_elems_read_per_iteration_y = 3;
205 kernel_name = is_qasymm ?
"dwc_3x3_native_quantized8" :
"depthwise_convolution_3x3";
206 kernel_name += (is_qasymm && is_dot8_supported ?
"_dot8" :
"");
207 kernel_name += (is_qasymm ?
"_nchw" :
"");
210 num_elems_written_per_iteration_y = (is_qasymm && conv_stride_y == 1 && dilation.y() == 1) ? 2 : 1;
211 num_elems_read_per_iteration_x = 3 + (num_elems_written_per_iteration_x - 1) * conv_stride_x + (conv_stride_x > 1 ? 1 : 0);
212 num_elems_read_per_iteration_y = num_elems_written_per_iteration_y + 2;
217 num_elems_read_per_iteration_x += 2 * dilation.x();
218 num_elems_read_per_iteration_y += 2 * dilation.y();
221 Window win =
calculate_max_window(*output, Steps(num_elems_written_per_iteration_x, num_elems_written_per_iteration_y));
223 AccessWindowRectangle input_access(input, -conv_info.pad_left(), -conv_info.pad_top(),
224 num_elems_read_per_iteration_x, num_elems_read_per_iteration_y,
226 AccessWindowStatic weights_access(weights, 0, 0, 3, 3);
227 AccessWindowRectangle output_access(output, 0, 0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_y);
231 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
234 return std::make_pair(err, win);
239 : _conv_stride_x(0), _conv_pad_top(0), _conv_pad_left(0)
252 configure(
CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation, output_multipliers, output_shifts);
261 conv_info, depth_multiplier, act_info, dilation,
262 (output_multipliers !=
nullptr) ? output_multipliers->
info() :
nullptr,
263 (output_shifts !=
nullptr) ? output_shifts->
info() :
nullptr));
269 _conv_stride_x = conv_info.
stride().first;
270 _conv_stride_y = conv_info.
stride().second;
271 _conv_pad_left = conv_info.
pad_left();
272 _conv_pad_top = conv_info.
pad_top();
273 _output_multipliers = output_multipliers;
274 _output_shifts = output_shifts;
281 auto win_config = validate_and_configure_window(input->
info(), weights->
info(), output->
info(),
conv_info, depth_multiplier, gpu_target,
kernel_name, dilation);
283 ICLKernel::configure_internal(win_config.second);
295 build_opts.add_option_if(_biases !=
nullptr,
"-DHAS_BIAS");
310 build_opts.add_option_if(is_quantized_per_channel,
"-DPER_CHANNEL_QUANTIZATION");
311 build_opts.add_option_if(is_dot8_supported,
"-DIS_DOT8");
315 int output_multiplier = 0;
316 int output_shift = 0;
321 if(act_info.enabled())
327 const int o1 = oq_info.
offset;
333 const float s1 = iq_info.
scale;
353 _kernel =
create_kernel(compile_context, kernel_name, build_opts.options());
392 Window collapsed_in = collapsed;
416 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.
bool dot8_supported(const cl::Device &device)
Helper function to check whether the cl_arm_integer_dot_product_int8 extension is supported...
void enqueue(IGCKernel &kernel, const Window &window, const gles::NDRange &lws=gles::NDRange(1U, 1U, 1U))
Add the kernel to the command queue with the given window.
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info, unsigned int depth_multiplier, const Size2D &dilation=Size2D(1U, 1U))
Calculate the depthwise convolution output shape of a tensor.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
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(), GPUTarget gpu_target=GPUTarget::MIDGARD, 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...
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)
unsigned int pad_top() const
Get the top padding.
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
GPUTarget get_arch_from_target(GPUTarget target)
Helper function to get the GPU arch.
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.
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.
quantized, asymmetric fixed-point 8-bit number unsigned
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
const size_t conv_stride_x
GPUTarget get_target() const
Get the targeted GPU architecture.
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.
virtual PaddingSize padding() const =0
Padding of tensor.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
#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.
const size_t conv_stride_y
Lower and Upper Bounded Rectifier ( )
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) override
Initialize the function's source, destination, conv and border_size.
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.
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.
GPUTarget
Available GPU Targets.
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.
unsigned int pad_left() const
Get the left padding.
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.