Compute Library
 23.11
NEReorgLayerKernel Class Reference

Interface for the kernel to perform tensor re-organization. More...

#include <NEReorgLayerKernel.h>

Collaboration diagram for NEReorgLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEReorgLayerKernel ()
 Default constructor. More...
 
 NEReorgLayerKernel (const NEReorgLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEReorgLayerKerneloperator= (const NEReorgLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEReorgLayerKernel (NEReorgLayerKernel &&)=default
 Default Move Constructor. More...
 
NEReorgLayerKerneloperator= (NEReorgLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~NEReorgLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output, int32_t stride)
 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...
 
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 *input, const ITensorInfo *output, int32_t stride)
 Static function to check if given info will lead to a valid configuration. More...
 

Additional Inherited Members

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

Detailed Description

Interface for the kernel to perform tensor re-organization.

Definition at line 35 of file NEReorgLayerKernel.h.

Constructor & Destructor Documentation

◆ NEReorgLayerKernel() [1/3]

Default constructor.

Definition at line 72 of file NEReorgLayerKernel.cpp.

72  : _input(nullptr), _output(nullptr), _stride(1)
73 {
74 }

◆ NEReorgLayerKernel() [2/3]

NEReorgLayerKernel ( const NEReorgLayerKernel )
delete

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

◆ NEReorgLayerKernel() [3/3]

Default Move Constructor.

◆ ~NEReorgLayerKernel()

~NEReorgLayerKernel ( )
default

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output,
int32_t  stride 
)

Set the input and output of the kernel.

Parameters
[in]inputSource tensor. Data type supported: All
[out]outputDestination tensor. Data type supported: Same as input
[in]strideStride to be used during data re-organization. It defines the spatial distance between 2 consecutive pixels in the x and y direction

Definition at line 76 of file NEReorgLayerKernel.cpp.

77 {
79 
80  // Output auto inizialitation if not yet initialized
81  const TensorShape output_shape = misc::shape_calculator::compute_reorg_output_shape(*input->info(), stride);
82  auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
83 
84  // Perform validation step
85  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), stride));
86 
87  _input = input;
88  _output = output;
89  _stride = stride;
90 
91  // The NEReorgLayerKernel doesn't need padding so update_window_and_padding() can be skipped
92 
93  // Configure kernel window
94  Window win = calculate_max_window(*output->info(), Steps());
95 
96  ICPPKernel::configure(win);
97 }

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_reorg_output_shape(), ITensor::info(), arm_compute::test::validation::input, arm_compute::test::validation::output_shape, and arm_compute::cpu::kernels::validate_arguments().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 38 of file NEReorgLayerKernel.h.

39  {
40  return "NEReorgLayerKernel";
41  }

◆ operator=() [1/2]

NEReorgLayerKernel& operator= ( const NEReorgLayerKernel )
delete

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

◆ operator=() [2/2]

NEReorgLayerKernel& operator= ( NEReorgLayerKernel &&  )
default

Default move assignment operator.

◆ 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 105 of file NEReorgLayerKernel.cpp.

106 {
110 
111  const DataLayout data_layout = _input->info()->data_layout();
115 
116  const unsigned int stride = _stride;
117  const unsigned int out_c = _output->info()->tensor_shape()[idx_c] / (stride * stride);
118  const uint8_t *in_ptr = _input->buffer();
119 
120  // Collapse
121  Window collapsed_window = window.collapse_if_possible(window, 4);
122 
123  // Create Iterator
124  Iterator out(_output, collapsed_window);
125 
126  // Perform reorg
128  collapsed_window,
129  [&](const Coordinates &id)
130  {
131  // Get spatial coords and channels
132  const unsigned int w = id[idx_w];
133  const unsigned int h = id[idx_h];
134  const unsigned int c = id[idx_c];
135 
136  // Calculate mapping
137  const unsigned int offset = c / out_c;
138  Coordinates map_coords = id;
139  map_coords.set(idx_w, w * stride + offset % stride);
140  map_coords.set(idx_h, h * stride + offset / stride);
141  map_coords.set(idx_c, c % out_c);
142 
143  // Perform mapping
144  std::memcpy(out.ptr(), in_ptr + _input->info()->offset_element_in_bytes(map_coords),
145  _input->info()->element_size());
146  },
147  out);
148 }

References ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, ITensor::buffer(), arm_compute::CHANNEL, Window::collapse_if_possible(), arm_compute::cpu::data_layout, ITensorInfo::data_layout(), ITensorInfo::element_size(), arm_compute::execute_window_loop(), arm_compute::get_data_layout_dimension_index(), arm_compute::HEIGHT, ITensor::info(), arm_compute::test::validation::info, offset(), ITensorInfo::offset_element_in_bytes(), Iterator::ptr(), Dimensions< T >::set(), ITensorInfo::tensor_shape(), arm_compute::test::validation::w, arm_compute::WIDTH, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
int32_t  stride 
)
static

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

Parameters
[in]inputSource tensor info. Data type supported: All
[in]outputDestination tensor info. Data type supported: Same as input
[in]strideStride to be used during data re-organization It defines the spatial distance between 2 consecutive pixels in the x and y direction
Returns
a status

Definition at line 99 of file NEReorgLayerKernel.cpp.

100 {
102  return Status{};
103 }

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::input, and arm_compute::cpu::kernels::validate_arguments().

Referenced by NEReorgLayer::validate().


The documentation for this class was generated from the following files:
arm_compute::ITensorInfo::data_layout
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.
arm_compute::ITensorInfo::tensor_shape
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
arm_compute::DataLayout
DataLayout
[DataLayout enum definition]
Definition: CoreTypes.h:110
arm_compute::DataLayoutDimension::CHANNEL
@ CHANNEL
channel
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::output_shape
TensorShape output_shape
Definition: LSTMLayerQuantized.cpp:469
arm_compute::cpu::kernels::validate_arguments
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
Definition: CpuDirectConv2dKernel.cpp:57
ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:1079
arm_compute::ITensorInfo::element_size
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
arm_compute::ITensorInfo::offset_element_in_bytes
virtual int32_t offset_element_in_bytes(const Coordinates &pos) const =0
The offset in bytes from the beginning of the memory allocation to access the element at position (x,...
arm_compute::Window::collapse_if_possible
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
Definition: Window.inl:72
arm_compute::DataLayoutDimension::WIDTH
@ WIDTH
width
arm_compute::cpu::data_layout
constexpr auto data_layout
Definition: impl.h:36
arm_compute::misc::shape_calculator::compute_reorg_output_shape
TensorShape compute_reorg_output_shape(const ITensorInfo &input, int32_t stride)
Calculate the output shape of the reorg layer given a stride.
Definition: ShapeCalculator.h:126
ARM_COMPUTE_RETURN_ON_ERROR
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:205
ARM_COMPUTE_ERROR_ON_NULLPTR
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
arm_compute::ITensor::info
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
ARM_COMPUTE_ERROR_THROW_ON
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
arm_compute::execute_window_loop
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:74
arm_compute::DataLayoutDimension::HEIGHT
@ HEIGHT
height
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::test::validation::w
SimpleTensor< float > w
Definition: DFT.cpp:156
ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:203
offset
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
Definition: helpers.h:1128
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::get_data_layout_dimension_index
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Definition: Helpers.inl:201
arm_compute::test::validation::info
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
arm_compute::test::validation::input
auto input
Definition: LSTMLayerQuantized.cpp:486
arm_compute::ITensor::buffer
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory.