Compute Library
 19.08
CLDeconvolutionLayerUpsampleKernel Class Reference

Interface for the Deconvolution layer kernel on OpenCL. More...

#include <CLDeconvolutionLayerUpsampleKernel.h>

Collaboration diagram for CLDeconvolutionLayerUpsampleKernel:
[legend]

Public Member Functions

 CLDeconvolutionLayerUpsampleKernel ()
 Constructor. More...
 
 CLDeconvolutionLayerUpsampleKernel (const CLDeconvolutionLayerUpsampleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLDeconvolutionLayerUpsampleKerneloperator= (const CLDeconvolutionLayerUpsampleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLDeconvolutionLayerUpsampleKernel (CLDeconvolutionLayerUpsampleKernel &&)=default
 Default Move Constructor. More...
 
CLDeconvolutionLayerUpsampleKerneloperator= (CLDeconvolutionLayerUpsampleKernel &&)=default
 Default move assignment operator. More...
 
 ~CLDeconvolutionLayerUpsampleKernel ()=default
 Default destructor. More...
 
void configure (const ICLTensor *input, ICLTensor *output, const PadStrideInfo &info)
 Initialise the kernel's input and output. 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 PadStrideInfo &info)
 Static function to check if given info will lead to a valid configuration of CLDeconvolutionLayerUpsample. 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 Deconvolution layer kernel on OpenCL.

Definition at line 35 of file CLDeconvolutionLayerUpsampleKernel.h.

Constructor & Destructor Documentation

◆ CLDeconvolutionLayerUpsampleKernel() [1/3]

Constructor.

Definition at line 37 of file CLDeconvolutionLayerUpsampleKernel.cpp.

38  : _input(nullptr), _output(nullptr), _info()
39 {
40 }

◆ CLDeconvolutionLayerUpsampleKernel() [2/3]

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

◆ CLDeconvolutionLayerUpsampleKernel() [3/3]

Default Move Constructor.

◆ ~CLDeconvolutionLayerUpsampleKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output,
const PadStrideInfo info 
)

Initialise the kernel's input and output.

Parameters
[in]inputSource tensor. Data types supported: QASYMM8/F16/F32.
[out]outputDestination tensor. Data types supported: same as input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
[in]infoContains padding and stride information described in PadStrideInfo.

Definition at line 70 of file CLDeconvolutionLayerUpsampleKernel.cpp.

72 {
73  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
74 
75  _input = input;
76  _output = output;
77  _info = info;
78 
79  // Perform validation step
81 
82  // Create kernel
83  CLBuildOptions build_opts;
84  build_opts.add_option(("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type())));
85  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("deconvolution_upsample", build_opts.options()));
86 
87  constexpr unsigned int num_elems_processed_per_iteration = 1;
88 
89  // Configure kernel window
90  Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
91  AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
92  output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
93 
94  ICLKernel::configure_internal(win);
95 }
const StringSet & options() const
Gets the current options list set.
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
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PadStrideInfo &info)
Static function to check if given info will lead to a valid configuration of CLDeconvolutionLayerUpsa...
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
void add_option(std::string option)
Adds option to the existing build option list.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
Implementation of a row access pattern.
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 ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39
void set_valid_region(const Window &window, const ValidRegion &input_valid_region, bool border_undefined=false, const BorderSize &border_size=BorderSize(0))
Set the valid region based on access pattern, valid region of the inputs and border mode.

References CLBuildOptions::add_option(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), arm_compute::create_kernel(), ITensorInfo::data_type(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), arm_compute::test::validation::info, CLBuildOptions::options(), AccessWindowRectangle::set_valid_region(), ITensorInfo::tensor_shape(), and CLDeconvolutionLayerUpsampleKernel::validate().

Referenced by CLDeconvolutionLayerUpsample::configure().

◆ operator=() [1/2]

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

◆ operator=() [2/2]

Default move assignment operator.

◆ 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 97 of file CLDeconvolutionLayerUpsampleKernel.cpp.

98 {
101 
102  const DataLayout data_layout = _input->info()->data_layout();
103 
106 
107  const int out_start_x = _info.pad().first;
108  const int out_end_x = _output->info()->dimension(idx_w) - _info.pad().first + _info.stride().first - 1;
109  const int out_step_x = _info.stride().first;
110 
111  const int out_start_y = _info.pad().second;
112  const int out_end_y = _output->info()->dimension(idx_h) - _info.pad().second + _info.stride().second - 1;
113  const int out_step_y = _info.stride().second;
114 
115  switch(data_layout)
116  {
117  case DataLayout::NCHW:
118  {
120 
121  Window slice_out = collapsed.first_slice_window_3D();
122  slice_out.set(Window::DimX, Window::Dimension(out_start_x, out_end_x, out_step_x));
123  slice_out.set(Window::DimY, Window::Dimension(out_start_y, out_end_y, out_step_y));
124 
125  Window slice_in = collapsed.first_slice_window_3D();
126 
127  do
128  {
129  unsigned int idx = 0;
130  add_3D_tensor_argument(idx, _input, slice_in);
131  add_3D_tensor_argument(idx, _output, slice_out);
132  enqueue(queue, *this, slice_out);
133  }
134  while(collapsed.slide_window_slice_3D(slice_in) && collapsed.slide_window_slice_3D(slice_out));
135  break;
136  }
137  case DataLayout::NHWC:
138  {
139  // NOTE: not collapsing in NHWC
140  Window slice_out = window.first_slice_window_3D();
141  slice_out.set(Window::DimY, Window::Dimension(out_start_x, out_end_x, out_step_x));
142  slice_out.set(Window::DimZ, Window::Dimension(out_start_y, out_end_y, out_step_y));
143 
144  Window slice_in = window.first_slice_window_3D();
145 
146  do
147  {
148  unsigned int idx = 0;
149  add_3D_tensor_argument(idx, _input, slice_in);
150  add_3D_tensor_argument(idx, _output, slice_out);
151  enqueue(queue, *this, slice_out);
152  }
153  while(window.slide_window_slice_3D(slice_in) && window.slide_window_slice_3D(slice_out));
154  break;
155  }
156  default:
157  ARM_COMPUTE_ERROR("Unsupported data layout");
158  }
159 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
const DataLayout data_layout
Definition: Im2Col.cpp:146
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
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
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:54
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Definition: Types.h:724
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
Num samples, channels, height, width.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Num samples, height, width, channels.
std::pair< unsigned int, unsigned int > pad() const
Get the padding.
Definition: Types.h:742
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:326
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::collapse_if_possible(), arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::enqueue(), Window::first_slice_window_3D(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, ITensor::info(), arm_compute::NCHW, arm_compute::NHWC, PadStrideInfo::pad(), Window::set(), Window::slide_window_slice_3D(), PadStrideInfo::stride(), arm_compute::WIDTH, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
const PadStrideInfo info 
)
static

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

Parameters
[in]inputSource tensor info. Data types supported: QASYMM8/F16/F32.
[in]outputDestination tensor info. Data types supported: same as input. All but the lowest two dimensions must be the same size as in the input tensor, i.e. scaling is only performed within the XY-plane.
[in]infoContains padding and stride information described in PadStrideInfo.
Returns
a status

Definition at line 42 of file CLDeconvolutionLayerUpsampleKernel.cpp.

44 {
50 
51  const DataLayout data_layout = input->data_layout();
52 
56 
57  ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(idx_w) == 0);
58  ARM_COMPUTE_RETURN_ERROR_ON(output->dimension(idx_h) == 0);
59  ARM_COMPUTE_RETURN_ERROR_ON(!info.padding_is_symmetric());
60 
61  ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(idx_c) != output->dimension(idx_c));
62  for(size_t i = 3; i < Coordinates::num_max_dimensions; ++i)
63  {
64  ARM_COMPUTE_RETURN_ERROR_ON(input->dimension(i) != output->dimension(i));
65  }
66 
67  return Status{};
68 }
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
Definition: CLValidate.h:34
const DataLayout data_layout
Definition: Im2Col.cpp:146
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:791
1 channel, 1 F32 per channel
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:244
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Definition: Validate.h:610
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
size_t get_data_layout_dimension_index(const DataLayout data_layout, const DataLayoutDimension data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:326
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Definition: Dimensions.h:45
DataLayout
[DataLayout enum definition]
Definition: Types.h:114
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, arm_compute::CHANNEL, arm_compute::test::validation::data_layout, ITensorInfo::data_layout(), ITensorInfo::dimension(), arm_compute::F16, arm_compute::F32, arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, arm_compute::test::validation::info, Dimensions< int >::num_max_dimensions, arm_compute::QASYMM8, and arm_compute::WIDTH.

Referenced by CLDeconvolutionLayerUpsampleKernel::configure(), and CLDeconvolutionLayerUpsample::validate().


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