Compute Library
CpuTransposeKernel Class Reference

Kernel which transposes the elements of a matrix. More...

#include <CpuTransposeKernel.h>

Collaboration diagram for CpuTransposeKernel:

Public Member Functions

 CpuTransposeKernel ()=default
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...
virtual size_t get_mws (const CPUInfo &platform, size_t thread_count) const
 Return minimum workload size of the relevant kernel. 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. More...
- Static Public Member Functions inherited from ICpuKernel< CpuTransposeKernel >
static const auto * get_implementation (const SelectorType &selector, KernelSelectionType selection_type=KernelSelectionType::Supported)
 Micro-kernel selector. More...

Additional Inherited Members

- Static Public Attributes inherited from ICPPKernel
static constexpr size_t default_mws = 1

Detailed Description

Kernel which transposes the elements of a matrix.

Definition at line 37 of file CpuTransposeKernel.h.

Constructor & Destructor Documentation

◆ CpuTransposeKernel()

CpuTransposeKernel ( )

Member Function Documentation



◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst 

Configure kernel for a given list of arguments.

[in]srcSrouce tensor to permute. Data types supported: All
[out]dstDestination tensor. Data types supported: Same as src

Definition at line 427 of file CpuTransposeKernel.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_transposed_shape(), arm_compute::test::validation::dst_shape, ITensorInfo::element_size(), ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and CpuTransposeKernel::validate().

428 {
431  // Destination auto inizialitation if not yet initialized
433  auto_init_if_empty(*dst, src->clone()->set_tensor_shape(dst_shape));
435  // Perform validation step
438  // Note: This kernel performs 16 elements per iteration.
439  // However, since we use a left-over for loop on both dimensions (X and Y), we cannot have any read or write out of memory
440  // For this reason num_elems_processed_per_iteration_x is set to 1
441  const unsigned int num_elems_processed_per_iteration_x = 1;
442  const unsigned int num_elems_processed_per_iteration_y = num_elems_processed(src->element_size());
444  // Configure kernel window
445  Window win = calculate_max_window(*src, Steps(num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y));
447  // The CpuTranspose doesn't need padding so update_window_and_padding() can be skipped
448  Coordinates coord;
449  coord.set_num_dimensions(dst->num_dimensions());
450  dst->set_valid_region(ValidRegion(coord, dst->tensor_shape()));
452  ICpuKernel::configure(win);
453 }
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: Error.h:455
SimpleTensor< float > src
Definition: DFT.cpp:155
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
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: Validate.h:157

◆ name()

const char * name ( ) const

Name of the kernel.

Kernel name

Implements ICPPKernel.

Definition at line 504 of file CpuTransposeKernel.cpp.

505 {
506  return "CpuTransposeKernel";
507 }

◆ run_op()

void run_op ( ITensorPack tensors,
const Window window,
const ThreadInfo info 

Execute the kernel on the passed window.

If is_parallelisable() returns false then the passed window must be equal to window()
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().
[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 478 of file CpuTransposeKernel.cpp.

References arm_compute::ACL_DST, arm_compute::ACL_SRC, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::dst, ITensorPack::get_const_tensor(), ITensorPack::get_tensor(), arm_compute::test::validation::src, and IKernel::window().

479 {
484  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
485  auto dst = tensors.get_tensor(TensorType::ACL_DST);
487  switch(src->info()->element_size())
488  {
489  case 1:
490  transpose_8bit_elements(src, dst, window);
491  break;
492  case 2:
493  transpose_16bit_elements(src, dst, window);
494  break;
495  case 4:
496  transpose_32bit_elements(src, dst, window);
497  break;
498  default:
499  ARM_COMPUTE_ERROR("Element size not supported");
500  break;
501  }
502 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
SimpleTensor< float > src
Definition: DFT.cpp:155
To avoid unused variables warnings.
Definition: Error.h:152
Definition: Validate.h:915
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Definition: Validate.h:201

◆ validate()

Status validate ( const ITensorInfo src,
const ITensorInfo dst 

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

Similar to CpuTransposeKernel::configure()

a status

Definition at line 455 of file CpuTransposeKernel.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_MSG, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, arm_compute::misc::shape_calculator::compute_transposed_shape(), ITensorInfo::data_type(), arm_compute::test::validation::dst_shape, ITensorInfo::element_size(), ITensorInfo::tensor_shape(), ITensorInfo::total_size(), and arm_compute::UNKNOWN.

Referenced by CpuTransposeKernel::configure(), CpuTranspose::validate(), and CpuFullyConnected::validate().

456 {
458  //Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use CPU FP16 instructions.
461  // Error if input is not 8 bit, 16bit or 32bit
462  ARM_COMPUTE_RETURN_ERROR_ON_MSG(src->element_size() != 1 && src->element_size() != 2 && src->element_size() != 4,
463  "Element size not supported");
465  // Validate configured destination
466  if(dst->total_size() != 0)
467  {
473  }
475  return Status{};
476 }
Definition: Validate.h:606
If the condition is true, an error is returned.
Definition: Error.h:296
Definition: Validate.h:284
SimpleTensor< float > src
Definition: DFT.cpp:155
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
Definition: Validate.h:159
Definition: Validate.h:541
If the condition is true, an error is returned.
Definition: Error.h:244

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