Compute Library
 22.02
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/Cast.h"
39 #include "support/StringSupport.h"
40 
41 #include <cmath>
42 #include <tuple>
43 #include <utility>
44 
45 namespace arm_compute
46 {
47 using namespace misc::shape_calculator;
48 namespace opencl
49 {
50 namespace kernels
51 {
52 namespace
53 {
54 struct Im2ColConfiguration
55 {
56  std::string kernel_name{};
57  std::set<std::string> build_options{};
60 };
61 
62 Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
63  unsigned int num_groups)
64 {
65  const unsigned int channel_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::CHANNEL);
66 
69  ARM_COMPUTE_RETURN_ERROR_ON(is_data_type_quantized(src->data_type()) && has_bias);
71  ARM_COMPUTE_RETURN_ERROR_ON((dilation.x() < 1) || (dilation.y() < 1));
72  ARM_COMPUTE_RETURN_ERROR_ON(src->data_layout() == DataLayout::UNKNOWN);
73  ARM_COMPUTE_RETURN_ERROR_ON(num_groups == 0);
74  ARM_COMPUTE_RETURN_ERROR_ON(src->data_layout() == DataLayout::NHWC && num_groups > 1);
75  ARM_COMPUTE_RETURN_ERROR_ON((src->dimension(channel_idx) % num_groups) != 0);
76 
77  // Since there's no implicit padding added, check the total input spatial dimensions (with conv paddings) are big enough for the kernel dimensions
78  const unsigned int width_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::WIDTH);
79  const unsigned int height_idx = get_data_layout_dimension_index(src->data_layout(), DataLayoutDimension::HEIGHT);
80  const unsigned total_width = src->dimension(width_idx) + conv_info.pad_left() + conv_info.pad_right();
81  const unsigned total_height = src->dimension(height_idx) + conv_info.pad_top() + conv_info.pad_bottom();
82  ARM_COMPUTE_RETURN_ERROR_ON((total_width < kernel_dims.width) || (total_height < kernel_dims.height));
83 
84  if(dst->total_size() > 0)
85  {
86  const TensorInfo tensor_info_output = dst->clone()->set_tensor_shape(compute_im2col_conv_shape(src, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups));
87  ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(dst, &tensor_info_output);
90  }
91 
92  return Status{};
93 }
94 
95 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *src, ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
96  unsigned int num_elems_processed_per_iteration, bool is_padding_required_nchw, unsigned int num_groups)
97 {
99 
100  // Output tensor auto initialization if not yet initialized
101  TensorShape expected_output_shape = compute_im2col_conv_shape(src, kernel_dims, conv_info, has_bias, dilation, num_groups == 1, num_groups);
102 
103  auto_init_if_empty(*dst, src->clone()->set_tensor_shape(expected_output_shape));
104 
105  const DataLayout data_layout = src->data_layout();
106  const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
107  const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
108  const unsigned int input_width = src->dimension(width_idx);
109  const unsigned int input_height = src->dimension(height_idx);
110 
111  // Configure the execute window based on the selected optimal OpenCL kernel
112  bool window_changed = false;
113  Window win;
114 
115  if(data_layout == DataLayout::NHWC)
116  {
117  win = calculate_max_window(*src, Steps(num_elems_processed_per_iteration));
118  }
119  else
120  {
121  if(is_padding_required_nchw)
122  {
123  const BorderSize border(conv_info.pad_top(), conv_info.pad_right(), conv_info.pad_bottom(), conv_info.pad_left());
124  win = calculate_max_window(*src,
125  Steps(num_elems_processed_per_iteration * conv_info.stride().first, conv_info.stride().second));
126  AccessWindowStatic input_access(src,
127  -border.left,
128  -border.top,
129  ceil_to_multiple(input_width + border.right, kernel_dims.width * num_elems_processed_per_iteration),
130  input_height + border.bottom);
131  window_changed = window_changed || update_window_and_padding(win, input_access);
132  }
133  else
134  {
135  // For the generic case, CLIm2ColKernel doesn't need padding (we do not read out-of-bounds elements) so
136  // update_window_and_padding() can be skipped
137  win = calculate_max_window(*src, Steps());
138  }
139  }
140 
141  // set the Z dimension's step same size as the whole dimension so that one can't split across the Z dimension
142  win.set_dimension_step(Window::DimZ, win[Window::DimZ].end() - win[Window::DimZ].start());
143 
144  Status err = (window_changed) ? ARM_COMPUTE_CREATE_ERROR(ErrorCode::RUNTIME_ERROR, "Insufficient Padding!") : Status{};
145  return std::make_pair(err, win);
146 }
147 
148 Im2ColConfiguration configure_opencl_kernel(const ITensorInfo *src, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation, unsigned int num_groups)
149 {
150  const DataLayout data_layout = src->data_layout();
151  const DataType data_type = src->data_type();
152  const unsigned int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
153  const unsigned int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
154  const unsigned int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
155  const unsigned int input_width = src->dimension(width_idx);
156  const unsigned int input_height = src->dimension(height_idx);
157  const unsigned int input_channel = src->dimension(channel_idx);
158 
159  const std::pair<unsigned int, unsigned int> convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
160 
161  // Im2Col configuration
162  std::string kernel_name = "im2col_generic_";
163  CLBuildOptions build_opts;
164  unsigned int num_elems_processed_per_iteration = 1;
165  bool is_padding_required_nchw = false;
166  const UniformQuantizationInfo qinfo = src->quantization_info().uniform();
167 
168  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type));
169  build_opts.add_option("-DELEMENT_SIZE=" + support::cpp11::to_string(src->element_size()));
170  build_opts.add_option("-DKERNEL_WIDTH=" + support::cpp11::to_string(kernel_dims.width));
171  build_opts.add_option("-DKERNEL_HEIGHT=" + support::cpp11::to_string(kernel_dims.height));
172  build_opts.add_option("-DCONVOLVED_WIDTH=" + support::cpp11::to_string(convolved_dims.first));
173  build_opts.add_option("-DCONVOLVED_HEIGHT=" + support::cpp11::to_string(convolved_dims.second));
174  build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.stride().first));
175  build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.stride().second));
176  build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left()));
177  build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top()));
178  build_opts.add_option("-DPAD_RIGHT=" + support::cpp11::to_string(conv_info.pad_right()));
179  build_opts.add_option("-DPAD_BOTTOM=" + support::cpp11::to_string(conv_info.pad_bottom()));
180  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(input_width));
181  build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(input_height));
182  build_opts.add_option("-DSRC_DEPTH=" + support::cpp11::to_string(input_channel));
183  build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(dilation.x()));
184  build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(dilation.y()));
185  build_opts.add_option_if(num_groups > 1, "-DNUM_GROUPS=" + support::cpp11::to_string(num_groups));
186  build_opts.add_option_if_else(is_data_type_quantized(data_type), "-DPAD_VALUE=" + support::cpp11::to_string(qinfo.offset), "-DPAD_VALUE=0");
187  build_opts.add_option_if(has_bias, "-DHAS_BIAS");
188 
189  if(data_layout == DataLayout::NHWC)
190  {
191  num_elems_processed_per_iteration = std::min(2U, input_channel);
192  is_padding_required_nchw = false;
193 
194  // Only the 3x3 and 9x9 cases are optimized for NHWC
195  if(kernel_dims == Size2D(3U, 3U))
196  {
197  kernel_name = "im2col3x3_";
198  build_opts.add_option("-DIM2COL_3X3");
199  }
200  else if(kernel_dims == Size2D(9U, 9U))
201  {
202  kernel_name = "im2col9x9_";
203  build_opts.add_option("-DIM2COL_9X9");
204  }
205  else
206  {
207  build_opts.add_option("-DIM2COL_GENERIC");
208  }
209 
210  // Get boundary vector (the first/last vector with potentially a partial vector size) size
211  // If input_channel is a multiple of num_elems_processed_per_iteration, the boundary vec size is the (full) vector size
212  // otherwise, the boundary vec size is the (partial) remainder vector size
213  const unsigned int vec_size = num_elems_processed_per_iteration;
214  const unsigned int partial_vec_size = input_channel % vec_size;
215  const unsigned int boundary_vec_size = vec_size - ((vec_size - partial_vec_size) % vec_size);
216  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vec_size));
217  build_opts.add_option("-DBOUNDARY_VECTOR_SIZE=" + support::cpp11::to_string(boundary_vec_size));
218  }
219  else
220  {
221  if(dilation == Size2D(1U, 1U))
222  {
223  const bool squared_im2col = kernel_dims.width == kernel_dims.height;
224  if(squared_im2col)
225  {
226  // Check if we can run an optimized im2col for NCHW
227  switch(kernel_dims.width)
228  {
229  case 1:
230  // Optimized im2col1x1 if stride_x = 1 and conv_info.has_padding() = false
231  if(conv_info.stride().first == 1 && !conv_info.has_padding())
232  {
233  kernel_name = "im2col1x1_stridex1_";
234  num_elems_processed_per_iteration = 4;
235  is_padding_required_nchw = true;
236  }
237  break;
238  case 3:
239  kernel_name = "im2col3x3_";
240  num_elems_processed_per_iteration = 1;
241  is_padding_required_nchw = true;
242  break;
243  case 5:
244  kernel_name = "im2col5x5_";
245  num_elems_processed_per_iteration = 1;
246  is_padding_required_nchw = true;
247  break;
248  case 11:
249  // Optimized im2col11x11 if pad_x = pad_y = 0
250  if(!conv_info.has_padding())
251  {
252  kernel_name = "im2col11x11_padx0_pady0_";
253  num_elems_processed_per_iteration = 1;
254  is_padding_required_nchw = true;
255  }
256  break;
257  default:
258  kernel_name = "im2col_generic_";
259  num_elems_processed_per_iteration = 1;
260  is_padding_required_nchw = false;
261  break;
262  }
263  }
264  else if(kernel_dims.width > 1 && !conv_info.has_padding())
265  {
266  kernel_name = "im2col_generic_padx0_pady0_";
267  num_elems_processed_per_iteration = 1;
268  is_padding_required_nchw = false;
269 
270  // Optimized im2col is performed using one or more vector operations with the specified vector size
271  // and a remainder. For example, for 5x5 convolutions, im2col is performed using vectors of size 4
272  // and scalars; for 7x7 convolutions, using vectors of size 4 and vectors of size 3.
273  // Using the vector size of 4 is always safe since OpenCL supports vectors of size 2 and 3.
274  // Using the vector size of 8, however, may be faster.
275  // For 2x2 convolutions, use vectors of size 2. (For 3x3 convolutions, im2col_kernel3x3_padx0_pady0
276  // is used instead.)
277  const size_t vector_size = std::min(static_cast<size_t>(4), kernel_dims.width);
278  const size_t width_mod_vector_size = kernel_dims.width % vector_size;
279  build_opts.add_option("-DVECTOR_SIZE=" + support::cpp11::to_string(vector_size));
280  build_opts.add_option("-DWIDTH_MOD_VECTOR_SIZE=" + support::cpp11::to_string(width_mod_vector_size));
281  }
282  }
283  }
284 
285  // Append the data layout to the kernel_name
286  kernel_name += lower_string(string_from_data_layout(data_layout));
287 
288  Im2ColConfiguration im2col_config;
289  im2col_config.kernel_name = kernel_name;
290  im2col_config.build_options = build_opts.options();
291  im2col_config.num_elems_processed_per_iteration = num_elems_processed_per_iteration;
292  im2col_config.is_padding_required_nchw = is_padding_required_nchw;
293 
294  return im2col_config;
295 }
296 } // namespace
297 
299  : _data_layout(DataLayout::UNKNOWN), _convolved_dims(), _num_elems_processed_per_iteration(1), _kernel_dims(), _conv_info(), _num_groups()
300 {
302 }
303 
304 void ClIm2ColKernel::configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias,
305  const Size2D &dilation,
306  unsigned int num_groups)
307 {
309  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, kernel_dims, conv_info, has_bias, dilation, num_groups));
310 
311  auto padding_info = get_padding_info({ src, dst });
312  _data_layout = src->data_layout();
313 
314  const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
315  const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
316  const unsigned int input_width = src->dimension(width_idx);
317  const unsigned int input_height = src->dimension(height_idx);
318 
319  // Select and configure the optimal OpenCL kernel to run.
320  // This function returns the OpenCL kernel's name, the arguments to pass at compile time, the number of elements processed per iteration
321  // and the padding requirement flag
322  Im2ColConfiguration im2col_config = configure_opencl_kernel(src, kernel_dims, conv_info, has_bias, dilation, num_groups);
323 
324  // Create kernel
325  _kernel = create_kernel(compile_context, im2col_config.kernel_name, im2col_config.build_options);
326 
327  _convolved_dims = scaled_dimensions(input_width, input_height, kernel_dims.width, kernel_dims.height, conv_info, dilation);
328  _num_elems_processed_per_iteration = im2col_config.num_elems_processed_per_iteration;
329  _kernel_dims = kernel_dims; // Only needed by the Tuner
330  _conv_info = conv_info; // Only needed by the Tuner
332 
333  // Configure kernel window
334  auto win_config = validate_and_configure_window(src, dst, kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
335  im2col_config.is_padding_required_nchw, num_groups);
336  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
337  IClKernel::configure_internal(win_config.second);
338 
339  // Set config_id for enabling LWS tuning
340  _config_id = im2col_config.kernel_name;
341  _config_id += "_";
342  _config_id += lower_string(string_from_data_type(src->data_type()));
343  _config_id += "_";
344  _config_id += support::cpp11::to_string(num_groups);
345  _config_id += "_";
346  _config_id += support::cpp11::to_string(dst->dimension(0));
347  _config_id += "_";
348  _config_id += support::cpp11::to_string(dst->dimension(1));
349  _config_id += "_";
350  _config_id += lower_string(string_from_data_layout(_data_layout));
351 
353 }
354 
355 Status ClIm2ColKernel::validate(const ITensorInfo *src, const ITensorInfo *dst, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation,
356  unsigned int num_groups)
357 {
358  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, dst, kernel_dims, conv_info, has_bias, dilation, num_groups));
359  Im2ColConfiguration im2col_config = configure_opencl_kernel(src, kernel_dims, conv_info, has_bias, dilation, num_groups);
360  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(src->clone().get(), dst->clone().get(), kernel_dims, conv_info, has_bias, dilation, im2col_config.num_elems_processed_per_iteration,
361  im2col_config.is_padding_required_nchw, num_groups)
362  .first);
363  return Status{};
364 }
365 
366 void ClIm2ColKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
367 {
370  ARM_COMPUTE_ERROR_ON(tensors.empty());
371 
372  // Get initial windows
373  // Collapse in order to have (SRC_DEPTH * BATCH_SIZE) on the 3rd dimension
374  Window window_collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimZ);
375  window_collapsed.set_dimension_step(Window::DimZ, 1);
376 
377  auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC));
378  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
380 
381  Window window_output;
382  window_output.use_tensor_dimensions(dst->info()->tensor_shape());
383 
384  const Window first_slice_3d = window_collapsed.first_slice_window_3D();
385 
386  Window slice = first_slice_3d;
387  Window slice_in = first_slice_3d;
388  Window slice_out = window_output.first_slice_window_2D();
389 
391  {
392  const Window tmp_win = window.collapse_if_possible(ICLKernel::window(), 3);
393  const int num_batches = tmp_win[3].end();
394 
395  slice.set(1, Window::Dimension(0, static_cast<int>(dst->info()->tensor_shape()[1]), 1));
396  slice.set(2, Window::Dimension(0, static_cast<int>(num_batches), 1));
397  }
398  else
399  {
401  slice.set(1, Window::Dimension(0, static_cast<int>(_convolved_dims.second), 1));
402  // Note: In case of NCHW the 3rd dimension is already set collapsing the input window
403  }
404 
405  // Setup input slice
406  // The dimensions of the input are increased within the OpenCL kernel
407  slice_in.set(Window::DimX, Window::Dimension(0, 0, 0));
408  slice_in.set(Window::DimY, Window::Dimension(0, 0, 0));
409  slice_in.set(Window::DimZ, Window::Dimension(0, 0, 0));
410 
411  // Setup output slice
412  // The dimensions of the output are increased within the OpenCL kernel
413  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
414  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
415 
417  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(src->info()->strides_in_bytes()[3]));
418  _kernel.setArg<cl_uint>(idx++, static_cast<unsigned int>(dst->info()->strides_in_bytes()[((_num_groups == 1) ? 2 : 3)]));
419  do
420  {
421  unsigned int idx = 0;
422  add_3D_tensor_argument(idx, src, slice_in);
423  if(_num_groups == 1)
424  {
425  add_2D_tensor_argument(idx, dst, slice_out);
426  }
427  else
428  {
429  add_3D_tensor_argument(idx, dst, slice_out);
430  }
431  enqueue(queue, *this, slice, lws_hint());
432  }
433  while(window_collapsed.slide_window_slice_3D(slice) && window_output.slide_window_slice_2D(slice_out) && window_collapsed.slide_window_slice_3D(slice_in));
434 }
435 } // namespace kernels
436 } // namespace opencl
437 } // namespace arm_compute
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:996
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:283
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
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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
Unknown CL kernel type.
Definition: CLTypes.h:81
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
bool empty() const
Checks if pack is empty.
Definition: ITensorPack.cpp:80
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:353
#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.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
bool is_padding_required_nchw
#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
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
Status class.
Definition: Error.h:52
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:338
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
std::set< std::string > build_options
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:214
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor&#39;s dimensions to fill the window dimensions.
Definition: Window.inl:276
SimpleTensor< float > src
Definition: DFT.cpp:155
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:91
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:414
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
const DataType data_type
Definition: Im2Col.cpp:150
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
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:391
const size_t input_width
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
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:291
#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
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
unsigned int num_elems_processed_per_iteration
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:39
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.
Padding and stride information class.
Definition: Types.h:656
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:283
Elementeise CL kernel type.
Definition: CLTypes.h:84
#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:552
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&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:190
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
Definition: ITensorPack.cpp:64
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:90
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
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...
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
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.
const size_t input_height
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
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:537
Wrapper to configure the Khronos OpenCL C++ header.
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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.
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.
quantized, asymmetric fixed-point 8-bit number signed
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:291
std::string kernel_name
DataType
Available data types.
Definition: Types.h:79
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
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
std::pair< unsigned int, unsigned int > _convolved_dims
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.