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