Compute Library
 19.08
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...
 
- 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 346 of file NEIm2ColKernel.cpp.

347  : _func(), _input(nullptr), _output(nullptr), _convolved_dims(), _conv_info(), _kernel_width(0), _kernel_height(0), _has_bias(false), _dilation(1U, 1U)
348 {
349 }

◆ 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.

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/F16/F32 Note: QASYMM8 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 351 of file NEIm2ColKernel.cpp.

353 {
354  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
355  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation, num_groups));
357 
358  const DataLayout data_layout = input->info()->data_layout();
361 
362  _input = input;
363  _output = output;
364  _conv_info = conv_info;
365  _kernel_width = kernel_dims.width;
366  _kernel_height = kernel_dims.height;
367  _dilation = dilation;
368  _convolved_dims = scaled_dimensions(input->info()->dimension(width_idx), input->info()->dimension(height_idx),
369  _kernel_width, _kernel_height,
370  _conv_info, _dilation);
371  _has_bias = has_bias;
372 
374  {
375  switch(_input->info()->data_type())
376  {
377  case DataType::F32:
378  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float, false, true> : &NEIm2ColKernel::run_im2col<float, true, true>;
379  break;
380 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
381  case DataType::F16:
382  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float16_t, false, true> : &NEIm2ColKernel::run_im2col<float16_t, true, true>;
383  break;
384 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
385  case DataType::QASYMM8:
386  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<qasymm8_t, false, true> : &NEIm2ColKernel::run_im2col<qasymm8_t, true, true>;
387  break;
388  default:
389  ARM_COMPUTE_ERROR("Data type not supported");
390  break;
391  }
392  }
393  else
394  {
395  switch(_input->info()->data_type())
396  {
397  case DataType::F32:
398  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float, false, false> : &NEIm2ColKernel::run_im2col<float, true, false>;
399  break;
400 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
401  case DataType::F16:
402  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<float16_t, false, false> : &NEIm2ColKernel::run_im2col<float16_t, true, false>;
403  break;
404 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
405  case DataType::QASYMM8:
406  _func = (!conv_info.has_padding()) ? &NEIm2ColKernel::run_im2col<qasymm8_t, false, false> : &NEIm2ColKernel::run_im2col<qasymm8_t, true, false>;
407  break;
408  default:
409  ARM_COMPUTE_ERROR("Data type not supported");
410  break;
411  }
412  }
413 
414  // Configure kernel window
415  auto win_config = validate_and_configure_window(input->info(), output->info(), kernel_dims, conv_info, has_bias, dilation);
416  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
417  INEKernel::configure(win_config.second);
418 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const DataLayout data_layout
Definition: Im2Col.cpp:146
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::pair< unsigned int, unsigned int > scaled_dimensions(unsigned int width, unsigned int height, unsigned int kernel_width, unsigned 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:387
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
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:327
size_t height
Height of the image region or rectangle.
Definition: Size2D.h:93
1 channel, 1 F16 per channel
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
quantized, asymmetric fixed-point 8-bit number
const unsigned int num_groups
Definition: Im2Col.cpp:148
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
Num samples, channels, height, width.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
size_t width
Width of the image region or rectangle.
Definition: Size2D.h:92
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:326
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_UNUSED, arm_compute::test::validation::conv_info, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::data_type(), arm_compute::test::validation::dilation, 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::NCHW, arm_compute::test::validation::num_groups, arm_compute::QASYMM8, arm_compute::scaled_dimensions(), arm_compute::validate_and_configure_window(), Size2D::width, and arm_compute::WIDTH.

Referenced by NEIm2Col::configure(), NELocallyConnectedLayer::configure(), and NEGEMMConvolutionLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 60 of file NEIm2ColKernel.h.

61  {
62  return "NEIm2ColKernel";
63  }

◆ operator=() [1/2]

NEIm2ColKernel& operator= ( const NEIm2ColKernel )
delete

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

◆ 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.

Implements ICPPKernel.

Definition at line 428 of file NEIm2ColKernel.cpp.

429 {
433 
434  (this->*_func)(window);
435 }
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:160
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ 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/F16/F32 Note: QASYMM8 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 420 of file NEIm2ColKernel.cpp.

422 {
423  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, kernel_dims, conv_info, has_bias, dilation, num_groups));
424  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get(), kernel_dims, conv_info, has_bias, dilation).first);
425  return Status{};
426 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
const unsigned int num_groups
Definition: Im2Col.cpp:148
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

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

Referenced by NEIm2Col::validate(), NELocallyConnectedLayer::validate(), and NEGEMMConvolutionLayer::validate().


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