Compute Library
 21.08
NEStackLayerKernel Class Reference

Basic kernel to stack 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...
 
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...
 
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 *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

Basic kernel to stack 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 87 of file NEStackLayerKernel.cpp.

Referenced by NEStackLayerKernel::name().

88  : _input(nullptr), _output(nullptr), _axis(), _idx_input()
89 {
90 }

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

Referenced by NEStackLayerKernel::name().

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: All
[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 92 of file NEStackLayerKernel.cpp.

References ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ITensor::info(), and arm_compute::test::validation::input.

Referenced by NEStackLayerKernel::name().

93 {
95  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), axis, idx_input, num_tensors, output->info()));
96 
97  _input = input;
98  _output = output;
99  _axis = axis;
100  _idx_input = idx_input;
101 
102  // Configure kernel window
103  auto win_config = validate_and_configure_window(input->info(), axis, num_tensors, output->info());
104 
105  ARM_COMPUTE_ERROR_THROW_ON(win_config.first);
106  INEKernel::configure(win_config.second);
107 }
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157

◆ name()

◆ operator=() [1/2]

NEStackLayerKernel& operator= ( const NEStackLayerKernel )
delete

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

Referenced by NEStackLayerKernel::name().

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

Reimplemented from ICPPKernel.

Definition at line 116 of file NEStackLayerKernel.cpp.

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::input, ITensorInfo::num_dimensions(), Iterator::ptr(), ITensorInfo::strides_in_bytes(), ITensorInfo::tensor_shape(), Window::use_tensor_dimensions(), and IKernel::window().

Referenced by NEStackLayerKernel::name().

117 {
121 
122  Window window_out;
123  window_out.use_tensor_dimensions(_output->info()->tensor_shape());
124 
125  Iterator input(_input, window);
126  Iterator output(_output, window_out);
127 
128  const int stride_x = _output->info()->strides_in_bytes()[0];
129  const int stride_y = _output->info()->num_dimensions() >= 1 ? _output->info()->strides_in_bytes()[1] : 0;
130  const int stride_z = _output->info()->num_dimensions() >= 2 ? _output->info()->strides_in_bytes()[2] : 0;
131  const int stride_w = _output->info()->num_dimensions() >= 3 ? _output->info()->strides_in_bytes()[3] : 0;
132  const int stride_k = _output->info()->num_dimensions() >= 4 ? _output->info()->strides_in_bytes()[4] : 0;
133 
134  execute_window_loop(window, [&](const Coordinates & id)
135  {
136  Coordinates id_out = shift_from_axis_and_replace_coordinate(id, _axis, _idx_input);
137  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;
138  std::memcpy(output.ptr() + idx, input.ptr(), _input->info()->element_size());
139  },
140  input);
141 }
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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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()
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:915
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
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:201

◆ 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: All
[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 109 of file NEStackLayerKernel.cpp.

References ARM_COMPUTE_RETURN_ON_ERROR, and ICloneable< T >::clone().

Referenced by NEStackLayerKernel::name(), and NEStackLayer::validate().

110 {
111  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, axis, idx_input, num_tensors, output));
112  ARM_COMPUTE_RETURN_ON_ERROR(validate_and_configure_window(input->clone().get(), axis, num_tensors, output->clone().get()).first);
113  return Status{};
114 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

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