blob: 328a5eb0f7d4c8c2c2d0c945d593a9e416bf334c [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"
Matthew Jacksone69c3992019-09-09 14:31:21 +01009#include "FloatingPointConverter.hpp"
Derek Lambertif30f7d32019-04-09 10:25:02 +010010
Francis Murtagh43aec582019-05-27 12:14:10 +010011#include <boost/assert.hpp>
12
Derek Lambertif30f7d32019-04-09 10:25:02 +010013namespace armnn
14{
15
16template<typename T>
Matthew Benthamc394a6d2019-06-24 12:51:25 +010017inline std::unique_ptr<Decoder<T>> MakeDecoder(const TensorInfo& info, const void* data = nullptr);
Derek Lambertif30f7d32019-04-09 10:25:02 +010018
19template<>
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010020inline std::unique_ptr<Decoder<float>> MakeDecoder(const TensorInfo& info, const void* data)
Derek Lambertif30f7d32019-04-09 10:25:02 +010021{
22 switch(info.GetDataType())
23 {
Matthew Jacksone69c3992019-09-09 14:31:21 +010024 case DataType::QuantisedAsymm8:
Derek Lambertif30f7d32019-04-09 10:25:02 +010025 {
26 return std::make_unique<QASymm8Decoder>(
27 static_cast<const uint8_t*>(data),
28 info.GetQuantizationScale(),
29 info.GetQuantizationOffset());
30 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010031 case DataType::QuantisedSymm16:
Derek Lambertif30f7d32019-04-09 10:25:02 +010032 {
33 return std::make_unique<QSymm16Decoder>(
34 static_cast<const int16_t*>(data),
35 info.GetQuantizationScale(),
36 info.GetQuantizationOffset());
37 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010038 case DataType::Float16:
Derek Lambertif30f7d32019-04-09 10:25:02 +010039 {
Matthew Jacksone69c3992019-09-09 14:31:21 +010040 return std::make_unique<Float16Decoder>(static_cast<const Half*>(data));
Derek Lambertif30f7d32019-04-09 10:25:02 +010041 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010042 case DataType::Float32:
43 {
44 return std::make_unique<Float32Decoder>(static_cast<const float*>(data));
45 }
46 case DataType::Signed32:
Mike Kelly9b398322019-05-22 17:21:49 +010047 {
Aron Virginas-Tar198ee402019-08-02 18:54:28 +010048 const float scale = info.GetQuantizationScale();
49 if (scale == 0.f)
50 {
51 return std::make_unique<Int32Decoder>(static_cast<const int32_t*>(data));
52 }
53 // NOTE: ScaledInt32Decoder is used for quantized convolution biases
54 return std::make_unique<ScaledInt32Decoder>(static_cast<const int32_t*>(data), scale);
Mike Kelly9b398322019-05-22 17:21:49 +010055 }
Derek Lambertif30f7d32019-04-09 10:25:02 +010056 default:
57 {
58 BOOST_ASSERT_MSG(false, "Not supported Data Type!");
59 break;
60 }
61 }
62 return nullptr;
63}
64
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010065} //namespace armnn