46 using namespace misc::shape_calculator;
50 struct Im2ColConfiguration
80 if(output->total_size() > 0)
91 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *
input, ITensorInfo *output,
const Size2D &kernel_dims,
const PadStrideInfo &
conv_info,
bool has_bias,
const Size2D &dilation,
108 bool window_changed =
false;
122 AccessWindowStatic input_access(
input,
141 return std::make_pair(err, win);
144 Im2ColConfiguration configure_opencl_kernel(
const ITensorInfo *
input,
const Size2D &kernel_dims,
const PadStrideInfo &
conv_info,
bool has_bias,
const Size2D &dilation,
unsigned int num_groups)
153 const unsigned int input_channel =
input->dimension(channel_idx);
159 CLBuildOptions build_opts;
162 const UniformQuantizationInfo
qinfo =
input->quantization_info().uniform();
183 build_opts.add_option_if(
has_bias,
"-DHAS_BIAS");
191 if(kernel_dims == Size2D(3U, 3U))
195 else if(kernel_dims == Size2D(9U, 9U))
204 const unsigned int partial_vec_size = input_channel % vec_size;
205 const unsigned int boundary_vec_size = vec_size - ((vec_size - partial_vec_size) % vec_size);
211 if(dilation == Size2D(1U, 1U))
213 const bool squared_im2col = kernel_dims.width == kernel_dims.height;
217 switch(kernel_dims.width)
254 else if(kernel_dims.width > 1 && !
conv_info.has_padding())
267 const size_t vector_size = std::min(static_cast<size_t>(4), kernel_dims.width);
268 const size_t width_mod_vector_size = kernel_dims.width % vector_size;
278 Im2ColConfiguration im2col_config;
280 im2col_config.build_options = build_opts.options();
284 return im2col_config;
289 : _input(nullptr), _output(nullptr), _data_layout(
DataLayout::
UNKNOWN), _convolved_dims(), _num_elems_processed_per_iteration(1), _kernel_dims(), _conv_info(), _num_groups()
320 _kernel =
create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options);
331 auto win_config = validate_and_configure_window(
input->info(), output->
info(), kernel_dims,
conv_info,
has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
332 im2col_config.is_padding_required_nchw,
num_groups);
334 ICLKernel::configure_internal(win_config.second);
337 _config_id = im2col_config.kernel_name;
358 im2col_config.is_padding_required_nchw,
num_groups)
379 Window slice_in = first_slice_3d;
385 const int num_batches = tmp_win[3].end();
413 unsigned int idx = 0;
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Window first_slice_window_2D() const
First 2D slice of the window.
const std::vector< int32_t > & offset() const
Offset vector accessor.
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)
void configure(const ICLTensor *input, ICLTensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation=Size2D(1U, 1U), unsigned int num_groups=1)
Set the input and output of the kernel.
const Window & window() const
The maximum window the kernel can be executed on.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
std::pair< unsigned int, unsigned int > _convolved_dims
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.
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.
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 DataLayout data_layout
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.
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.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
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.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Copyright (c) 2017-2021 Arm Limited.
size_t height
Height of the image region or rectangle.
1 channel, 1 F16 per channel
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
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 Status validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation=Size2D(1U, 1U), unsigned int num_groups=1)
Static function to check if given info will lead to a valid configuration of CLIm2ColKernel.
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.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
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.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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
const unsigned int num_groups
std::set< std::string > build_options
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.
const size_t input_height
Padding and stride information class.
void end(TokenStream &in, bool &valid)
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
#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.
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.
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.
Interface for OpenCL tensor.
bool is_padding_required_nchw
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
size_t width
Width of the image region or rectangle.
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.
const QuantizationInfo qinfo
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
#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)
Wrapper to configure the Khronos OpenCL C++ header.
unsigned int _num_elems_processed_per_iteration
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
quantized, asymmetric fixed-point 8-bit number signed
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Window first_slice_window_3D() const
First 3D slice of the window.
DataType
Available data types.
DataLayout
[DataLayout enum definition]
TensorShape compute_im2col_conv_shape(const ITensorInfo *input, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, bool batch_size_on_z, unsigned int num_groups=1)
Calculate the im2col output shape of a tensor.
Describe a multidimensional execution window.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
CLIm2ColKernel()
Default constructor.