39 uint32_t last_padding_dimension(
const PaddingList &padding)
41 int last_padding_dim = padding.size() - 1;
42 for(; last_padding_dim >= 0; --last_padding_dim)
44 if(padding[last_padding_dim].first > 0 || padding[last_padding_dim].second > 0)
49 return static_cast<uint32_t>(last_padding_dim);
56 : _copy_kernel(), _pad_kernel(), _mode(), _padding(), _num_dimensions(0), _slice_functions(), _concat_functions(), _slice_results(), _concat_results()
62 _pad_kernel = arm_compute::support::cpp14::make_unique<NEPadLayerKernel>();
66 void NEPadLayer::configure_reflect_symmetric_mode(ITensor *
input, ITensor *output)
78 _slice_functions.resize(2 * _num_dimensions);
79 _slice_results.resize(2 * _num_dimensions);
80 _concat_functions.resize(_num_dimensions);
81 _concat_results.resize(_num_dimensions - 1);
83 Coordinates starts_before{};
84 Coordinates ends_before{};
85 Coordinates starts_after{};
86 Coordinates ends_after{};
87 Coordinates strides{};
88 ITensor *prev =
input;
89 for(uint32_t i = 0; i < _num_dimensions; ++i)
94 strides.set(i - 1, 1);
97 if(_padding[i].first > 0 || _padding[i].second > 0)
104 starts_before.set(i, _padding[i].first);
105 ends_before.set(i, 0);
106 starts_after.set(i,
input->info()->dimension(i) - 2);
107 ends_after.set(i,
input->info()->dimension(i) - _padding[i].second - 2);
112 starts_before.set(i, _padding[i].first - 1);
113 ends_before.set(i, -1);
114 starts_after.set(i,
input->info()->dimension(i) - 1);
115 ends_after.set(i,
input->info()->dimension(i) - _padding[i].second - 1);
121 const int32_t begin_mask_before = starts_before[i] < 0 ? ~0 : ~(1u << i);
122 const int32_t end_mask_before = ends_before[i] < 0 ? ~0 : ~(1u << i);
123 const int32_t begin_mask_after = starts_after[i] < 0 ? ~0 : ~(1u << i);
124 const int32_t end_mask_after = ends_after[i] < 0 ? ~0 : ~(1u << i);
127 std::vector<const ITensor *> concat_vector;
128 if(_padding[i].first > 0)
130 if(i < prev->
info()->num_dimensions())
132 _slice_functions[2 * i].configure(prev, &_slice_results[2 * i], starts_before, ends_before, strides, begin_mask_before, end_mask_before);
133 concat_vector.emplace_back(&_slice_results[2 * i]);
138 concat_vector.push_back(prev);
141 concat_vector.push_back(prev);
142 if(_padding[i].second > 0)
144 if(i < prev->
info()->num_dimensions())
146 _slice_functions[2 * i + 1].configure(prev, &_slice_results[2 * i + 1], starts_after, ends_after, strides, begin_mask_after, end_mask_after);
147 concat_vector.emplace_back(&_slice_results[2 * i + 1]);
152 concat_vector.push_back(prev);
156 ITensor *out = (i == _num_dimensions - 1) ? output : &_concat_results[i];
157 _concat_functions[i].configure(concat_vector, out, i);
158 if(i != _num_dimensions - 1)
160 _concat_results[i].allocator()->allocate();
164 _slice_results[2 * i].allocator()->allocate();
165 _slice_results[2 * i + 1].allocator()->allocate();
181 _num_dimensions = last_padding_dimension(padding) + 1;
182 if(_num_dimensions > 0)
188 configure_constant_mode(
input, output, padding, constant_value);
194 configure_reflect_symmetric_mode(
input, output);
204 _copy_kernel = arm_compute::support::cpp14::make_unique<NECopyKernel>();
205 _copy_kernel->configure(
input, output);
230 for(uint32_t i = 0; i < padding.size(); ++i)
255 if(_num_dimensions > 0)
267 for(uint32_t i = 0; i < _num_dimensions; ++i)
269 if(_padding[i].first > 0 || _padding[i].second > 0)
271 if(_padding[i].first > 0 && _slice_results[2 * i].
info()->total_size() > 0)
273 _slice_functions[2 * i].run();
275 if(_padding[i].second > 0 && _slice_results[2 * i + 1].
info()->total_size() > 0)
277 _slice_functions[2 * i + 1].run();
279 _concat_functions[i].run();
Class describing the value of a pixel for any image format.
std::vector< PaddingInfo > PaddingList
List of padding information.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(...)
Copyright (c) 2017-2020 Arm Limited.
#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.
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.
~NEPadLayer()
Default destructor.
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 ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
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.
NEPadLayer()
Default Constructor.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
void run() override
Run the kernels contained in the function.
void configure(ITensor *input, ITensor *output, const PaddingList &padding, const PixelValue constant_value=PixelValue(), const PaddingMode mode=PaddingMode::CONSTANT)
Initialize the function.
static IScheduler & get()
Access the scheduler singleton.