Compute Library
 19.08
NEStackLayerKernel Class Reference

NEON kernel to stacks a rank-R tensor into one with rank-(R+1) along the axis dimension. More...

#include <NEStackLayerKernel.h>

Collaboration diagram for NEStackLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEStackLayerKernel ()
 Default constructor. More...
 
 NEStackLayerKernel (const NEStackLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEStackLayerKerneloperator= (const NEStackLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEStackLayerKernel (NEStackLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEStackLayerKerneloperator= (NEStackLayerKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEStackLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, unsigned int axis, unsigned int idx_input, unsigned int num_tensors, ITensor *output)
 Initialise the kernel's inputs and output. 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...
 
- 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, unsigned int axis, unsigned int idx_input, unsigned int num_tensors, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of NEStackLayerKernel. More...
 

Detailed Description

NEON kernel to stacks a rank-R tensor into one with rank-(R+1) along the axis dimension.

Definition at line 36 of file NEStackLayerKernel.h.

Constructor & Destructor Documentation

◆ NEStackLayerKernel() [1/3]

Default constructor.

Definition at line 89 of file NEStackLayerKernel.cpp.

90  : _input(nullptr), _output(nullptr), _axis(), _idx_input()
91 {
92 }

◆ NEStackLayerKernel() [2/3]

NEStackLayerKernel ( const NEStackLayerKernel )
delete

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

◆ NEStackLayerKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEStackLayerKernel()

~NEStackLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
unsigned int  axis,
unsigned int  idx_input,
unsigned int  num_tensors,
ITensor output 
)

Initialise the kernel's inputs and output.

Note
Supported input tensor rank: up to 4
Parameters
[in]inputInput tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]axisThe dimension to stack the tensors along. It must be smaller than the number of input dimensions.
[in]idx_inputIndex of the input tensor in the list of tensors to stack. All tensors in the list must have the same shape
[in]num_tensorsNumber of tensors to stack
[out]outputOutput tensor. Data types supported: Same as input.

Definition at line 94 of file NEStackLayerKernel.cpp.

95 {
96  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
97  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), axis, idx_input, num_tensors, output->info()));
98 
99  _input = input;
100  _output = output;
101  _axis = axis;
102  _idx_input = idx_input;
103 
104  // Configure kernel window
105  auto win_config = validate_and_configure_window(input->info(), axis, num_tensors, output->info());
106 
107  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
108  INEKernel::configure(win_config.second);
109 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::test::validation::axis, ITensor::info(), arm_compute::test::validation::num_tensors, and arm_compute::validate_and_configure_window().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 39 of file NEStackLayerKernel.h.

40  {
41  return "NEStackLayerKernel";
42  }

◆ operator=() [1/2]

NEStackLayerKernel& operator= ( const NEStackLayerKernel )
delete

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

◆ operator=() [2/2]

NEStackLayerKernel& operator= ( NEStackLayerKernel &&  )
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.

Implements ICPPKernel.

Definition at line 118 of file NEStackLayerKernel.cpp.

119 {
123 
124  Window window_out;
125  window_out.use_tensor_dimensions(_output->info()->tensor_shape());
126 
127  Iterator input(_input, window);
128  Iterator output(_output, window_out);
129 
130  const int stride_x = _output->info()->strides_in_bytes()[0];
131  const int stride_y = _output->info()->num_dimensions() >= 1 ? _output->info()->strides_in_bytes()[1] : 0;
132  const int stride_z = _output->info()->num_dimensions() >= 2 ? _output->info()->strides_in_bytes()[2] : 0;
133  const int stride_w = _output->info()->num_dimensions() >= 3 ? _output->info()->strides_in_bytes()[3] : 0;
134  const int stride_k = _output->info()->num_dimensions() >= 4 ? _output->info()->strides_in_bytes()[4] : 0;
135 
136  execute_window_loop(window, [&](const Coordinates & id)
137  {
138  Coordinates id_out = shift_from_axis_and_replace_coordinate(id, _axis, _idx_input);
139  const int idx = id_out[0] * stride_x + id_out[1] * stride_y + id_out[2] * stride_z + id_out[3] * stride_w + id_out[4] * stride_k;
140  std::memcpy(output.ptr() + idx, input.ptr(), _input->info()->element_size());
141  },
142  input);
143 }
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
void use_tensor_dimensions(const TensorShape &shape, size_t first_dimension=Window::DimX)
Use the tensor's dimensions to fill the window dimensions.
Definition: Window.inl:250
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:160
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Coordinates of an item.
Definition: Coordinates.h:37
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
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:122
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
Iterator updated by execute_window_loop for each window element.
Definition: Helpers.h:318
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
Describe a multidimensional execution window.
Definition: Window.h:39
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:940

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensorInfo::element_size(), arm_compute::execute_window_loop(), ITensor::info(), arm_compute::test::validation::info, ITensorInfo::num_dimensions(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), ITensorInfo::tensor_shape(), Window::use_tensor_dimensions(), and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
unsigned int  axis,
unsigned int  idx_input,
unsigned int  num_tensors,
const ITensorInfo output 
)
static

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

Note
Supported input tensor rank: up to 4
Parameters
[in]inputInput tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32
[in]axisThe dimension to stack the tensors along. It must be smaller than the number of input dimensions.
[in]idx_inputIndex of the input tensor in the list of tensors to stack All tensors in the list must have the same shape
[in]num_tensorsNumber of tensors to stack
[in]outputOutput tensor info. Data types supported: Same as input.
Returns
a status

Definition at line 111 of file NEStackLayerKernel.cpp.

112 {
113  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, axis, idx_input, num_tensors, output));
114  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), axis, num_tensors, output->clone().get()).first);
115  return Status{};
116 }
std::pair< Status, Window > validate_and_configure_window(ITensorInfo *input, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *output, const PadStrideInfo &conv_info, unsigned int depth_multiplier, const Size2D &dilation)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
Status class.
Definition: Error.h:52
virtual std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::axis, ICloneable< T >::clone(), arm_compute::test::validation::num_tensors, and arm_compute::validate_and_configure_window().

Referenced by NEStackLayer::validate().


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