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" |
Matteo Martincigh | e011d20 | 2019-11-28 11:35:47 +0000 | [diff] [blame] | 9 | |
| 10 | #include <armnnUtils/TensorUtils.hpp> |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 11 | |
Matteo Martincigh | 3122bd5 | 2019-06-03 16:54:25 +0100 | [diff] [blame] | 12 | #include <boost/assert.hpp> |
| 13 | |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | template<typename T> |
Matthew Bentham | c394a6d | 2019-06-24 12:51:25 +0100 | [diff] [blame] | 18 | inline std::unique_ptr<Encoder<T>> MakeEncoder(const TensorInfo& info, void* data = nullptr); |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 19 | |
| 20 | template<> |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 21 | inline std::unique_ptr<Encoder<float>> MakeEncoder(const TensorInfo& info, void* data) |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 22 | { |
| 23 | switch(info.GetDataType()) |
| 24 | { |
Keith Davis | 5236e1d | 2019-11-04 08:58:33 +0000 | [diff] [blame] | 25 | case armnn::DataType::QuantizedSymm8PerAxis: |
| 26 | { |
| 27 | std::pair<unsigned int, std::vector<float>> params = armnnUtils::GetPerAxisParams(info); |
| 28 | return std::make_unique<QSymm8PerAxisEncoder>( |
| 29 | static_cast<int8_t*>(data), |
| 30 | params.second, |
| 31 | params.first); |
| 32 | } |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 33 | case armnn::DataType::QuantisedAsymm8: |
| 34 | { |
| 35 | return std::make_unique<QASymm8Encoder>( |
| 36 | static_cast<uint8_t*>(data), |
| 37 | info.GetQuantizationScale(), |
| 38 | info.GetQuantizationOffset()); |
| 39 | } |
| 40 | case armnn::DataType::QuantisedSymm16: |
| 41 | { |
| 42 | return std::make_unique<QSymm16Encoder>( |
| 43 | static_cast<int16_t*>(data), |
| 44 | info.GetQuantizationScale(), |
| 45 | info.GetQuantizationOffset()); |
| 46 | } |
Aron Virginas-Tar | 198ee40 | 2019-08-02 18:54:28 +0100 | [diff] [blame] | 47 | case armnn::DataType::Signed32: |
| 48 | { |
| 49 | return std::make_unique<Int32Encoder>(static_cast<int32_t*>(data)); |
| 50 | } |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 51 | case armnn::DataType::Float16: |
| 52 | { |
| 53 | return std::make_unique<Float16Encoder>(static_cast<Half*>(data)); |
| 54 | } |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 55 | case armnn::DataType::Float32: |
| 56 | { |
Matthew Jackson | e69c399 | 2019-09-09 14:31:21 +0100 | [diff] [blame] | 57 | return std::make_unique<Float32Encoder>(static_cast<float*>(data)); |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 58 | } |
| 59 | default: |
| 60 | { |
Keith Davis | 5236e1d | 2019-11-04 08:58:33 +0000 | [diff] [blame] | 61 | BOOST_ASSERT_MSG(false, "Unsupported target Data Type!"); |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 62 | break; |
| 63 | } |
| 64 | } |
| 65 | return nullptr; |
| 66 | } |
| 67 | |
| 68 | template<> |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 69 | inline std::unique_ptr<Encoder<bool>> MakeEncoder(const TensorInfo& info, void* data) |
Derek Lamberti | f30f7d3 | 2019-04-09 10:25:02 +0100 | [diff] [blame] | 70 | { |
| 71 | switch(info.GetDataType()) |
| 72 | { |
| 73 | case armnn::DataType::Boolean: |
| 74 | { |
| 75 | return std::make_unique<BooleanEncoder>(static_cast<uint8_t*>(data)); |
| 76 | } |
| 77 | default: |
| 78 | { |
| 79 | BOOST_ASSERT_MSG(false, "Cannot encode from boolean. Not supported target Data Type!"); |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | return nullptr; |
| 84 | } |
| 85 | |
Nattapat Chaimanowong | ae2c5f0 | 2019-04-24 16:19:57 +0100 | [diff] [blame] | 86 | } //namespace armnn |