45 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *weights,
const ITensorInfo *biases,
const ITensorInfo *output,
46 const PadStrideInfo &
conv_info,
unsigned int depth_multiplier,
const ActivationLayerInfo &act_info,
const Size2D &dilation,
47 const ITensorInfo *output_multipliers,
const ITensorInfo *output_shifts)
56 "For QASYMM8 only logistic, relu, lower bounded relu and lower-upper bounded relu are supported");
72 DepthwiseConvolutionReshapeInfo
info;
100 if(biases !=
nullptr)
115 if(output->total_size() != 0)
123 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *bias, ITensorInfo *output,
124 const PadStrideInfo &conv_info,
unsigned int depth_multiplier,
const Size2D &dilation,
125 ITensorInfo *output_multipliers, ITensorInfo *output_shifts)
130 const bool is_stride_1_dilation_1 = ((conv_info.stride().first == conv_info.stride().second) && (conv_info.stride().first == 1) && dilation.x() == 1 && dilation.y() == 1);
131 unsigned int num_rows_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1;
138 const unsigned int num_elems_accessed_per_iteration = 4;
139 const unsigned int num_rows_read_per_iteration = num_rows_processed_per_iteration + 2;
140 const unsigned int num_rows_written_per_iteration = std::ceil(num_rows_processed_per_iteration / static_cast<float>(conv_info.stride().first));
142 BorderSize border_size;
143 border_size = BorderSize(conv_info.pad_left(), 0, std::max(std::max(conv_info.pad_right(), conv_info.pad_bottom()), conv_info.pad_top()), 0);
146 win =
calculate_max_window(*output, Steps(num_elems_accessed_per_iteration, num_rows_written_per_iteration));
148 AccessWindowStatic input_access(input, 0, -border_size.top,
ceil_to_multiple(input->dimension(0), num_elems_accessed_per_iteration),
149 ceil_to_multiple(input->dimension(1) + border_size.bottom, num_rows_read_per_iteration));
150 AccessWindowRectangle output_access(output, 0, 0, num_elems_accessed_per_iteration, num_rows_written_per_iteration);
152 bool window_changed =
false;
154 if((output_multipliers !=
nullptr) && (output_shifts !=
nullptr))
156 AccessWindowHorizontal output_multipliers_access(output_multipliers, 0, num_elems_accessed_per_iteration);
157 AccessWindowHorizontal output_shifts_access(output_shifts, 0, num_elems_accessed_per_iteration);
158 window_changed = window_changed ||
update_window_and_padding(win, input_access, output_access, output_multipliers_access, output_shifts_access);
163 return std::make_pair(err, win);
168 AccessWindowHorizontal bias_access(bias, 0, num_elems_accessed_per_iteration);
171 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->tensor_shape()));
177 unsigned int num_elems_accessed_per_iteration =
adjust_vec_size(4 / input->element_size(), input->dimension(0));
178 win =
calculate_max_window(*output, Steps(num_elems_accessed_per_iteration, num_rows_processed_per_iteration));
181 return std::make_pair(err, win);
186 : _num_planes_processed_per_iteration(1)
199 configure(
CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, conv_info, depth_multiplier, act_info, dilation, output_multipliers, output_shifts);
208 conv_info, depth_multiplier, act_info, dilation,
209 (output_multipliers !=
nullptr) ? output_multipliers->
info() :
nullptr,
210 (output_shifts !=
nullptr) ? output_shifts->
info() :
nullptr));
214 auto win_config = validate_and_configure_window(input->
info(), weights->
info(), biases !=
nullptr ? biases->
info() :
nullptr, output->
info(),
216 (output_multipliers !=
nullptr) ? output_multipliers->
info() :
nullptr,
217 (output_shifts !=
nullptr) ? output_shifts->
info() :
nullptr);
219 const bool is_stride_1 = ((conv_info.
stride().first == conv_info.
stride().second) && (conv_info.
stride().first == 1));
220 const bool is_stride_1_dilation_1 = (is_stride_1 && dilation.x() == 1 && dilation.y() == 1);
228 _conv_stride_y = conv_info.
stride().second;
229 _num_planes_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1;
230 _output_multipliers = output_multipliers;
231 _output_shifts = output_shifts;
239 if(is_dot8_supported)
241 _num_planes_processed_per_iteration = 1;
246 unsigned int num_rows_processed_per_iteration = is_stride_1_dilation_1 ? 2 : 1;
258 build_opts.
add_option_if(_input->info()->tensor_shape().total_size_upper(3) > 1,
259 "-DDST_DEPTH=" +
support::cpp11::to_string(static_cast<int>(std::ceil(_output->info()->dimension(2) /
static_cast<float>(_num_planes_processed_per_iteration)))));
272 build_opts.
add_option_if(is_quantized_per_channel,
"-DPER_CHANNEL_QUANTIZATION");
277 int output_multiplier = 0;
278 int output_shift = 0;
283 if(act_info.enabled())
289 const int o1 = oq_info.
offset;
295 const float s1 = iq_info.
scale;
309 if(is_stride_1_dilation_1)
329 kernel_name = std::string(
"dwc_3x3_reshaped_quantized8");
330 kernel_name += (is_dot8_supported && is_stride_1_dilation_1 ?
"_dot8" :
"");
331 kernel_name += (is_stride_1_dilation_1 ?
"_stride1" :
"");
332 kernel_name +=
"_nhwc";
336 kernel_name = std::string(
"depthwise_convolution_3x3_nhwc");
337 kernel_name += (is_stride_1_dilation_1 ?
"_stride1" :
"");
340 ICLKernel::configure_internal(win_config.second);
367 biases !=
nullptr ? biases->
clone().get() :
nullptr,
369 (output_multipliers !=
nullptr) ? output_multipliers->
clone().get() :
nullptr,
370 (output_shifts !=
nullptr) ? output_shifts->
clone().get() :
nullptr)
380 const size_t total_batches = _input->info()->tensor_shape().total_size_upper(3);
383 win.
set(
Window::DimZ,
Window::Dimension(0, std::ceil(_output->info()->dimension(2) /
static_cast<float>(_num_planes_processed_per_iteration)) * total_batches, 1));
396 if(_biases !=
nullptr)
441 const int max_offset = ((_input->info()->dimension(1) * _input->info()->dimension(2)) + (_input->info()->padding().bottom + _input->info()->padding().top) * (_input->info()->dimension(
442 2) - 1)) * _input->info()->strides_in_bytes().y();
443 _kernel.setArg(idx, max_offset);
449 unsigned int idx = 0;
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
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.
const StringSet & options() const
Gets the current options list set.
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
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
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)
Describe one of the image's dimensions with a start, end and step.
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.
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.
const size_t weights_height
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.
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...
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.
BorderSize border_size() const override
The size of the border for that kernel.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
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.
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
quantized, asymmetric fixed-point 8-bit number unsigned
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
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
Default move assignment operator.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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.
unsigned int pad_right() const
Get the right padding.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
Padding and stride information class.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual PaddingSize padding() const =0
Padding of tensor.
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
static constexpr unsigned int num_arguments_per_4D_tensor()
Returns the number of arguments enqueued per 4D tensor object.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Num samples, channels, height, width.
src_info set_data_layout(data_layout)
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
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 ( )
CLDepthwiseConvolutionLayer3x3NHWCKernel()
Default constructor.
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx...
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(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
Window first_slice_window_4D() const
First 4D slice of the window.
bool slide_window_slice_4D(Window &slice) const
Slide the passed 4D window slice.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension, getting rounded down to its closest valid vector size.
quantized, asymmetric fixed-point 8-bit number signed
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...
const size_t weights_width
void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx...
unsigned int pad_left() const
Get the left padding.
Describe a multidimensional execution window.
#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.