Compute Library
 19.08
NEGEMMTranspose1xWKernel Class Reference

NEON 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 <NEGEMMTranspose1xWKernel.h>

Collaboration diagram for NEGEMMTranspose1xWKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
void configure (const ITensor *input, ITensor *output)
 Initialise the kernel's input and output. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPSimpleKernel
 ICPPSimpleKernel ()
 Constructor. More...
 
 ICPPSimpleKernel (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
ICPPSimpleKerneloperator= (const ICPPSimpleKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 ICPPSimpleKernel (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
ICPPSimpleKerneloperator= (ICPPSimpleKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~ICPPSimpleKernel ()=default
 Default destructor. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of NEGEMMTranspose1xWKernel. More...
 

Detailed Description

NEON 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 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) \]

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

\[ \left( \begin{array}{cccccccc} a00 & a01 & a02 & a03 & a04 & a05 & a06 & a07 \\ a10 & a11 & a12 & a13 & a14 & a15 & a16 & a17 \\ a20 & a21 & a22 & a23 & a24 & a25 & a26 & a27 \\ a30 & a31 & a32 & a33 & a34 & a35 & a36 & a37 \\ \end{array} \right) \rightarrow \left( \begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc} a00 & a01 & a02 & a03 & a04 & a05 & a06 & a07 & a10 & a11 & a12 & a13 & a14 & a15 & a16 & a17 & a20 & a21 & a22 & a23 & a24 & a25 & a26 & a27 & a30 & a31 & a32 & a33 & a34 & a35 & a36 & a37\\ \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 68 of file NEGEMMTranspose1xWKernel.h.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output 
)

Initialise the kernel's input and output.

Parameters
[in]inputInput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[out]outputOutput tensor. Data type supported: same as input.

Definition at line 96 of file NEGEMMTranspose1xWKernel.cpp.

97 {
98  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
99 
100  // Output tensor auto inizialitation if not yet initialized
101  auto_init_if_empty(*output->info(), get_output_shape(input->info()), 1, input->info()->data_type());
102 
103  // Perform validate step
104  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
105 
106  _input = input;
107  _output = output;
108 
109  // Configure kernel window
110  auto win_config = validate_and_configure_window(input->info(), output->info());
111  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
112  INEKernel::configure(win_config.second);
113 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
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
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), ITensorInfo::data_type(), ITensor::info(), and arm_compute::validate_and_configure_window().

Referenced by NEGEMM::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 71 of file NEGEMMTranspose1xWKernel.h.

72  {
73  return "NEGEMMTranspose1xWKernel";
74  }

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Implements ICPPKernel.

Definition at line 123 of file NEGEMMTranspose1xWKernel.cpp.

124 {
128 
129  /*
130  * Following an example of how the transposition1xW works when the input data type is F32
131  *
132  * |a00 a01 a02 a03|
133  * |a10 a11 a12 a13|
134  * |a20 a21 a22 a23| = | a00 a01 a02 a03 || a10 a11 a12 a13 || a20 a21 a22 a23 || a30 a31 a32 a33 |
135  * |a30 a31 a32 a33|
136  *
137  * The output matrix will have the following shape: [ height * W, ceil(width / W) ], where W = (16 / element size of the tensor)
138  */
139 
140  // Set window for output tensor. Set to 0 the X and Y dimensions in order to allow multi-threading implementation and future batched matrix multiplications
141  Window win_out(window);
142  win_out.set(Window::DimX, Window::Dimension(0, 0, 0));
143  win_out.set(Window::DimY, Window::Dimension(0, 0, 0));
144 
145  Iterator in(_input, window);
146  Iterator out(_output, win_out);
147 
148  switch(_input->info()->element_size())
149  {
150  case 1:
151  {
152  const size_t out_stride = _output->info()->strides_in_bytes()[1];
153  execute_window_loop(window, [&](const Coordinates & id)
154  {
155  // Output address = base addr + (y * 16) + (x / 16 ) * stride
156  const uint8_t *in_ptr = in.ptr();
157  uint8_t *const out_ptr = out.ptr() + (id.y() << 4) + (id.x() >> 4) * out_stride;
158  vst1q_u8(out_ptr, vld1q_u8(in_ptr));
159  },
160  in, out);
161  break;
162  }
163  case 2:
164  {
165  const size_t out_stride = _output->info()->strides_in_bytes()[1] / sizeof(int16_t);
166  execute_window_loop(window, [&](const Coordinates & id)
167  {
168  // Output address = base addr + (y * 8) + (x / 8 ) * stride
169  const auto in_ptr = reinterpret_cast<const uint16_t *>(in.ptr());
170  const auto out_ptr = reinterpret_cast<uint16_t *>(out.ptr()) + (id.y() << 3) + (id.x() >> 3) * out_stride;
171  vst1q_u16(out_ptr, vld1q_u16(in_ptr));
172  },
173  in, out);
174  break;
175  }
176  case 4:
177  {
178  const size_t out_stride = _output->info()->strides_in_bytes()[1] / sizeof(float);
179  execute_window_loop(window, [&](const Coordinates & id)
180  {
181  // Output address = base addr + (y * 4) + (x / 4 ) * stride
182  const auto in_ptr = reinterpret_cast<const uint32_t *>(in.ptr());
183  const auto out_ptr = reinterpret_cast<uint32_t *>(out.ptr()) + (id.y() << 2) + (id.x() >> 2) * out_stride;
184  vst1q_u32(out_ptr, vld1q_u32(in_ptr));
185  },
186  in, out);
187  break;
188  }
189  default:
190  {
191  ARM_COMPUTE_ERROR("Element size not supported");
192  break;
193  }
194  }
195 }
#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
Describe one of the image's dimensions with a start, end and step.
Definition: Window.h:75
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
Coordinates of an item.
Definition: Coordinates.h:37
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:122
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:318
#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

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, Window::DimX, Window::DimY, arm_compute::execute_window_loop(), arm_compute::test::validation::info, Iterator::ptr(), Window::set(), and IKernel::window().

◆ validate()

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

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

Parameters
[in]inputInput tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]outputOutput tensor info. Data type supported: same as input.
Returns
a status

Definition at line 115 of file NEGEMMTranspose1xWKernel.cpp.

116 {
117  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
118  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), output->clone().get()).first);
119 
120  return Status{};
121 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#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
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

References ARM_COMPUTE_RETURN_ON_ERROR, ICloneable< T >::clone(), and arm_compute::validate_and_configure_window().

Referenced by NEGEMMTranspose1xW::validate(), NEGEMM::validate(), and NEGEMMLowpMatrixMultiplyCore::validate().


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