Compute Library
 23.11
CpuTransposeKernel Class Reference

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

#include <CpuTransposeKernel.h>

Collaboration diagram for CpuTransposeKernel:
[legend]

Public Member Functions

 CpuTransposeKernel ()=default
 
 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE (CpuTransposeKernel)
 
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 ( )
default

Member Function Documentation

◆ ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE()

ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE ( CpuTransposeKernel  )

◆ configure()

void configure ( const ITensorInfo src,
ITensorInfo dst 
)

Configure kernel for a given list of arguments.

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

Definition at line 732 of file CpuTransposeKernel.cpp.

733 {
735 
736  // Destination auto inizialitation if not yet initialized
738  auto_init_if_empty(*dst, src->clone()->set_tensor_shape(dst_shape));
739 
740  // Explicitly set the tensor shape to preserve dimensions
741  dst->set_tensor_shape(dst_shape);
742 
743  // Perform validation step
745 
746  // Note: This kernel performs 16 elements per iteration.
747  // 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
748  // For this reason num_elems_processed_per_iteration_x is set to 1
749  const unsigned int num_elems_processed_per_iteration_x = 1;
750  const unsigned int num_elems_processed_per_iteration_y = num_elems_processed(src->element_size());
751 
752  // Configure kernel window
753  Window win =
754  calculate_max_window(*src, Steps(num_elems_processed_per_iteration_x, num_elems_processed_per_iteration_y));
755 
756  // The CpuTranspose doesn't need padding so update_window_and_padding() can be skipped
757  Coordinates coord;
758  coord.set_num_dimensions(dst->num_dimensions());
759  dst->set_valid_region(ValidRegion(coord, dst->tensor_shape()));
760 
761  ICpuKernel::configure(win);
762 }

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::auto_init_if_empty(), arm_compute::calculate_max_window(), arm_compute::misc::shape_calculator::compute_transposed_shape(), arm_compute::test::validation::dst, arm_compute::test::validation::dst_shape, Dimensions< T >::set_num_dimensions(), arm_compute::test::validation::src, and CpuTransposeKernel::validate().

◆ name()

const char * name ( ) const
overridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 813 of file CpuTransposeKernel.cpp.

814 {
815  return "CpuTransposeKernel";
816 }

◆ 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 787 of file CpuTransposeKernel.cpp.

788 {
792 
793  const auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
794  auto dst = tensors.get_tensor(TensorType::ACL_DST);
795 
796  switch (src->info()->element_size())
797  {
798  case 1:
799  transpose_8bit_elements(src, dst, window);
800  break;
801  case 2:
802  transpose_16bit_elements(src, dst, window);
803  break;
804  case 4:
805  transpose_32bit_elements(src, dst, window);
806  break;
807  default:
808  ARM_COMPUTE_ERROR("Element size not supported");
809  break;
810  }
811 }

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::info, arm_compute::test::validation::src, and IKernel::window().

◆ validate()

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

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

Similar to CpuTransposeKernel::configure()

Returns
a status

Definition at line 764 of file CpuTransposeKernel.cpp.

765 {
767  //Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use CPU FP16 instructions.
769 
770  // Error if input is not 8 bit, 16bit or 32bit
771  ARM_COMPUTE_RETURN_ERROR_ON_MSG(src->element_size() != 1 && src->element_size() != 2 && src->element_size() != 4,
772  "Element size not supported");
773 
774  // Validate configured destination
775  if (dst->total_size() != 0)
776  {
778 
782  }
783 
784  return Status{};
785 }

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(), arm_compute::test::validation::dst, arm_compute::test::validation::dst_shape, arm_compute::test::validation::src, and arm_compute::UNKNOWN.

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


The documentation for this class was generated from the following files:
arm_compute::test::validation::dst_shape
TensorShape dst_shape
Definition: DFT.cpp:164
arm_compute::test::validation::src
SimpleTensor< float > src
Definition: DFT.cpp:155
arm_compute::calculate_max_window
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Definition: WindowHelpers.cpp:29
arm_compute::test::validation::dst
auto dst
Definition: DFT.cpp:170
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1079
ARM_COMPUTE_ERROR
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:354
arm_compute::misc::shape_calculator::compute_transposed_shape
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
Definition: ShapeCalculator.h:415
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:677
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::cpu::kernels::CpuTransposeKernel::validate
static Status validate(const ITensorInfo *src, const ITensorInfo *dst)
Static function to check if given info will lead to a valid configuration.
Definition: CpuTransposeKernel.cpp:764
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
ARM_COMPUTE_RETURN_ERROR_ON
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:298
arm_compute::ACL_DST
@ ACL_DST
Definition: Types.h:55
arm_compute::auto_init_if_empty
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: AutoConfiguration.h:43
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:203
ARM_COMPUTE_UNUSED
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:151
arm_compute::IKernel::window
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Definition: Validate.h:753
ARM_COMPUTE_RETURN_ERROR_ON_MSG
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Definition: Error.h:245
ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Definition: Validate.h:294
ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
arm_compute::ACL_SRC
@ ACL_SRC
Definition: Types.h:44
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::DataType::UNKNOWN
@ UNKNOWN
Unknown data type.