Compute Library
 21.05
CLFullyConnectedLayer.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 
44 #include "support/Cast.h"
45 
46 #include <algorithm>
47 
48 namespace arm_compute
49 {
51 using namespace arm_compute::utils::cast;
52 
53 namespace
54 {
55 Status construct_gemmlowp_output_stage(const ITensorInfo &input, const ITensorInfo &weights, const ITensorInfo &output,
56  GEMMLowpOutputStageInfo &gemmlowp_output_stage, ActivationLayerInfo activation_info)
57 {
58  gemmlowp_output_stage.type = GEMMLowpOutputStageType::QUANTIZE_DOWN_FIXEDPOINT;
59  gemmlowp_output_stage.gemmlowp_offset = 0;
60  gemmlowp_output_stage.gemmlowp_multiplier = 0;
61  gemmlowp_output_stage.gemmlowp_shift = 0;
62 
63  const auto data_type = input.data_type();
64 
65  // Configure output stage for quantized case
67  {
68  const QuantizationInfo oq_info = output.quantization_info();
69  const UniformQuantizationInfo iq_unif = input.quantization_info().uniform();
70  const UniformQuantizationInfo wq_unif = weights.quantization_info().uniform();
71  const UniformQuantizationInfo oq_unif = oq_info.uniform();
72 
73  const auto output_quant_info = (output.total_size() == 0) ? iq_unif : oq_unif;
74 
75  const float multiplier = (iq_unif.scale * wq_unif.scale) / output_quant_info.scale;
76  int output_multiplier = 0;
77  int output_shift = 0;
78  ARM_COMPUTE_RETURN_ON_ERROR(quantization::calculate_quantized_multiplier(multiplier, &output_multiplier, &output_shift));
79 
80  PixelValue type_min{};
81  PixelValue type_max{};
82  std::tie(type_min, type_max) = get_min_max(data_type);
83 
84  if(activation_info.enabled())
85  {
86  std::tie(type_min, type_max) = get_quantized_activation_min_max(activation_info, data_type, output_quant_info);
87  }
88 
89  // Set the GEMMLowp output stage info
90  gemmlowp_output_stage.gemmlowp_offset = output_quant_info.offset;
91  gemmlowp_output_stage.gemmlowp_multiplier = output_multiplier;
92  gemmlowp_output_stage.gemmlowp_shift = output_shift;
93  gemmlowp_output_stage.gemmlowp_multipliers.push_back(output_multiplier);
94  gemmlowp_output_stage.gemmlowp_shifts.push_back(output_shift);
95  type_min.get(gemmlowp_output_stage.gemmlowp_min_bound);
96  type_max.get(gemmlowp_output_stage.gemmlowp_max_bound);
97  }
98 
99  return Status{};
100 }
101 
102 Status validate_mm(const ITensorInfo &input, const ITensorInfo &weights, const ITensorInfo *bias, const ITensorInfo &output, const FullyConnectedLayerInfo &fc_info)
103 {
104  GEMMLowpOutputStageInfo gemmlowp_output_stage;
105  ARM_COMPUTE_RETURN_ON_ERROR(construct_gemmlowp_output_stage(input, weights, output, gemmlowp_output_stage, fc_info.activation_info));
106 
107  const GEMMInfo &gemm_info = GEMMInfo(false, // is_a_reshaped
108  false, // is_b_reshaped
109  true, // reshape_b_only_on_first_run
110  0, // depth_output_gemm3d
111  false, // reinterpret_input_as_3d
112  fc_info.retain_internal_weights, // retain_internal_weights
113  gemmlowp_output_stage, // gemmlowp_output_stage
114  fc_info.fp_mixed_precision, // fp_mixed_precision
115  true, // broadcast_bias
116  ActivationLayerInfo()); // activation_info
117 
119  {
120  const UniformQuantizationInfo iq_info = input.quantization_info().uniform();
121  const UniformQuantizationInfo wq_info = weights.quantization_info().uniform();
122 
123  // Since we need negative offsets for computing convolution, we need to change QuantizationInfo()
124  // Extract and negate input and weights offset
125  const QuantizationInfo input_quantization_info(iq_info.scale, -iq_info.offset);
126  const QuantizationInfo weights_quantization_info(wq_info.scale, -wq_info.offset);
127 
128  // Validate gemmlowp function
129  ARM_COMPUTE_RETURN_ON_ERROR(CLGEMMLowpMatrixMultiplyCore::validate(&input.clone()->set_quantization_info(input_quantization_info),
130  &weights.clone()->set_quantization_info(weights_quantization_info),
131  bias,
132  &output,
133  gemm_info));
134  }
135  else
136  {
137  ARM_COMPUTE_RETURN_ON_ERROR(CLGEMM::validate(&input, &weights, bias, &output, 1.f, 1.f, gemm_info));
138  }
139 
140  return Status{};
141 }
142 } // namespace
143 
144 CLFullyConnectedLayer::CLFullyConnectedLayer(std::shared_ptr<IMemoryManager> memory_manager, IWeightsManager *weights_manager)
145  : _memory_group(memory_manager), _weights_manager(weights_manager), _convert_weights(), _convert_weights_managed(), _reshape_weights_managed_function(), _flatten_layer(), _reshape_weights_function(),
146  _mm_gemm(memory_manager, weights_manager), _mm_gemmlowp(memory_manager), _flatten_output(), _converted_weights_output(), _reshape_weights_output(), _are_weights_converted(true),
147  _are_weights_reshaped(true), _is_fc_after_conv(true), _is_quantized(false), _is_prepared(false), _original_weights(nullptr)
148 {
149 }
150 
151 void CLFullyConnectedLayer::configure_mm(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *bias, ICLTensor *output,
152  const FullyConnectedLayerInfo &fc_info)
153 {
154  GEMMLowpOutputStageInfo gemmlowp_output_stage;
155  construct_gemmlowp_output_stage(*input->info(), *weights->info(), *output->info(), gemmlowp_output_stage, fc_info.activation_info);
156 
157  const GEMMInfo &gemm_info = GEMMInfo(false, // is_a_reshaped
158  false, // is_b_reshaped
159  true, // reshape_b_only_on_first_run
160  0, // depth_output_gemm3d
161  false, // reinterpret_input_as_3d
162  fc_info.retain_internal_weights, // retain_internal_weights
163  gemmlowp_output_stage, // gemmlowp_output_stage
164  fc_info.fp_mixed_precision, // fp_mixed_precision
165  true, // broadcast_bias
166  fc_info.activation_info); // activation_info
167 
168  if(_is_quantized)
169  {
170  // Since we need negative offsets for computing convolution, we need to change QuantizationInfo()
171  // Extract and negate input and weights offset
172  const QuantizationInfo input_quantization_info = input->info()->quantization_info();
173  const QuantizationInfo weights_quantization_info = weights->info()->quantization_info();
174 
175  input->info()->set_quantization_info(QuantizationInfo(input_quantization_info.uniform().scale, -input_quantization_info.uniform().offset));
176  weights->info()->set_quantization_info(QuantizationInfo(weights_quantization_info.uniform().scale, -weights_quantization_info.uniform().offset));
177 
178  // Configure gemmlowp function
179  _mm_gemmlowp.configure(compile_context, input, weights, bias, output, gemm_info);
180 
181  // Revert back QuantizatioInfo as input and weights could be used in other fully connected layers
182  input->info()->set_quantization_info(input_quantization_info);
183  weights->info()->set_quantization_info(weights_quantization_info);
184  }
185  else
186  {
187  // Configure matrix multiply kernel
188  _mm_gemm.configure(compile_context, input, weights, bias, output, 1.f, 1.f, gemm_info);
189  }
190 }
191 
192 void CLFullyConnectedLayer::configure_conv_fc(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *bias, ICLTensor *output,
193  const FullyConnectedLayerInfo &fc_info)
194 {
195  ARM_COMPUTE_ERROR_ON((weights->info()->dimension(1) != (input->info()->dimension(0) * input->info()->dimension(1) * input->info()->dimension(2))));
196 
197  // If the fully connected layer is called after a convolution layer, the input tensor must be linearized
198 
199  // Initialize output tensor for flatten
200  TensorShape shape_flatten = compute_flatten_shape(input->info());
201  _flatten_output.allocator()->init(input->info()->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(shape_flatten).set_data_layout(DataLayout::NCHW));
202 
203  // Configure flatten kernel
204  _memory_group.manage(&_flatten_output);
205  _flatten_layer.configure(compile_context, input, &_flatten_output);
206 
207  // Configure matrix multiply kernel
208  configure_mm(compile_context, &_flatten_output, weights, bias, output, fc_info);
209 
210  // Allocate the output tensor for flatten once all the configure methods have been called
211  _flatten_output.allocator()->allocate();
212 }
213 
214 void CLFullyConnectedLayer::configure_fc_fc(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *bias, ICLTensor *output,
215  const FullyConnectedLayerInfo &fc_info)
216 {
217  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != weights->info()->dimension(1));
218 
219  // Configure matrix multiply kernel
220  configure_mm(compile_context, input, weights, bias, output, fc_info);
221 }
222 
223 void CLFullyConnectedLayer::configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
224  FullyConnectedLayerInfo fc_info)
225 {
226  configure(CLKernelLibrary::get().get_compile_context(), input, weights, biases, output, fc_info);
227 }
228 
229 void CLFullyConnectedLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output,
230  FullyConnectedLayerInfo fc_info)
231 {
232  ARM_COMPUTE_ERROR_ON_NULLPTR(input, weights, output);
233 
234  // Perform validate step
236  weights->info(),
237  biases != nullptr ? biases->info() : nullptr,
238  output->info(),
239  fc_info));
240 
241  _are_weights_converted = true;
242  _are_weights_reshaped = fc_info.transpose_weights ? fc_info.are_weights_reshaped : true;
243  _is_fc_after_conv = true;
244  _is_quantized = is_data_type_quantized_asymmetric(input->info()->data_type());
245  _is_prepared = fc_info.retain_internal_weights;
246  _original_weights = weights;
247 
248  if(_weights_manager)
249  {
250  _weights_manager->manage(weights);
251  }
252 
253  const ICLTensor *weights_to_use = weights;
254 
255  // With the Fully Connected layer we can have 4 different cases:
256  // 1) Convolution layer -> Fully Connected layer without batches
257  // 2) Fully Connected layer -> Fully Connected layer without batches
258  // 3) Convolution layer -> Fully Connected layer with batches
259  // 4) Fully Connected layer -> Fully Connected layer with batches
260 
261  // Check if we have a fully connected layer with batches
262  const bool is_batched_fc_layer = output->info()->dimension(1) > 1;
263  if(is_batched_fc_layer)
264  {
265  _is_fc_after_conv = (TensorShape::num_max_dimensions >= 4) && (std::equal(input->info()->tensor_shape().cbegin() + 3,
266  input->info()->tensor_shape().cend(),
267  output->info()->tensor_shape().cbegin() + 1));
268  }
269  else
270  {
271  _is_fc_after_conv = input->info()->num_dimensions() > 1;
272  }
273 
274  // Reshape weights if needed
275  if(!_are_weights_reshaped)
276  {
277  if(_weights_manager && _weights_manager->are_weights_managed(weights))
278  {
279  _reshape_weights_managed_function.configure(compile_context, weights);
280  weights_to_use = utils::cast::polymorphic_downcast<ICLTensor *>(_weights_manager->acquire(weights, &_reshape_weights_managed_function));
281  }
282  else
283  {
284  // Reshape the weights
285  _reshape_weights_function.configure(compile_context, weights, &_reshape_weights_output);
286  weights_to_use = &_reshape_weights_output;
287  }
288  }
289 
290  // Convert weights if needed
291  if(_is_fc_after_conv && (input->info()->data_layout() != fc_info.weights_trained_layout))
292  {
293  if(_weights_manager && _weights_manager->are_weights_managed(weights_to_use))
294  {
295  _convert_weights_managed.configure(compile_context, weights_to_use,
296  input->info()->tensor_shape(),
297  fc_info.weights_trained_layout);
298  weights_to_use = utils::cast::polymorphic_downcast<ICLTensor *>(_weights_manager->acquire(weights, &_convert_weights_managed));
299  }
300  else
301  {
302  // Convert weights
303  _convert_weights.configure(compile_context, weights_to_use,
304  &_converted_weights_output,
305  input->info()->tensor_shape(),
306  fc_info.weights_trained_layout);
307 
308  weights_to_use = &_converted_weights_output;
309  }
310  _are_weights_converted = false;
311  }
312 
313  if(_is_fc_after_conv)
314  {
315  // Fully Connected layer after a Convolution Layer without batches
316  configure_conv_fc(compile_context, input, weights_to_use, biases, output, fc_info);
317  }
318  else
319  {
320  // Fully Connected layer after a Fully Connected Layer without batches
321  configure_fc_fc(compile_context, input, weights_to_use, biases, output, fc_info);
322  }
323 }
324 
325 Status CLFullyConnectedLayer::validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output,
326  FullyConnectedLayerInfo fc_info)
327 {
328  ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, weights, output);
334 
335  bool weights_reshaped = fc_info.transpose_weights ? fc_info.are_weights_reshaped : true;
336  bool is_fc_after_conv = true;
337 
338  const ITensorInfo &flatten_input = TensorInfo(input->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(compute_flatten_shape(input)).set_data_layout(DataLayout::NCHW));
339  const ITensorInfo &reshaped_weights = TensorInfo(weights->clone()->set_is_resizable(true).reset_padding().set_tensor_shape(compute_transposed_shape(*weights)));
340  const ITensorInfo &converted_weights = weights_reshaped ? TensorInfo(weights->clone()->set_is_resizable(true).reset_padding()) : TensorInfo(*reshaped_weights.clone());
341 
342  // With the Fully Connected layer we can have 4 different cases:
343  // 1) Convolution layer -> Fully Connected layer without batches
344  // 2) Fully Connected layer -> Fully Connected layer without batches
345  // 3) Convolution layer -> Fully Connected layer with batches
346  // 4) Fully Connected layer -> Fully Connected layer with batches
347 
348  const ITensorInfo *input_to_use = input;
349  const ITensorInfo *weights_to_use = weights;
350 
351  // Check if we have a fully connected layer with batches
352  const bool is_batched_fc_layer = output->dimension(1) > 1;
353  if(is_batched_fc_layer)
354  {
355  is_fc_after_conv = (TensorShape::num_max_dimensions >= 4) && (std::equal(input->tensor_shape().cbegin() + 3,
356  input->tensor_shape().cend(),
357  output->tensor_shape().cbegin() + 1));
358  }
359  else
360  {
361  is_fc_after_conv = input->num_dimensions() > 1;
362  }
363 
364  if(!weights_reshaped)
365  {
366  // Validate reshape weights kernel
367  ARM_COMPUTE_RETURN_ON_ERROR(CLTranspose::validate(weights, &reshaped_weights));
368  weights_to_use = &reshaped_weights;
369  }
370 
371  if(is_fc_after_conv && (input->data_layout() != fc_info.weights_trained_layout))
372  {
373  // Validate convert weights kernel
375  &converted_weights,
376  input->tensor_shape(),
377  fc_info.weights_trained_layout));
378  weights_to_use = &converted_weights;
379  }
380 
381  if(is_fc_after_conv)
382  {
383  // Fully Connected layer after a Convolution Layer without batches
384  ARM_COMPUTE_RETURN_ERROR_ON((weights_to_use->dimension(1) != (input->dimension(0) * input->dimension(1) * input->dimension(2))));
385 
386  // Validate flatten kernel
388  input_to_use = &flatten_input;
389  }
390  else
391  {
392  // Fully Connected layer after a Fully Connected Layer without batches
393  ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(0) != weights_to_use->dimension(1));
394  }
395 
396  // Validate matrix multiply kernel
397  ARM_COMPUTE_RETURN_ON_ERROR(validate_mm(*input_to_use, *weights_to_use, biases, *output, fc_info));
398 
399  return Status{};
400 }
401 
403 {
404  prepare();
405 
406  MemoryGroupResourceScope scope_mg(_memory_group);
407 
408  // Linearize input if it comes from a convolutional layer
409  if(_is_fc_after_conv)
410  {
411  _flatten_layer.run();
412  }
413 
414  // Run matrix multiply
415  if(_is_quantized)
416  {
417  _mm_gemmlowp.run();
418  }
419  else
420  {
421  _mm_gemm.run();
422  }
423 }
424 
426 {
427  if(!_is_prepared)
428  {
429  if(!_weights_manager)
430  {
431  ARM_COMPUTE_ERROR_ON(!_original_weights->is_used());
432  }
433 
434  auto release_unused = [](CLTensor * w)
435  {
436  if(!w->is_used())
437  {
438  CLScheduler::get().queue().finish();
439  w->allocator()->free();
440  }
441  };
442 
443  // Pointer to current weights
444  const ICLTensor *cur_weights = _original_weights;
445 
446  // Reshape of the weights if needed (happens only once)
447  if(!_are_weights_reshaped)
448  {
449  if(_weights_manager && _weights_manager->are_weights_managed(_original_weights))
450  {
451  cur_weights = utils::cast::polymorphic_downcast<ICLTensor *>(_weights_manager->run(cur_weights, &_reshape_weights_managed_function));
452  }
453  else
454  {
455  // Run reshape weights kernel and mark weights as unused
456  _reshape_weights_output.allocator()->allocate();
457  _reshape_weights_function.run();
458 
459  cur_weights->mark_as_unused();
460  cur_weights = &_reshape_weights_output;
461  }
462  _are_weights_reshaped = true;
463  }
464 
465  // Convert weights if needed (happens only once)
466  if(!_are_weights_converted)
467  {
468  if(_weights_manager && _weights_manager->are_weights_managed(cur_weights))
469  {
470  _weights_manager->run(cur_weights, &_convert_weights_managed);
471  }
472  else
473  {
474  _converted_weights_output.allocator()->allocate();
475  _convert_weights.run();
476  cur_weights->mark_as_unused();
477  }
478 
479  _are_weights_converted = true;
480  }
481 
482  // Release reshaped weights if unused
483  release_unused(&_reshape_weights_output);
484 
485  // Prepare GEMM prepare and release unused weights
486  if(!_is_quantized)
487  {
488  _mm_gemm.prepare();
489  }
490 
491  // Release converted weights if unused
492  release_unused(&_reshape_weights_output);
493  release_unused(&_converted_weights_output);
494 
495  _is_prepared = true;
496  }
497 }
498 } // namespace arm_compute
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Definition: Utils.h:967
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLFlattenLayer.
SimpleTensor< float > w
Definition: DFT.cpp:156
Quantize using a fixed point multiplication.
void prepare() override
Prepare the function for executing.
Definition: CLGEMM.cpp:870
CLFullyConnectedLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
Constructor.
void run() override
Run the kernels contained in the function.
Definition: CLGEMM.cpp:778
bool enabled() const
Check if initialised.
Definition: Types.h:1528
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool retain_internal_weights
Retain internal reshaped weights.
Definition: Types.h:1546
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
bool is_used() const
Flags if the tensor is used or not.
Definition: ITensor.cpp:163
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
void configure(const ICLTensor *input)
Configures the CLTranspose function.
Fully connected layer info.
Definition: Types.h:1541
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs, output.
Status calculate_quantized_multiplier(float multiplier, int32_t *quant_multiplier, int32_t *shift, bool ignore_epsilon=false)
Calculate quantized representation of multiplier.
void manage(const ITensor *weights, ITransformWeights *parent=nullptr)
Start managing a weights tensor.
Status class.
Definition: Error.h:52
void run() override
Run the kernels contained in the function.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
void prepare() override
Prepare the function for executing.
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
void mark_as_unused() const
Marks a tensor as unused.
Definition: ITensor.cpp:168
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
bool are_weights_managed(const ITensor *weights)
Check if the weights are managed.
TensorShape compute_flatten_shape(const ITensorInfo *input)
Calculate the flattened output shape of a tensor.
const DataType data_type
Definition: Im2Col.cpp:150
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo())
Set the input and output tensors.
Quantization information.
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of CLGEMMLowpMatrixMultiply...
void run() override
Run the kernels contained in the function.
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:459
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo())
Static function to check if given info will lead to a valid configuration of CLFullyConnectedLayer.
quantized, asymmetric fixed-point 8-bit number unsigned
bool are_weights_reshaped
Reshape the weights tensor if false.
Definition: Types.h:1545
void run() override
Run the kernels contained in the function.
Definition: CLTranspose.cpp:66
void run() override
Run the kernels contained in the function.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
GEMMLowp output stage info.
Definition: Types.h:1887
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel's input and output.
virtual ITensorInfo & set_quantization_info(const QuantizationInfo &quantization_info)=0
Set the quantization settings (scale and offset) of the tensor.
void run() override
Run the kernels contained in the function.
ActivationLayerInfo activation_info
Fused activation to apply after the matrix multiplication.
Definition: Types.h:1548
cl::CommandQueue & queue()
Accessor for the associated CL command queue.
Definition: CLScheduler.cpp:39
Weights manager interface to handle weights transformations.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
Num samples, channels, height, width.
CLCompileContext class.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const TensorShape &original_input_shape, DataLayout data_layout)
Static function to check if given info will lead to a valid configuration of CLConvertFullyConnectedW...
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
Definition: Utils.h:989
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
std::array< T, num_max_dimensions >::const_iterator cbegin() const
Returns a read-only (constant) iterator that points to the first element in the dimension array.
Definition: Dimensions.h:231
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of CLTranspose.
Definition: CLTranspose.cpp:61
void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs and output.
Definition: CLGEMM.cpp:666
DataLayout weights_trained_layout
Layout that the weights have been trained with.
Definition: Types.h:1543
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
void configure(const ICLTensor *input, ICLTensor *output, const TensorShape &original_input_shape, DataLayout data_layout)
Initialize the function.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
bool fp_mixed_precision
Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Definition: Types.h:1547
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of CLGEMM.
Definition: CLGEMM.cpp:727
void configure(const ICLTensor *input, const TensorShape &original_input_shape, DataLayout data_layout)
Configures the CLConvertFullyConnectedWeights function.
bool transpose_weights
Transpose weights if true.
Definition: Types.h:1544
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
Store the tensor's metadata.
Definition: TensorInfo.h:43
GEMM information class.
Definition: Types.h:1938
ITensor * run(const ITensor *weights, ITransformWeights *weights_transform)
Run the reshape function.
ActivationFunction activation() const
Get the type of activation function.
Definition: Types.h:1513
quantized, asymmetric fixed-point 8-bit number signed
void configure(const ICLTensor *input, ICLTensor *output)
Initialise the kernel's inputs and output.
Definition: CLTranspose.cpp:47
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:46
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
Definition: Utils.h:564
ITensor * acquire(const ITensor *weights, ITransformWeights *weights_transform)
Acquire the requested reshape tensor of the selected weights.
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41