blob: 0101789bec23d0e05908d1acffe84675ec3cf48e [file] [log] [blame]
Derek Lambertif30f7d32019-04-09 10:25:02 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
8#include "BaseIterator.hpp"
9
Francis Murtagh43aec582019-05-27 12:14:10 +010010#include <boost/assert.hpp>
11
Derek Lambertif30f7d32019-04-09 10:25:02 +010012namespace armnn
13{
14
15template<typename T>
Matthew Benthamc394a6d2019-06-24 12:51:25 +010016inline std::unique_ptr<Decoder<T>> MakeDecoder(const TensorInfo& info, const void* data = nullptr);
Derek Lambertif30f7d32019-04-09 10:25:02 +010017
18template<>
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010019inline std::unique_ptr<Decoder<float>> MakeDecoder(const TensorInfo& info, const void* data)
Derek Lambertif30f7d32019-04-09 10:25:02 +010020{
21 switch(info.GetDataType())
22 {
23 case armnn::DataType::QuantisedAsymm8:
24 {
25 return std::make_unique<QASymm8Decoder>(
26 static_cast<const uint8_t*>(data),
27 info.GetQuantizationScale(),
28 info.GetQuantizationOffset());
29 }
30 case armnn::DataType::QuantisedSymm16:
31 {
32 return std::make_unique<QSymm16Decoder>(
33 static_cast<const int16_t*>(data),
34 info.GetQuantizationScale(),
35 info.GetQuantizationOffset());
36 }
37 case armnn::DataType::Float32:
38 {
39 return std::make_unique<FloatDecoder>(static_cast<const float*>(data));
40 }
Mike Kelly9b398322019-05-22 17:21:49 +010041 case armnn::DataType::Signed32:
42 {
Aron Virginas-Tar198ee402019-08-02 18:54:28 +010043 const float scale = info.GetQuantizationScale();
44 if (scale == 0.f)
45 {
46 return std::make_unique<Int32Decoder>(static_cast<const int32_t*>(data));
47 }
48 // NOTE: ScaledInt32Decoder is used for quantized convolution biases
49 return std::make_unique<ScaledInt32Decoder>(static_cast<const int32_t*>(data), scale);
Mike Kelly9b398322019-05-22 17:21:49 +010050 }
Derek Lambertif30f7d32019-04-09 10:25:02 +010051 default:
52 {
53 BOOST_ASSERT_MSG(false, "Not supported Data Type!");
54 break;
55 }
56 }
57 return nullptr;
58}
59
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010060} //namespace armnn