Compute Library
 19.08
GCTransposeKernel Class Reference

OpenGL ES kernel which transposes the elements of a matrix. More...

#include <GCTransposeKernel.h>

Collaboration diagram for GCTransposeKernel:
[legend]

Public Member Functions

void configure (const IGCTensor *input, IGCTensor *output)
 Initialise the kernel's input and output. More...
 
void run (const Window &window) override
 Enqueue the OpenGL ES shader to process the given window. More...
 
- Public Member Functions inherited from IGCSimpleKernel
 IGCSimpleKernel ()
 Constructor. More...
 
 IGCSimpleKernel (const IGCSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
IGCSimpleKerneloperator= (const IGCSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 IGCSimpleKernel (IGCSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
IGCSimpleKerneloperator= (IGCSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~IGCSimpleKernel ()=default
 Default destructor. More...
 
void configure (const IGCTensor *input, IGCTensor *output, unsigned int num_elems_processed_per_iteration, bool border_undefined=false, const BorderSize &border_size=BorderSize())
 Configure the kernel. 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

OpenGL ES kernel which transposes the elements of a matrix.

[width, height, batch] -> [height, width, batch]

Definition at line 38 of file GCTransposeKernel.h.

Member Function Documentation

◆ configure()

void configure ( const IGCTensor input,
IGCTensor output 
)

Initialise the kernel's input and output.

Parameters
[in]inputInput tensor. Data types supported: F16/F32
[out]outputOutput tensor. Data type supported: Same as input

Definition at line 40 of file GCTransposeKernel.cpp.

41 {
44 
46  const size_t w_out = input->info()->dimension(1);
47  const size_t h_out = input->info()->dimension(0);
48  output_shape.set(0, w_out);
49  output_shape.set(1, h_out);
50 
51  // Output tensor auto inizialitation if not yet initialized
52  auto_init_if_empty(*output->info(), output_shape, 1, input->info()->data_type());
53 
56 
57  _input = input;
58  _output = output;
59 
60  // for better performance
61  if(w_out < 512 && h_out < 512)
62  {
63  _lws_hint = gles::NDRange(8U, 1U, 1U);
64  }
65  else
66  {
67  _lws_hint = gles::NDRange(1U, 8U, 1U);
68  }
69 
70  std::set<std::string> build_opts;
71  std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
72  build_opts.emplace(("#define " + dt_name));
73  build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(_lws_hint[0]));
74  build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(_lws_hint[1]));
75  build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(_lws_hint[2]));
76 
77  // Configure kernel window
78  unsigned int num_elems_processed_per_iteration = 4;
79 
80  if(input->info()->data_type() == DataType::F16)
81  {
82 #define TRANSPOSE_8X8
83 
84 #if defined(TRANSPOSE_4X4)
85  build_opts.emplace(("#define TRANSPOSE_4X4"));
86  num_elems_processed_per_iteration = 4;
87 #elif defined(TRANSPOSE_8X8) /* TRANSPOSE_4X4 */
88  if(w_out != h_out)
89  {
90  build_opts.emplace("#define TRANSPOSE_8X8");
91  num_elems_processed_per_iteration = 8;
92  }
93  else
94  {
95  build_opts.emplace("#define TRANSPOSE_8X8_SQUARE");
96  num_elems_processed_per_iteration = 8;
97  }
98 #endif /* TRANSPOSE_4X4 */
99  }
100 
101  // Create kernel
102  _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("transpose", build_opts));
103 
104  const unsigned int width_aligned = num_elems_processed_per_iteration * static_cast<unsigned int>(_lws_hint[0]);
105  const unsigned int height_aligned = num_elems_processed_per_iteration * static_cast<unsigned int>(_lws_hint[1]);
106 
107  AccessWindowStatic input_access(input->info(), 0, 0,
108  ceil_to_multiple(input->info()->dimension(0), width_aligned),
109  ceil_to_multiple(input->info()->dimension(1), height_aligned));
110  AccessWindowStatic output_access(output->info(), 0, 0,
111  ceil_to_multiple(output->info()->dimension(0), height_aligned),
112  ceil_to_multiple(output->info()->dimension(1), width_aligned));
113 
114  Window win = calculate_max_window(*input->info(), Steps(width_aligned, height_aligned));
115  win.set_dimension_step(Window::DimX, num_elems_processed_per_iteration);
116  win.set_dimension_step(Window::DimY, num_elems_processed_per_iteration);
117  update_window_and_padding(win, input_access, output_access);
118  output_access.set_valid_region(win, output->info()->valid_region());
119 
120  IGCKernel::configure(win);
121 }
Shape of a tensor.
Definition: TensorShape.h:39
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
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
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
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
1 channel, 1 F16 per channel
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
Implementation of a static rectangular access pattern.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: Helpers.h:402
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
auto ceil_to_multiple(S value, T divisor) -> decltype(((value+divisor - 1)/divisor) *divisor)
Computes the smallest number larger or equal to value that is a multiple of divisor.
Definition: Utils.h:66
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
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_DIMENSIONS(...)
Definition: Validate.h:286
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_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.
void set_dimension_step(size_t dimension, int step)
Set the step of a given dimension.
Definition: Window.inl:153
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Class interface for specifying NDRange values.
Definition: OpenGLES.h:53
Describe a multidimensional execution window.
Definition: Window.h:39

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), arm_compute::ceil_to_multiple(), arm_compute::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), Window::DimX, Window::DimY, arm_compute::F16, arm_compute::F32, GCKernelLibrary::get(), ITensor::info(), arm_compute::test::validation::output_shape, Window::set_dimension_step(), AccessWindowStatic::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::U, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

◆ 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()).

Reimplemented from IGCSimple2DKernel.

Definition at line 123 of file GCTransposeKernel.cpp.

124 {
127 
128  _kernel.use();
129 
131 
132  do
133  {
134  unsigned int idx = 0;
135 
136  add_2D_tensor_argument(idx, _input, 1, slice);
137  add_2D_tensor_argument(idx, _output, 2, slice);
138  _kernel.update_shader_params();
139  enqueue(*this, slice, _lws_hint);
140  }
142 }
Window first_slice_window_2D() const
First 2D slice of the window.
Definition: Window.h:267
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
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Definition: Window.h:307
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.
Definition: IGCKernel.cpp:127
#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_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, arm_compute::enqueue(), Window::first_slice_window_2D(), arm_compute::test::validation::reference::slice(), Window::slide_window_slice_2D(), and IKernel::window().


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