aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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 'src')
-rw-r--r--src/core/CL/kernels/CLActivationLayerKernel.cpp4
-rw-r--r--src/core/Utils.cpp34
-rw-r--r--src/runtime/CL/functions/CLPoolingLayer.cpp2
3 files changed, 37 insertions, 3 deletions
diff --git a/src/core/CL/kernels/CLActivationLayerKernel.cpp b/src/core/CL/kernels/CLActivationLayerKernel.cpp
index 0f7003a38c..8172aafca9 100644
--- a/src/core/CL/kernels/CLActivationLayerKernel.cpp
+++ b/src/core/CL/kernels/CLActivationLayerKernel.cpp
@@ -131,8 +131,8 @@ void CLActivationLayerKernel::configure(ICLTensor *input, ICLTensor *output, Act
}
else
{
- a_const_int = input->info()->quantization_info().quantize(a_const);
- b_const_int = input->info()->quantization_info().quantize(b_const);
+ a_const_int = input->info()->quantization_info().quantize(a_const, RoundingPolicy::TO_NEAREST_UP);
+ b_const_int = input->info()->quantization_info().quantize(b_const, RoundingPolicy::TO_NEAREST_UP);
}
}
diff --git a/src/core/Utils.cpp b/src/core/Utils.cpp
index af864f57f7..af50bbbaf7 100644
--- a/src/core/Utils.cpp
+++ b/src/core/Utils.cpp
@@ -21,10 +21,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
+
#include "arm_compute/core/Utils.h"
#include "arm_compute/core/FixedPoint.h"
+#include "support/ToolchainSupport.h"
+
#include <algorithm>
#include <cmath>
#include <cstdint>
@@ -387,3 +390,34 @@ int arm_compute::max_consecutive_elements_display_width(std::ostream &s, DataTyp
}
return 0;
}
+
+int arm_compute::round(float x, RoundingPolicy rounding_policy)
+{
+ using namespace std;
+ int rounded = 0;
+ switch(rounding_policy)
+ {
+ case RoundingPolicy::TO_ZERO:
+ {
+ rounded = static_cast<int>(x);
+ break;
+ }
+ case RoundingPolicy::TO_NEAREST_UP:
+ {
+ rounded = static_cast<int>(support::cpp11::round(x));
+ break;
+ }
+ case RoundingPolicy::TO_NEAREST_EVEN:
+ {
+ ARM_COMPUTE_ERROR("TO_NEAREST_EVEN rounding policy is not supported.");
+ break;
+ }
+ default:
+ {
+ ARM_COMPUTE_ERROR("Unsupported rounding policy.");
+ break;
+ }
+ }
+
+ return rounded;
+}
diff --git a/src/runtime/CL/functions/CLPoolingLayer.cpp b/src/runtime/CL/functions/CLPoolingLayer.cpp
index ac360fbb3d..20564f6c9d 100644
--- a/src/runtime/CL/functions/CLPoolingLayer.cpp
+++ b/src/runtime/CL/functions/CLPoolingLayer.cpp
@@ -46,7 +46,7 @@ void CLPoolingLayer::configure(ICLTensor *input, ICLTensor *output, const Poolin
uint32_t border_value = 0;
if(is_data_type_quantized_asymmetric(input->info()->data_type()) && !pool_info.exclude_padding())
{
- border_value = static_cast<uint32_t>(input->info()->quantization_info().quantize(0));
+ border_value = static_cast<uint32_t>(input->info()->quantization_info().quantize(0.f, RoundingPolicy::TO_NEAREST_UP));
}
_border_handler.configure(input, _kernel->border_size(), border_mode, PixelValue(border_value));