Compute Library
 21.05
CLIm2ColKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021 Arm Limited.
3  *
4  * SPDX-License-Identifier: MIT
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to
8  * deal in the Software without restriction, including without limitation the
9  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10  * sell copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
25 
35 #include "src/core/CL/CLValidate.h"
38 #include "support/StringSupport.h"
39 
40 #include <cmath>
41 #include <tuple>
42 #include <utility>
43 
44 namespace arm_compute
45 {
46 using namespace misc::shape_calculator;
47 
48 namespace
49 {
50 struct Im2ColConfiguration
51 {
52  std::string kernel_name{};
53  std::set<std::string> build_options{};
56 };
57 
58 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
59  unsigned int num_groups)
60 {
61  const unsigned int channel_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL);
62 
67  ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1));
71  ARM_COMPUTE_RETURN_ERROR_ON((input->dimension(channel_idx) % num_groups) != 0);
72 
73  // Since there's no implicit padding added, check the total input spatial dimensions (with conv paddings) are big enough for the kernel dimensions
74  const unsigned int width_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::WIDTH);
75  const unsigned int height_idx = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::HEIGHT);
76  const unsigned total_width = input->dimension(width_idx) + conv_info.pad_left() + conv_info.pad_right();
77  const unsigned total_height = input->dimension(height_idx) + conv_info.pad_top() + conv_info.pad_bottom();
78  ARM_COMPUTE_RETURN_ERROR_ON((total_width < kernel_dims.width) || (total_height < kernel_dims.height));
79 
80  if(output->total_size() > 0)
81  {
82  const TensorInfo tensor_info_output = output->clone()->set_tensor_shape(compute_im2col_conv_shape(input, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups));
83  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(output, &tensor_info_output);
86  }
87 
88  return Status{};
89 }
90 
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,
93 {
95 
96  // Output tensor auto initialization if not yet initialized
97  TensorShape expected_output_shape = compute_im2col_conv_shape(input, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups);
98 
99  auto_init_if_empty(*output, input->clone()->set_tensor_shape(expected_output_shape));
100 
101  const DataLayout data_layout = input->data_layout();
104  const unsigned int input_width = input->dimension(width_idx);
105  const unsigned int input_height = input->dimension(height_idx);
106 
107  // Configure the execute window based on the selected optimal OpenCL kernel
108  bool window_changed = false;
109  Window win;
110 
112  {
114  }
115  else
116  {
118  {
119  const BorderSize border(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left());
121  Steps(num_elems_processed_per_iteration * conv_info.stride().first, conv_info.stride().second));
122  AccessWindowStatic input_access(input,
123  -border.left,
124  -border.top,
125  ceil_to_multiple(input_width + border.right, kernel_dims.width * num_elems_processed_per_iteration),
126  input_height + border.bottom);
127  window_changed = window_changed || update_window_and_padding(win, input_access);
128  }
129  else
130  {
131  // For the generic case, CLIm2ColKernel doesn't need padding (we do not read out-of-bounds elements) so
132  // update_window_and_padding() can be skipped
133  win = calculate_max_window(*input, Steps());
134  }
135  }
136 
137  // set the Z dimension's step same size as the whole dimension so that one can't split across the Z dimension
138  win.set_dimension_step(Window::DimZ, win[Window::DimZ].end() - win[Window::DimZ].start());
139 
140  Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
141  return std::make_pair(err, win);
142 }
143 
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)
145 {
146  const DataLayout data_layout = input->data_layout();
147  const DataType data_type = input->data_type();
151  const unsigned int input_width = input->dimension(width_idx);
152  const unsigned int input_height = input->dimension(height_idx);
153  const unsigned int input_channel = input->dimension(channel_idx);
154 
155  const std::pair<unsigned int, unsigned int> convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
156 
157  // Im2Col configuration
158  std::string kernel_name = "im2col_generic_";
159  CLBuildOptions build_opts;
160  unsigned int num_elems_processed_per_iteration = 1;
161  bool is_padding_required_nchw = false;
162  const UniformQuantizationInfo qinfo = input->quantization_info().uniform();
163 
164  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
165  build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(input->element_size()));
166  build_opts.add_option("-DKERNEL_WIDTH=" + support::cpp11::to_string(kernel_dims.width));
167  build_opts.add_option("-DKERNEL_HEIGHT=" + support::cpp11::to_string(kernel_dims.height));
168  build_opts.add_option("-DCONVOLVED_WIDTH=" + support::cpp11::to_string(convolved_dims.first));
169  build_opts.add_option("-DCONVOLVED_HEIGHT=" + support::cpp11::to_string(convolved_dims.second));
170  build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.stride().first));
171  build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.stride().second));
172  build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left()));
173  build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top()));
174  build_opts.add_option("-DPAD_RIGHT=" + support::cpp11::to_string(conv_info.pad_right()));
175  build_opts.add_option("-DPAD_BOTTOM=" + support::cpp11::to_string(conv_info.pad_bottom()));
176  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input_width));
177  build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input_height));
178  build_opts.add_option("-DSRC_DEPTH=" + support::cpp11::to_string(input_channel));
179  build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(dilation.x()));
180  build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(dilation.y()));
181  build_opts.add_option_if(num_groups > 1, "-DNUM_GROUPS=" + support::cpp11::to_string(num_groups));
182  build_opts.add_option_if_else(is_data_type_quantized(data_type), "-DPAD_VALUE=" + support::cpp11::to_string(qinfo.offset), "-DPAD_VALUE=0");
183  build_opts.add_option_if(has_bias, "-DHAS_BIAS");
184 
186  {
187  num_elems_processed_per_iteration = std::min(2U, input_channel);
188  is_padding_required_nchw = false;
189 
190  // Only the 3x3 and 9x9 cases are optimized for NHWC
191  if(kernel_dims == Size2D(3U, 3U))
192  {
193  kernel_name = "im2col3x3_";
194  }
195  else if(kernel_dims == Size2D(9U, 9U))
196  {
197  kernel_name = "im2col9x9_";
198  }
199 
200  // Get boundary vector (the first/last vector with potentially a partial vector size) size
201  // If input_channel is a multiple of num_elems_processed_per_iteration, the boundary vec size is the (full) vector size
202  // otherwise, the boundary vec size is the (partial) remainder vector size
203  const unsigned int vec_size = num_elems_processed_per_iteration;
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);
206  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vec_size));
207  build_opts.add_option("-DBOUNDARY_VECTOR_SIZE=" + support::cpp11::to_string(boundary_vec_size));
208  }
209  else
210  {
211  if(dilation == Size2D(1U, 1U))
212  {
213  const bool squared_im2col = kernel_dims.width == kernel_dims.height;
214  if(squared_im2col)
215  {
216  // Check if we can run an optimized im2col for NCHW
217  switch(kernel_dims.width)
218  {
219  case 1:
220  // Optimized im2col1x1 if stride_x = 1 and conv_info.has_padding() = false
221  if(conv_info.stride().first == 1 && !conv_info.has_padding())
222  {
223  kernel_name = "im2col1x1_stridex1_";
226  }
227  break;
228  case 3:
229  kernel_name = "im2col3x3_";
232  break;
233  case 5:
234  kernel_name = "im2col5x5_";
237  break;
238  case 11:
239  // Optimized im2col11x11 if pad_x = pad_y = 0
240  if(!conv_info.has_padding())
241  {
242  kernel_name = "im2col11x11_padx0_pady0_";
245  }
246  break;
247  default:
248  kernel_name = "im2col_generic_";
250  is_padding_required_nchw = false;
251  break;
252  }
253  }
254  else if(kernel_dims.width > 1 && !conv_info.has_padding())
255  {
256  kernel_name = "im2col_generic_padx0_pady0_";
258  is_padding_required_nchw = false;
259 
260  // Optimized im2col is performed using one or more vector operations with the specified vector size
261  // and a remainder. For example, for 5x5 convolutions, im2col is performed using vectors of size 4
262  // and scalars; for 7x7 convolutions, using vectors of size 4 and vectors of size 3.
263  // Using the vector size of 4 is always safe since OpenCL supports vectors of size 2 and 3.
264  // Using the vector size of 8, however, may be faster.
265  // For 2x2 convolutions, use vectors of size 2. (For 3x3 convolutions, im2col_kernel3x3_padx0_pady0
266  // is used instead.)
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;
269  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vector_size));
270  build_opts.add_option("-DWIDTH_MOD_VECTOR_SIZE=" + support::cpp11::to_string(width_mod_vector_size));
271  }
272  }
273  }
274 
275  // Append the data layout to the kernel_name
277 
278  Im2ColConfiguration im2col_config;
279  im2col_config.kernel_name = kernel_name;
280  im2col_config.build_options = build_opts.options();
281  im2col_config.num_elems_processed_per_iteration = num_elems_processed_per_iteration;
282  im2col_config.is_padding_required_nchw = is_padding_required_nchw;
283 
284  return im2col_config;
285 }
286 } // namespace
287 
289  : _input(nullptr), _output(nullptr), _data_layout(DataLayout::UNKNOWN), _convolved_dims(), _num_elems_processed_per_iteration(1), _kernel_dims(), _conv_info(), _num_groups()
290 {
291 }
292 
293 void CLIm2ColKernel::configure(const ICLTensor *input, ICLTensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
294  unsigned int num_groups)
295 {
296  configure(CLKernelLibrary::get().get_compile_context(), input, output, kernel_dims, conv_info, has_bias, dilation, num_groups);
297 }
298 
299 void CLIm2ColKernel::configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias,
300  const Size2D &dilation,
301  unsigned int num_groups)
302 {
304  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation, num_groups));
305 
306  auto padding_info = get_padding_info({ input, output });
307  _data_layout = input->info()->data_layout();
308 
311  const unsigned int input_width = input->info()->dimension(width_idx);
312  const unsigned int input_height = input->info()->dimension(height_idx);
313 
314  // Select and configure the optimal OpenCL kernel to run.
315  // This function returns the OpenCL kernel's name, the arguments to pass at compile time, the number of elements processed per iteration
316  // and the padding requirement flag
317  Im2ColConfiguration im2col_config = configure_opencl_kernel(input->info(), kernel_dims, conv_info, has_bias, dilation, num_groups);
318 
319  // Create kernel
320  _kernel = create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options);
321 
322  _input = input;
323  _output = output;
324  _convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
325  _num_elems_processed_per_iteration = im2col_config.num_elems_processed_per_iteration;
326  _kernel_dims = kernel_dims; // Only needed by the Tuner
327  _conv_info = conv_info; // Only needed by the Tuner
329 
330  // Configure kernel window
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);
333  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
334  ICLKernel::configure_internal(win_config.second);
335 
336  // Set config_id for enabling LWS tuning
337  _config_id = im2col_config.kernel_name;
338  _config_id += "_";
339  _config_id += lower_string(string_from_data_type(input->info()->data_type()));
340  _config_id += "_";
341  _config_id += support::cpp11::to_string(num_groups);
342  _config_id += "_";
343  _config_id += support::cpp11::to_string(output->info()->dimension(0));
344  _config_id += "_";
345  _config_id += support::cpp11::to_string(output->info()->dimension(1));
346  _config_id += "_";
348 
349  ARM_COMPUTE_ERROR_ON(input->info()->data_layout() == DataLayout::NHWC && has_padding_changed(padding_info));
350 }
351 
352 Status CLIm2ColKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
353  unsigned int num_groups)
354 {
356  Im2ColConfiguration im2col_config = configure_opencl_kernel(input, kernel_dims, conv_info, has_bias, dilation, num_groups);
357  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
358  im2col_config.is_padding_required_nchw, num_groups)
359  .first);
360  return Status{};
361 }
362 
363 void CLIm2ColKernel::run(const Window &window, cl::CommandQueue &queue)
364 {
367 
368  // Get initial windows
369  // Collapse in order to have (SRC_DEPTH * BATCH_SIZE) on the 3rd dimension
371  window_collapsed.set_dimension_step(Window::DimZ, 1);
372 
373  Window window_output;
374  window_output.use_tensor_dimensions(_output->info()->tensor_shape());
375 
376  const Window first_slice_3d = window_collapsed.first_slice_window_3D();
377 
378  Window slice = first_slice_3d;
379  Window slice_in = first_slice_3d;
380  Window slice_out = window_output.first_slice_window_2D();
381 
383  {
384  const Window tmp_win = window.collapse_if_possible(ICLKernel::window(), 3);
385  const int num_batches = tmp_win[3].end();
386 
387  slice.set(1, Window::Dimension(0, static_cast<int>(_output->info()->tensor_shape()[1]), 1));
388  slice.set(2, Window::Dimension(0, static_cast<int>(num_batches), 1));
389  }
390  else
391  {
393  slice.set(1, Window::Dimension(0, static_cast<int>(_convolved_dims.second), 1));
394  // Note: In case of NCHW the 3rd dimension is already set collapsing the input window
395  }
396 
397  // Setup input slice
398  // The dimensions of the input are increased within the OpenCL kernel
399  slice_in.set(Window::DimX, Window::Dimension(0, 0, 0));
400  slice_in.set(Window::DimY, Window::Dimension(0, 0, 0));
401  slice_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
402 
403  // Setup output slice
404  // The dimensions of the output are increased within the OpenCL kernel
405  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
406  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
407 
409  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_input->info()->strides_in_bytes()[3]));
410  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(_output->info()->strides_in_bytes()[((_num_groups == 1) ? 2 : 3)]));
411  do
412  {
413  unsigned int idx = 0;
414  add_3D_tensor_argument(idx, _input, slice_in);
415  if(_num_groups == 1)
416  {
417  add_2D_tensor_argument(idx, _output, slice_out);
418  }
419  else
420  {
421  add_3D_tensor_argument(idx, _output, slice_out);
422  }
423  enqueue(queue, *this, slice, lws_hint());
424  }
425  while(window_collapsed.slide_window_slice_3D(slice) && window_output.slide_window_slice_2D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in));
426 }
427 } // namespace arm_compute
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:967
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
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)
Definition: CLValidate.h:35
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.
Definition: IKernel.cpp:28
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
Definition: Utils.cpp:489
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(...)
Definition: Validate.h:606
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.
Definition: ICLKernel.cpp:32
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:276
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
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.
Definition: Error.h:466
const DataLayout data_layout
Definition: Im2Col.cpp:151
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:77
Status class.
Definition: Error.h:52
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:326
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
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.
Definition: ICLKernel.h:172
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Definition: Window.inl:276
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:323
Copyright (c) 2017-2021 Arm Limited.
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:90
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.
Definition: Utils.cpp:395
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
const DataType data_type
Definition: Im2Col.cpp:150
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.
Definition: CLHelpers.cpp:403
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
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.
Definition: Window.h:43
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:214
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:179
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.
Definition: Window.inl:68
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.
Definition: Utils.h:71
quantized, asymmetric fixed-point 8-bit number unsigned
const unsigned int num_groups
Definition: Im2Col.cpp:153
std::set< std::string > build_options
const size_t input_width
std::string kernel_name
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:37
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.
Definition: Types.h:650
void end(TokenStream &in, bool &valid)
Definition: MLGOParser.cpp:290
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
static constexpr unsigned int num_arguments_per_2D_tensor()
Returns the number of arguments enqueued per 2D tensor object.
Definition: ICLKernel.h:206
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:335
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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.
Definition: Utils.cpp:504
CLCompileContext class.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:167
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.
Definition: ICLKernel.h:148
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
bool is_padding_required_nchw
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:123
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:439
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
Definition: Error.h:159
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
const QuantizationInfo qinfo
Definition: Im2Col.cpp:155
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
Num samples, height, width, channels.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
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(...)
Definition: Validate.h:157
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.
Definition: Helpers.inl:193
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:291
DataType
Available data types.
Definition: Types.h:77
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
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.
Definition: Window.h:39
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
CLIm2ColKernel()
Default constructor.