aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core
diff options
context:
space:
mode:
authorJaroslaw Rzepecki <jaroslaw.rzepecki@arm.com>2017-11-22 17:16:39 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:42:17 +0000
commit0a878ae1bbb13002e50f8287721750d2e4b22680 (patch)
treeb0e18e7df45e01f9440208ecaa06fe6845d02155 /arm_compute/core
parent8795ffb03c1bb84a0d93e4ece153ceaa86118594 (diff)
downloadComputeLibrary-0a878ae1bbb13002e50f8287721750d2e4b22680.tar.gz
COMPMID-556: Added a rounding policy to the quantize function
Change-Id: I6272a36636c5d9baff6d35dee0a50dc847f65bfa Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/110266 Tested-by: BSG Visual Compute Jenkins server to access repositories on http://mpd-gerrit.cambridge.arm.com <bsgcomp@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute/core')
-rw-r--r--arm_compute/core/Types.h23
-rw-r--r--arm_compute/core/Utils.h9
2 files changed, 22 insertions, 10 deletions
diff --git a/arm_compute/core/Types.h b/arm_compute/core/Types.h
index 36ec38ff68..c77f1d4157 100644
--- a/arm_compute/core/Types.h
+++ b/arm_compute/core/Types.h
@@ -102,6 +102,17 @@ constexpr float SCALE_PYRAMID_HALF = 0.5f;
/* Constant value used to indicate a ORB scaled pyramid */
constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
+/** Rounding method */
+enum class RoundingPolicy
+{
+ TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
+ TO_NEAREST_UP, /**< Rounds to nearest value; half rounds away from zero */
+ TO_NEAREST_EVEN, /**< Rounds to nearest value; half rounds to nearest even */
+};
+
+//forward declare round function
+int round(float, RoundingPolicy);
+
/** Quantization settings (used for QASYMM8 data type) */
struct QuantizationInfo
{
@@ -129,10 +140,10 @@ struct QuantizationInfo
int offset; /**< offset */
/** Quantizes a value using the scale/offset in this QuantizationInfo */
- uint8_t quantize(float value) const
+ uint8_t quantize(float value, RoundingPolicy rounding_policy) const
{
ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
- int quantized = static_cast<int>(value / scale + offset);
+ int quantized = arm_compute::round(value / scale, rounding_policy) + offset;
quantized = std::max(0, std::min(quantized, 255));
return quantized;
}
@@ -296,14 +307,6 @@ enum class ThresholdType
RANGE /**< Threshold with two values*/
};
-/** Rounding method */
-enum class RoundingPolicy
-{
- TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
- TO_NEAREST_UP, /**< Rounds to nearest value; half rounds up */
- TO_NEAREST_EVEN /**< Rounds to nearest value; half rounds to nearest even */
-};
-
/** Termination criteria */
enum class Termination
{
diff --git a/arm_compute/core/Utils.h b/arm_compute/core/Utils.h
index af9cf23548..9397d507f8 100644
--- a/arm_compute/core/Utils.h
+++ b/arm_compute/core/Utils.h
@@ -62,6 +62,15 @@ constexpr auto DIV_CEIL(S val, T m) -> decltype((val + m - 1) / m)
return (val + m - 1) / m;
}
+/** Return a rounded value of x. Rounding is done according to the rounding_policy.
+ *
+ * @param[in] x Float value to be rounded.
+ * @param[in] rounding_policy Policy determining how rounding is done.
+ *
+ * @return Rounded value of the argument x.
+ */
+int round(float x, RoundingPolicy rounding_policy);
+
/** Returns the arm_compute library build information
*
* Contains the version number and the build options used to build the library