From 05078ec491da8f282f4597b4cf1fe79cc16f4b22 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 2 Nov 2017 13:06:59 +0000 Subject: COMPMID-556: Rework CLActivationLayer Refactoring. Change-Id: I879353299b655ec3026cccdfcfca2ee98abf14ea Reviewed-on: http://mpd-gerrit.cambridge.arm.com/94191 Reviewed-by: Michel Iwaniec Tested-by: Kaizen Reviewed-by: Anthony Barbier --- arm_compute/core/Helpers.h | 20 +++++++++++++++++++- arm_compute/core/Helpers.inl | 19 ++++++++++++++++++- arm_compute/core/Utils.h | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) (limited to 'arm_compute') diff --git a/arm_compute/core/Helpers.h b/arm_compute/core/Helpers.h index 6e4d987180..edb05e99a1 100644 --- a/arm_compute/core/Helpers.h +++ b/arm_compute/core/Helpers.h @@ -466,10 +466,15 @@ inline Strides compute_strides(const ITensorInfo &info) * @param[in] num_channels New number of channels. * @param[in] data_type New data type * @param[in] fixed_point_position New fixed point position + * @param[in] quantization_info (Optional) New quantization info * * @return True if the tensor info has been initialized */ -bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, int fixed_point_position); +bool auto_init_if_empty(ITensorInfo &info, + const TensorShape &shape, + int num_channels, DataType data_type, + int fixed_point_position, + QuantizationInfo quantization_info = QuantizationInfo()); /* Set the shape to the specified value if the current assignment is empty. * @@ -509,6 +514,17 @@ bool set_data_type_if_unknown(ITensorInfo &info, DataType data_type); * @return True if the fixed point position has been changed. */ bool set_fixed_point_position_if_zero(ITensorInfo &info, int fixed_point_position); + +/* Set the quantization info to the specified value if + * the current quantization info is empty and the data type of asymmetric quantized type + * + * @param[in,out] info Tensor info used to check and assign. + * @param[in] quantization_info Quantization info + * + * @return True if the quantization info has been changed. + */ +bool set_quantization_info_if_empty(ITensorInfo &info, QuantizationInfo quantization_info); + /** Helper function to calculate the Valid Region for Scale. * * @param[in] src_info Input tensor info used to check. @@ -520,6 +536,7 @@ bool set_fixed_point_position_if_zero(ITensorInfo &info, int fixed_point_positio * @return The corrispondent valid region */ ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const TensorShape &dst_shape, InterpolationPolicy policy, BorderSize border_size, bool border_undefined); + /** Convert a linear index into n-dimensional coordinates. * * @param[in] shape Shape of the n-dimensional tensor. @@ -528,6 +545,7 @@ ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const Tens * @return n-dimensional coordinates. */ inline Coordinates index2coords(const TensorShape &shape, int index); + /** Convert n-dimensional coordinates into a linear index. * * @param[in] shape Shape of the n-dimensional tensor. diff --git a/arm_compute/core/Helpers.inl b/arm_compute/core/Helpers.inl index de6c85ec76..1a27684c9c 100644 --- a/arm_compute/core/Helpers.inl +++ b/arm_compute/core/Helpers.inl @@ -197,7 +197,12 @@ inline void Iterator::reset(const size_t dimension) } } -inline bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, int fixed_point_position) +inline bool auto_init_if_empty(ITensorInfo &info, + const TensorShape &shape, + int num_channels, + DataType data_type, + int fixed_point_position, + QuantizationInfo quantization_info) { if(info.tensor_shape().total_size() == 0) { @@ -205,6 +210,7 @@ inline bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int info.set_num_channels(num_channels); info.set_tensor_shape(shape); info.set_fixed_point_position(fixed_point_position); + info.set_quantization_info(quantization_info); return true; } @@ -255,6 +261,17 @@ inline bool set_fixed_point_position_if_zero(ITensorInfo &info, int fixed_point_ return false; } +inline bool set_quantization_info_if_empty(ITensorInfo &info, QuantizationInfo quantization_info) +{ + if(info.quantization_info().empty() && (is_data_type_assymetric(info.data_type()))) + { + info.set_quantization_info(quantization_info); + return true; + } + + return false; +} + inline ValidRegion calculate_valid_region_scale(const ITensorInfo &src_info, const TensorShape &dst_shape, InterpolationPolicy policy, BorderSize border_size, bool border_undefined) { const auto wr = static_cast(dst_shape[0]) / static_cast(src_info.tensor_shape()[0]); diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h index 149e404f5b..8e15a0a988 100644 --- a/arm_compute/core/Utils.h +++ b/arm_compute/core/Utils.h @@ -708,6 +708,28 @@ inline bool is_data_type_float(DataType dt) } } +/** Check if a given data type is of quantized type + * + * @note Quantized is considered a super-set of fixed-point and asymmetric data types. + * + * @param[in] dt Input data type. + * + * @return True if data type is of quantized type, else false. + */ +inline bool is_data_type_quantized(DataType dt) +{ + switch(dt) + { + case DataType::QS8: + case DataType::QASYMM8: + case DataType::QS16: + case DataType::QS32: + return true; + default: + return false; + } +} + /** Check if a given data type is of fixed point type * * @param[in] dt Input data type. @@ -727,6 +749,23 @@ inline bool is_data_type_fixed_point(DataType dt) } } +/** Check if a given data type is of asymmetric quantized type + * + * @param[in] dt Input data type. + * + * @return True if data type is of symmetric quantized type, else false. + */ +inline bool is_data_type_assymetric(DataType dt) +{ + switch(dt) + { + case DataType::QASYMM8: + return true; + default: + return false; + } +} + /** Create a string with the float in full precision. * * @param val Floating point value -- cgit v1.2.1