Compute Library
 19.08
CLDepthwiseVectorToTensorKernel Class Reference

Interface for the depthwise vector to tensor kernel. More...

#include <CLDepthwiseVectorToTensorKernel.h>

Collaboration diagram for CLDepthwiseVectorToTensorKernel:
[legend]

Public Member Functions

 CLDepthwiseVectorToTensorKernel ()
 Default constructor. More...
 
 CLDepthwiseVectorToTensorKernel (const CLDepthwiseVectorToTensorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLDepthwiseVectorToTensorKerneloperator= (const CLDepthwiseVectorToTensorKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLDepthwiseVectorToTensorKernel (CLDepthwiseVectorToTensorKernel &&)=default
 Allow instances of this class to be moved. More...
 
CLDepthwiseVectorToTensorKerneloperator= (CLDepthwiseVectorToTensorKernel &&)=default
 Allow instances of this class to be moved. More...
 
void configure (const ICLTensor *input, ICLTensor *output, size_t conv_w, size_t conv_h)
 Set the input and output of the kernel. 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, size_t conv_w, size_t conv_h)
 Static function to check if given info will lead to a valid configuration of CLDepthwiseVectorToTensorKernel. 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 depthwise vector to tensor kernel.

This kernel takes the 1D tensor that's been produced by the MatrixVectorMultiply kernel and reshapes it to given width and height (previously calculated, based on input/weights dimensions and convolution strides and padding).

Definition at line 40 of file CLDepthwiseVectorToTensorKernel.h.

Constructor & Destructor Documentation

◆ CLDepthwiseVectorToTensorKernel() [1/3]

Default constructor.

Definition at line 59 of file CLDepthwiseVectorToTensorKernel.cpp.

60  : _input(nullptr), _output(nullptr)
61 {
62 }

◆ CLDepthwiseVectorToTensorKernel() [2/3]

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

◆ CLDepthwiseVectorToTensorKernel() [3/3]

Allow instances of this class to be moved.

Member Function Documentation

◆ configure()

void configure ( const ICLTensor input,
ICLTensor output,
size_t  conv_w,
size_t  conv_h 
)

Set the input and output of the kernel.

Parameters
[in]inputThe input vector to convert. Data type supported: QASYMM8/S32/F16/F32.
[out]outputThe output tensor. 3 lower dimensions represent a single input [width, height, IFM]. Data type supported: same as input.
[in]conv_wThe converted tensor's width.
[in]conv_hThe converted tensor's height.

Definition at line 64 of file CLDepthwiseVectorToTensorKernel.cpp.

65 {
66  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
67 
68  // Output auto inizialitation if not yet initialized
70  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
71 
72  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), conv_w, conv_h));
73 
74  _input = input;
75  _output = output;
76 
77  // Create kernel
78  CLBuildOptions build_opts;
79  build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
80  build_opts.add_option("-DCONV_WIDTH=" + support::cpp11::to_string(conv_w));
81  build_opts.add_option("-DCONV_HEIGHT=" + support::cpp11::to_string(conv_h));
82  build_opts.add_option("-D" + string_from_data_layout(output->info()->data_layout()));
83 
84  _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("depthwise_vector_to_tensor", build_opts.options()));
85 
86  // Configure kernel window
87  Window win = calculate_max_window(*input->info(), Steps());
88  // The CLDepthwisevectorToTensorKernel doesn't need padding so update_window_and_padding() can be skipped
89  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
90 
91  ICLKernel::configure_internal(win);
92 }
Shape of a tensor.
Definition: TensorShape.h:39
const StringSet & options() const
Gets the current options list set.
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
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
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
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.
TensorShape compute_vector_to_tensor_output_shape(const TensorShape &input, size_t conv_w, size_t conv_h, const DataLayout &data_layout)
Calculate the output tensor shape of a vector input given the convolution dimensions.
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
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.
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
Container for valid region of a window.
Definition: Types.h:174
Describe a multidimensional execution window.
Definition: Window.h:39
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.

References CLBuildOptions::add_option(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), ICloneable< T >::clone(), arm_compute::misc::shape_calculator::compute_vector_to_tensor_output_shape(), arm_compute::create_kernel(), ITensorInfo::data_layout(), ITensorInfo::data_type(), CLKernelLibrary::get(), arm_compute::get_cl_type_from_data_type(), ITensor::info(), CLBuildOptions::options(), arm_compute::test::validation::output_shape, ITensorInfo::set_valid_region(), arm_compute::string_from_data_layout(), ITensorInfo::tensor_shape(), and arm_compute::support::cpp11::to_string().

Referenced by CLDepthwiseConvolutionLayer::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 100 of file CLDepthwiseVectorToTensorKernel.cpp.

101 {
104 
106  Window slice_out = window.first_slice_window_3D();
107 
108  // Setup slice
109  slice.set(Window::DimX, Window::Dimension(0, _input->info()->dimension(0), 1));
110 
111  // Setup output slice
112  // The first three dimensions of the output are increased by the inner loops
113  slice_out.set(Window::DimX, Window::Dimension(0, 0, 0));
114  slice_out.set(Window::DimY, Window::Dimension(0, 0, 0));
115  slice_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
116 
117  do
118  {
119  unsigned int idx = 0;
120  add_1D_tensor_argument(idx, _input, slice);
121  add_3D_tensor_argument(idx, _output, slice_out);
122  enqueue(queue, *this, slice);
123  }
125 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
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
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(f, w)
Definition: Validate.h:183
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
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
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.
Definition: ICLKernel.h:110
Window first_slice_window_3D() const
First 3D slice of the window.
Definition: Window.h:275
bool slide_window_slice_1D(Window &slice) const
Slide the passed 1D window slice.
Definition: Window.h:295
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
Window first_slice_window_1D() const
First 1D slice of the window.
Definition: Window.h:259
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References ICLKernel::add_1D_tensor_argument(), ICLKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::enqueue(), Window::first_slice_window_1D(), Window::first_slice_window_3D(), ITensor::info(), Window::set(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_1D(), Window::slide_window_slice_3D(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
size_t  conv_w,
size_t  conv_h 
)
static

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

Parameters
[in]inputThe input vector to convert. Data type supported: QASYMM8/S32/F16/F32.
[in]outputThe output tensor. 3 lower dimensions represent a single input [width, height, IFM]. Data type supported: same as input.
[in]conv_wThe converted tensor's width.
[in]conv_hThe converted tensor's height.
Returns
a status

Definition at line 94 of file CLDepthwiseVectorToTensorKernel.cpp.

95 {
96  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, conv_w, conv_h));
97  return Status{};
98 }
#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

References ARM_COMPUTE_RETURN_ON_ERROR.

Referenced by CLDepthwiseConvolutionLayer::validate().


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