Compute Library
 21.08
CpuGemmInterleave4x4Kernel Class Reference

Kernel to interleave the elements of a matrix. More...

#include <CpuGemmInterleave4x4Kernel.h>

Collaboration diagram for CpuGemmInterleave4x4Kernel:
[legend]

Public Member Functions

 CpuGemmInterleave4x4Kernel ()=default
 
void configure (const ITensorInfo *src, ITensorInfo *dst)
 Initialise the kernel's src and dst. 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 CpuGemmInterleave4x4Kernel. More...
 

Detailed Description

Kernel to interleave the elements of a matrix.

This function puts the values in a 4x4 block of Matrix A on the same row (Interleaved values)

\[ \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 & a10 & a20 & a30 & a01 & a11 & a21 & a31 & a02 & a12 & a22 & a32 & a03 & a13 & a23 & a33 \\ \end{array} \right) \]

After this operation, the dst matrix will have the following shape: [ height * 4, ceil(width / 4.0f) ]

Definition at line 55 of file CpuGemmInterleave4x4Kernel.h.

Constructor & Destructor Documentation

◆ CpuGemmInterleave4x4Kernel()

Member Function Documentation

◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst 
)

Initialise the kernel's src and dst.

Parameters
[in]srcInput tensor info. Data types supported: All
[out]dstOutput tensor info which stores the interleaved matrix. Data type supported: same as src.

Definition at line 43 of file CpuGemmInterleave4x4Kernel.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_interleaved_shape(), and CpuGemmInterleave4x4Kernel::validate().

44 {
46 
47  // dst auto inizialitation if not yet initialized
48  auto_init_if_empty(*dst, src->clone()->set_tensor_shape(compute_interleaved_shape(*src)));
49 
50  // Perform validate step
52 
53  Window win = calculate_max_window(*src, Steps(1, 4));
54  ICPPKernel::configure(win);
55 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height=1, bool reinterpret_input_as_3d=false)
Calculate the interleaved shape of an input tensor.
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...
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration of CpuGemmInterleave4x4Kern...
#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 145 of file CpuGemmInterleave4x4Kernel.cpp.

146 {
147  return "CpuGemmInterleave4x4Kernel";
148 }

◆ 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 74 of file CpuGemmInterleave4x4Kernel.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, Window::DimX, Window::DimY, arm_compute::test::validation::dst, ITensorPack::empty(), Window::Dimension::end(), arm_compute::execute_window_loop(), ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), Iterator::ptr(), Window::scale(), Window::set(), arm_compute::test::validation::src, Window::Dimension::start(), IKernel::window(), and Window::x().

75 {
79  ARM_COMPUTE_ERROR_ON(tensors.empty());
80  /*
81  * This kernel puts the values in a 4x4 block of Matrix A on the same row (Interleaved values)
82  * |a00 a01 a02 a03|
83  * |a10 a11 a12 a13|
84  * |a20 a21 a22 a23| = | a00 a10 a20 a30 || a01 a11 a21 a31 || a02 a12 a22 a32 || a03 a13 a23 a33 |
85  * |a30 a31 a32 a33|
86  *
87  * After this operation, the dst matrix will have the following shape: [ height * 4, ceil(width / 4.0f) ]
88  */
89  const ITensor *src = tensors.get_const_tensor(TensorType::ACL_SRC);
90  ITensor *dst = tensors.get_tensor(TensorType::ACL_DST);
91 
92  const size_t window_start_x = window.x().start();
93  const size_t window_end_x = window.x().end();
94 
95  const size_t in_height = src->info()->dimension(1);
96  const size_t in_stride = src->info()->strides_in_bytes()[1];
97 
98  const size_t partial_y = in_height % 4;
99 
100  const size_t element_size = src->info()->element_size();
101 
102  // Set window for the src tensor
103  Window win = window;
104  win.set(Window::DimX, Window::Dimension(0, 1, 1));
105 
106  // Set window for the dst tensor
107  Window win_out(window);
108  win_out.set(Window::DimX, Window::Dimension(0, 1, 1));
109  win_out.scale(Window::DimY, 0.25f);
110 
111  Iterator in(src, win);
112  Iterator out(dst, win_out);
113 
114  execute_window_loop(win, [&](const Coordinates & id)
115  {
116  if(id.y() + 4 <= static_cast<int>(in_height))
117  {
118  for(size_t x = window_start_x; x < window_end_x; ++x)
119  {
120  std::memcpy(out.ptr() + (x * 4 + 0) * element_size, (in.ptr() + 0 * in_stride) + x * element_size, element_size);
121  std::memcpy(out.ptr() + (x * 4 + 1) * element_size, (in.ptr() + 1 * in_stride) + x * element_size, element_size);
122  std::memcpy(out.ptr() + (x * 4 + 2) * element_size, (in.ptr() + 2 * in_stride) + x * element_size, element_size);
123  std::memcpy(out.ptr() + (x * 4 + 3) * element_size, (in.ptr() + 3 * in_stride) + x * element_size, element_size);
124  }
125  }
126  else
127  {
128  for(size_t x = window_start_x; x < window_end_x; ++x)
129  {
130  size_t y = 0;
131  for(; y < partial_y; ++y)
132  {
133  std::memcpy(out.ptr() + (x * 4 + y) * element_size, (in.ptr() + y * in_stride) + x * element_size, element_size);
134  }
135  for(; y < 4; ++y)
136  {
137  std::memset(out.ptr() + (x * 4 + y) * element_size, 0, element_size);
138  }
139  }
140  }
141  },
142  in, out);
143 }
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
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
Definition: Window.inl:49
#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
constexpr int end() const
Return the end of the dimension.
Definition: Window.h:99
constexpr int start() const
Return the start of the dimension.
Definition: Window.h:94
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
Definition: Window.h:145

◆ validate()

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

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

Similar to CpuGemmInterleave4x4Kernel::configure()

Returns
a status

Definition at line 57 of file CpuGemmInterleave4x4Kernel.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_interleaved_shape(), ITensorInfo::data_type(), arm_compute::test::validation::dst_shape, ITensorInfo::tensor_shape(), ITensorInfo::total_size(), and arm_compute::UNKNOWN.

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

58 {
60  //Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(src) is not needed here as this kernel doesn't use CPU FP16 instructions.
62 
63  if(dst->total_size() != 0)
64  {
65  const TensorShape dst_shape = compute_interleaved_shape(*src);
69  }
70 
71  return Status{};
72 }
#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
TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height=1, bool reinterpret_input_as_3d=false)
Calculate the interleaved shape of an input tensor.
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: