44 Status
validate_arguments(
const ITensorInfo *
src,
const ITensorInfo *
dst,
const PoolingLayerInfo &pool_info,
const ITensorInfo *indices)
50 "Unsupported combination of parameters!");
55 const bool is_global_pooling = pool_info.is_global_pooling;
56 unsigned int pool_size_x = is_global_pooling ? src->dimension(idx_width) : pool_info.pool_size.width;
57 unsigned int pool_size_y = is_global_pooling ? src->dimension(idx_height) : pool_info.pool_size.height;
59 int output_height = 0;
64 pool_size_x, pool_size_y, pool_info.pad_stride_info);
74 if(indices->total_size() != 0)
82 if(dst->total_size() != 0)
86 TensorInfo out_info(TensorInfo(
compute_pool_shape(*src, pool_info), 1, dst->data_type()));
115 _pool_info = pool_info;
120 int pool_stride_x = 0;
121 int pool_stride_y = 0;
131 std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.
stride();
132 const int pool_pad_top = pad_stride_info.
pad_top();
133 const int pool_pad_left = pad_stride_info.
pad_left();
180 std::tie(type_min, std::ignore) =
get_min_max(data_type);
200 const auto use_wider_accumulator = use_fp_mixed_precision && (pool_type !=
PoolingType::MAX);
202 build_opts.
add_option(
"-DACC_DATA_TYPE=" + acc_data_type);
203 build_opts.
add_option_if(use_wider_accumulator,
"-DFP_MIXED_PRECISION");
207 build_opts.
add_option_if(exclude_padding,
"-DEXCLUDE_PADDING");
213 std::string
kernel_name =
"pooling_layer_2_nchw_indices";
218 std::string
kernel_name =
"pooling_layer_MxN_nchw";
233 if(use_fp_mixed_precision)
243 build_opts.
add_option_if(use_fp_mixed_precision,
"-DFP_MIXED_PRECISION");
244 build_opts.
add_option_if(exclude_padding,
"-DEXCLUDE_PADDING");
255 std::string
kernel_name =
"pooling_layer_2x2_nhwc";
271 ICLKernel::configure_internal(win);
274 _config_id =
"pooling_layer_";
301 unsigned int pool_stride_x = 0;
302 unsigned int pool_stride_y = 0;
303 std::tie(pool_stride_x, pool_stride_y) = _pool_info.pad_stride_info.stride();
316 Window slice = window_collapsed.first_slice_window_3D();
320 unsigned int idx = 0;
321 add_3D_tensor_argument(idx, src, slice);
322 add_3D_tensor_argument(idx, dst, slice);
325 add_3D_tensor_argument(idx, indices, slice);
327 enqueue(queue, *
this, slice, lws_hint());
329 while(window_collapsed.slide_window_slice_3D(slice));
334 const size_t batch_size = dst->info()->tensor_shape().total_size_upper(3);
336 Window slice = window_collapsed.first_slice_window_4D();
345 unsigned int idx = 0;
346 add_4D_tensor_argument(idx, src, in_slice);
347 add_4D_tensor_argument(idx, dst, slice);
350 add_4D_tensor_argument(idx, indices, slice);
352 enqueue(queue, *
this, slice, lws_hint());
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
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)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
const StringSet & options() const
Gets the current options list set.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Store the tensor's metadata.
void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Describe one of the image's dimensions with a start, end and step.
unsigned int pad_top() const
Get the top padding.
std::string lower_string(const std::string &val)
Lower a given string.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
size_t total_size_lower(size_t dimension) const
Compute size of dimensions lower than the given one.
SimpleTensor< float > src
Copyright (c) 2017-2022 Arm Limited.
size_t height
Height of the image region or rectangle.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
void add_option(std::string option)
Adds option to the existing build option list.
std::pair< int, int > scaled_dimensions_signed(int width, int height, int kernel_width, int kernel_height, const PadStrideInfo &pad_stride_info)
Returns calculated width and height of output scaled tensor depending on dimensions rounding mode...
TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output pool shape of a tensor.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
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.
1 channel, 1 U32 per channel
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
Pooling Layer Information struct.
UniformQuantizationInfo uniform() const
Return per layer quantization info.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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.
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
Padding and stride information class.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
void configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const PoolingLayerInfo &pool_info, ITensorInfo *indices=nullptr)
Configure kernel for a given list of arguments.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
Num samples, channels, height, width.
static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const PoolingLayerInfo &pool_info, const ITensorInfo *indices=nullptr)
Static function to check if given info will lead to a valid configuration.
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
PoolingType
Available pooling types.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
PadStrideInfo pad_stride_info
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
size_t width
Width of the image region or rectangle.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Class for specifying the size of an image or rectangle.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Num samples, height, width, channels.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo *> infos)
Stores padding information before configuring a kernel.
Window first_slice_window_4D() const
First 4D slice of the window.
bool slide_window_slice_4D(Window &slice) const
Slide the passed 4D window slice.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
bool is_pool_region_entirely_outside_input(const PoolingLayerInfo &info)
Check if the pool region is entirely outside the input tensor.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension, getting rounded down to its closest valid vector size.
quantized, asymmetric fixed-point 8-bit number signed
DataType
Available data types.
unsigned int pad_left() const
Get the left padding.
const std::string & string_from_pooling_type(PoolingType type)
Translates a given pooling type to a string.
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
Describe a multidimensional execution window.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.