Compute Library
 21.08
CpuGemmTranspose1xWKernel Class Reference

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 <CpuGemmTranspose1xWKernel.h>

Collaboration diagram for CpuGemmTranspose1xWKernel:
[legend]

Public Member Functions

 CpuGemmTranspose1xWKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuGemmTranspose1xWKernel)
 
void configure (const ITensorInfo *src, ITensorInfo *dst)
 Configure kernel for a given list of arguments. More...
 
void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
const char * name () const override
 Name of the kernel. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run (const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version 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...
 
bool is_window_configured () const
 Function to check if the embedded window of this kernel has been configured. More...
 

Static Public Member Functions

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

Detailed Description

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 71 of file CpuGemmTranspose1xWKernel.h.

Constructor & Destructor Documentation

◆ CpuGemmTranspose1xWKernel()

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuGemmTranspose1xWKernel  )

◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst 
)

Configure kernel for a given list of arguments.

Parameters
[in]srcInput tensor info. Data types supported: All
[out]dstOutput tensor info. Data type supported: same as src.

Definition at line 43 of file CpuGemmTranspose1xWKernel.cpp.

References 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_transpose1xW_with_element_size_shape(), ITensorInfo::element_size(), and CpuGemmTranspose1xWKernel::validate().

44 {
46 
47  // Output tensor auto inizialitation if not yet initialized
49 
50  // Perform validate step
52 
53  const size_t vector_size = 16 / src->element_size();
54 
55  // Configure kernel window
56  Window win = calculate_max_window(*src, Steps(vector_size));
57  ICPPKernel::configure(win);
58 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
TensorShape compute_transpose1xW_with_element_size_shape(const ITensorInfo &b, int mult_transpose1xW_width=1)
Calculate the transposed 1xW width element shape.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of CpuGemmTranspose1xWKerne...
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
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...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 131 of file CpuGemmTranspose1xWKernel.cpp.

132 {
133  return "CpuGemmTranspose1xWKernel";
134 }

◆ run_op()

void run_op ( ITensorPack tensors,
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]tensorsA vector containing the tensors to operate on.
[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.

Reimplemented from ICPPKernel.

Definition at line 76 of file CpuGemmTranspose1xWKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::dimension(), Window::DimX, Window::DimY, arm_compute::test::validation::dst, ITensorInfo::element_size(), ITensorPack::empty(), arm_compute::execute_window_loop(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), ITensor::info(), Iterator::ptr(), arm_compute::test::validation::src, ITensorInfo::strides_in_bytes(), and IKernel::window().

77 {
81  ARM_COMPUTE_ERROR_ON(tensors.empty());
82 
83  /*
84  * Following an example of how the transposition1xW works when the src data type is F32
85  *
86  * |a00 a01 a02 a03|
87  * |a10 a11 a12 a13|
88  * |a20 a21 a22 a23| = | a00 a01 a02 a03 || a10 a11 a12 a13 || a20 a21 a22 a23 || a30 a31 a32 a33 |
89  * |a30 a31 a32 a33|
90  *
91  * The dst matrix will have the following shape: [ height * W, ceil(width / W) ], where W = (16 / element size of the tensor)
92  */
93 
94  // Set window for dst tensor. Set to 0 the X and Y dimensions in order to allow multi-threading implementation and future batched matrix multiplications
95  Window win_out(window);
96  win_out.set(Window::DimX, Window::Dimension(0, 0, 0));
97  win_out.set(Window::DimY, Window::Dimension(0, 0, 0));
98 
99  const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC);
100  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
101 
102  Iterator in(src, window);
103  Iterator out(dst, win_out);
104 
105  const size_t in_width = src->info()->dimension(0);
106  const size_t element_size = src->info()->element_size();
107  const size_t out_stride = dst->info()->strides_in_bytes()[1];
108  const size_t vector_size = 16 / element_size;
109 
110  execute_window_loop(window, [&](const Coordinates & id)
111  {
112  const uint8_t *in_ptr = in.ptr();
113  uint8_t *const out_ptr = out.ptr() + (id.y() * vector_size) * element_size + (id.x() / vector_size) * out_stride;
114 
115  for(size_t k = 0; k < vector_size; ++k)
116  {
117  // If the src width is not multiple of W, we fill the reference with 0s
118  if((id.x() + k) >= in_width)
119  {
120  std::memset(out_ptr + k * element_size, 0, element_size);
121  }
122  else
123  {
124  std::memcpy(out_ptr + k * element_size, in_ptr + k * element_size, element_size);
125  }
126  }
127  },
128  in, out);
129 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
SimpleTensor< float > src
Definition: DFT.cpp:155
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:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
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:77
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst 
)
static

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

Similar to CpuGemmTranspose1xWKernel::configure()

Returns
a status

Definition at line 60 of file CpuGemmTranspose1xWKernel.cpp.

References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, arm_compute::misc::shape_calculator::compute_transpose1xW_with_element_size_shape(), ITensorInfo::data_type(), ITensorInfo::tensor_shape(), ITensorInfo::total_size(), and arm_compute::UNKNOWN.

Referenced by CpuGemmTranspose1xWKernel::configure(), CpuGemm::validate(), and CpuGemmLowpMatrixMultiplyCore::validate().

61 {
64  //Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src) is not needed here as this kernel doesn't use CPU FP16 instructions.
65 
66  if(dst->total_size() != 0)
67  {
71  }
72 
73  return Status{};
74 }
TensorShape compute_transpose1xW_with_element_size_shape(const ITensorInfo &b, int mult_transpose1xW_width=1)
Calculate the transposed 1xW width element shape.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Definition: Validate.h:606
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:284
SimpleTensor< float > src
Definition: DFT.cpp:155
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541

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