Compute Library
 19.08
GCTensorShiftKernel Class Reference

Interface for the kernel to shift valid data on a tensor. More...

#include <GCTensorShiftKernel.h>

Collaboration diagram for GCTensorShiftKernel:
[legend]

Public Member Functions

 GCTensorShiftKernel ()
 Default constructor. More...
 
 GCTensorShiftKernel (const GCTensorShiftKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
GCTensorShiftKerneloperator= (const GCTensorShiftKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 GCTensorShiftKernel (GCTensorShiftKernel &&)=default
 Allow instances of this class to be moved. More...
 
GCTensorShiftKerneloperator= (GCTensorShiftKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~GCTensorShiftKernel ()=default
 Default destructor. More...
 
void configure (IGCTensor *input)
 Set the input of the kernel. More...
 
void run (const Window &window) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
- Public Member Functions inherited from IGCKernel
 IGCKernel ()
 Constructor. More...
 
GCKernelkernel ()
 Returns a reference to the GLES kernel of this object. More...
 
void add_1D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_2D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, 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_3D_tensor_argument (unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
 Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx. More...
 
unsigned int num_arguments_per_1D_tensor () const
 Returns the number of arguments enqueued per 1D tensor object. More...
 
unsigned int num_arguments_per_2D_tensor () const
 Returns the number of arguments enqueued per 2D tensor object. More...
 
unsigned int num_arguments_per_3D_tensor () const
 Returns the number of arguments enqueued per 3D tensor object. More...
 
void set_lws_hint (gles::NDRange &lws_hint)
 Set the Local-Workgroup-Size hint. More...
 
void set_target (GPUTarget target)
 Set the targeted GPU architecture. More...
 
GPUTarget get_target () const
 Get the targeted GPU architecture. 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...
 

Detailed Description

Interface for the kernel to shift valid data on a tensor.

For example shifting 3x3 valid data with padding of 1 to right:

\[ \left( \begin{array}{ccccc} 0 & 0 & 0 & 0 & 0 \\ a00 & a01 & a02 & 0 & 0 \\ a10 & a11 & a12 & 0 & 0 \\ a20 & a21 & a22 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ \end{array} \right) = \left( \begin{array}{ccccc} 0 & 0 & 0 & 0 & 0 \\ 0 & a00 & a01 & a02 & 0 \\ 0 & a10 & a11 & a12 & 0 \\ 0 & a20 & a21 & a22 & 0 \\ 0 & 0 & 0 & 0 & 0 \\ \end{array} \right) \]

Definition at line 54 of file GCTensorShiftKernel.h.

Constructor & Destructor Documentation

◆ GCTensorShiftKernel() [1/3]

Default constructor.

Definition at line 40 of file GCTensorShiftKernel.cpp.

41  : _input(nullptr), _lws(gles::NDRange(1U, 1U, 1U)), _left_padding(0)
42 {
43 }
Class interface for specifying NDRange values.
Definition: OpenGLES.h:53

◆ GCTensorShiftKernel() [2/3]

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

◆ GCTensorShiftKernel() [3/3]

Allow instances of this class to be moved.

◆ ~GCTensorShiftKernel()

~GCTensorShiftKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( IGCTensor input)

Set the input of the kernel.

Parameters
[in,out]inputSource tensor. Data types supported: F16/F32

Definition at line 45 of file GCTensorShiftKernel.cpp.

46 {
48 
49  _input = input;
50 
51  std::set<std::string> options;
52  options.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(_lws[0]));
53  options.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(_lws[1]));
54  options.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(_lws[2]));
55  options.emplace("#define WIDTH " + support::cpp11::to_string(input->info()->dimension(0)));
56 
57  std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
58  options.emplace(("#define " + dt_name));
59 
60  unsigned int num_elems_written_per_iteration_x = input->info()->dimension(0) + input->info()->padding().left + input->info()->padding().right;
61 
62  std::stringstream kernel_name;
63  kernel_name << "tensorshift";
64 
65  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel(kernel_name.str(), options));
66 
67  Window win;
68  win.set(Window::DimX, Window::Dimension(0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_x));
71 
72  _left_padding = _input->info()->padding().left;
73 
74  IGCKernel::configure(win);
75 }
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
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.
1 channel, 1 F32 per channel
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
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
1 channel, 1 F16 per channel
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
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.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:48
virtual PaddingSize padding() const =0
Padding of tensor.
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
unsigned int left
left of the border
Definition: Types.h:342
unsigned int right
right of the border
Definition: Types.h:340
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Definition: Window.h:47
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, Window::DimZ, arm_compute::F16, arm_compute::F32, GCKernelLibrary::get(), ITensor::info(), BorderSize::left, ITensorInfo::padding(), BorderSize::right, Window::set(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), and Window::use_tensor_dimensions().

Referenced by GCPoolingLayer::configure(), GCDepthwiseConvolutionLayer3x3::configure(), and GCDirectConvolutionLayer::configure().

◆ operator=() [1/2]

GCTensorShiftKernel& operator= ( const GCTensorShiftKernel )
delete

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

◆ operator=() [2/2]

GCTensorShiftKernel& operator= ( GCTensorShiftKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window)
overridevirtual

Enqueue the OpenGL ES shader to process the given window.

Parameters
[in]windowRegion on which to execute the kernel. (Must be a valid region of the window returned by window()).

Implements IGCKernel.

Definition at line 77 of file GCTensorShiftKernel.cpp.

78 {
81 
82  if(int(_left_padding) == 0 || !_input->needs_shifting())
83  {
84  return;
85  }
86 
87  _kernel.use();
88 
89  // Get initial windows
91  slice.shift(Window::DimX, -(_input->info()->padding()).left);
92 
93  do
94  {
95  unsigned int idx = 0;
96 
97  add_3D_tensor_argument(idx, _input, 1, slice);
98 
99  _kernel.set_argument(idx++, static_cast<unsigned int>(_left_padding));
100 
101  _kernel.update_shader_params();
102  enqueue(*this, slice, _lws);
103  }
105 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void add_3D_tensor_argument(unsigned int &idx, const IGCTensor *tensor, const unsigned int binding_point, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
Definition: IGCKernel.cpp:132
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
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.
virtual PaddingSize padding() const =0
Padding of tensor.
bool needs_shifting() const
Flag indicating whether the tensor has been left aligned by a kernel and therefore needs shifting.
Definition: IGCTensor.cpp:56
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
Definition: Window.h:319
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
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)

References IGCKernel::add_3D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimX, arm_compute::enqueue(), Window::first_slice_window_3D(), ITensor::info(), IGCTensor::needs_shifting(), ITensorInfo::padding(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_3D(), and IKernel::window().


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