blob: dd2b28a50fd9c79cea572bb57edc719d3bc9da50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
//
// Copyright © 2017 Arm Ltd. All rights reserved.
// SPDX-License-Identifier: MIT
//
#pragma once
#include "BaseIterator.hpp"
#include "FloatingPointConverter.hpp"
#include "TensorUtils.hpp"
#include <boost/assert.hpp>
namespace armnn
{
template<typename T>
inline std::unique_ptr<Decoder<T>> MakeDecoder(const TensorInfo& info, const void* data = nullptr);
template<>
inline std::unique_ptr<Decoder<float>> MakeDecoder(const TensorInfo& info, const void* data)
{
switch(info.GetDataType())
{
case armnn::DataType::QuantizedSymm8PerAxis:
{
std::pair<unsigned int, std::vector<float>> params = armnnUtils::GetPerAxisParams(info);
return std::make_unique<QSymm8PerAxisDecoder>(
static_cast<const int8_t*>(data),
params.second,
params.first);
}
case DataType::QuantisedAsymm8:
{
return std::make_unique<QASymm8Decoder>(
static_cast<const uint8_t*>(data),
info.GetQuantizationScale(),
info.GetQuantizationOffset());
}
case DataType::QuantisedSymm16:
{
return std::make_unique<QSymm16Decoder>(
static_cast<const int16_t*>(data),
info.GetQuantizationScale(),
info.GetQuantizationOffset());
}
case DataType::Float16:
{
return std::make_unique<Float16Decoder>(static_cast<const Half*>(data));
}
case DataType::Float32:
{
return std::make_unique<Float32Decoder>(static_cast<const float*>(data));
}
case DataType::Signed32:
{
const float scale = info.GetQuantizationScale();
if (scale == 0.f)
{
return std::make_unique<Int32Decoder>(static_cast<const int32_t*>(data));
}
// NOTE: ScaledInt32Decoder is used for quantized convolution biases
return std::make_unique<ScaledInt32Decoder>(static_cast<const int32_t*>(data), scale);
}
default:
{
BOOST_ASSERT_MSG(false, "Unsupported Data Type!");
break;
}
}
return nullptr;
}
} //namespace armnn
|