Compute Library
 19.11
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< T >
virtual ~INEWinogradLayerTransformInputKernel ()
 Destructor. 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 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 100 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 196 of file NEWinogradConvolutionLayerKernel.h.

◆ WinogradConv

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

Winograd convolution kernel.

Definition at line 198 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 351 of file NEWinogradConvolutionLayerKernel.cpp.

352  : _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(),
353  _padding_right(), _padding_bottom(), _workspace(nullptr)
354 {
355 }

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: 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< T >.

Definition at line 358 of file NEWinogradConvolutionLayerKernel.cpp.

368 {
369  _input_nhwc = input_nhwc;
370  _num_batches = num_batches;
371  _num_rows = num_rows;
372  _num_cols = num_cols;
373  _num_channels = num_channels;
374  _padding = padding;
375  _output = output;
376  _matrix_stride = matrix_stride;
377  _workspace = workspace;
378 
379  _padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
380  _padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
381  _padding_bottom = (padding == PADDING_SAME) ? iceildiv(KernelRows - 1, 2) : 0;
382  _padding_right = (padding == PADDING_SAME) ? iceildiv(KernelCols - 1, 2) : 0;
383 
384  _transform = arm_compute::support::cpp14::make_unique<InputTransform>(
385  KernelRows,
386  KernelCols,
387  num_batches,
388  num_rows,
389  num_cols,
390  num_channels,
391  _padding_top, /**< Padding to apply to the top of the image. */
392  _padding_left, /**< Padding to apply to the left of the image. */
393  _padding_bottom, /**< Padding to apply to the bottom of the image. */
394  _padding_right /**< Padding to apply to the right of the image. */
395  );
396 
397  Window win;
398  auto win_last = _transform->get_window();
399  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
400  INEKernel::configure(win);
401 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:38
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43

References arm_compute::test::validation::padding.

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

Definition at line 318 of file NEWinogradConvolutionLayerKernel.cpp.

325 {
326  // Construct shapes for the input and kernel tensors.
327  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
328  const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
329  // Return the size, converted into units of TIn
330  return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding) / sizeof(T));
331 }

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

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

Definition at line 340 of file NEWinogradConvolutionLayerKernel.cpp.

346 {
347  return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
348 }

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

Definition at line 334 of file NEWinogradConvolutionLayerKernel.cpp.

335 {
336  return _transform->get_working_space_size(num_threads) / sizeof(T);
337 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 164 of file NEWinogradConvolutionLayerKernel.h.

165  {
166  return "NEWinogradLayerTransformInputKernel";
167  }

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

Implements ICPPKernel.

Definition at line 404 of file NEWinogradConvolutionLayerKernel.cpp.

405 {
408  ARM_COMPUTE_ERROR_ON_NULLPTR(_workspace);
409 
410  const int element_size_in_bytes = _input_nhwc->info()->element_size();
411  const int input_col_stride = _input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
412  const int input_row_stride = _input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
413  const int input_batch_stride = _input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
414  const auto input_nhwc_ptr = reinterpret_cast<const T *>(_input_nhwc->buffer() + _input_nhwc->info()->offset_first_element_in_bytes());
415  auto output_ptr = reinterpret_cast<T *>(_output->buffer() + _output->info()->offset_first_element_in_bytes());
416  ARM_COMPUTE_ERROR_ON_NULLPTR(output_ptr);
417 
418  _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
419  _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
420 
421  _transform->set_working_space(_workspace->buffer());
422 
423  // The code below cannot be moved to configure because biases hasn't been allocated at that point
424  const size_t fst = window.x().start();
425  const size_t lst = window.x().end();
426  _transform->run(fst, lst, info.thread_id);
427 }
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:91
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's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
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.
#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:86
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:97
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:92
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and arm_compute::test::validation::info.

◆ 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: 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 430 of file NEWinogradConvolutionLayerKernel.cpp.

431 {
432  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info));
433  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first);
434 
435  return Status{};
436 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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


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