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

Kernel to perform Winograd input transform. More...

#include <CpuWinogradConv2dKernel.h>

Collaboration diagram for CpuWinogradConv2dTransformInputKernel< 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

 CpuWinogradConv2dTransformInputKernel (const CpuWinogradConv2dTransformInputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CpuWinogradConv2dTransformInputKerneloperator= (const CpuWinogradConv2dTransformInputKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CpuWinogradConv2dTransformInputKernel (CpuWinogradConv2dTransformInputKernel &&)=default
 Allow instances of this class to be moved. More...
 
CpuWinogradConv2dTransformInputKerneloperator= (CpuWinogradConv2dTransformInputKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CpuWinogradConv2dTransformInputKernel ()=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...
 
 CpuWinogradConv2dTransformInputKernel ()
 Default constructor. More...
 
const char * name () const override
 Name of the kernel. More...
 
void configure (const ITensorInfo *input_nhwc, const int num_batches, const int num_rows, const int num_cols, const int num_channels, const PaddingType padding, ITensorInfo *output, const int matrix_stride, ITensorInfo *workspace) 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 ICpuWinogradConv2dTransformInputKernel
virtual ~ICpuWinogradConv2dTransformInputKernel ()
 Destructor. More...
 
- 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 *output, const WinogradInfo &winograd_info)
 Static function to check if given info will lead to a valid configuration of CpuWinogradConv2dTransformInputKernel. More...
 

Detailed Description

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

Kernel to perform Winograd input transform.

Definition at line 100 of file CpuWinogradConv2dKernel.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 CpuWinogradConv2dKernel.h.

◆ WinogradConv

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

Winograd convolution kernel.

Definition at line 198 of file CpuWinogradConv2dKernel.h.

Constructor & Destructor Documentation

◆ CpuWinogradConv2dTransformInputKernel() [1/3]

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

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

◆ CpuWinogradConv2dTransformInputKernel() [2/3]

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

Allow instances of this class to be moved.

◆ ~CpuWinogradConv2dTransformInputKernel()

Default destructor.

◆ CpuWinogradConv2dTransformInputKernel() [3/3]

Default constructor.

Definition at line 321 of file CpuWinogradConv2dKernel.cpp.

322  : _transform(nullptr), _num_channels(0), _matrix_stride(0)
323 {
324 }

Member Function Documentation

◆ configure()

void configure ( const ITensorInfo input_nhwc,
const int  num_batches,
const int  num_rows,
const int  num_cols,
const int  num_channels,
const PaddingType  padding,
ITensorInfo output,
const int  matrix_stride,
ITensorInfo 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 ICpuWinogradConv2dTransformInputKernel.

Definition at line 327 of file CpuWinogradConv2dKernel.cpp.

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

337 {
338  ARM_COMPUTE_UNUSED(input_nhwc, output, matrix_stride, workspace);
339 
340  _num_channels = num_channels;
341  _matrix_stride = matrix_stride;
342 
343  const int padding_top = (padding == PADDING_SAME) ? (KernelRows - 1) / 2 : 0;
344  const int padding_left = (padding == PADDING_SAME) ? (KernelCols - 1) / 2 : 0;
345  const int padding_bottom = (padding == PADDING_SAME) ? iceildiv(KernelRows - 1, 2) : 0;
346  const int padding_right = (padding == PADDING_SAME) ? iceildiv(KernelCols - 1, 2) : 0;
347 
348  _transform = std::make_unique<InputTransform>(
349  KernelRows,
350  KernelCols,
351  num_batches,
352  num_rows,
353  num_cols,
354  num_channels,
355  padding_top, /**< Padding to apply to the top of the image. */
356  padding_left, /**< Padding to apply to the left of the image. */
357  padding_bottom, /**< Padding to apply to the bottom of the image. */
358  padding_right /**< Padding to apply to the right of the image. */
359  );
360 
361  Window win;
362  auto win_last = _transform->get_window();
363  win.set(Window::DimX, Window::Dimension(0, win_last, 1));
364  ICpuKernel::configure(win);
365 }
T iceildiv(const T a, const T b)
Definition: utils.hpp:65
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_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 ICpuWinogradConv2dTransformInputKernel.

Definition at line 289 of file CpuWinogradConv2dKernel.cpp.

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

296 {
297  // Construct shapes for the input and kernel tensors.
298  const Tensor4DShape input_shape(num_batches, num_rows, num_cols, num_channels);
299  const KernelShape kern_shape(1, KernelRows, KernelCols, num_channels);
300  return static_cast<unsigned int>(WinogradConv::get_input_storage_size(num_batches, num_rows, num_cols, num_channels, same_padding));
301 }
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 ICpuWinogradConv2dTransformInputKernel.

Definition at line 310 of file CpuWinogradConv2dKernel.cpp.

316 {
317  return WinogradConv::get_input_matrix_stride(num_batches, num_rows, num_cols, num_channels, same_padding);
318 }

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

Definition at line 304 of file CpuWinogradConv2dKernel.cpp.

305 {
306  return _transform->get_working_space_size(num_threads);
307 }

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 164 of file CpuWinogradConv2dKernel.h.

References ICpuWinogradConv2dTransformInputKernel::configure(), arm_compute::test::validation::info, ICPPKernel::run_op(), and IKernel::window().

165  {
166  return "CpuWinogradConv2dTransformInputKernel";
167  }

◆ operator=() [1/2]

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

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

◆ operator=() [2/2]

CpuWinogradConv2dTransformInputKernel& operator= ( CpuWinogradConv2dTransformInputKernel< 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 368 of file CpuWinogradConv2dKernel.cpp.

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

369 {
372  ARM_COMPUTE_ERROR_ON(tensors.empty());
373 
374  const ITensor *input_nhwc = tensors.get_const_tensor(TensorType::ACL_SRC);
375  const ITensor *workspace = tensors.get_const_tensor(TensorType::ACL_INT);
376  ITensor *output = tensors.get_tensor(TensorType::ACL_DST);
377 
378  const int element_size_in_bytes = input_nhwc->info()->element_size();
379  const int input_col_stride = input_nhwc->info()->strides_in_bytes().y() / element_size_in_bytes;
380  const int input_row_stride = input_nhwc->info()->strides_in_bytes().z() / element_size_in_bytes;
381  const int input_batch_stride = input_nhwc->info()->strides_in_bytes()[3] / element_size_in_bytes;
382  const auto input_nhwc_ptr = reinterpret_cast<const T *>(input_nhwc->buffer() + input_nhwc->info()->offset_first_element_in_bytes());
383  auto output_ptr = reinterpret_cast<T *>(output->buffer() + output->info()->offset_first_element_in_bytes());
384  ARM_COMPUTE_ERROR_ON_NULLPTR(output_ptr);
385 
386  _transform->set_input_tensor(input_nhwc_ptr, input_batch_stride, input_row_stride, input_col_stride);
387  _transform->set_output_matrices(output_ptr, _matrix_stride, _num_channels);
388 
389  _transform->set_working_space(workspace->buffer());
390 
391  // The code below cannot be moved to configure because biases hasn't been allocated at that point
392  const size_t fst = window.x().start();
393  const size_t lst = window.x().end();
394  _transform->run(fst, lst, info.thread_id);
395 }
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_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
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 CpuWinogradConv2dTransformInputKernel.

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 398 of file CpuWinogradConv2dKernel.cpp.

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

400 {
401  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments_winograd_input_trans(input, output, winograd_info));
402  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window_winograd_input_trans(input->clone().get(), output->clone().get(), winograd_info).first);
403 
404  return Status{};
405 }
#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: