Compute Library
 21.08
CLDepthwiseConvolutionLayerNativeKernel.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019-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 
31 #include "arm_compute/core/Utils.h"
34 #include "src/core/CL/CLUtils.h"
35 #include "src/core/CL/CLValidate.h"
36 #include "src/core/CL/ICLKernel.h"
40 #include "support/StringSupport.h"
41 
42 namespace arm_compute
43 {
44 namespace
45 {
46 Status validate_arguments(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const DWCComputeKernelInfo &dwc_info,
47  const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers, const ITensorInfo *output_shifts)
48 {
49  ARM_COMPUTE_UNUSED(dwc_info);
50  bool in_place = false;
51  if(output == nullptr || output == input)
52  {
53  in_place = true;
54  output = input;
55  }
60  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.depth_multiplier > 1 && dwc_info.n0 != 1);
61  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first > 1 && dwc_info.m0 != 1);
62  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation.x() > 1 && dwc_info.m0 != 1);
63  ARM_COMPUTE_RETURN_ERROR_ON_MSG((dwc_info.export_weights_to_cl_image == true) && (export_weights_to_cl_image(weights) == false), "Export to cl_image not supported!");
64  ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_weights_to_cl_image == true) && (conv_info.depth_multiplier > 1));
65  ARM_COMPUTE_RETURN_ERROR_ON((dwc_info.export_weights_to_cl_image == true) && ((dwc_info.n0 % 4) != 0));
66  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().first < 1);
67  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride().second < 1);
68  ARM_COMPUTE_RETURN_ERROR_ON((conv_info.dilation.x() < 1) || (conv_info.dilation.y() < 1));
69  const size_t idx_c = get_data_layout_dimension_index(input->data_layout(), DataLayoutDimension::CHANNEL);
70  ARM_COMPUTE_UNUSED(idx_c);
71  ARM_COMPUTE_RETURN_ERROR_ON(weights->dimension(idx_c) != (input->dimension(idx_c) * conv_info.depth_multiplier));
72 
73  // In place restrictions
74  if(in_place)
75  {
76  const int weights_width_idx = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::WIDTH);
77  const int weights_height_idx = get_data_layout_dimension_index(weights->data_layout(), DataLayoutDimension::HEIGHT);
78  ARM_COMPUTE_RETURN_ERROR_ON(weights->tensor_shape()[weights_width_idx] != 1U || weights->tensor_shape()[weights_height_idx] != 1U);
79  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.depth_multiplier != 1U);
80  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.stride() != std::make_pair(1U, 1U));
81  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.dilation != Size2D(1U, 1U));
82  ARM_COMPUTE_RETURN_ERROR_ON(conv_info.pad_stride_info.has_padding()); // Note that in princple padding can be supported with in_place but we choose not to support it
83  }
84 
85  const ConvolutionInfo info{ conv_info.pad_stride_info, conv_info.depth_multiplier, ActivationLayerInfo(), conv_info.dilation };
86  const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape(*input, *weights, conv_info);
87 
88  const bool is_quantized = is_data_type_quantized(input->data_type());
89 
90  if(biases != nullptr)
91  {
92  ARM_COMPUTE_RETURN_ERROR_ON(biases->dimension(0) != output_shape[idx_c]);
93  ARM_COMPUTE_RETURN_ERROR_ON(biases->num_dimensions() > 1);
94 
95  if(is_quantized)
96  {
98  }
99  else
100  {
102  }
103  }
104 
105  if(is_quantized)
106  {
107  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(output_multipliers, output_shifts);
110  ARM_COMPUTE_RETURN_ERROR_ON(output_multipliers->num_dimensions() > 1);
111  ARM_COMPUTE_RETURN_ERROR_ON(output_shifts->num_dimensions() > 1);
112 
113  if(is_data_type_quantized_per_channel(weights->data_type()))
114  {
116  ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_multipliers->dimension(0));
117  ARM_COMPUTE_RETURN_ERROR_ON(output_shape[idx_c] != output_shifts->dimension(0));
118  }
119  else
120  {
122  ARM_COMPUTE_RETURN_ERROR_ON(1 != output_multipliers->dimension(0));
123  ARM_COMPUTE_RETURN_ERROR_ON(1 != output_shifts->dimension(0));
124  }
125  }
126  else
127  {
129  }
130 
131  if(output->total_size() != 0)
132  {
135  }
136 
137  if(is_data_type_quantized(input->data_type()))
138  {
139  const UniformQuantizationInfo iq_info = input->quantization_info().uniform();
140  const UniformQuantizationInfo wq_info = weights->quantization_info().uniform();
141  const UniformQuantizationInfo oq_info = (output->total_size() != 0) ? output->quantization_info().uniform() : iq_info;
142 
143  float multiplier = iq_info.scale * wq_info.scale / oq_info.scale;
144  int output_multiplier = 0;
145  int output_shift = 0;
146  ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift));
147  }
148 
149  return Status{};
150 }
151 } // namespace
152 
154  : _input(nullptr),
155  _weights(nullptr),
156  _biases(nullptr),
157  _output(nullptr),
158  _depth_multiplier(1),
159  _output_multipliers(nullptr),
160  _output_shifts(nullptr),
161  _export_to_cl_image(false),
162  _is_quantized(false)
163 {
164  _type = CLKernelType::DEPTHWISE;
165 }
166 
168  const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info,
169  const ICLTensor *output_multipliers, const ICLTensor *output_shifts)
170 {
171  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts);
172 }
173 
174 void CLDepthwiseConvolutionLayerNativeKernel::configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
175  const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info,
176  const ICLTensor *output_multipliers, const ICLTensor *output_shifts)
177 {
178  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights);
179  if(output == nullptr)
180  {
181  // In-place
182  output = input;
183  }
184  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), weights->info(), (biases != nullptr) ? biases->info() : nullptr, output->info(),
185  dwc_info, conv_info, (output_multipliers != nullptr) ? output_multipliers->info() : nullptr, (output_shifts != nullptr) ? output_shifts->info() : nullptr));
186 
187  auto padding_info = get_padding_info({ input, output });
188 
189  const TensorShape output_shape = arm_compute::misc::shape_calculator::compute_depthwise_convolution_shape(*(input->info()), *(weights->info()), conv_info);
190  auto_init_if_empty(*(output->info()), input->info()->clone()->set_tensor_shape(output_shape).set_quantization_info(output->info()->quantization_info()));
191 
192  _input = input;
193  _output = output;
194  _weights = weights;
195  _biases = biases;
196  _depth_multiplier = conv_info.depth_multiplier;
197  _output_multipliers = output_multipliers;
198  _output_shifts = output_shifts;
199  _export_to_cl_image = dwc_info.export_weights_to_cl_image;
200  _is_quantized = is_data_type_quantized(input->info()->data_type());
201 
202  const unsigned int n0 = adjust_vec_size(dwc_info.n0, input->info()->dimension(0));
203  const unsigned int m0 = std::min(dwc_info.m0, (unsigned int)output->info()->dimension(1));
204  std::string kernel_name = "";
205 
206  CLBuildOptions build_opts;
207 
208  // Update the padding for the weights tensor if we can export to cl_image
209  if(_export_to_cl_image)
210  {
212  }
213 
214  build_opts.add_option("-cl-fast-relaxed-math");
215  build_opts.add_option("-DACTIVATION_TYPE=" + lower_string(string_from_activation_func(conv_info.act_info.activation())));
216  build_opts.add_option("-DDEPTH_MULTIPLIER=" + support::cpp11::to_string(conv_info.depth_multiplier));
217  build_opts.add_option("-DSRC_TENSOR_TYPE=BUFFER");
218  build_opts.add_option("-DSRC_WIDTH=" + support::cpp11::to_string(_input->info()->dimension(1)));
219  build_opts.add_option("-DSRC_HEIGHT=" + support::cpp11::to_string(_input->info()->dimension(2)));
220  // Note: SRC_DATA_TYPE must have the same data type of WEI_DATA_TYPE. In quantized, we could
221  // have a case where the data types for the activation and weights are different. However, since the implementation
222  // only works when both have same data type, we have to change the offset to take into account this aspect
223  build_opts.add_option("-DSRC_DATA_TYPE=" + get_cl_type_from_data_type(_input->info()->data_type()));
224  build_opts.add_option("-DDST_TENSOR_TYPE=BUFFER");
225  build_opts.add_option("-DDST_WIDTH=" + support::cpp11::to_string(_output->info()->dimension(1)));
226  build_opts.add_option("-DDST_HEIGHT=" + support::cpp11::to_string(_output->info()->dimension(2)));
227  build_opts.add_option("-DDST_DATA_TYPE=" + get_cl_type_from_data_type(_output->info()->data_type()));
228  build_opts.add_option_if_else(_export_to_cl_image, "-DWEI_TENSOR_TYPE=IMAGE", "-DWEI_TENSOR_TYPE=BUFFER");
229  build_opts.add_option("-DWEI_WIDTH=" + support::cpp11::to_string(_weights->info()->dimension(1)));
230  build_opts.add_option("-DWEI_HEIGHT=" + support::cpp11::to_string(_weights->info()->dimension(2)));
231  build_opts.add_option("-DWEI_DATA_TYPE=" + get_cl_type_from_data_type(_weights->info()->data_type()));
232  build_opts.add_option("-DPAD_TOP=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_top()));
233  build_opts.add_option("-DPAD_LEFT=" + support::cpp11::to_string(conv_info.pad_stride_info.pad_left()));
234  build_opts.add_option("-DSTRIDE_X=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().first));
235  build_opts.add_option("-DSTRIDE_Y=" + support::cpp11::to_string(conv_info.pad_stride_info.stride().second));
236  build_opts.add_option("-DDILATION_X=" + support::cpp11::to_string(conv_info.dilation.x()));
237  build_opts.add_option("-DDILATION_Y=" + support::cpp11::to_string(conv_info.dilation.y()));
238  build_opts.add_option("-DN0=" + support::cpp11::to_string(n0));
239  build_opts.add_option("-DM0=" + support::cpp11::to_string(m0));
240  build_opts.add_option("-DM0_A=" + support::cpp11::to_string(_weights->info()->dimension(1) + m0 - 1));
241  build_opts.add_option("-DPARTIAL_N0=" + support::cpp11::to_string(_input->info()->dimension(0) % n0));
242  build_opts.add_option_if(_input->info()->num_dimensions() > 3, "-DBATCHED_EXECUTION");
243 
244  // Force unroll with pragma when any of the following values exceed the maximum number of manual unroll
245  set_unroll_with_pragma(build_opts, { static_cast<int>(_weights->info()->dimension(1) + m0 - 1),
246  static_cast<int>(_weights->info()->dimension(1)),
247  static_cast<int>(_weights->info()->dimension(2))
248  });
249 
250  if(biases != nullptr)
251  {
252  build_opts.add_option(std::string("-DHAS_BIAS"));
253  build_opts.add_option(std::string("-DBIA_DATA_TYPE=" + get_cl_type_from_data_type(biases->info()->data_type())));
254  }
255 
256  if(_is_quantized)
257  {
258  kernel_name = "dwc_native_quantized_nhwc";
259  const UniformQuantizationInfo iqinfo = input->info()->quantization_info().uniform();
260  const UniformQuantizationInfo wqinfo = weights->info()->quantization_info().uniform();
261  const UniformQuantizationInfo oqinfo = output->info()->quantization_info().uniform();
262 
263  PixelValue zero_value = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
264  int zero_value_s32;
265  zero_value.get(zero_value_s32);
266 
267  float multiplier = iqinfo.scale * wqinfo.scale / oqinfo.scale;
268  int output_multiplier = 0;
269  int output_shift = 0;
270  quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift);
271  build_opts.add_option("-DDST_MULTIPLIER=" + support::cpp11::to_string(output_multiplier));
272  build_opts.add_option("-DDST_SHIFT=" + support::cpp11::to_string(output_shift));
273  build_opts.add_option("-DSRC_OFFSET=" + support::cpp11::to_string(-iqinfo.offset));
274  build_opts.add_option("-DWEI_OFFSET=" + support::cpp11::to_string(-wqinfo.offset));
275  build_opts.add_option("-DDST_OFFSET=" + support::cpp11::to_string(oqinfo.offset));
276  build_opts.add_option("-DZERO_VALUE=" + support::cpp11::to_string(zero_value_s32));
277  build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(DataType::S32));
278  build_opts.add_option("-DDST_MULTIPLIERS_DATA_TYPE=" + get_cl_type_from_data_type(_output_multipliers->info()->data_type()));
279  build_opts.add_option("-DDST_SHIFTS_DATA_TYPE=" + get_cl_type_from_data_type(_output_shifts->info()->data_type()));
280  build_opts.add_option_if_else(weights->info()->data_type() == DataType::QSYMM8_PER_CHANNEL, "-DQUANTIZATION_TYPE=PER_CHANNEL", "-DQUANTIZATION_TYPE=PER_TENSOR");
281  // Note: We expect the input and output tensors to always adopt a per-tensor quantization approach
282  int a_val{};
283  int b_val{};
284  std::tie(b_val, a_val) = get_quantized_activation_min_max(conv_info.act_info, input->info()->data_type(), oqinfo);
285 
286  build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + support::cpp11::to_string(a_val));
287  build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + support::cpp11::to_string(b_val));
288  }
289  else
290  {
291  kernel_name = "dwc_native_fp_nhwc";
292  build_opts.add_option("-DACC_DATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
293  build_opts.add_option("-DZERO_VALUE=" + support::cpp11::to_string(0));
294  build_opts.add_option_if(conv_info.act_info.enabled(), "-DA_VAL=" + float_to_string_with_full_precision(conv_info.act_info.a()));
295  build_opts.add_option_if(conv_info.act_info.enabled(), "-DB_VAL=" + float_to_string_with_full_precision(conv_info.act_info.b()));
296  }
297 
298  Window win = calculate_max_window(*(output->info()), Steps(n0, m0));
299  ICLKernel::configure_internal(win);
300 
301  _kernel = create_kernel(compile_context, kernel_name, build_opts.options());
302 
304 
305  // Set config_id for enabling LWS tuning
306  _config_id = kernel_name;
307  _config_id += "_";
308  _config_id += support::cpp11::to_string(input->info()->dimension(0));
309  _config_id += "_";
310  _config_id += support::cpp11::to_string(input->info()->dimension(1));
311  _config_id += "_";
312  _config_id += support::cpp11::to_string(input->info()->dimension(2));
313  _config_id += "_";
314  _config_id += support::cpp11::to_string(output->info()->dimension(0));
315  _config_id += "_";
316  _config_id += support::cpp11::to_string(output->info()->dimension(1));
317  _config_id += "_";
318  _config_id += support::cpp11::to_string(output->info()->dimension(2));
319  _config_id += "_";
320  _config_id += string_from_data_type(input->info()->data_type());
321 }
322 
324  const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers, const ITensorInfo *output_shifts)
325 {
326  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, weights, biases, output, dwc_info, conv_info, output_multipliers, output_shifts));
327  return Status{};
328 }
329 
330 void CLDepthwiseConvolutionLayerNativeKernel::run(const Window &window, cl::CommandQueue &queue)
331 {
334 
335  // Collapse window
336  Window window_collapsed = window.collapse(ICLKernel::window(), Window::DimZ);
337 
338  Window slice = window_collapsed.first_slice_window_4D();
339 
340  if(_depth_multiplier != 1)
341  {
342  // If the depth multiplier > 1, we need to use the input channels rather than the output channels
343  ARM_COMPUTE_ERROR_ON(slice.x().step() != 1);
344  slice.set(Window::DimX, Window::Dimension(0, _input->info()->tensor_shape()[0], 1));
345  }
346 
347  cl::Image2D weights_cl_image;
348 
349  if(_export_to_cl_image)
350  {
351  const size_t image_w = _weights->info()->dimension(0) / 4;
352  const size_t image_h = _weights->info()->dimension(1) * _weights->info()->dimension(2) * _weights->info()->dimension(3);
353  const TensorShape shape2d(image_w, image_h);
354  const size_t image_row_pitch = _weights->info()->strides_in_bytes()[1];
355 
356  // Export cl_buffer to cl_image
357  weights_cl_image = create_image2d_from_buffer(CLKernelLibrary::get().context(), _weights->cl_buffer(), shape2d, _weights->info()->data_type(), image_row_pitch);
358  }
359 
360  unsigned int idx = 0;
361  add_4D_tensor_argument(idx, _input, slice);
362  add_4D_tensor_argument(idx, _output, slice);
363  if(_export_to_cl_image)
364  {
365  _kernel.setArg(idx++, weights_cl_image);
366  }
367  add_4D_tensor_argument(idx, _weights, slice);
368  if(_is_quantized)
369  {
370  add_1D_tensor_argument(idx, _output_multipliers, slice);
371  add_1D_tensor_argument(idx, _output_shifts, slice);
372  }
373  if(_biases != nullptr)
374  {
375  add_1D_tensor_argument(idx, _biases, slice);
376  }
377  enqueue(queue, *this, slice, lws_hint());
378 }
379 } // namespace arm_compute
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:981
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
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
TensorShape compute_depthwise_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, const ConvolutionInfo &info)
Calculate the depthwise convolution output shape of a tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_LAYOUT_NOT_IN(t,...)
Definition: Validate.h:742
bool export_weights_to_cl_image(const ITensorInfo *tensor)
Definition: CLHelpers.cpp:431
void set_unroll_with_pragma(CLBuildOptions &built_opts, std::initializer_list< int > values)
Definition: CLHelpers.cpp:469
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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.
constexpr int step() const
Return the step of the dimension.
Definition: Window.h:104
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
Definition: ICLKernel.h:318
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
#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 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.
Describe one of the image&#39;s dimensions with a start, end and step.
Definition: Window.h:77
void configure(const CLCompileContext &compile_context, ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info, const ICLTensor *output_multipliers=nullptr, const ICLTensor *output_shifts=nullptr)
Initialize the function&#39;s source, destination and parameters.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context...
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
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 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
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
1 channel, 1 S32 per channel
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_option(std::string option)
Adds option to the existing build option list.
Window collapse(const Window &full_window, size_t first, size_t last=Coordinates::num_max_dimensions) const
Collapse the dimensions between first and last.
Definition: Window.inl:111
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 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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
bool is_data_type_quantized_per_channel(DataType dt)
Check if a given data type is of per channel type.
Definition: Utils.h:1058
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
Definition: Utils.h:1075
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
std::pair< int32_t, int32_t > get_quantized_activation_min_max(ActivationLayerInfo act_info, DataType data_type, UniformQuantizationInfo oq_info)
Returns a pair of minimum and maximum values for a quantized activation.
Definition: Utils.cpp:488
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
unsigned int n0
Number of columns processed by each thread.
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.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
bool export_weights_to_cl_image
Export the weights to cl_image.
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
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:533
CLCompileContext class.
Compute descriptor used by the depthwise convolution native kernel.
Depthwise CL kernel type.
Definition: CLTypes.h:82
quantized, symmetric per channel fixed-point 8-bit number
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
#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
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const DWCComputeKernelInfo &dwc_info, const ConvolutionInfo &conv_info, const ITensorInfo *output_multipliers=nullptr, const ITensorInfo *output_shifts=nullptr)
Static function to check if given info will lead to a valid configuration of CLDepthwiseConvolutionLa...
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:518
unsigned int m0
Number of rows processed by each thread.
Window first_slice_window_4D() const
First 4D slice of the window.
Definition: Window.h:299
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:244
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
#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:29
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:1171
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
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:166
std::string kernel_name
void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 4D tensor&#39;s parameters to the object&#39;s kernel&#39;s arguments starting from the index idx...
Definition: ICLKernel.h:224
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145
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.