Compute Library
 19.08
NEWinogradLayerTransformOutputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > Class Template Reference

NEON kernel to perform Winograd output transform. More...

#include <NEWinogradConvolutionLayerKernel.h>

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

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEWinogradLayerTransformOutputKernel ()
 Constructor. More...
 
 NEWinogradLayerTransformOutputKernel (const NEWinogradLayerTransformOutputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEWinogradLayerTransformOutputKerneloperator= (const NEWinogradLayerTransformOutputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEWinogradLayerTransformOutputKernel (NEWinogradLayerTransformOutputKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEWinogradLayerTransformOutputKerneloperator= (NEWinogradLayerTransformOutputKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEWinogradLayerTransformOutputKernel ()=default
 Default destructor. More...
 
unsigned int get_output_storage_size (int num_batches, int num_rows, int num_cols, int num_output_channels, bool same_padding) const override
 Determine how much memory (in units of TOut) to allocate for the (Winograd domain) output. More...
 
int get_matrix_stride (const KernelShape &kernel_shape, const Tensor4DShape &input_shape, const PaddingType padding_type) const override
 Gets the stride between matrices in the output worspace. More...
 
Tensor4DShape get_output_shape (const KernelShape &kernel_shape, const Tensor4DShape &in_shape, const PaddingType padding) const override
 Get the output shape of a convolution. More...
 
unsigned int get_working_space_size (unsigned int num_threads) const override
 Get the working space required to perform the transformation. More...
 
void configure (const ITensor *biases, const ITensor *transformed_output, const int matrix_stride, ITensor *output_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, 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 INEWinogradLayerTransformOutputKernel< T >
virtual ~INEWinogradLayerTransformOutputKernel ()
 
- 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 *bias, const ITensorInfo *output, const WinogradInfo &winograd_info)
 Static function to check if given info will lead to a valid configuration of NEWinogradLayerTransformOutputKernel. More...
 

Detailed Description

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

NEON kernel to perform Winograd output transform.

Definition at line 300 of file NEWinogradConvolutionLayerKernel.h.

Constructor & Destructor Documentation

◆ NEWinogradLayerTransformOutputKernel() [1/3]

Constructor.

Definition at line 467 of file NEWinogradConvolutionLayerKernel.cpp.

468  : _transform(nullptr), _biases(nullptr), _transformed_output(nullptr), _workspace(nullptr), _matrix_stride(0), _matrix_row_stride(0), _output_nhwc(nullptr), _num_batches(0), _num_rows(0),
469  _num_cols(0), _num_channels(0)
470 {
471 }

◆ NEWinogradLayerTransformOutputKernel() [2/3]

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

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

◆ NEWinogradLayerTransformOutputKernel() [3/3]

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

Allow instances of this class to be moved.

◆ ~NEWinogradLayerTransformOutputKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor biases,
const ITensor transformed_output,
const int  matrix_stride,
ITensor output_nhwc,
const int  num_batches,
const int  num_rows,
const int  num_cols,
const int  num_channels,
ITensor workspace 
)
overridevirtual

Configure the output transform kernel.

Parameters
[in]biasesPointer to the biases tensor.
[in]transformed_outputPointer to working space for the output tensor in the Winograd domain.
[in]matrix_strideOutput matrix stride, can be computed with winograd::WinogradGEMM<2, 2, 3, 3>::Convolution<float, float>::get_output_matrix_stride()
[out]output_nhwcPointer to a tensor with NHWC data layout, in the spatial domain.
[in]num_batchesNumber of batches in the input tensor.
[in]num_rowsNumber of rows in output tensor.
[in]num_colsNumber of columns in output tensor.
[in]num_channelsNumber of feature maps in the output tensor.
[in]workspaceTensor to be used as the working space during the computation.

Implements INEWinogradLayerTransformOutputKernel< T >.

Definition at line 493 of file NEWinogradConvolutionLayerKernel.cpp.

503 {
504  _biases = biases;
505  _workspace = workspace;
506  _transformed_output = transformed_output;
507  _matrix_stride = matrix_stride;
508  _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK);
509  _output_nhwc = output_nhwc;
510  _num_batches = num_batches;
511  _num_rows = num_rows;
512  _num_cols = num_cols;
513  _num_channels = num_channels;
514  // We don't have the biases buffer at this stage as it hasn't been allocated, we pass in nullptr OutputTransform is only used here to compute the window
515  _transform = arm_compute::support::cpp14::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels);
516  Window win;
517  auto win_last = _transform->get_window();
518  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
519  _output_nhwc->info()->set_valid_region(ValidRegion(Coordinates(), _output_nhwc->info()->tensor_shape()));
520 
521  INEKernel::configure(win);
522 }
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
T roundup(const T a, const T b)
Definition: utils.hpp:41

◆ get_matrix_stride()

int get_matrix_stride ( const KernelShape &  kernel_shape,
const Tensor4DShape &  input_shape,
const PaddingType  padding_type 
) const
overridevirtual

Gets the stride between matrices in the output worspace.

Parameters
[in]kernel_shapeThe shape of the weights tensor.
[in]input_shapeThe shape of the input tensor.
[in]padding_typeThe type of padding to be used.
Returns
Stride expressed in bytes.

Implements INEWinogradLayerTransformOutputKernel< T >.

Definition at line 480 of file NEWinogradConvolutionLayerKernel.cpp.

482 {
483  return WinogradConv::get_output_matrix_stride(kernel_shape, input_shape, padding_type);
484 }

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

◆ get_output_shape()

Tensor4DShape get_output_shape ( const KernelShape &  kernel_shape,
const Tensor4DShape &  in_shape,
const PaddingType  padding 
) const
overridevirtual

Get the output shape of a convolution.

Parameters
[in]kernel_shapeThe shape of the weights tensor.
[in]in_shapeThe shape of the input tensor.
[in]paddingThe type of padding to be used.
Returns
Stride expressed in bytes.

Implements INEWinogradLayerTransformOutputKernel< T >.

Definition at line 486 of file NEWinogradConvolutionLayerKernel.cpp.

488 {
489  return WinogradConv::get_output_shape(kernel_shape, in_shape, padding);
490 }

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

◆ get_output_storage_size()

unsigned int get_output_storage_size ( int  num_batches,
int  num_rows,
int  num_cols,
int  num_output_channels,
bool  same_padding 
) const
overridevirtual

Determine how much memory (in units of TOut) to allocate for the (Winograd domain) output.

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

Implements INEWinogradLayerTransformOutputKernel< T >.

Definition at line 448 of file NEWinogradConvolutionLayerKernel.cpp.

455 {
456  // Construct shapes for the input and kernel tensors.
457  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1);
458  const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
459  const PaddingType padding = (same_padding) ? PADDING_SAME : PADDING_VALID;
460 
461  // Return the size, converted into units of TOut
462  return static_cast<unsigned int>(
463  WinogradConv::get_output_storage_size(kern_shape, input_shape, padding) / sizeof(T));
464 }

References arm_compute::test::validation::input_shape, and arm_compute::test::validation::padding.

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

Definition at line 474 of file NEWinogradConvolutionLayerKernel.cpp.

475 {
476  return _transform->get_working_space_size(num_threads) / sizeof(T);
477 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 303 of file NEWinogradConvolutionLayerKernel.h.

304  {
305  return "NEWinogradLayerTransformOutputKernel";
306  }

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

NEWinogradLayerTransformOutputKernel& operator= ( NEWinogradLayerTransformOutputKernel< 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 525 of file NEWinogradConvolutionLayerKernel.cpp.

526 {
529  ARM_COMPUTE_ERROR_ON_NULLPTR(_workspace);
530  ARM_COMPUTE_ERROR_ON_NULLPTR(_transformed_output);
531  ARM_COMPUTE_ERROR_ON_NULLPTR(_output_nhwc);
532 
533  const int out_batch_stride = _output_nhwc->info()->strides_in_bytes()[3] / sizeof(T);
534  const int out_row_stride = _output_nhwc->info()->strides_in_bytes()[2] / sizeof(T);
535  const int out_col_stride = _output_nhwc->info()->strides_in_bytes()[1] / sizeof(T);
536 
537  _transform->set_input_matrices(_transformed_output->buffer(), _matrix_stride, _matrix_row_stride);
538  _transform->set_bias((_biases ? reinterpret_cast<T *>(_biases->buffer() + _biases->info()->offset_first_element_in_bytes()) : nullptr));
539  _transform->set_output_tensor(_output_nhwc->buffer() + _output_nhwc->info()->offset_first_element_in_bytes(), out_batch_stride, out_row_stride, out_col_stride);
540  _transform->set_working_space(_workspace->buffer());
541  // The code below cannot be moved to configure because biases hasn't been allocated at that point
542  const size_t fst = window.x().start();
543  const size_t lst = window.x().end();
544  _transform->run(fst, lst, info.thread_id);
545 }
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
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 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
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:940
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 bias,
const ITensorInfo output,
const WinogradInfo winograd_info 
)
static

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

Parameters
[in]inputSource tensor info with shape [C, N, 16, batches] or [C, N, 36, batches]. Data types supported: F32.
[in]biasBiases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. It can be a nullptr. Data type supported: as input
[in]outputDestination tensor info with shape [output_convolved_dims.width, output_convolved_dims.height, C, batches]. Data type supported: same as input
[in]winograd_infoContains Winograd's information described in WinogradInfo
Returns
a status

Definition at line 548 of file NEWinogradConvolutionLayerKernel.cpp.

550 {
551  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info));
552  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), (bias != nullptr ? bias->clone().get() : nullptr), output->clone().get(),
554  .first);
555 
556  return Status{};
557 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193

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


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