Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "BaseIterator.hpp" |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 9 | #include "FloatingPointConverter.hpp" |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 10 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 11 | #include <boost/assert.hpp> |
| 12 | |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 13 | namespace armnn |
| 14 | { |
| 15 | |
| 16 | template<typename T> |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 17 | inline std::unique_ptr<Decoder<T>> MakeDecoder(const TensorInfo& info, const void* data = nullptr); |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 18 | |
| 19 | template<> |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 20 | inline std::unique_ptr<Decoder<float>> MakeDecoder(const TensorInfo& info, const void* data) |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 21 | { |
| 22 | switch(info.GetDataType()) |
| 23 | { |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 24 | case DataType::QuantisedAsymm8: |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 25 | { |
| 26 | return std::make_unique<QASymm8Decoder>( |
| 27 | static_cast<const uint8_t*>(data), |
| 28 | info.GetQuantizationScale(), |
| 29 | info.GetQuantizationOffset()); |
| 30 | } |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 31 | case DataType::QuantisedSymm16: |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 32 | { |
| 33 | return std::make_unique<QSymm16Decoder>( |
| 34 | static_cast<const int16_t*>(data), |
| 35 | info.GetQuantizationScale(), |
| 36 | info.GetQuantizationOffset()); |
| 37 | } |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 38 | case DataType::Float16: |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 39 | { |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 40 | return std::make_unique<Float16Decoder>(static_cast<const Half*>(data)); |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 41 | } |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 42 | case DataType::Float32: |
| 43 | { |
| 44 | return std::make_unique<Float32Decoder>(static_cast<const float*>(data)); |
| 45 | } |
| 46 | case DataType::Signed32: |
Mike Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 47 | { |
Aron Virginas-Tar | 198ee40 | 2019-08-02 18:54:28 +0100 | [diff] [blame] | 48 | 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 Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 55 | } |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 56 | default: |
| 57 | { |
| 58 | BOOST_ASSERT_MSG(false, "Not supported Data Type!"); |
| 59 | break; |
| 60 | } |
| 61 | } |
| 62 | return nullptr; |
| 63 | } |
| 64 | |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 65 | } //namespace armnn |