Compute Library
 19.08
CLWinogradFilterTransformKernel Class Reference

Interface for the Winograd filter transform kernel. More...

#include <CLWinogradFilterTransformKernel.h>

Collaboration diagram for CLWinogradFilterTransformKernel:
[legend]

Public Member Functions

 CLWinogradFilterTransformKernel ()
 Default constructor. More...
 
 CLWinogradFilterTransformKernel (const CLWinogradFilterTransformKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLWinogradFilterTransformKerneloperator= (const CLWinogradFilterTransformKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLWinogradFilterTransformKernel (CLWinogradFilterTransformKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLWinogradFilterTransformKerneloperator= (CLWinogradFilterTransformKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLWinogradFilterTransformKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output, const WinogradInfo &winograd_info)
 Set the input and output tensor. More...
 
void run (const Window &window, cl::CommandQueue &queue) override
 Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue. More...
 
- Public Member Functions inherited from ICLKernel
 ICLKernel ()
 Constructor. More...
 
cl::Kernel & kernel ()
 Returns a reference to the OpenCL kernel of this object. More...
 
template<typename T >
void add_1D_array_argument (unsigned int &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed 1D array's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_1D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_2D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_2D_tensor_argument_if (bool cond, unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx if the condition is true. More...
 
void add_3D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
void add_4D_tensor_argument (unsigned int &idx, const ICLTensor *tensor, const Window &window)
 Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<typename T >
void add_argument (unsigned int &idx, T value)
 Add the passed parameters to the object's kernel's arguments starting from the index idx. More...
 
void set_lws_hint (const cl::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
cl::NDRange lws_hint () const
 Return the Local-Workgroup-Size hint. More...
 
const std::string & config_id () const
 Get the configuration ID. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
void set_target (cl::Device &device)
 Set the targeted GPU architecture according to the CL device. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. More...
 
size_t get_max_workgroup_size ()
 Get the maximum workgroup size for the device the CLKernelLibrary uses. More...
 
template<typename T , unsigned int dimension_size>
void add_array_argument (unsigned &idx, const ICLArray< T > *array, const Strides &strides, unsigned int num_dimensions, const Window &window)
 Add the passed array's parameters to the object's kernel's arguments starting from the index idx. More...
 
template<unsigned int dimension_size>
void add_tensor_argument (unsigned &idx, const ICLTensor *tensor, const Window &window)
 
- 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 CLWinogradFilterTransformKernel. More...
 
- Static Public Member Functions inherited from ICLKernel
static constexpr unsigned int num_arguments_per_1D_array ()
 Returns the number of arguments enqueued per 1D array object. More...
 
static constexpr unsigned int num_arguments_per_1D_tensor ()
 Returns the number of arguments enqueued per 1D tensor object. More...
 
static constexpr unsigned int num_arguments_per_2D_tensor ()
 Returns the number of arguments enqueued per 2D tensor object. More...
 
static constexpr unsigned int num_arguments_per_3D_tensor ()
 Returns the number of arguments enqueued per 3D tensor object. More...
 
static constexpr unsigned int num_arguments_per_4D_tensor ()
 Returns the number of arguments enqueued per 4D tensor object. More...
 
static cl::NDRange gws_from_window (const Window &window)
 Get the global work size given an execution window. More...
 

Detailed Description

Interface for the Winograd filter transform kernel.

Definition at line 34 of file CLWinogradFilterTransformKernel.h.

Constructor & Destructor Documentation

◆ CLWinogradFilterTransformKernel() [1/3]

Default constructor.

Definition at line 97 of file CLWinogradFilterTransformKernel.cpp.

98  : _input(nullptr), _output(nullptr)
99 {
100 }

◆ CLWinogradFilterTransformKernel() [2/3]

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

◆ CLWinogradFilterTransformKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CLWinogradFilterTransformKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output,
const WinogradInfo winograd_info 
)

Set the input and output tensor.

Note
Winograd filter transform supports the following configurations for NCWH data layout F(output tile, kernel size):F(2x2, 3x3), F(2x1, 3x1), F(1x2, 1x3), F(4x4, 3x3), F(4x1, 3x1), F(1x4, 1x3), F(4x4, 5x5), F(4x1, 5x1), F(1x4, 1x5)
Winograd filter transform supports the following configurations for NHWC data layout F(output tile, kernel size):F(4x4, 3x3), F(4x1, 3x1), F(1x4, 1x3), F(4x4, 5x5), F(4x1, 5x1), F(1x4, 1x5)

Strides: only unit strides

Parameters
[in]inputSource tensor. The input is a 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM] (NCHW data layout) or [IFM, kernel_x, kernel_y, OFM] (NHWC data layout). Data types supported: F16/F32.
[out]outputThe output tensor. The shape for this tensor can be calculated using the utility function compute_winograd_filter_transform_shape. Data types supported: Same as input
[in]winograd_infoContains Winograd's information described in WinogradInfo

Definition at line 102 of file CLWinogradFilterTransformKernel.cpp.

103 {
104  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
105 
106  // Output auto initialization if not yet initialized
107  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(compute_winograd_filter_transform_shape(*input->info(), winograd_info)));
108 
109  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), winograd_info));
110 
111  // Set build options
112  CLBuildOptions build_opts;
113  build_opts.add_option("-DSRC_DIM_Z=" + support::cpp11::to_string(input->info()->dimension(2)));
114  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
115  build_opts.add_option_if(winograd_info.kernel_size.height == 1, "-DWINOGRAD_FILTER_TRANSFORM_HORIZONTAL");
116  build_opts.add_option_if(winograd_info.kernel_size.width == 1, "-DWINOGRAD_FILTER_TRANSFORM_VERTICAL");
117  const Size2D kernel_size = winograd_info.kernel_size;
118  const Size2D output_tile_size = winograd_info.output_tile_size;
119 
120  // Create kernel
121  std::string kernel_name = "winograd_filter_transform_" + output_tile_size.to_string() + "_" + kernel_size.to_string() + "_" + lower_string(string_from_data_layout(input->info()->data_layout()));
122  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel(kernel_name, build_opts.options()));
123 
124  _input = input;
125  _output = output;
126 
127  // Configure kernel window
128  auto win_config = validate_and_configure_window(input->info(), output->info());
129  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
130  ICLKernel::configure_internal(win_config.second);
131 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
const StringSet & options() const
Gets the current options list set.
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
std::string lower_string(const std::string &val)
Lower a given string.
Definition: Utils.cpp:327
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
Definition: Helpers.inl:201
void add_option(std::string option)
Adds option to the existing build option list.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
Definition: CLHelpers.cpp:35
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
TensorShape compute_winograd_filter_transform_shape(const ITensorInfo &input, const WinogradInfo &winograd_info)
Calculate the winograd filter transform shape.
std::unique_ptr< Kernel > create_kernel()
Helper function to create and return a unique_ptr pointed to a CL/GLES kernel object.
Definition: Helpers.h:86
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
Definition: Utils.cpp:132
Class for specifying the size of an image or rectangle.
Definition: Size2D.h:34
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
std::string to_string() const
Definition: Size2D.h:68

References CLBuildOptions::add_option(), CLBuildOptions::add_option_if(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_winograd_filter_transform_shape(), arm_compute::create_kernel(), ITensorInfo::data_layout(), ITensorInfo::data_type(), ITensorInfo::dimension(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::lower_string(), CLBuildOptions::options(), arm_compute::string_from_data_layout(), Size2D::to_string(), arm_compute::support::cpp11::to_string(), arm_compute::validate_and_configure_window(), and arm_compute::test::validation::winograd_info.

Referenced by CLWinogradConvolutionLayer::configure().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
cl::CommandQueue &  queue 
)
overridevirtual

Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.

Note
The queue is not flushed by this method, and therefore the kernel will not have been executed by the time this method returns.
Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).
[in,out]queueCommand queue on which to enqueue the kernel.

Implements ICLKernel.

Definition at line 141 of file CLWinogradFilterTransformKernel.cpp.

142 {
145 
146  // Setup output window
147  Window window_out;
148  window_out.use_tensor_dimensions(_output->info()->tensor_shape(), 0);
149 
150  unsigned int idx = 0;
151  add_4D_tensor_argument(idx, _input, window);
152  add_3D_tensor_argument(idx, _output, window_out);
153  enqueue(queue, *this, window);
154 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
Definition: ICLKernel.cpp:39
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:158
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Definition: Window.inl:250
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.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: ICLKernel.h:168
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ICLKernel::add_3D_tensor_argument(), ICLKernel::add_4D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), ITensor::info(), ITensorInfo::tensor_shape(), Window::use_tensor_dimensions(), and IKernel::window().

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

Note
Winograd filter transform supports the following configurations for NCWH data layout F(output tile, kernel size):F(2x2, 3x3), F(2x1, 3x1), F(1x2, 1x3), F(4x4, 3x3), F(4x1, 3x1), F(1x4, 1x3), F(4x4, 5x5), F(4x1, 5x1), F(1x4, 1x5)
Winograd filter transform supports the following configurations for NHWC data layout F(output tile, kernel size):F(4x4, 3x3), F(4x1, 3x1), F(1x4, 1x3), F(4x4, 5x5), F(4x1, 5x1), F(1x4, 1x5)

Strides: only unit strides

Parameters
[in]inputSource tensor. The input is a 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM] (NCHW data layout) or [IFM, kernel_x, kernel_y, OFM] (NHWC data layout). Data types supported: F16/F32.
[out]outputThe output tensor. The shape for this tensor can be calculated using the utility function compute_winograd_filter_transform_shape. Data types supported: Same as input
[in]winograd_infoContains Winograd's information described in WinogradInfo
Returns
a status

Definition at line 133 of file CLWinogradFilterTransformKernel.cpp.

134 {
135  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, winograd_info));
136  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
137 
138  return Status{};
139 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

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

Referenced by CLWinogradConvolutionLayer::validate().


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