blob: 75473b4ae628ab5d4f1365ee3007ba6cea115c7b [file] [log] [blame]
Matteo Martincigha8d572d2019-02-07 17:51:09 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "NetworkQuantizerUtils.hpp"
7
8#include <algorithm>
9#include <cmath>
10#include <stdint.h>
11
12namespace armnn
13{
14
Matteo Martincigha8d572d2019-02-07 17:51:09 +000015ConstTensor CreateQuantizedConst(const ConstTensor& tensor, std::vector<uint8_t>& backing)
16{
17 float scale = 0.0f;
18 int offset = 0;
19
20 // Reserve the backing memory
21 backing.resize(tensor.GetInfo().GetNumElements());
22
23 DataType type = tensor.GetInfo().GetDataType();
24 switch(type)
25 {
26 case DataType::Float32:
27 {
Nattapat Chaimanowong7ac07f32019-03-20 11:51:14 +000028 QuantizeConstant(static_cast<const float*>(tensor.GetMemoryArea()),
29 backing.data(),
30 backing.size(),
31 scale,
32 offset);
Matteo Martincigha8d572d2019-02-07 17:51:09 +000033 }
34 break;
35 default:
36 BOOST_ASSERT_MSG(false, "Can't quantize unsupported data type");
37 }
38
Derek Lambertif90c56d2020-01-10 17:14:08 +000039 TensorInfo qInfo(tensor.GetInfo().GetShape(), DataType::QAsymmU8, scale, offset);
Matteo Martincigha8d572d2019-02-07 17:51:09 +000040 return ConstTensor(qInfo, backing);
41}
42
43} // namespace armnn