blob: dd2b28a50fd9c79cea572bb57edc719d3bc9da50 [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"
Keith Davis5236e1d2019-11-04 08:58:33 +000010#include "TensorUtils.hpp"
Derek Lambertif30f7d32019-04-09 10:25:02 +010011
Francis Murtagh43aec582019-05-27 12:14:10 +010012#include <boost/assert.hpp>
13
Derek Lambertif30f7d32019-04-09 10:25:02 +010014namespace armnn
15{
16
17template<typename T>
Matthew Benthamc394a6d2019-06-24 12:51:25 +010018inline std::unique_ptr<Decoder<T>> MakeDecoder(const TensorInfo& info, const void* data = nullptr);
Derek Lambertif30f7d32019-04-09 10:25:02 +010019
20template<>
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010021inline std::unique_ptr<Decoder<float>> MakeDecoder(const TensorInfo& info, const void* data)
Derek Lambertif30f7d32019-04-09 10:25:02 +010022{
23 switch(info.GetDataType())
24 {
Keith Davis5236e1d2019-11-04 08:58:33 +000025 case armnn::DataType::QuantizedSymm8PerAxis:
26 {
27 std::pair<unsigned int, std::vector<float>> params = armnnUtils::GetPerAxisParams(info);
28 return std::make_unique<QSymm8PerAxisDecoder>(
29 static_cast<const int8_t*>(data),
30 params.second,
31 params.first);
32 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010033 case DataType::QuantisedAsymm8:
Derek Lambertif30f7d32019-04-09 10:25:02 +010034 {
35 return std::make_unique<QASymm8Decoder>(
36 static_cast<const uint8_t*>(data),
37 info.GetQuantizationScale(),
38 info.GetQuantizationOffset());
39 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010040 case DataType::QuantisedSymm16:
Derek Lambertif30f7d32019-04-09 10:25:02 +010041 {
42 return std::make_unique<QSymm16Decoder>(
43 static_cast<const int16_t*>(data),
44 info.GetQuantizationScale(),
45 info.GetQuantizationOffset());
46 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010047 case DataType::Float16:
Derek Lambertif30f7d32019-04-09 10:25:02 +010048 {
Matthew Jacksone69c3992019-09-09 14:31:21 +010049 return std::make_unique<Float16Decoder>(static_cast<const Half*>(data));
Derek Lambertif30f7d32019-04-09 10:25:02 +010050 }
Matthew Jacksone69c3992019-09-09 14:31:21 +010051 case DataType::Float32:
52 {
53 return std::make_unique<Float32Decoder>(static_cast<const float*>(data));
54 }
55 case DataType::Signed32:
Mike Kelly9b398322019-05-22 17:21:49 +010056 {
Aron Virginas-Tar198ee402019-08-02 18:54:28 +010057 const float scale = info.GetQuantizationScale();
58 if (scale == 0.f)
59 {
60 return std::make_unique<Int32Decoder>(static_cast<const int32_t*>(data));
61 }
62 // NOTE: ScaledInt32Decoder is used for quantized convolution biases
63 return std::make_unique<ScaledInt32Decoder>(static_cast<const int32_t*>(data), scale);
Mike Kelly9b398322019-05-22 17:21:49 +010064 }
Derek Lambertif30f7d32019-04-09 10:25:02 +010065 default:
66 {
Keith Davis5236e1d2019-11-04 08:58:33 +000067 BOOST_ASSERT_MSG(false, "Unsupported Data Type!");
Derek Lambertif30f7d32019-04-09 10:25:02 +010068 break;
69 }
70 }
71 return nullptr;
72}
73
Nattapat Chaimanowongae2c5f02019-04-24 16:19:57 +010074} //namespace armnn