From 375156937a0783432c5d18e199b5d8d2b3ec33f7 Mon Sep 17 00:00:00 2001 From: ramelg01 Date: Sat, 26 Feb 2022 22:06:20 +0000 Subject: Implementation of ClPooling3d - For NDHWC layout - For F16 and F32 data types - Mixed Precision stil not supported Resolves: COMPMID-4670 Signed-off-by: ramy.elgammal@arm.com Change-Id: I0e14a13e4625569e8e5ee67e6033bd1efe0da469 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/7262 Comments-Addressed: Arm Jenkins Reviewed-by: SiCong Li Reviewed-by: Gunes Bayir Tested-by: Arm Jenkins --- arm_compute/core/utils/misc/ShapeCalculator.h | 63 +++++++++------------------ 1 file changed, 20 insertions(+), 43 deletions(-) (limited to 'arm_compute/core/utils') diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index ee4fe0c02f..df907c106e 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -1467,52 +1467,29 @@ inline TensorShape compute_conv3d_shape(const TensorShape &src, const TensorShap * * @return the calculated shape */ -inline TensorShape compute_pool3d_shape(const TensorShape &src, Pool3DInfo pool3d_info) +inline TensorShape compute_pool3d_shape(const TensorShape &src, Pooling3dLayerInfo pool3d_info) { TensorShape output_shape{ src }; - const int idx_width = 1; - const int idx_height = 2; - const int idx_depth = 3; - const int pool_size_width = pool3d_info.is_global_pooling ? src[idx_width] : pool3d_info.pool_size.width; - const int pool_size_height = pool3d_info.is_global_pooling ? src[idx_height] : pool3d_info.pool_size.height; - const int pool_size_depth = pool3d_info.is_global_pooling ? src[idx_depth] : pool3d_info.pool_size.depth; - const int pool_stride_width = pool3d_info.strides.width; - const int pool_stride_height = pool3d_info.strides.height; - const int pool_stride_depth = pool3d_info.strides.depth; - - int output_width_size = 0; - int output_height_size = 0; - int output_depth_size = 0; - - const size_t pad_left = pool3d_info.padding.left; - const size_t pad_right = pool3d_info.padding.right; - const size_t pad_top = pool3d_info.padding.top; - const size_t pad_bottom = pool3d_info.padding.bottom; - const size_t pad_front = pool3d_info.padding.front; - const size_t pad_back = pool3d_info.padding.back; - - switch(pool3d_info.round_type) - { - case DimensionRoundingType::FLOOR: - output_width_size = static_cast(std::floor((static_cast(src[idx_width] + pad_left + pad_right - pool_size_width)) / pool_stride_width) + 1); - output_height_size = static_cast(std::floor((static_cast(src[idx_height] + pad_top + pad_bottom - pool_size_height)) / pool_stride_height) + 1); - output_depth_size = static_cast(std::floor((static_cast(src[idx_depth] + pad_front + pad_back - pool_size_depth)) / pool_stride_depth) + 1); - break; - case DimensionRoundingType::CEIL: - output_width_size = static_cast(std::ceil((static_cast(src[idx_width] + pad_left + pad_right - pool_size_width)) / pool_stride_width) + 1); - output_height_size = static_cast(std::ceil((static_cast(src[idx_height] + pad_top + pad_bottom - pool_size_height)) / pool_stride_height) + 1); - output_depth_size = static_cast(std::ceil((static_cast(src[idx_depth] + pad_front + pad_back - pool_size_depth)) / pool_stride_depth) + 1); - break; - default: - ARM_COMPUTE_ERROR("Unsupported rounding type"); - } - - ARM_COMPUTE_ERROR_ON_MSG((output_width_size < 1 || output_height_size < 1 || output_depth_size < 1), "Calculated output dimension size is invalid"); - - output_shape.set(idx_width, static_cast(output_width_size)); - output_shape.set(idx_height, static_cast(output_height_size)); - output_shape.set(idx_depth, static_cast(output_depth_size)); + const auto data_layout = DataLayout::NDHWC; + const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); + const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); + const int idx_depth = get_data_layout_dimension_index(data_layout, DataLayoutDimension::DEPTH); + const int pool_size_width = pool3d_info.is_global_pooling ? src[idx_width] : pool3d_info.pool_size.width; + const int pool_size_height = pool3d_info.is_global_pooling ? src[idx_height] : pool3d_info.pool_size.height; + const int pool_size_depth = pool3d_info.is_global_pooling ? src[idx_depth] : pool3d_info.pool_size.depth; + int output_width = 0; + int output_height = 0; + int output_depth = 0; + + std::tie(output_width, output_height, output_depth) = scaled_3d_dimensions_signed(src[idx_width], src[idx_height], src[idx_depth], pool_size_width, pool_size_height, + pool_size_depth, pool3d_info); + + ARM_COMPUTE_ERROR_ON_MSG((output_width < 1 || output_height < 1 || output_depth < 1), "Calculated output dimension size is invalid"); + + output_shape.set(idx_width, static_cast(output_width)); + output_shape.set(idx_height, static_cast(output_height)); + output_shape.set(idx_depth, static_cast(output_depth)); return output_shape; } -- cgit v1.2.1