From 0063380ca6e43d04722707c707e610b59e1f8dde Mon Sep 17 00:00:00 2001 From: Michel Iwaniec Date: Thu, 12 Oct 2017 14:14:15 +0100 Subject: IVGCVSW-619: Support for Cl u8 bounded Relu Change-Id: I3c39ecbd36f06d5376c35ed4eb38dd73533ef97e Reviewed-on: http://mpd-gerrit.cambridge.arm.com/93686 Tested-by: Kaizen Reviewed-by: Anthony Barbier --- arm_compute/core/Types.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'arm_compute/core/Types.h') diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h index f52dd12597..e567bac860 100644 --- a/arm_compute/core/Types.h +++ b/arm_compute/core/Types.h @@ -67,6 +67,7 @@ enum class DataType U8, S8, QS8, + QASYMM8, U16, S16, QS16, @@ -90,6 +91,46 @@ constexpr float SCALE_PYRAMID_HALF = 0.5f; /* Constant value used to indicate a ORB scaled pyramid */ constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01; +/** Quantization settings (used for QASYMM8 data type) */ +struct QuantizationInfo +{ + QuantizationInfo() + : scale(0.0f), offset(0) + { + } + + QuantizationInfo(float scale, int offset) + : scale(scale), offset(offset) + { + } + + float scale; /**< scale */ + int offset; /**< offset */ + + /** Quantizes a value using the scale/offset in this QuantizationInfo */ + uint8_t quantize(float value) const + { + ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0"); + int quantized = static_cast(value / scale + offset); + quantized = std::max(0, std::min(quantized, 255)); + return quantized; + } + + /** Dequantizes a value using the scale/offset in this QuantizationInfo */ + float dequantize(uint8_t value) const + { + ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0"); + float dequantized = (value - offset) * scale; + return dequantized; + } + + /** Indicates whether this QuantizationInfo has valid settings or not */ + bool empty() const + { + return scale == 0; + } +}; + struct ValidRegion { ValidRegion() -- cgit v1.2.1