diff options
author | Jim Flynn <jim.flynn@arm.com> | 2019-05-02 11:33:25 +0100 |
---|---|---|
committer | Ruomei Yan <ruomei.yan@arm.com> | 2019-05-08 16:10:59 +0000 |
commit | f92dfced4498f12b9315c0fa377ba7be8998b607 (patch) | |
tree | 4015208a5493ea414babba76c18bc72b6dbef875 /src/armnnUtils/TensorUtils.cpp | |
parent | a4247d5a50502811a6956dffd990c0254622b7e1 (diff) | |
download | armnn-f92dfced4498f12b9315c0fa377ba7be8998b607.tar.gz |
IVGCVSW-2833 Add Dynamic Quantization
Change-Id: Iba91e3f3625639f01d66f81a9f3e419e0e285d66
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Diffstat (limited to 'src/armnnUtils/TensorUtils.cpp')
-rw-r--r-- | src/armnnUtils/TensorUtils.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/armnnUtils/TensorUtils.cpp b/src/armnnUtils/TensorUtils.cpp index 57f823fe13..c2fbbe0bcc 100644 --- a/src/armnnUtils/TensorUtils.cpp +++ b/src/armnnUtils/TensorUtils.cpp @@ -4,6 +4,7 @@ // #include "TensorUtils.hpp" +#include <backendsCommon/ITensorHandle.hpp> namespace armnnUtils { @@ -47,4 +48,31 @@ armnn::TensorInfo GetTensorInfo(unsigned int numberOfBatches, } } +std::pair<float, float> FindMinMax(armnn::ITensorHandle* tensorHandle) +{ + auto tensor_data = static_cast<const float *>(tensorHandle->Map(true)); + auto tensor_size = tensorHandle->GetShape().GetNumElements(); + + // Set min/max initially to first value in tensor + float min = tensor_data[0]; + float max = tensor_data[0]; + + // Loop over rest of tensor and update min/max if necessary + for (unsigned int val = 1; val < tensor_size; val++) + { + if (tensor_data[val] < min) + { + min = tensor_data[val]; + } + else if (tensor_data[val] > max) + { + max = tensor_data[val]; + } + } + + tensorHandle->Unmap(); + + return std::make_pair(min, max); +} + } |