Compute Library
 21.08
CpuWinogradConv2dTransformOutputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > Class Template Reference

Kernel to perform Winograd output transform. More...

#include <CpuWinogradConv2dKernel.h>

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

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CpuWinogradConv2dTransformOutputKernel ()
 Constructor. More...
 
 CpuWinogradConv2dTransformOutputKernel (const CpuWinogradConv2dTransformOutputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CpuWinogradConv2dTransformOutputKerneloperator= (const CpuWinogradConv2dTransformOutputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CpuWinogradConv2dTransformOutputKernel (CpuWinogradConv2dTransformOutputKernel &&)=default
 Allow instances of this class to be moved. More...
 
CpuWinogradConv2dTransformOutputKerneloperator= (CpuWinogradConv2dTransformOutputKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CpuWinogradConv2dTransformOutputKernel ()=default
 Default destructor. More...
 
unsigned int get_output_storage_size (int num_batches, int num_rows, int num_cols, int num_output_channels) const override
 Determine how much memory (in units of TOut) to allocate for the (Winograd domain) output. More...
 
int get_matrix_stride (int num_batches, int num_rows, int num_cols, int num_output_channels) const override
 Gets the stride between matrices in the output worspace. More...
 
std::pair< unsigned int, unsigned int > get_output_shape (int num_rows, int num_cols, bool padding_same) 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 ITensorInfo *biases, const ITensorInfo *transformed_output, const int matrix_stride, ITensorInfo *output_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, ITensorInfo *workspace, const arm_gemm::Activation &activation) override
 Configure the output transform kernel. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICpuWinogradConv2dTransformOutputKernel
virtual ~ICpuWinogradConv2dTransformOutputKernel ()
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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...
 
- 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. 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 CpuWinogradConv2dTransformOutputKernel. More...
 

Detailed Description

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

Kernel to perform Winograd output transform.

Definition at line 303 of file CpuWinogradConv2dKernel.h.

Constructor & Destructor Documentation

◆ CpuWinogradConv2dTransformOutputKernel() [1/3]

Constructor.

Definition at line 440 of file CpuWinogradConv2dKernel.cpp.

441  : _transform(nullptr), _matrix_stride(0), _matrix_row_stride(0)
442 {
443 }

◆ CpuWinogradConv2dTransformOutputKernel() [2/3]

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

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

◆ CpuWinogradConv2dTransformOutputKernel() [3/3]

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

Allow instances of this class to be moved.

◆ ~CpuWinogradConv2dTransformOutputKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensorInfo biases,
const ITensorInfo transformed_output,
const int  matrix_stride,
ITensorInfo output_nhwc,
const int  num_batches,
const int  num_rows,
const int  num_cols,
const int  num_channels,
ITensorInfo workspace,
const arm_gemm::Activation activation 
)
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.
[in]activationActivation to be used

Implements ICpuWinogradConv2dTransformOutputKernel.

Definition at line 472 of file CpuWinogradConv2dKernel.cpp.

References ARM_COMPUTE_UNUSED, Window::DimX, and arm_gemm::roundup().

483 {
484  ARM_COMPUTE_UNUSED(biases, transformed_output, output_nhwc, num_batches, num_rows, num_cols, workspace, activation);
485 
486  _matrix_stride = matrix_stride;
487  _matrix_row_stride = roundup(num_channels, WinogradConv::N_BLOCK);
488 
489  // 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
490  _transform = std::make_unique<OutputTransform>(num_batches, num_rows, num_cols, num_channels, activation);
491  Window win;
492  auto win_last = _transform->get_window();
493  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
494 
495  ICpuKernel::configure(win);
496 }
T roundup(const T a, const T b)
Definition: utils.hpp:70
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152

◆ get_matrix_stride()

int get_matrix_stride ( int  num_batches,
int  num_rows,
int  num_cols,
int  num_output_channels 
) const
overridevirtual

Gets the stride between matrices in the output worspace.

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.
Returns
Stride expressed in bytes.

Implements ICpuWinogradConv2dTransformOutputKernel.

Definition at line 452 of file CpuWinogradConv2dKernel.cpp.

458 {
459  return WinogradConv::get_output_matrix_stride(num_batches, num_rows, num_cols, num_output_channels);
460 }

◆ get_output_shape()

std::pair< unsigned int, unsigned int > get_output_shape ( int  num_rows,
int  num_cols,
bool  padding_same 
) const
overridevirtual

Get the output shape of a convolution.

Parameters
[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]padding_sameTrue if padding is SAME, false otherwise
Returns
Shape of the output tensor

Implements ICpuWinogradConv2dTransformOutputKernel.

Definition at line 463 of file CpuWinogradConv2dKernel.cpp.

467 {
468  return WinogradConv::get_output_shape(std::make_pair<unsigned int, unsigned int>(num_rows, num_cols), padding_same);
469 }

◆ get_output_storage_size()

unsigned int get_output_storage_size ( int  num_batches,
int  num_rows,
int  num_cols,
int  num_output_channels 
) 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.
Returns
Storage size (in units of TOut) required.

Implements ICpuWinogradConv2dTransformOutputKernel.

Definition at line 425 of file CpuWinogradConv2dKernel.cpp.

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

431 {
432  // Construct shapes for the input and kernel tensors.
433  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, 1);
434  const KernelShape kern_shape(num_output_channels, KernelRows, KernelCols, 1);
435  return static_cast<unsigned int>(
436  WinogradConv::get_output_storage_size(num_batches, num_rows, num_cols, num_output_channels));
437 }
TensorShape input_shape
Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros we use to check the validity of given a...

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

Definition at line 446 of file CpuWinogradConv2dKernel.cpp.

447 {
448  return _transform->get_working_space_size(num_threads);
449 }

◆ name()

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

CpuWinogradConv2dTransformOutputKernel& operator= ( CpuWinogradConv2dTransformOutputKernel< T, OutputTileRows, OutputTileCols, KernelRows, KernelCols > &&  )
default

Allow instances of this class to be moved.

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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 499 of file CpuWinogradConv2dKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_INT, arm_compute::ACL_SRC_0, arm_compute::ACL_SRC_1, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ITensor::buffer(), ITensorPack::empty(), Window::Dimension::end(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), ITensor::info(), ITensorInfo::offset_first_element_in_bytes(), Window::Dimension::start(), ITensorInfo::strides_in_bytes(), ThreadInfo::thread_id, and Window::x().

500 {
502  ARM_COMPUTE_ERROR_ON(tensors.empty());
503 
504  const ITensor *biases = tensors.get_const_tensor(TensorType::ACL_SRC_0);
505  const ITensor *transformed_output = tensors.get_const_tensor(TensorType::ACL_SRC_1);
506  ITensor *workspace = tensors.get_tensor(TensorType::ACL_INT);
507  ITensor *dst_nhwc = tensors.get_tensor(TensorType::ACL_DST);
508 
509  const int out_batch_stride = dst_nhwc->info()->strides_in_bytes()[3] / sizeof(T);
510  const int out_row_stride = dst_nhwc->info()->strides_in_bytes()[2] / sizeof(T);
511  const int out_col_stride = dst_nhwc->info()->strides_in_bytes()[1] / sizeof(T);
512 
513  _transform->set_input_matrices(transformed_output->buffer(), _matrix_stride, _matrix_row_stride);
514  _transform->set_bias((biases ? reinterpret_cast<T *>(biases->buffer() + biases->info()->offset_first_element_in_bytes()) : nullptr));
515  _transform->set_output_tensor(dst_nhwc->buffer() + dst_nhwc->info()->offset_first_element_in_bytes(), out_batch_stride, out_row_stride, out_col_stride);
516  _transform->set_working_space(workspace->buffer());
517 
518  // The code below cannot be moved to configure because biases hasn't been allocated at that point
519  const size_t fst = window.x().start();
520  const size_t lst = window.x().end();
521  _transform->run(fst, lst, info.thread_id);
522 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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 bias,
const ITensorInfo output,
const WinogradInfo winograd_info 
)
static

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

Parameters
[in]inputSource tensor info with shape [C, N, 16, batches] or [C, N, 36, batches]. Data types supported: F16/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 525 of file CpuWinogradConv2dKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and ICloneable< T >::clone().

527 {
528  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_output_trans(input, (bias != nullptr ? bias->clone().get() : nullptr), output, winograd_info));
529  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_output_trans(input->clone().get(), output->clone().get(), winograd_info).first);
530 
531  return Status{};
532 }
#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: