Compute Library
 22.08
ClDirectConv2dKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2022 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 
32 #include "arm_compute/core/Utils.h"
36 #include "src/core/CL/CLUtils.h"
37 #include "src/core/CL/CLValidate.h"
41 #include "support/Cast.h"
42 #include "support/StringSupport.h"
43 
44 namespace arm_compute
45 {
46 namespace opencl
47 {
48 namespace kernels
49 {
50 namespace
51 {
52 Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst,
53  const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
54 {
58 
59  const DataLayout data_layout = src->data_layout();
60  const int width_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH);
61  const int height_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT);
62  const int channel_idx = get_data_layout_dimension_index(data_layout, DataLayoutDimension::CHANNEL);
63 
64  ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(channel_idx) != src->dimension(channel_idx), "Weights feature map dimension should match the respective src's one");
65  ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->num_dimensions() > 4, "Weights can be at most 4 dimensional");
66 
67  if(data_layout == DataLayout::NCHW)
68  {
69  ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != weights->dimension(height_idx), "Weights should have same width and height");
70  ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(width_idx) == 1) && std::get<0>(conv_info.stride()) > 3, "Strides larger than 3 not supported for 1x1 convolution.");
71  ARM_COMPUTE_RETURN_ERROR_ON_MSG((weights->dimension(width_idx) == 3 || weights->dimension(width_idx) == 5 || weights->dimension(width_idx) == 9) && std::get<0>(conv_info.stride()) > 2,
72  "Strides larger than 2 not supported for 3x3, 5x5, 9x9 convolution.");
73  ARM_COMPUTE_RETURN_ERROR_ON_MSG(!is_data_type_float(src->data_type()) && act_info.enabled(), "Activation supported only for floating point and NHWC.");
74 
75  if(is_data_type_quantized(src->data_type()))
76  {
77  ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != 1 && weights->dimension(width_idx) != 3 && weights->dimension(width_idx) != 5 && weights->dimension(width_idx) != 9,
78  "Kernel sizes other than 1x1, 3x3, 5x5 or 9x9 are not supported with quantized data types");
79  }
80  else
81  {
82  ARM_COMPUTE_RETURN_ERROR_ON_MSG(weights->dimension(width_idx) != 1 && weights->dimension(width_idx) != 3 && weights->dimension(width_idx) != 5,
83  "Kernel sizes other than 1x1, 3x3 or 5x5 are not supported with float data types");
84  }
85  }
86 
87  if(data_layout == DataLayout::NHWC)
88  {
89  ARM_COMPUTE_RETURN_ERROR_ON_MSG(desc.n0 != 1 && desc.n0 != 2 && desc.n0 != 3 && desc.n0 != 4 && desc.n0 != 8 && desc.n0 != 16,
90  "N0 can only be: 1, 2, 3, 4, 8, and 16");
91  ARM_COMPUTE_RETURN_ERROR_ON_MSG(desc.k0 != 1 && desc.k0 != 2 && desc.k0 != 3 && desc.k0 != 4 && desc.k0 != 8 && desc.k0 != 16,
92  "K0 can only be: 1, 2, 3, 4, 8, and 16");
93  if(desc.export_weights_to_cl_image)
94  {
95  ARM_COMPUTE_RETURN_ERROR_ON_MSG(desc.k0 != 4 && desc.k0 != 8 && desc.k0 != 16,
96  "K0 can only be: 4, 8, and 16");
98  "Export to CLImage is not supported for this weight configuration");
99  }
100  }
101 
102  if(biases != nullptr)
103  {
104  if(is_data_type_quantized_asymmetric(src->data_type()))
105  {
107  }
108  else
109  {
111  }
112  ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->dimension(0) != weights->dimension(3),
113  "Biases size and number of dst feature maps should match");
114  ARM_COMPUTE_RETURN_ERROR_ON_MSG(biases->num_dimensions() > 1,
115  "Biases should be one dimensional");
116  }
117 
118  // Checks performed when dst is configured
119  if(dst->total_size() != 0)
120  {
122  misc::shape_calculator::compute_deep_convolution_shape(*src, *weights, conv_info));
124  }
125 
126  const auto data_type = src->data_type();
128  {
129  const UniformQuantizationInfo iqinfo = src->quantization_info().uniform();
130  const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform();
131  const UniformQuantizationInfo oqinfo = dst->quantization_info().uniform();
132 
133  float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
134  int output_multiplier = 0;
135  int output_shift = 0;
136  ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift));
137  }
138  return Status{};
139 }
140 } // namespace
141 
143 {
144  _type = CLKernelType::DIRECT;
145 }
146 
147 void ClDirectConv2dKernel::configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst,
148  const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
149 {
150  ARM_COMPUTE_ERROR_ON_NULLPTR(src, weights, dst);
151 
152  // Perform validation
153  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, weights, biases, dst, conv_info, act_info, desc));
154 
155  const int conv_stride_x = std::get<0>(conv_info.stride());
156  const int conv_stride_y = std::get<1>(conv_info.stride());
157 
158  _data_layout = src->data_layout();
160 
161  const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
162  const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
163  const unsigned int channel_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::CHANNEL);
164  const unsigned int kernel_size = weights->dimension(width_idx);
165  const DataType data_type = src->data_type();
166 
167  const GPUTarget gpu_target = get_target();
168  unsigned int _num_elems_processed_per_iteration = 0;
169 
170  // Get dst shape
172 
173  // Output auto inizialitation if not yet initialized
174  auto_init_if_empty(*dst, output_shape,
175  1,
176  src->data_type(),
177  src->quantization_info());
178 
179  // Configure kernel window
180  Window win;
181  if(_data_layout == DataLayout::NHWC)
182  {
183  output_shape.collapse(2U, 1U);
184  const unsigned int n0 = adjust_vec_size(desc.n0, output_shape[0]);
185  const unsigned int m0 = adjust_vec_size(desc.m0, output_shape[1]);
186 
187  // Create window and update padding
188  win = calculate_max_window(output_shape, Steps(n0, m0));
189  }
190  else if(_data_layout == DataLayout::NCHW)
191  {
192  _num_elems_processed_per_iteration = 1u;
193  win = calculate_max_window(*dst, Steps(_num_elems_processed_per_iteration));
194  }
195 
196  ICLKernel::configure_internal(win);
197 
198  std::stringstream kernel_name;
200 
201  if(_data_layout == DataLayout::NHWC)
202  {
203  kernel_name << "direct_convolution_nhwc";
204 
205  const unsigned int n0 = win.x().step();
206  const unsigned int m0 = win.y().step();
207  const unsigned int k0 = adjust_vec_size(desc.k0, src->dimension(channel_idx));
208  const unsigned int partial_store_n0 = dst->dimension(channel_idx) % n0;
209  const unsigned int pad_left = conv_info.pad_left();
210  const unsigned int pad_top = conv_info.pad_top();
211 
213 
214  // Update the padding for the weights tensor if we can export to cl_image
216  {
218  }
219 
220  if(biases != nullptr)
221  {
222  build_options.add_option(std::string("-DHAS_BIAS"));
223  build_options.add_option(std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(biases->data_type())));
224  }
225 
226  // Conditions of -cl-fast-relaxed-math causing accuracy issues can be traced from COMPMID-5324
227  const auto act_function = act_info.activation();
228  const auto dst_data_type = dst->data_type();
229 
230  if((gpu_target != GPUTarget::G71 && (gpu_target & GPUTarget::GPU_ARCH_MASK) == GPUTarget::BIFROST)
232  && (dst_data_type == DataType::F32 || dst_data_type == DataType::F16))
233  {
234  // -cl-fast-relaxed-math also sets -cl-finite-math-only and -cl-unsafe-math-optimizations
235  // to disable -cl-finite-math-only, we only include -cl-unsafe-math-optimizations
236  build_options.add_option("-cl-unsafe-math-optimizations");
237  }
238  else
239  {
240  build_options.add_option("-cl-fast-relaxed-math");
241  }
242 
243  build_options.add_option("-DSRC_TENSOR_TYPE=BUFFER");
244  build_options.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(src->data_type()));
245  build_options.add_option("-DDST_TENSOR_TYPE=BUFFER");
246  build_options.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(dst_data_type));
247  build_options.add_option_if_else(_export_to_cl_image, "-DWEI_TENSOR_TYPE=IMAGE", "-DWEI_TENSOR_TYPE=BUFFER");
248  build_options.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(weights->dimension(width_idx)));
249  build_options.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(weights->dimension(height_idx)));
250  build_options.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(weights->data_type()));
251  build_options.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_stride_x));
252  build_options.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_stride_y));
253  build_options.add_option("-DPAD_LEFT=" + support::cpp11::to_string(pad_left));
254  build_options.add_option("-DPAD_TOP=" + support::cpp11::to_string(pad_top));
255  build_options.add_option("-DN0=" + support::cpp11::to_string(n0));
256  build_options.add_option("-DM0=" + support::cpp11::to_string(m0));
257  build_options.add_option("-DK0=" + support::cpp11::to_string(k0));
258  build_options.add_option("-DPARTIAL_N0=" + support::cpp11::to_string(partial_store_n0));
259  build_options.add_option_if((src->dimension(channel_idx) % k0) != 0, "-DLEFTOVER_LOOP");
260  build_options.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(act_function)));
261 
262  if(is_data_type_quantized(data_type))
263  {
264  const UniformQuantizationInfo iqinfo = src->quantization_info().uniform();
265  const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform();
266  const UniformQuantizationInfo oqinfo = dst->quantization_info().uniform();
267 
268  PixelValue zero_value = PixelValue(0, src->data_type(), src->quantization_info());
269  int zero_value_s32;
270  zero_value.get(zero_value_s32);
271 
272  float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
273  int output_multiplier = 0;
274  int output_shift = 0;
275  quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
276  build_options.add_option("-DIS_QUANTIZED");
277  build_options.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier));
278  build_options.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift));
279  build_options.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset));
280  build_options.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset));
281  build_options.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset));
282  build_options.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32));
283  build_options.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32));
284  }
285  else
286  {
287  build_options.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(data_type));
288  build_options.add_option("-DZERO_VALUE=" + support::cpp11::to_string(0));
289  build_options.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(0));
290  build_options.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(0));
291  build_options.add_option("-DDST_OFFSET=" + support::cpp11::to_string(0));
292  build_options.add_option_if(act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(act_info.a()));
293  build_options.add_option_if(act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(act_info.b()));
294  }
295  }
296  else
297  {
298  _export_to_cl_image = false;
299 
300  kernel_name << "direct_convolution_nchw";
301  build_options.add_option_if(biases != nullptr, std::string("-DHAS_BIAS"));
302  build_options.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(src->dimension(width_idx)));
303  build_options.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(src->dimension(height_idx)));
304  build_options.add_option("-DSRC_CHANNELS=" + support::cpp11::to_string(src->dimension(channel_idx)));
305  build_options.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_left()));
306  build_options.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_top()));
307  build_options.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_stride_x));
308  build_options.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_stride_y));
309  build_options.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(weights->dimension(width_idx)));
310  build_options.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(weights->dimension(height_idx)));
311  build_options.add_option(std::string("-DDATA_TYPE=" + get_cl_type_from_data_type(data_type)));
312  build_options.add_option(std::string("-DDATA_SIZE=" + get_data_size_from_data_type(data_type)));
313  build_options.add_option(std::string("-DWEIGHTS_DEPTH=" + support::cpp11::to_string(weights->dimension(channel_idx))));
314  build_options.add_option(std::string("-DSTRIDE_X=" + support::cpp11::to_string(conv_stride_x)));
315  build_options.add_option(std::string("-DDATA_TYPE_PROMOTED=" + get_cl_type_from_data_type(data_type)));
316  build_options.add_option(std::string("-DVEC_SIZE=" + support::cpp11::to_string(_num_elems_processed_per_iteration)));
317  build_options.add_option(std::string("-DVEC_SIZE_LEFTOVER=" + support::cpp11::to_string(src->dimension(0) % _num_elems_processed_per_iteration)));
318 
319  if(is_data_type_quantized(data_type))
320  {
321  const UniformQuantizationInfo iqinfo = src->quantization_info().uniform();
322  const UniformQuantizationInfo wqinfo = weights->quantization_info().uniform();
323  const UniformQuantizationInfo oqinfo = dst->quantization_info().uniform();
324 
325  float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
326  int output_multiplier = 0;
327  int output_shift = 0;
328  quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
329  build_options.add_option("-DIS_QUANTIZED");
330  build_options.add_option("-DOUTPUT_MULTIPLIER=" + support::cpp11::to_string(output_multiplier));
331  build_options.add_option("-DOUTPUT_SHIFT=" + support::cpp11::to_string(output_shift));
332  build_options.add_option("-DKERNEL_SIZE=" + support::cpp11::to_string(kernel_size));
333  build_options.add_option("-DINPUT_OFFSET=" + support::cpp11::to_string(-iqinfo.offset));
334  build_options.add_option("-DWEIGHTS_OFFSET=" + support::cpp11::to_string(-wqinfo.offset));
335  build_options.add_option("-DOUTPUT_OFFSET=" + support::cpp11::to_string(oqinfo.offset));
336  }
337  }
338 
339  _kernel = create_kernel(compile_context, kernel_name.str(), build_options.options());
340 
341  // Set config_id for enabling LWS tuning
342  _config_id = kernel_name.str();
343  _config_id += "_";
344  _config_id += lower_string(string_from_data_type(data_type));
345  _config_id += "_";
346  _config_id += support::cpp11::to_string(kernel_size);
347  _config_id += "_";
348  _config_id += support::cpp11::to_string(border_size().left);
349  _config_id += "_";
350  _config_id += support::cpp11::to_string(border_size().top);
351  _config_id += "_";
352  _config_id += support::cpp11::to_string(border_size().right);
353  _config_id += "_";
354  _config_id += support::cpp11::to_string(border_size().bottom);
355  _config_id += "_";
356  _config_id += support::cpp11::to_string(conv_stride_x);
357  _config_id += "_";
358  _config_id += support::cpp11::to_string(conv_stride_y);
359  _config_id += "_";
360  _config_id += support::cpp11::to_string(dst->dimension(width_idx));
361  _config_id += "_";
362  _config_id += support::cpp11::to_string(dst->dimension(height_idx));
363  _config_id += "_";
364  _config_id += lower_string(string_from_data_layout(_data_layout));
365 }
366 
367 Status ClDirectConv2dKernel::validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst,
368  const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
369 {
370  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, weights, biases, dst, conv_info, act_info, desc));
371  return Status{};
372 }
373 
374 void ClDirectConv2dKernel::run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue)
375 {
378 
379  // Get initial windows
381 
382  const auto src = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_0));
383  const auto weights = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_1));
384  const auto biases = utils::cast::polymorphic_downcast<const ICLTensor *>(tensors.get_const_tensor(TensorType::ACL_SRC_2));
385  auto dst = utils::cast::polymorphic_downcast<ICLTensor *>(tensors.get_tensor(TensorType::ACL_DST));
386 
388  {
389  cl::Image2D weights_cl_image;
390 
392  {
393  const size_t image_w = weights->info()->dimension(0) / 4;
394  const size_t image_h = weights->info()->dimension(1) * weights->info()->dimension(2) * weights->info()->dimension(3);
395  const TensorShape shape2d(image_w, image_h);
396  const size_t image_row_pitch = weights->info()->strides_in_bytes()[1];
397 
398  // Export cl_buffer to cl_image
399  weights_cl_image = create_image2d_from_buffer(CLKernelLibrary::get().context(), weights->cl_buffer(), shape2d, weights->info()->data_type(), image_row_pitch);
400  }
401 
402  unsigned int idx = 0;
403  add_4d_tensor_nhwc_argument(idx, src);
404  add_4d_tensor_nhwc_argument(idx, dst);
406  {
407  _kernel.setArg(idx++, weights_cl_image);
408  }
409  add_4d_tensor_nhwc_argument(idx, weights);
410  if(biases != nullptr)
411  {
412  add_1D_tensor_argument(idx, biases, slice);
413  }
414  enqueue(queue, *this, slice, lws_hint());
415  }
416  else
417  {
418  unsigned int idx1 = 2 * num_arguments_per_3D_tensor();
419  add_3D_tensor_argument(idx1, weights, slice);
420 
421  if(biases != nullptr)
422  {
423  Window slice_biases;
424  slice_biases.use_tensor_dimensions(biases->info()->tensor_shape());
425  add_1D_tensor_argument(idx1, biases, slice_biases);
426  }
427 
428  _kernel.setArg(idx1++, static_cast<unsigned int>(weights->info()->strides_in_bytes()[3]));
429 
430  do
431  {
432  unsigned int idx = 0;
433  add_3D_tensor_argument(idx, src, slice);
434  add_3D_tensor_argument(idx, dst, slice);
435  enqueue(queue, *this, slice, lws_hint());
436  }
437  while(window.slide_window_slice_3D(slice));
438  }
439 }
440 } // namespace kernels
441 } // namespace opencl
442 } // namespace arm_compute
void add_4d_tensor_nhwc_argument(unsigned int &idx, const ICLTensor *tensor)
Add the passed NHWC 4D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments by passing strides...
Definition: ICLKernel.cpp:144
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:1030
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
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
Shape of a tensor.
Definition: TensorShape.h:39
bool export_weights_to_cl_image(const ITensorInfo *tensor)
Definition: CLHelpers.cpp:444
bool enabled() const
Check if initialised.
Definition: Types.h:1678
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
Static function to check if given info will lead to a valid configuration.
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
const StringSet & options() const
Gets the current options list set.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:384
float a() const
Get the alpha value.
Definition: Types.h:1668
void get(uint8_t &v) const
Interpret the pixel value as a U8.
Definition: PixelValue.h:244
#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
const std::string & string_from_activation_func(ActivationLayerInfo::ActivationFunction act)
Translates a given activation function to a string.
Definition: Utils.cpp:163
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
Quantization info when assuming per layer quantization.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
unsigned int pad_top() const
Get the top padding.
Definition: Types.h:753
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
Status class.
Definition: Error.h:52
bool export_weights_to_cl_image
Flag to export the weights to cl_image.
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:351
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Activation Layer Information class.
Definition: Types.h:1625
std::set< std::string > build_options
void update_padding_for_cl_image(ITensorInfo *tensor)
Update padding required to export the OpenCL buffer to OpenCL image2d.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:284
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:227
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
Copyright (c) 2017-2022 Arm Limited.
1 channel, 1 F16 per channel
1 channel, 1 S32 per channel
void add_option(std::string option)
Adds option to the existing build option list.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
Definition: ITensorPack.cpp:54
const size_t conv_stride_y
Definition: impl.cpp:58
int32_t n0
Number of columns to be processed by the kernel.
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:404
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
Definition: Utils.cpp:135
std::string get_data_size_from_data_type(const DataType &dt)
Get the size of a data type in number of bits.
Definition: CLHelpers.cpp:193
static constexpr unsigned int num_arguments_per_3D_tensor()
Returns the number of arguments enqueued per 3D tensor object.
Definition: ICLKernel.h:314
int32_t k0
Number of partial accumulations to be processed in a single iteration by the kernel.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1124
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:717
GPUTarget get_target() const
Get the targeted GPU architecture.
Definition: ICLKernel.h:444
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 BorderSize border_size() const
The size of the border for that kernel.
Definition: IKernel.cpp:46
Compute descriptor used by the direct convolution kernel.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
Padding and stride information class.
Definition: Types.h:669
void configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info, const ActivationLayerInfo &act_info, const DirectConvComputeKernelInfo &desc)
Set the src, weights, biases and dst tensors info.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:349
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
Num samples, channels, height, width.
CLCompileContext class.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:1052
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
GPUTarget
Available GPU Targets.
Definition: GPUTarget.h:34
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
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_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
Num samples, height, width, channels.
int32_t m0
Number of rows to be processed by the kernel.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
Tensor packing service.
Definition: ITensorPack.h:39
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
cl::Image2D create_image2d_from_buffer(const cl::Context &ctx, const cl::Buffer &buffer, const TensorShape &shape2d, DataType data_type, size_t image_row_pitch)
Create a cl::Image2D object from an OpenCL buffer.
Definition: CLUtils.cpp:35
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&#39;s first dimension, getting rounded down to its closest valid vector size.
Definition: Utils.h:1222
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1663
float b() const
Get the beta value.
Definition: Types.h:1673
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&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:179
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:305
std::string kernel_name
DataType
Available data types.
Definition: Types.h:79
unsigned int pad_left() const
Get the left padding.
Definition: Types.h:743
DataLayout
[DataLayout enum definition]
Definition: Types.h:113
const size_t conv_stride_x
Definition: impl.cpp:57
Describe a multidimensional execution window.
Definition: Window.h:39
void collapse(size_t n, size_t first=0)
Collapse the first n dimensions.
Definition: TensorShape.h:133
TensorShape compute_deep_convolution_shape(const TensorShape &input_shape, DataLayout input_data_layout, const TensorShape &weights_shape, const PadStrideInfo &conv_info)
Calculate the deep convolution shape output shape of a tensor.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
Definition: Utils.h:1010
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
void add_option_if_else(bool cond, std::string option_true, std::string option_false)
Adds first option if condition is true else the second one.