24.02.1
|
Go to the documentation of this file.
48 const ITensorInfo *
dst,
49 const PoolingLayerInfo &pool_info,
50 const ITensorInfo *indices)
58 "Unsupported combination of parameters!");
63 const bool is_global_pooling = pool_info.is_global_pooling;
64 unsigned int pool_size_x = is_global_pooling ?
src->dimension(
idx_width) : pool_info.pool_size.width;
65 unsigned int pool_size_y = is_global_pooling ?
src->dimension(
idx_height) : pool_info.pool_size.height;
67 int output_height = 0;
70 "Pooling region that is entirely outside input tensor is unsupported");
72 std::tie(output_width, output_height) =
74 pool_size_y, pool_info.pad_stride_info);
76 "Calculated output dimension size is invalid");
83 "Pooling indices only supported for MAX pooling method");
85 "Pooling indices only supported for pool size 2x2");
87 if (indices->total_size() != 0)
95 if (
dst->total_size() != 0)
132 _pool_info = pool_info;
134 _num_elems_processed_per_iteration =
136 _num_elems_processed_per_iteration =
adjust_vec_size(_num_elems_processed_per_iteration,
dst->dimension(0));
138 int pool_stride_x = 0;
139 int pool_stride_y = 0;
149 std::tie(pool_stride_x, pool_stride_y) = pad_stride_info.
stride();
150 const int pool_pad_top = pad_stride_info.
pad_top();
151 const int pool_pad_left = pad_stride_info.
pad_left();
183 if (
src->quantization_info() !=
dst->quantization_info())
209 build_opts.
add_option(
"-DINITIAL_VALUE=" + initial_value);
219 switch (_data_layout)
224 const auto use_wider_accumulator = use_fp_mixed_precision && (pool_type !=
PoolingType::MAX);
228 build_opts.
add_option(
"-DACC_DATA_TYPE=" + acc_data_type);
229 build_opts.
add_option_if(use_wider_accumulator,
"-DFP_MIXED_PRECISION");
233 build_opts.
add_option_if(exclude_padding,
"-DEXCLUDE_PADDING");
240 std::string
kernel_name =
"pooling_layer_2_nchw_indices";
245 std::string
kernel_name =
"pooling_layer_MxN_nchw";
253 const auto use_fp_mixed_precision =
261 if (use_fp_mixed_precision)
271 build_opts.
add_option_if(use_fp_mixed_precision,
"-DFP_MIXED_PRECISION");
272 build_opts.
add_option_if(exclude_padding,
"-DEXCLUDE_PADDING");
278 build_opts.
add_option(
"-DVEC_SIZE_LEFTOVER=" +
284 std::string
kernel_name =
"pooling_layer_2x2_nhwc";
290 ?
"pooling_layer_MxN_quantized_nhwc"
291 :
"pooling_layer_MxN_nhwc";
302 ICLKernel::configure_internal(win);
305 _config_id =
"pooling_layer_";
335 unsigned int pool_stride_x = 0;
336 unsigned int pool_stride_y = 0;
337 std::tie(pool_stride_x, pool_stride_y) = _pool_info.pad_stride_info.stride();
347 switch (_data_layout)
355 unsigned int idx = 0;
356 add_3D_tensor_argument(idx,
src,
slice);
357 add_3D_tensor_argument(idx,
dst,
slice);
360 add_3D_tensor_argument(idx, indices,
slice);
368 const size_t batch_size =
dst->info()->tensor_shape().total_size_upper(3);
380 unsigned int idx = 0;
381 add_4D_tensor_argument(idx,
src, in_slice);
382 add_4D_tensor_argument(idx,
dst,
slice);
386 add_4D_tensor_argument(idx, indices,
slice);
Class to describe a number of elements in each dimension.
@ NCHW
Num samples, channels, height, width.
std::string to_string(T &&value)
Convert integer and float values to string.
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.
SimpleTensor< float > src
const std::string & string_from_pooling_type(PoolingType type)
Translates a given pooling type to a string.
Class describing the value of a pixel for any image format.
const StringSet & options() const
Gets the current options list set.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ POOL
Pool CL kernel type.
@ NHWC
Num samples, height, width, channels.
TensorShape compute_pool_shape(const ITensorInfo &input, PoolingLayerInfo pool_info)
Calculate the output pool shape of a tensor.
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
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)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
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.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Class for specifying the size of an image or rectangle.
size_t height
Height of the image region or rectangle.
ITensor * get_tensor(int id)
Get tensor of a given id from the pac.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
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.
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
constexpr auto data_layout
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
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.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
const ITensor * get_const_tensor(int id) const
Get constant tensor of a given id.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
@ U32
unsigned 32-bit number
size_t width
Width of the image region or rectangle.
void add_option(std::string option)
Adds option to the existing build option list.
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...
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
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.
Pooling Layer Information struct.
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
PoolingType
Available pooling types.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(...)
Describe one of the image's dimensions with a start, end and step.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Window first_slice_window_3D() const
First 3D slice of the window.
unsigned int pad_left() const
Get the left padding.
const Window & window() const
The maximum window the kernel can be executed on.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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.
size_t get_data_layout_dimension_index(const DataLayout &data_layout, const DataLayoutDimension &data_layout_dimension)
Get the index of the given dimension.
Describe a multidimensional execution window.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
@ F16
16-bit floating-point number
bool is_pool_region_entirely_outside_input(const PoolingLayerInfo &info)
Check if the pool region is entirely outside the input tensor.
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,...
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.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
@ S32
signed 32-bit number
bool is_data_type_quantized_asymmetric(DataType dt)
Check if a given data type is of asymmetric quantized type.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
@ UNKNOWN
Unknown data layout.
Store the tensor's metadata.
Window first_slice_window_4D() const
First 4D slice of the window.
@ F32
32-bit floating-point number
std::tuple< PixelValue, PixelValue > get_min_max(DataType dt)
Compute the mininum and maximum values a data type can take.
bool slide_window_slice_4D(Window &slice) const
Slide the passed 4D window slice.
PadStrideInfo pad_stride_info
DataType
Available data types.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
unsigned int pad_top() const
Get the top padding.
std::pair< unsigned int, unsigned int > stride() const
Get the stride.
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.