Cathal Corbett | 9c9d5b9 | 2022-08-17 17:30:16 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include <armnn/Tensor.hpp> |
| 9 | #include <armnn/Types.hpp> |
| 10 | |
| 11 | #include <tosa_generated.h> |
| 12 | |
| 13 | using namespace armnn; |
| 14 | using namespace tosa; |
| 15 | |
| 16 | // Function to return Tosa datatype from input ArmNN datatype. |
| 17 | DType ArmNNToDType(const DataType& type) |
| 18 | { |
| 19 | switch (type) |
| 20 | { |
| 21 | case DataType::Float16: |
Cathal Corbett | 9c9d5b9 | 2022-08-17 17:30:16 +0100 | [diff] [blame] | 22 | case DataType::BFloat16: |
Matthew Sloyan | da824cc | 2022-10-10 12:43:20 +0100 | [diff] [blame^] | 23 | return DType_FP16; |
| 24 | case DataType::Float32: |
| 25 | return DType_FP32; |
Cathal Corbett | 9c9d5b9 | 2022-08-17 17:30:16 +0100 | [diff] [blame] | 26 | case DataType::QAsymmU8: |
| 27 | return DType_UINT8; |
| 28 | case DataType::QSymmS8: |
| 29 | case DataType::QAsymmS8: |
| 30 | return DType_INT8; |
| 31 | case DataType::QSymmS16: |
| 32 | return DType_INT16; |
| 33 | case DataType::Signed32: |
| 34 | return DType_INT32; |
| 35 | case DataType::Signed64: |
| 36 | // No signed 64, only DType_INT48. |
| 37 | return DType_UNKNOWN; |
| 38 | case DataType::Boolean: |
| 39 | return DType_BOOL; |
| 40 | default: |
| 41 | return DType_UNKNOWN; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // Function to return Tosa tensor shape from input ArmNN tensor shape. |
| 46 | std::vector<int32_t> GetTosaTensorShape(const TensorShape& shape) |
| 47 | { |
| 48 | std::vector<int32_t> returnShape; |
| 49 | for (u_int32_t i = 0; i < shape.GetNumDimensions(); i++) |
| 50 | { |
| 51 | returnShape.push_back(static_cast<int32_t>(shape[i])); |
| 52 | } |
| 53 | return returnShape; |
| 54 | } |
| 55 | |
| 56 | // Function to return unique int as a string to ensure uniqueness between all input, output and block names. |
| 57 | static int uniqueTosaMappingID = 0; |
| 58 | std::string GetUniqueTosaMappingID() |
| 59 | { |
| 60 | return std::to_string(++uniqueTosaMappingID); |
| 61 | } |