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" |
| 9 | |
Francis Murtagh | 43aec58 | 2019-05-27 12:14:10 +0100 | [diff] [blame] | 10 | #include <boost/assert.hpp> |
| 11 | |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 12 | namespace armnn |
| 13 | { |
| 14 | |
| 15 | template<typename T> |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 16 | 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] | 17 | |
| 18 | template<> |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 19 | 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] | 20 | { |
| 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 Kelly | 9b39832 | 2019-05-22 17:21:49 +0100 | [diff] [blame] | 41 | case armnn::DataType::Signed32: |
| 42 | { |
| 43 | return std::make_unique<ScaledInt32Decoder>( |
| 44 | static_cast<const int32_t*>(data), |
| 45 | info.GetQuantizationScale()); |
| 46 | } |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 47 | default: |
| 48 | { |
| 49 | BOOST_ASSERT_MSG(false, "Not supported Data Type!"); |
| 50 | break; |
| 51 | } |
| 52 | } |
| 53 | return nullptr; |
| 54 | } |
| 55 | |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 56 | } //namespace armnn |