Compute Library
 19.08
GCGEMMTranspose1xWKernel Class Reference

OpenGLES kernel which transposes the elements of a matrix in chunks of 1xW, where W is equal to (16 / element size of the tensor) More...

#include <GCGEMMTranspose1xWKernel.h>

Collaboration diagram for GCGEMMTranspose1xWKernel:
[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

OpenGLES kernel which transposes the elements of a matrix in chunks of 1xW, where W is equal to (16 / element size of the tensor)

Following an example of how the transposition1xW works when the input data type is F32

\[ \left( \begin{array}{cccc} a00 & a01 & a02 & a03 \\ a10 & a11 & a12 & a13 \\ a20 & a21 & a22 & a23 \\ a30 & a31 & a32 & a33 \\ \end{array} \right) \rightarrow \left( \begin{array}{ccccccccccccccccc} a00 & a01 & a02 & a03 & a10 & a11 & a12 & a13 & a20 & a21 & a22 & a23 & a30 & a31 & a32 & a33 \\ \end{array} \right) \]

Note
The output matrix will have the following shape: [ height * W, ceil(width / W) ], where W = (16 / element size of the tensor)

Definition at line 53 of file GCGEMMTranspose1xWKernel.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 41 of file GCGEMMTranspose1xWKernel.cpp.

42 {
45 
47  const size_t transpose_w = 16 / input->info()->element_size();
48  output_shape.set(0, input->info()->dimension(1) * transpose_w);
49  output_shape.set(1, static_cast<size_t>(std::ceil((input->info()->dimension(0) / static_cast<float>(transpose_w)))));
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  const unsigned int num_elems_processed_per_iteration = 16 / input->info()->element_size();
58  const int scale_x = num_elems_processed_per_iteration;
59 
60  _input = input;
61  _output = output;
62 
63  std::set<std::string> build_opts;
64  std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
65  build_opts.emplace(("#define " + dt_name));
66  build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(1));
67  build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1));
68  build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1));
69  /*
70  * Following an example of how the transposition1xW works when the input data type is F32
71  *
72  * |a00 a01 a02 a03|
73  * |a10 a11 a12 a13|
74  * |a20 a21 a22 a23| = | a00 a01 a02 a03 || a10 a11 a12 a13 || a20 a21 a22 a23 || a30 a31 a32 a33 |
75  * |a30 a31 a32 a33|
76  *
77  * The output matrix will have the following shape: [ height * W, ceil(width / W) ], where W = (16 / element size of the tensor)
78  */
79  // Create kernel
80  build_opts.emplace("#define GEMM_TRANSPOSE1xW");
81  _kernel = GCKernelLibrary::get().create_kernel("gemm_transpose1x4", build_opts);
82 
83  // Configure window
84  Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
85 
86  ARM_COMPUTE_ERROR_ON_MSG((win.x().end() / scale_x) == 0, "Transposed shape would be 0 in the second dimension");
87 
88  AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
89  AccessWindowTranspose output_access(output->info(), 0, 0, num_elems_processed_per_iteration, 1, scale_x, 1.f / scale_x);
90 
91  update_window_and_padding(win, input_access, output_access);
92 
93  output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape()));
94 
95  IGCKernel::configure(win);
96 }
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
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
1 channel, 1 F16 per channel
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.
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.
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
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:789
static GCKernelLibrary & get()
Get the static instance of GCKernelLibrary.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Implementation of a XY-transpose access pattern.
GCKernel create_kernel(const std::string &shader_name, const StringSet &build_options_set={}) const
Creates a kernel from the kernel library.
Container for valid region of a window.
Definition: Types.h:174
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:97
Describe a multidimensional execution window.
Definition: Window.h:39
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143
#define ARM_COMPUTE_ERROR_ON_MSG(cond,...)
Definition: Error.h:328

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_MSG, ARM_COMPUTE_ERROR_ON_NULLPTR, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), GCKernelLibrary::create_kernel(), ITensorInfo::data_type(), ITensorInfo::dimension(), ITensorInfo::element_size(), Window::Dimension::end(), arm_compute::F16, arm_compute::F32, GCKernelLibrary::get(), ITensor::info(), arm_compute::test::validation::output_shape, ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), arm_compute::support::cpp11::to_string(), arm_compute::update_window_and_padding(), and Window::x().

Referenced by GCGEMM::configure().

◆ 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 98 of file GCGEMMTranspose1xWKernel.cpp.

99 {
102 
103  _kernel.use();
104 
105  // Output is transposed
106  Window out_window(window);
107  out_window.set(Window::DimX, window.y());
108  out_window.set(Window::DimY, window.x());
109 
110  Window in_slice = window.first_slice_window_2D();
111  Window out_slice = out_window.first_slice_window_2D();
112 
113  do
114  {
115  unsigned int idx = 0;
116  add_2D_tensor_argument(idx, _input, 1, in_slice);
117  add_2D_tensor_argument(idx, _output, 2, out_slice);
118 
119  _kernel.update_shader_params();
120 
121  enqueue(*this, in_slice);
122  }
123  while(window.slide_window_slice_2D(in_slice) && out_window.slide_window_slice_2D(out_slice));
124 }
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
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
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
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
constexpr const Dimension & y() const
Alias to access the second dimension of the window.
Definition: Window.h:152
#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
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:143

References IGCKernel::add_2D_tensor_argument(), ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, Window::DimX, Window::DimY, arm_compute::enqueue(), Window::first_slice_window_2D(), Window::set(), Window::slide_window_slice_2D(), IKernel::window(), Window::x(), and Window::y().


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