Compute Library
 21.02
NEIm2ColKernel Class Reference

Interface for the im2col reshape kernel. More...

#include <NEIm2ColKernel.h>

Collaboration diagram for NEIm2ColKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEIm2ColKernel ()
 Default constructor. More...
 
 NEIm2ColKernel (const NEIm2ColKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEIm2ColKerneloperator= (const NEIm2ColKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEIm2ColKernel (NEIm2ColKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEIm2ColKerneloperator= (NEIm2ColKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEIm2ColKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation=Size2D(1U, 1U), unsigned int num_groups=1)
 Set the input and output of the kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias, const Size2D &dilation=Size2D(1U, 1U), unsigned int num_groups=1)
 Static function to check if given info will lead to a valid configuration of NEIm2ColKernel. More...
 

Detailed Description

Interface for the im2col reshape kernel.

Rearranges image blocks into columns. It is used to strip out each convolution block to a single column. It is used to transform a convolution to a plain matrix multiplication.

For example taking into account the image below and assuming 3x3 image blocks with stride of 1 we have:

\[ \left( \begin{array}{cccc} a00 & a01 & a02 & a03 \\ a10 & a11 & a12 & a13 \\ a20 & a21 & a22 & a23 \\ a30 & a31 & a32 & a33 \\ \end{array} \right) \rightarrow \left( \begin{array}{ccccccccc} a00 & a01 & a02 & a10 & a11 & a12 & a20 & a21 & a22 \\ a01 & a02 & a03 & a11 & a12 & a13 & a21 & a22 & a23 \\ a10 & a11 & a12 & a20 & a21 & a22 & a30 & a31 & a32 \\ a11 & a12 & a13 & a21 & a22 & a23 & a31 & a32 & a33 \\ \end{array} \right) \]

Definition at line 57 of file NEIm2ColKernel.h.

Constructor & Destructor Documentation

◆ NEIm2ColKernel() [1/3]

Default constructor.

Definition at line 358 of file NEIm2ColKernel.cpp.

Referenced by NEIm2ColKernel::name().

359  : _func(), _input(nullptr), _output(nullptr), _convolved_dims(), _conv_info(), _kernel_width(0), _kernel_height(0), _has_bias(false), _dilation(1U, 1U), _data_layout(DataLayout::UNKNOWN)
360 {
361 }

◆ NEIm2ColKernel() [2/3]

NEIm2ColKernel ( const NEIm2ColKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEIm2ColKernel() [3/3]

NEIm2ColKernel ( NEIm2ColKernel &&  )
default

Allow instances of this class to be moved.

◆ ~NEIm2ColKernel()

~NEIm2ColKernel ( )
default

Default destructor.

Referenced by NEIm2ColKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const Size2D kernel_dims,
const PadStrideInfo conv_info,
bool  has_bias,
const Size2D dilation = Size2D(1U, 1U),
unsigned int  num_groups = 1 
)

Set the input and output of the kernel.

Parameters
[in]inputThe input tensor to convert. 3 lower dimensions represent a single input [width, height, IFM], while every optional dimension from 4 and above represent a batch of inputs. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32 Note: QASYMM8/QASYMM8_SIGNED works only for has_bias = false
[out]outputThe output tensor. Data types supported: Same as input
[in]kernel_dimsThe kernel dimensions (width and height).
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]has_biasIn case biases are provided expands the matrix with 1.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
[in]num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported

Definition at line 363 of file NEIm2ColKernel.cpp.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::BFLOAT16, arm_compute::test::validation::conv_info, ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), arm_compute::F16, arm_compute::F32, arm_compute::get_data_layout_dimension_index(), arm_compute::test::validation::has_bias, Size2D::height, arm_compute::HEIGHT, ITensor::info(), arm_compute::test::validation::input, arm_compute::NCHW, arm_compute::test::validation::num_groups, arm_compute::QASYMM8, arm_compute::QASYMM8_SIGNED, arm_compute::scaled_dimensions(), arm_compute::validate_arguments(), Size2D::width, and arm_compute::WIDTH.

Referenced by NEIm2ColKernel::name().

365 {
366  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
367  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation, num_groups));
369 
370  _data_layout = input->info()->data_layout();
371  const unsigned int width_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::WIDTH);
372  const unsigned int height_idx = get_data_layout_dimension_index(_data_layout, DataLayoutDimension::HEIGHT);
373 
374  _input = input;
375  _output = output;
376  _conv_info = conv_info;
377  _kernel_width = kernel_dims.width;
378  _kernel_height = kernel_dims.height;
379  _dilation = dilation;
380  _convolved_dims = scaled_dimensions(input->info()->dimension(width_idx), input->info()->dimension(height_idx),
381  _kernel_width, _kernel_height,
382  _conv_info, _dilation);
383  _has_bias = has_bias;
384 
385  if(_data_layout == DataLayout::NCHW)
386  {
387  switch(_input->info()->data_type())
388  {
389  case DataType::F32:
390  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float, false, true> : &NEIm2ColKernel::run_im2col<float, true, true>;
391  break;
392 #if defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16)
393  case DataType::BFLOAT16:
394  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<bfloat16, false, true> : &NEIm2ColKernel::run_im2col<bfloat16, true, true>;
395  break;
396 #endif /* defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16) */
397 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
398  case DataType::F16:
399  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float16_t, false, true> : &NEIm2ColKernel::run_im2col<float16_t, true, true>;
400  break;
401 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
403  case DataType::QASYMM8:
404  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<qasymm8_t, false, true> : &NEIm2ColKernel::run_im2col<qasymm8_t, true, true>;
405  break;
406  default:
407  ARM_COMPUTE_ERROR("Data type not supported");
408  break;
409  }
410  }
411  else
412  {
413  switch(_input->info()->data_type())
414  {
415  case DataType::F32:
416  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float, false, false> : &NEIm2ColKernel::run_im2col<float, true, false>;
417  break;
418 #if defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16)
419  case DataType::BFLOAT16:
420  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<bfloat16, false, false> : &NEIm2ColKernel::run_im2col<bfloat16, true, false>;
421  break;
422 #endif /* defined(__ARM_FEATURE_BF16_VECTOR_ARITHMETIC) || defined(ARM_COMPUTE_FORCE_BF16) */
423 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
424  case DataType::F16:
425  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float16_t, false, false> : &NEIm2ColKernel::run_im2col<float16_t, true, false>;
426  break;
427 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
428  case DataType::QASYMM8:
429  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<uint8_t, false, false> : &NEIm2ColKernel::run_im2col<qasymm8_t, true, false>;
430  break;
432  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<int8_t, false, false> : &NEIm2ColKernel::run_im2col<qasymm8_t, true, false>;
433  break;
434  default:
435  ARM_COMPUTE_ERROR("Data type not supported");
436  break;
437  }
438  }
439 
440  // Configure kernel window
441  auto win_config = validate_and_configure_window(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation);
442  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
443  INEKernel::configure(win_config.second);
444 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
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_THROW_ON(status)
Definition: Error.h:455
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:90
1 channel, 1 F16 per channel
std::pair< unsigned int, unsigned int > scaled_dimensions(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info, const Size2D &dilation=Size2D(1U, 1U))
Returns expected width and height of output scaled tensor depending on dimensions rounding mode...
Definition: Utils.cpp:419
16-bit brain floating-point number
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
quantized, asymmetric fixed-point 8-bit number unsigned
const unsigned int num_groups
Definition: Im2Col.cpp:153
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Num samples, channels, height, width.
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:89
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
quantized, asymmetric fixed-point 8-bit number signed
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
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
bool has_padding() const
Check whether this has any padding.
Definition: Types.h:823

◆ name()

◆ operator=() [1/2]

NEIm2ColKernel& operator= ( const NEIm2ColKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by NEIm2ColKernel::name().

◆ operator=() [2/2]

NEIm2ColKernel& operator= ( NEIm2ColKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 454 of file NEIm2ColKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by NEIm2ColKernel::name().

455 {
456  ARM_COMPUTE_UNUSED(info);
459 
460  (this->*_func)(window);
461 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

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

Static function to check if given info will lead to a valid configuration of NEIm2ColKernel.

Parameters
[in]inputThe input tensor to convert. 3 lower dimensions represent a single input [width, height, IFM], while every optional dimension from 4 and above represent a batch of inputs. Data types supported: QASYMM8/QASYMM8_SIGNED/BFLOAT16/F16/F32 Note: QASYMM8/QASYMM8_SIGNED works only for has_bias = false
[in]outputThe output tensor. Data types supported: Same as input
[in]kernel_dimsThe kernel dimensions (width and height).
[in]conv_infoContains padding and stride information described in PadStrideInfo.
[in]has_biasIn case biases are provided expands the matrix with 1.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
[in]num_groups(Optional) Number of groups when performing a grouped convolution. num_groups != 1 is not supported
Returns
a status

Definition at line 446 of file NEIm2ColKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), arm_compute::test::validation::conv_info, arm_compute::test::validation::has_bias, and arm_compute::validate_arguments().

Referenced by NEIm2ColKernel::name(), and NEGEMMConvolutionLayer::validate().

448 {
449  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, kernel_dims, conv_info, has_bias, dilation, num_groups));
450  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), kernel_dims, conv_info, has_bias, dilation).first);
451  return Status{};
452 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status class.
Definition: Error.h:52
const unsigned int num_groups
Definition: Im2Col.cpp:153
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

The documentation for this class was generated from the following files: