47 if(output->total_size() != 0)
50 const TensorInfo expected_output_info = input->clone()->set_tensor_shape(expected_output_shape);
59 void NEPadLayerKernel::run_pad_constant(
const Window &window)
61 Window output_window{ window };
62 output_window.set(
Window::DimX, Window::Dimension(0, 1, 1));
65 Iterator output_it(_output, output_window);
68 Coordinates idin{
id };
69 for(
size_t dim = _padding.size() - 1; dim > 0; --dim)
71 idin[dim] -= _padding[dim].first;
72 if(idin[dim] < 0 || static_cast<int>(_input->
info()->
dimension(dim)) - 1 < idin[dim])
74 std::fill_n(reinterpret_cast<T *>(output_it.ptr()), _output->
info()->
dimension(0), _constant_value.
get<T>());
78 T *input_it_ptr =
reinterpret_cast<T *
>(_input->
ptr_to_element(idin));
79 T *output_it_ptr =
reinterpret_cast<T *
>(output_it.ptr());
80 std::fill_n(output_it_ptr, _padding[0].first, _constant_value.
get<T>());
81 memcpy(output_it_ptr + _padding[0].first, input_it_ptr, _input->
info()->
dimension(0) * element_size);
82 std::fill_n(output_it_ptr + _padding[0].first + _input->
info()->
dimension(0), _padding[0].second, _constant_value.
get<T>());
87 void NEPadLayerKernel::run_pad_constant_uint8_3Dinput_3Dpad(
const Window &window)
91 const size_t start_plane = window.z().start();
92 const size_t end_plane = window.z().end();
94 size_t start_plane_input = start_plane;
95 if(_padding.size() > 2)
97 start_plane_input = (start_plane < _padding[2].first) ? 0 : start_plane - _padding[2].first;
102 const int pad_y_elems_top = (_padding.size() > 1 ? _padding[1].first : 0) * _output->
info()->
dimension(0);
103 const int pad_y_elems_bot = (_padding.size() > 1 ? _padding[1].second : 0) * _output->
info()->
dimension(0);
105 const size_t jump_to_next_row_input = _input->
info()->
dimension(0);
106 const size_t jump_to_next_row_output = _padding[0].first + _padding[0].second;
110 const auto pad_value = _constant_value.
get<uint8_t>();
112 for(
size_t z_i = start_plane; z_i < end_plane; ++z_i)
114 if(_padding.size() > 2 && z_i < _padding[2].first)
116 memset(output_row_ptr, pad_value, output_plane_size);
117 output_row_ptr += output_plane_size;
119 else if(_padding.size() > 2 && z_i > (_input->
info()->
dimension(2) + _padding[2].first - 1))
121 memset(output_row_ptr, pad_value, output_plane_size);
122 output_row_ptr += output_plane_size;
126 memset(output_row_ptr, pad_value, pad_y_elems_top);
127 output_row_ptr += pad_y_elems_top;
130 for(; y_i > 3; y_i -= 4)
132 memset(output_row_ptr, pad_value, _padding[0].first);
133 output_row_ptr += _padding[0].first;
135 memcpy(output_row_ptr, input_it_ptr, _input->
info()->
dimension(0));
137 input_it_ptr += jump_to_next_row_input;
139 memset(output_row_ptr, pad_value, _padding[0].second + _padding[0].first);
140 output_row_ptr += jump_to_next_row_output;
142 memcpy(output_row_ptr, input_it_ptr, _input->
info()->
dimension(0));
144 input_it_ptr += jump_to_next_row_input;
146 memset(output_row_ptr, pad_value, _padding[0].second + _padding[0].first);
147 output_row_ptr += jump_to_next_row_output;
149 memcpy(output_row_ptr, input_it_ptr, _input->
info()->
dimension(0));
151 input_it_ptr += jump_to_next_row_input;
153 memset(output_row_ptr, pad_value, _padding[0].second + _padding[0].first);
154 output_row_ptr += jump_to_next_row_output;
156 memcpy(output_row_ptr, input_it_ptr, _input->
info()->
dimension(0));
158 input_it_ptr += jump_to_next_row_input;
160 memset(output_row_ptr, pad_value, _padding[0].second);
161 output_row_ptr += _padding[0].second;
163 for(; y_i > 0; --y_i)
165 memset(output_row_ptr, pad_value, _padding[0].first);
166 output_row_ptr += _padding[0].first;
168 memcpy(output_row_ptr, input_it_ptr, _input->
info()->
dimension(0));
172 memset(output_row_ptr, pad_value, _padding[0].second);
173 output_row_ptr += _padding[0].second;
175 memset(output_row_ptr, pad_value, pad_y_elems_bot);
176 output_row_ptr += pad_y_elems_bot;
182 : _func(), _input(nullptr), _output(nullptr), _padding(), _constant_value(), _mode()
191 const TensorInfo expected_output_info = input->
info()->
clone()->set_tensor_shape(expected_output_shape);
200 _constant_value = constant_value;
209 padding.size() <= 3 &&
212 _func = &NEPadLayerKernel::run_pad_constant_uint8_3Dinput_3Dpad;
216 _func = &NEPadLayerKernel::run_pad_constant<uint8_t>;
220 _func = &NEPadLayerKernel::run_pad_constant<uint16_t>;
223 _func = &NEPadLayerKernel::run_pad_constant<uint32_t>;
243 ICPPKernel::configure(win);
261 (this->*_func)(window);
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Class describing the value of a pixel for any image format.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
const Window & window() const
The maximum window the kernel can be executed on.
uint8_t * ptr_to_element(const Coordinates &id) const
Return a pointer to the element at the passed coordinates.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
std::vector< PaddingInfo > PaddingList
List of padding information.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
void get(uint8_t &v) const
Interpret the pixel value as a U8.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
NEPadLayerKernel()
Default constructor.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for Neon tensor.
Copyright (c) 2017-2021 Arm Limited.
virtual void set_valid_region(const ValidRegion &valid_region)=0
Set the valid region of the tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
PaddingMode
Padding mode to use for PadLayer.
Class to describe a number of elements in each dimension.
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory. ...
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's metadata.
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
TensorShape compute_padded_shape(const TensorShape &input_shape, const PaddingList &padding)
Calculate the padded shape of a tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Static function to check if given info will lead to a valid configuration of NEPadLayer.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
virtual size_t offset_first_element_in_bytes() const =0
The offset from the beginning of the memory allocation to the first element of the tensor...
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
void configure(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Initialize the function.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
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...
void set_num_dimensions(size_t num_dimensions)
Set number of dimensions.
Includes all wrapper headers at once.
Container for valid region of a window.
Describe a multidimensional execution window.
virtual bool has_padding() const =0
Checks if the tensor has been allocated with padding or not.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)