Compute Library
 21.02
CPPPermuteKernel Class Reference

CPP kernel to perform tensor permutation. More...

#include <CPPPermuteKernel.h>

Collaboration diagram for CPPPermuteKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 CPPPermuteKernel ()
 Default constructor. More...
 
 CPPPermuteKernel (const CPPPermuteKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CPPPermuteKerneloperator= (const CPPPermuteKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CPPPermuteKernel (CPPPermuteKernel &&)=default
 Allow instances of this class to be moved. More...
 
CPPPermuteKerneloperator= (CPPPermuteKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~CPPPermuteKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, const PermutationVector &perm)
 Set the input and output of the kernel. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. 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 void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. 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, const PermutationVector &perm)
 Static function to check if given info will lead to a valid configuration of CPPPermuteKernel. More...
 

Detailed Description

CPP kernel to perform tensor permutation.

Permutes given a permutation vector

Definition at line 37 of file CPPPermuteKernel.h.

Constructor & Destructor Documentation

◆ CPPPermuteKernel() [1/3]

Default constructor.

Definition at line 97 of file CPPPermuteKernel.cpp.

Referenced by CPPPermuteKernel::name().

98  : _func(), _input(nullptr), _output(nullptr), _perm()
99 {
100 }

◆ CPPPermuteKernel() [2/3]

CPPPermuteKernel ( const CPPPermuteKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ CPPPermuteKernel() [3/3]

Allow instances of this class to be moved.

◆ ~CPPPermuteKernel()

~CPPPermuteKernel ( )
default

Default destructor.

Referenced by CPPPermuteKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
const PermutationVector perm 
)

Set the input and output of the kernel.

Parameters
[in]inputThe input tensor to permute. Data types supported: All.
[out]outputThe output tensor. Data types supported: same as input
[in]permPermutation vector

Definition at line 102 of file CPPPermuteKernel.cpp.

References ARM_COMPUTE_ERROR, 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_permutation_output_shape(), ITensorInfo::element_size(), ITensor::info(), arm_compute::test::validation::input, ITensorInfo::num_dimensions(), Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), ITensorInfo::tensor_shape(), and arm_compute::validate_arguments().

Referenced by CPPPermuteKernel::name().

103 {
104  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
106  // Output auto inizialitation if not yet initialized
107  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
108 
109  // Perform validation step
110  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), perm));
111 
112  _input = input;
113  _output = output;
114  _perm = perm;
115 
116  switch(input->info()->element_size())
117  {
118  case 1:
119  _func = &CPPPermuteKernel::run_permute<uint8_t>;
120  break;
121  case 2:
122  _func = &CPPPermuteKernel::run_permute<uint16_t>;
123  break;
124  case 4:
125  _func = &CPPPermuteKernel::run_permute<uint32_t>;
126  break;
127  default:
128  ARM_COMPUTE_ERROR("Element size not supported");
129  break;
130  }
131 
132  // Configure kernel window
133  Window win = calculate_max_window(*input->info(), Steps());
134 
135  // The CPPPermute doesn't need padding so update_window_and_padding() can be skipped
136  Coordinates coord;
137  coord.set_num_dimensions(output->info()->num_dimensions());
138  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
139 
140  ICPPKernel::configure(win);
141 }
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Shape of a tensor.
Definition: TensorShape.h:39
TensorShape compute_permutation_output_shape(const ITensorInfo &input, const PermutationVector &perm)
Calculate the permuted shape of an input given a permutation vector.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Class to describe a number of elements in each dimension.
Definition: Steps.h:40
Coordinates of an item.
Definition: Coordinates.h:37
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...
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
Definition: Dimensions.h:149
Container for valid region of a window.
Definition: Types.h:188
Describe a multidimensional execution window.
Definition: Window.h:39

◆ name()

const char* name ( ) const
inlineoverridevirtual

◆ operator=() [1/2]

CPPPermuteKernel& operator= ( const CPPPermuteKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by CPPPermuteKernel::name().

◆ operator=() [2/2]

CPPPermuteKernel& operator= ( CPPPermuteKernel &&  )
default

Allow instances of this class to be moved.

◆ 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.

Reimplemented from ICPPKernel.

Definition at line 149 of file CPPPermuteKernel.cpp.

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, and IKernel::window().

Referenced by CPPPermuteKernel::name().

150 {
151  ARM_COMPUTE_UNUSED(info);
154 
155  if(_func != nullptr)
156  {
157  (this->*_func)(window);
158  }
159 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

◆ validate()

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

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

Parameters
[in]inputThe input tensor to permute. Data types supported: All.
[in]outputThe output tensor. Data types supported: same as input
[in]permPermutation vector
Returns
a status

Definition at line 143 of file CPPPermuteKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::validate_arguments().

Referenced by CPPPermuteKernel::name(), and CPPPermute::validate().

144 {
145  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, perm));
146  return Status{};
147 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
Status class.
Definition: Error.h:52
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)

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