From 2aa7fd011a4baff52dceb00a71b3674f819df8fc Mon Sep 17 00:00:00 2001 From: Sang-Hoon Park Date: Wed, 18 Sep 2019 13:39:00 +0100 Subject: COMPMID-2601 [CL] add mixed precision support to PoolingLayer * PoolingLayerInfo is updated with a new flag. * CL Kernel is updated to use FP32 accumulation. * CL pooling layer testscases are added for mixed precision. * Reference pooling layer is updated to use FP32 accumulation. Change-Id: I4ab2167cc7f86c86293cf50a0ca5119c04dc9c7e Signed-off-by: Sang-Hoon Park Reviewed-on: https://review.mlplatform.org/c/1973 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: VidhyaSudhan Loganathan --- arm_compute/core/Types.h | 51 +++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h index 7f60638d05..9641089e7b 100644 --- a/arm_compute/core/Types.h +++ b/arm_compute/core/Types.h @@ -1195,39 +1195,44 @@ class PoolingLayerInfo public: /** Default Constructor */ PoolingLayerInfo() - : _pool_type(PoolingType::MAX), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false) + : _pool_type(PoolingType::MAX), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false), _fp_mixed_precision(false) { } /** Default Constructor * - * @param[in] pool_type Pooling type @ref PoolingType. - * @param[in] pool_size Pooling size, in elements, across x and y. - * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo - * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. - * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). - * Defaults to false; + * @param[in] pool_type Pooling type @ref PoolingType. + * @param[in] pool_size Pooling size, in elements, across x and y. + * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo + * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. + * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). + * Defaults to false; + * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. */ explicit PoolingLayerInfo(PoolingType pool_type, unsigned int pool_size, - PadStrideInfo pad_stride_info = PadStrideInfo(), - bool exclude_padding = false) - : _pool_type(pool_type), _pool_size(Size2D(pool_size, pool_size)), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false) + PadStrideInfo pad_stride_info = PadStrideInfo(), + bool exclude_padding = false, + bool fp_mixed_precision = false) + : _pool_type(pool_type), _pool_size(Size2D(pool_size, pool_size)), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false), + _fp_mixed_precision(fp_mixed_precision) { } /** Default Constructor * - * @param[in] pool_type Pooling type @ref PoolingType. - * @param[in] pool_size Pooling size, in elements, across x and y. - * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo - * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. - * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). - * Defaults to false; + * @param[in] pool_type Pooling type @ref PoolingType. + * @param[in] pool_size Pooling size, in elements, across x and y. + * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo + * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations. + * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area). + * Defaults to false; + * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy. */ explicit PoolingLayerInfo(PoolingType pool_type, Size2D pool_size, - PadStrideInfo pad_stride_info = PadStrideInfo(), - bool exclude_padding = false) - : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false) + PadStrideInfo pad_stride_info = PadStrideInfo(), + bool exclude_padding = false, + bool fp_mixed_precision = false) + : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false), _fp_mixed_precision(fp_mixed_precision) { } /** Default Constructor @@ -1237,7 +1242,7 @@ public: * @param[in] pool_type Pooling type @ref PoolingType. */ explicit PoolingLayerInfo(PoolingType pool_type) - : _pool_type(pool_type), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true) + : _pool_type(pool_type), _pool_size(Size2D()), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true), _fp_mixed_precision(false) { } /** Get the pooling type */ @@ -1260,6 +1265,11 @@ public: { return _exclude_padding; } + /** Check if a wider accumulator should be used. */ + bool fp_mixed_precision() const + { + return _fp_mixed_precision; + } /** Check if is global pooling */ bool is_global_pooling() const { @@ -1272,6 +1282,7 @@ private: PadStrideInfo _pad_stride_info; bool _exclude_padding; bool _is_global_pooling; + bool _fp_mixed_precision; }; /** ROI Pooling Layer Information class */ -- cgit v1.2.1