24.02.1
|
Go to the documentation of this file.
49 using namespace misc::shape_calculator;
56 struct Im2ColConfiguration
65 const ITensorInfo *
dst,
66 const Size2D &kernel_dims,
69 const Size2D &dilation,
92 if (
dst->total_size() > 0)
94 const TensorInfo tensor_info_output =
dst->clone()->set_tensor_shape(
106 const Size2D &kernel_dims,
109 const Size2D &dilation,
117 TensorShape expected_output_shape =
125 const unsigned int input_width =
src->dimension(
width_idx);
126 const unsigned int input_height =
src->dimension(
height_idx);
129 bool window_changed =
false;
144 AccessWindowStatic input_access(
145 src, -border.left, -border.top,
147 input_height + border.bottom);
163 return std::make_pair(err, win);
166 Im2ColConfiguration configure_opencl_kernel(
const ITensorInfo *
src,
167 const Size2D &kernel_dims,
170 const Size2D &dilation,
178 const unsigned int input_width =
src->dimension(
width_idx);
179 const unsigned int input_height =
src->dimension(
height_idx);
182 const std::pair<unsigned int, unsigned int> convolved_dims =
187 CLBuildOptions build_opts;
190 const UniformQuantizationInfo
qinfo =
src->quantization_info().uniform();
212 build_opts.add_option_if(
has_bias,
"-DHAS_BIAS");
220 if (kernel_dims == Size2D(3U, 3U))
223 build_opts.add_option(
"-DIM2COL_3X3");
225 else if (kernel_dims == Size2D(9U, 9U))
228 build_opts.add_option(
"-DIM2COL_9X9");
232 build_opts.add_option(
"-DIM2COL_GENERIC");
239 const unsigned int partial_vec_size = input_channel % vec_size;
240 const unsigned int boundary_vec_size = vec_size - ((vec_size - partial_vec_size) % vec_size);
246 if (dilation == Size2D(1U, 1U))
248 const bool squared_im2col = kernel_dims.width == kernel_dims.height;
252 switch (kernel_dims.width)
289 else if (kernel_dims.width > 1 && !
conv_info.has_padding())
302 const size_t vector_size = std::min(
static_cast<size_t>(4), kernel_dims.width);
303 const size_t width_mod_vector_size = kernel_dims.width %
vector_size;
313 Im2ColConfiguration im2col_config;
315 im2col_config.build_options = build_opts.options();
319 return im2col_config;
326 _num_elems_processed_per_iteration(1),
337 const Size2D &kernel_dims,
351 const unsigned int input_width =
src->dimension(
width_idx);
352 const unsigned int input_height =
src->dimension(
height_idx);
357 Im2ColConfiguration im2col_config =
361 _kernel =
create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options);
372 im2col_config.num_elems_processed_per_iteration,
373 im2col_config.is_padding_required_nchw,
num_groups);
375 IClKernel::configure_internal(win_config.second);
378 _config_id = im2col_config.kernel_name;
395 const Size2D &kernel_dims,
402 Im2ColConfiguration im2col_config =
406 im2col_config.num_elems_processed_per_iteration,
407 im2col_config.is_padding_required_nchw,
num_groups)
433 Window slice_in = first_slice_3d;
439 const int num_batches = tmp_win[3].end();
467 _kernel.setArg<cl_uint>(idx++,
static_cast<unsigned int>(
src->info()->strides_in_bytes()[3]));
468 _kernel.setArg<cl_uint>(idx++,
469 static_cast<unsigned int>(
dst->info()->strides_in_bytes()[((
_num_groups == 1) ? 2 : 3)]));
472 unsigned int idx = 0;
std::string to_string(T &&value)
Convert integer and float values to string.
ClIm2ColKernel()
Default constructor.
SimpleTensor< float > src
constexpr size_t vector_size
DataLayout
[DataLayout enum definition]
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ NHWC
Num samples, height, width, channels.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
std::string lower_string(const std::string &val)
Lower a given string.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
constexpr static unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
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.
unsigned int _num_elems_processed_per_iteration
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.
Class for specifying the size of an image or rectangle.
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
size_t height
Height of the image region or rectangle.
bool update_window_and_padding(Window &win, Ts &&...patterns)
Update window and padding size for each of the access patterns.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
constexpr auto data_layout
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.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
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, unsigned int input_pad_right=0)
Calculate the im2col output shape of a tensor.
std::pair< unsigned int, unsigned int > _convolved_dims
void configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, 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.
bool empty() const
Checks if pack is empty.
@ RUNTIME_ERROR
Generic runtime error.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
size_t width
Width of the image region or rectangle.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
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.
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst)
Wrapper to configure the Khronos OpenCL C++ header.
Describe one of the image's dimensions with a start, end and step.
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.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
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.
Window first_slice_window_3D() const
First 3D slice of the window.
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
const unsigned int num_groups
Describe a multidimensional execution window.
@ ELEMENTWISE
Elementwise CL kernel type.
constexpr static unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Copyright (c) 2017-2024 Arm Limited.
@ F16
16-bit floating-point number
@ UNKNOWN
Unknown CL kernel type.
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 DimZ
Alias for dimension 2 also known as Z dimension.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
void end(TokenStream &in, bool &valid)
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
@ UNKNOWN
Unknown data layout.
Store the tensor's metadata.
bool is_padding_required_nchw
@ F32
32-bit floating-point number
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
unsigned int num_elems_processed_per_iteration
DataType
Available data types.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
const QuantizationInfo qinfo
Window first_slice_window_2D() const
First 2D slice of the window.
const std::vector< int32_t > & offset() const
Offset vector accessor.
std::set< std::string > build_options
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.