Compute Library
 19.08
NEDepthwiseIm2ColKernel Class Reference

Interface for the depthwise im2col reshape kernel. More...

#include <NEDepthwiseIm2ColKernel.h>

Collaboration diagram for NEDepthwiseIm2ColKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEDepthwiseIm2ColKernel ()
 Default constructor. More...
 
 NEDepthwiseIm2ColKernel (const NEDepthwiseIm2ColKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEDepthwiseIm2ColKerneloperator= (const NEDepthwiseIm2ColKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEDepthwiseIm2ColKernel (NEDepthwiseIm2ColKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEDepthwiseIm2ColKerneloperator= (NEDepthwiseIm2ColKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ITensor *input, ITensor *output, const Size2D &kernel_dims, const PadStrideInfo &conv_info, bool has_bias=false, unsigned int depth_multiplier=1, const Size2D &dilation=Size2D(1U, 1U))
 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=false, unsigned int depth_multiplier=1, const Size2D &dilation=Size2D(1U, 1U))
 Static function to check if given info will lead to a valid configuration of NEDepthwiseIm2ColKernel. More...
 

Detailed Description

Interface for the depthwise im2col reshape kernel.

This kernel reshape the input low 3 dimensions to a new 3D shape where the output's first dimension is the linear patch size (FILTER_WIDTH * FILTER_HEIGHT) and second dimension is number of patches in per image and third dimension unchanged .

Definition at line 38 of file NEDepthwiseIm2ColKernel.h.

Constructor & Destructor Documentation

◆ NEDepthwiseIm2ColKernel() [1/3]

Default constructor.

Definition at line 134 of file NEDepthwiseIm2ColKernel.cpp.

135  : _func(nullptr), _input(nullptr), _output(nullptr), _kernel_dims(), _conv_info(), _has_bias(), _depth_multiplier(1), _dilation()
136 {
137 }

◆ NEDepthwiseIm2ColKernel() [2/3]

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

◆ NEDepthwiseIm2ColKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

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

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
[out]outputThe output tensor. First 3 lower dimensions represent a transform of each 3D input, while every dimension above 3 represents a batch. 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_biasBoolean that specifies if the depthwise convolution has bias.
[in]depth_multiplier(Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).

Definition at line 139 of file NEDepthwiseIm2ColKernel.cpp.

141 {
142  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
143 
144  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), kernel_dims, conv_info, has_bias, depth_multiplier, dilation));
145 
146  _input = input;
147  _output = output;
148  _kernel_dims = kernel_dims;
149  _conv_info = conv_info;
150  _has_bias = has_bias;
151  _depth_multiplier = depth_multiplier;
152  _dilation = dilation;
153 
154  // Configure kernel window
155  Window win = calculate_max_window(*input->info(), Steps());
156 
157  // Set appropriate function to run
158  switch(input->info()->data_type())
159  {
160  case DataType::QASYMM8:
161  _func = &NEDepthwiseIm2ColKernel::run_generic<uint8_t>;
162  break;
163  case DataType::F16:
164  _func = &NEDepthwiseIm2ColKernel::run_generic<half>;
165  break;
166  case DataType::F32:
167  _func = &NEDepthwiseIm2ColKernel::run_generic<float>;
168  break;
169  default:
170  ARM_COMPUTE_ERROR("Unsupported data type");
171  }
172 
173  // The NEDepthwiseIm2ColKernel doesn't need padding so update_window_and_padding() can be skipped
174  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
175 
176  INEKernel::configure(win);
177 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
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
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
1 channel, 1 F16 per channel
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), arm_compute::test::validation::conv_info, ITensorInfo::data_type(), arm_compute::test::validation::dilation, arm_compute::F16, arm_compute::F32, arm_compute::test::validation::has_bias, ITensor::info(), arm_compute::QASYMM8, ITensorInfo::set_valid_region(), and ITensorInfo::tensor_shape().

Referenced by NEDepthwiseConvolutionLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 41 of file NEDepthwiseIm2ColKernel.h.

42  {
43  return "NEDepthwiseIm2ColKernel";
44  }

◆ operator=() [1/2]

NEDepthwiseIm2ColKernel& operator= ( const NEDepthwiseIm2ColKernel )
delete

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

◆ operator=() [2/2]

NEDepthwiseIm2ColKernel& operator= ( NEDepthwiseIm2ColKernel &&  )
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 187 of file NEDepthwiseIm2ColKernel.cpp.

188 {
192 
193  if(_func != nullptr)
194  {
195  (this->*_func)(window);
196  }
197 }
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 = false,
unsigned int  depth_multiplier = 1,
const Size2D dilation = Size2D(1U, 1U) 
)
static

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

Parameters
[in]inputThe input tensor info 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
[in]outputThe output tensor info. First 3 lower dimensions represent a transform of each 3D input, while every dimension above 3 represents a batch. 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_biasBoolean that specifies if the depthwise convolution has bias.
[in]depth_multiplier(Optional) Multiplier to apply to the input's depth in order to retrieve the output's depth. Defaults to 1.
[in]dilation(Optional) Dilation, in elements, across x and y. Defaults to (1, 1).
Returns
a status

Definition at line 179 of file NEDepthwiseIm2ColKernel.cpp.

181 {
183  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, kernel_dims, conv_info, has_bias, depth_multiplier, dilation));
184  return Status{};
185 }
#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
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163

References ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::conv_info, arm_compute::test::validation::dilation, and arm_compute::test::validation::has_bias.

Referenced by NEDepthwiseConvolutionLayer::validate().


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