Compute Library
 21.02
NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > Class Template Reference

Neon kernel to perform Winograd input transform. More...

#include <NEWinogradConvolutionLayerKernel.h>

Collaboration diagram for NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols >:
[legend]

Public Types

using WinogradBase = winograd::WinogradGEMM< OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers >
 Winograd base kernel. More...
 
using WinogradConv = typename WinogradBase::template Convolution< T, T >
 Winograd convolution kernel. More...
 

Public Member Functions

 NEWinogradLayerTransformInputKernel (const NEWinogradLayerTransformInputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEWinogradLayerTransformInputKerneloperator= (const NEWinogradLayerTransformInputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEWinogradLayerTransformInputKernel (NEWinogradLayerTransformInputKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEWinogradLayerTransformInputKerneloperator= (NEWinogradLayerTransformInputKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEWinogradLayerTransformInputKernel ()=default
 Default destructor. More...
 
unsigned int get_input_storage_size (int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const override
 Determine how much memory (in units of TIn) to allocate for the transformed input. More...
 
unsigned int get_working_space_size (unsigned int num_threads) const override
 Get the working space required to perform the transformation. More...
 
int get_matrix_stride (int num_batches, int num_channels, int num_rows, int num_cols, bool same_padding) const override
 Gets the stride between matrices in the input worspace. More...
 
 NEWinogradLayerTransformInputKernel ()
 Default constructor. More...
 
const char * name () const override
 Name of the kernel. More...
 
void configure (const ITensor *input_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, const PaddingType padding, ITensor *output, const int matrix_stride, ITensor *workspace) override
 Configure the output transform kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from INEWinogradLayerTransformInputKernel
virtual ~INEWinogradLayerTransformInputKernel ()
 Destructor. 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 WinogradInfo &winograd_info)
 Static function to check if given info will lead to a valid configuration of NEWinogradLayerTransformInputKernel. More...
 

Detailed Description

template<typename T, int OutputTileRows, int OutputTileCols, int KernelRows, int KernelCols>
class arm_compute::NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols >

Neon kernel to perform Winograd input transform.

Definition at line 101 of file NEWinogradConvolutionLayerKernel.h.

Member Typedef Documentation

◆ WinogradBase

using WinogradBase = winograd::WinogradGEMM<OutputTileRows, OutputTileCols, KernelRows, KernelCols, winograd::WinogradRoots::Integers>

Winograd base kernel.

Definition at line 197 of file NEWinogradConvolutionLayerKernel.h.

◆ WinogradConv

using WinogradConv = typename WinogradBase::template Convolution<T, T>

Winograd convolution kernel.

Definition at line 199 of file NEWinogradConvolutionLayerKernel.h.

Constructor & Destructor Documentation

◆ NEWinogradLayerTransformInputKernel() [1/3]

NEWinogradLayerTransformInputKernel ( const NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > &  )
delete

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

◆ NEWinogradLayerTransformInputKernel() [2/3]

NEWinogradLayerTransformInputKernel ( NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > &&  )
default

Allow instances of this class to be moved.

◆ ~NEWinogradLayerTransformInputKernel()

Default destructor.

◆ NEWinogradLayerTransformInputKernel() [3/3]

Default constructor.

Definition at line 318 of file NEWinogradConvolutionLayerKernel.cpp.

319  : _transform(nullptr), _input_nhwc(nullptr), _num_batches(0), _num_rows(0), _num_cols(0), _num_channels(0), _padding(), _output(nullptr), _matrix_stride(0), _padding_top(), _padding_left(),
320  _padding_right(), _padding_bottom(), _workspace(nullptr)
321 {
322 }

Member Function Documentation

◆ configure()

void configure ( const ITensor input_nhwc,
const int  num_batches,
const int  num_rows,
const int  num_cols,
const int  num_channels,
const PaddingType  padding,
ITensor output,
const int  matrix_stride,
ITensor workspace 
)
overridevirtual

Configure the output transform kernel.

Parameters
[in]input_nhwcInput tensor. Data types supported: F16/F32. Layout supported NHWC.
[in]num_batchesNumber of batches in input tensor.
[in]num_rowsNumber of rows in input tensor.
[in]num_colsNumber of columns in input tensor.
[in]num_channelsNumber of channels in input tensor.
[in]paddingPadding type.
[out]outputBase of output matrices.
[in]matrix_strideStride between output matrices.
[in]workspaceTensor to be used as the working space during the computation.

< Padding to apply to the top of the image.

< Padding to apply to the left of the image.

< Padding to apply to the bottom of the image.

< Padding to apply to the right of the image.

Implements INEWinogradLayerTransformInputKernel.

Definition at line 325 of file NEWinogradConvolutionLayerKernel.cpp.

References Window::DimX, and arm_gemm::iceildiv().

335 {
336  _input_nhwc = input_nhwc;
337  _num_batches = num_batches;
338  _num_rows = num_rows;
339  _num_cols = num_cols;
340  _num_channels = num_channels;
341  _padding = padding;
342  _output = output;
343  _matrix_stride = matrix_stride;
344  _workspace = workspace;
345 
346  _padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
347  _padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
348  _padding_bottom = (padding == PADDING_SAME) ? iceildiv(KernelRows - 1, 2) : 0;
349  _padding_right = (padding == PADDING_SAME) ? iceildiv(KernelCols - 1, 2) : 0;
350 
351  _transform = std::make_unique<InputTransform>(
352  KernelRows,
353  KernelCols,
354  num_batches,
355  num_rows,
356  num_cols,
357  num_channels,
358  _padding_top, /**< Padding to apply to the top of the image. */
359  _padding_left, /**< Padding to apply to the left of the image. */
360  _padding_bottom, /**< Padding to apply to the bottom of the image. */
361  _padding_right /**< Padding to apply to the right of the image. */
362  );
363 
364  Window win;
365  auto win_last = _transform->get_window();
366  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
367  INEKernel::configure(win);
368 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:40
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43

◆ get_input_storage_size()

unsigned int get_input_storage_size ( int  num_batches,
int  num_channels,
int  num_rows,
int  num_cols,
bool  same_padding 
) const
overridevirtual

Determine how much memory (in units of TIn) to allocate for the transformed input.

Parameters
[in]num_batchesNumber of batches in the input tensor.
[in]num_channelsNumber of feature maps in the input tensor.
[in]num_rowsNumber of rows in each feature map.
[in]num_colsNumber of columns in each feature map.
[in]same_paddingUse "SAME" padding, otherwise use "VALID".
Returns
Storage size (in units of TIn) required.

Implements INEWinogradLayerTransformInputKernel.

Definition at line 285 of file NEWinogradConvolutionLayerKernel.cpp.

References arm_compute::test::validation::input_shape.

292 {
293  // Construct shapes for the input and kernel tensors.
294  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
295  const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
296  // Return the size, converted into units of TIn
297  return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) / sizeof(T));
298 }
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

◆ get_matrix_stride()

int get_matrix_stride ( int  num_batches,
int  num_channels,
int  num_rows,
int  num_cols,
bool  same_padding 
) const
overridevirtual

Gets the stride between matrices in the input worspace.

Parameters
[in]num_batchesNumber of batches in the input tensor.
[in]num_channelsNumber of feature maps in the input tensor.
[in]num_rowsNumber of rows in each feature map.
[in]num_colsNumber of columns in each feature map.
[in]same_paddingUse "SAME" padding, otherwise use "VALID".
Returns
Stride expressed in bytes.

Implements INEWinogradLayerTransformInputKernel.

Definition at line 307 of file NEWinogradConvolutionLayerKernel.cpp.

313 {
314  return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
315 }

◆ get_working_space_size()

unsigned int get_working_space_size ( unsigned int  num_threads) const
overridevirtual

Get the working space required to perform the transformation.

Note, the working space is only required when performing the transformation - hence it can be reused whenever the transformation is not running.

Parameters
[in]num_threadsThe greatest number of threads that will be used to execute the transform.
Returns
Size of working space required in bytes.

Implements INEWinogradLayerTransformInputKernel.

Definition at line 301 of file NEWinogradConvolutionLayerKernel.cpp.

302 {
303  return _transform->get_working_space_size(num_threads) / sizeof(T);
304 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 165 of file NEWinogradConvolutionLayerKernel.h.

References INEWinogradLayerTransformInputKernel::configure(), arm_compute::test::validation::info, ICPPKernel::run(), and IKernel::window().

166  {
167  return "NEWinogradLayerTransformInputKernel";
168  }

◆ operator=() [1/2]

NEWinogradLayerTransformInputKernel& operator= ( const NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > &  )
delete

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

◆ operator=() [2/2]

NEWinogradLayerTransformInputKernel& operator= ( NEWinogradLayerTransformInputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > &&  )
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 371 of file NEWinogradConvolutionLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensor::buffer(), ITensorInfo::element_size(), Window::Dimension::end(), ITensor::info(), ITensorInfo::offset_first_element_in_bytes(), Window::Dimension::start(), ITensorInfo::strides_in_bytes(), ThreadInfo::thread_id, Window::x(), Dimensions< T >::y(), and Dimensions< T >::z().

372 {
375  ARM_COMPUTE_ERROR_ON_NULLPTR(_workspace);
376 
377  const int element_size_in_bytes = _input_nhwc->info()->element_size();
378  const int input_col_stride = _input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
379  const int input_row_stride = _input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
380  const int input_batch_stride = _input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
381  const auto input_nhwc_ptr = reinterpret_cast<const T *>(_input_nhwc->buffer() + _input_nhwc->info()->offset_first_element_in_bytes());
382  auto output_ptr = reinterpret_cast<T *>(_output->buffer() + _output->info()->offset_first_element_in_bytes());
383  ARM_COMPUTE_ERROR_ON_NULLPTR(output_ptr);
384 
385  _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
386  _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
387 
388  _transform->set_working_space(_workspace->buffer());
389 
390  // The code below cannot be moved to configure because biases hasn't been allocated at that point
391  const size_t fst = window.x().start();
392  const size_t lst = window.x().end();
393  _transform->run(fst, lst, info.thread_id);
394 }
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
T z() const
Alias to access the size of the third dimension.
Definition: Dimensions.h:97
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
T y() const
Alias to access the size of the second dimension.
Definition: Dimensions.h:92
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const WinogradInfo winograd_info 
)
static

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

Parameters
[in]inputFirst tensor input info. Data types supported: F16/F32.
[in]outputOutput tensor info. Data types supported: same as input.
[in]winograd_infoContains Winograd's information described in WinogradInfo
Returns
a status

Definition at line 397 of file NEWinogradConvolutionLayerKernel.cpp.

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

398 {
399  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info));
400  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first);
401 
402  return Status{};
403 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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