diff options
author | Sadik Armagan <sadik.armagan@arm.com> | 2021-11-17 15:01:00 +0000 |
---|---|---|
committer | Sadik Armagan <sadik.armagan@arm.com> | 2021-11-18 16:43:17 +0000 |
commit | 1342bed114effa8b183ba683189117cd730ab635 (patch) | |
tree | 8561e8eceb6043d74a0c69197de62fcbd3d8dd8e | |
parent | f9de771083f1f32393b0fe5a3bcdedf4c148be15 (diff) | |
download | armnn-1342bed114effa8b183ba683189117cd730ab635.tar.gz |
IVGCVSW-6452 'Move CompatibleTypes.hpp to the armnnUtils library'
* Moved CompatibleTypes.hpp to include folder
* Added implementation file to source CompatibleTypes.cpp
Signed-off-by: Sadik Armagan <sadik.armagan@arm.com>
Change-Id: I94d2bffdb82a0592943f497d4f57972151d9f2db
-rw-r--r-- | Android.mk | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 3 | ||||
-rw-r--r-- | include/armnnUtils/CompatibleTypes.hpp | 16 | ||||
-rw-r--r-- | src/armnnUtils/CompatibleTypes.cpp (renamed from src/armnn/CompatibleTypes.hpp) | 30 | ||||
-rw-r--r-- | src/backends/backendsCommon/TensorHandle.hpp | 22 |
5 files changed, 51 insertions, 21 deletions
diff --git a/Android.mk b/Android.mk index e39a0e8071..c3cb155731 100644 --- a/Android.mk +++ b/Android.mk @@ -144,6 +144,7 @@ LOCAL_SRC_FILES := \ src/armnn/Utils.cpp \ src/armnn/WallClockTimer.cpp \ src/armnn/WorkingMemHandle.cpp \ + src/armnnUtils/CompatibleTypes.cpp \ src/armnnUtils/DataLayoutIndexed.cpp \ src/armnnUtils/DotSerializer.cpp \ src/armnnUtils/FloatingPointConverter.cpp \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 4ea40de109..fde058216b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,7 @@ add_custom_target(AdditionalCMakeFiles SOURCES ${additional_cmake_files}) set(armnnUtils_sources) list(APPEND armnnUtils_sources + include/armnnUtils/CompatibleTypes.hpp include/armnnUtils/DataLayoutIndexed.hpp include/armnnUtils/Permute.hpp include/armnnUtils/Filesystem.hpp @@ -81,6 +82,7 @@ list(APPEND armnnUtils_sources include/armnnUtils/Threads.hpp include/armnnUtils/Transpose.hpp src/armnnUtils/BFloat16.hpp + src/armnnUtils/CompatibleTypes.cpp src/armnnUtils/Filesystem.cpp src/armnnUtils/GraphTopologicalSort.hpp src/armnnUtils/Half.hpp @@ -362,7 +364,6 @@ list(APPEND armnn_sources src/armnn/BackendRegistry.cpp src/armnn/BackendSettings.hpp src/armnn/BackendHelper.cpp - src/armnn/CompatibleTypes.hpp src/armnn/Descriptors.cpp src/armnn/DeviceSpec.hpp src/armnn/DllExport.hpp diff --git a/include/armnnUtils/CompatibleTypes.hpp b/include/armnnUtils/CompatibleTypes.hpp new file mode 100644 index 0000000000..0640fcc428 --- /dev/null +++ b/include/armnnUtils/CompatibleTypes.hpp @@ -0,0 +1,16 @@ +// +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include <armnn/Types.hpp> + +namespace armnnUtils +{ + +template<typename T> +bool CompatibleTypes(armnn::DataType); + +} //namespace armnnUtils diff --git a/src/armnn/CompatibleTypes.hpp b/src/armnnUtils/CompatibleTypes.cpp index e24d5dfc4c..9a3251d293 100644 --- a/src/armnn/CompatibleTypes.hpp +++ b/src/armnnUtils/CompatibleTypes.cpp @@ -1,16 +1,16 @@ // -// Copyright © 2017 Arm Ltd. All rights reserved. +// Copyright © 2021 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // - -#pragma once - #include <armnn/Types.hpp> +#include <armnnUtils/CompatibleTypes.hpp> + +#include "BFloat16.hpp" +#include "Half.hpp" -#include <BFloat16.hpp> -#include <Half.hpp> +using namespace armnn; -namespace armnn +namespace armnnUtils { template<typename T> @@ -20,46 +20,46 @@ bool CompatibleTypes(DataType) } template<> -inline bool CompatibleTypes<float>(DataType dataType) +bool CompatibleTypes<float>(DataType dataType) { return dataType == DataType::Float32; } template<> -inline bool CompatibleTypes<Half>(DataType dataType) +bool CompatibleTypes<Half>(DataType dataType) { return dataType == DataType::Float16; } template<> -inline bool CompatibleTypes<BFloat16>(DataType dataType) +bool CompatibleTypes<BFloat16>(DataType dataType) { return dataType == DataType::BFloat16; } template<> -inline bool CompatibleTypes<uint8_t>(DataType dataType) +bool CompatibleTypes<uint8_t>(DataType dataType) { return dataType == DataType::Boolean || dataType == DataType::QAsymmU8; } template<> -inline bool CompatibleTypes<int8_t>(DataType dataType) +bool CompatibleTypes<int8_t>(DataType dataType) { return dataType == DataType::QSymmS8 || dataType == DataType::QAsymmS8; } template<> -inline bool CompatibleTypes<int16_t>(DataType dataType) +bool CompatibleTypes<int16_t>(DataType dataType) { return dataType == DataType::QSymmS16; } template<> -inline bool CompatibleTypes<int32_t>(DataType dataType) +bool CompatibleTypes<int32_t>(DataType dataType) { return dataType == DataType::Signed32; } -} //namespace armnn +} //namespace armnnUtils diff --git a/src/backends/backendsCommon/TensorHandle.hpp b/src/backends/backendsCommon/TensorHandle.hpp index b898bd11a5..ba1fc16378 100644 --- a/src/backends/backendsCommon/TensorHandle.hpp +++ b/src/backends/backendsCommon/TensorHandle.hpp @@ -10,7 +10,7 @@ #include <armnn/TypesUtils.hpp> -#include <CompatibleTypes.hpp> +#include <armnnUtils/CompatibleTypes.hpp> #include <algorithm> @@ -30,8 +30,14 @@ public: template <typename T> const T* GetConstTensor() const { - ARMNN_ASSERT(CompatibleTypes<T>(GetTensorInfo().GetDataType())); - return reinterpret_cast<const T*>(m_Memory); + if (armnnUtils::CompatibleTypes<T>(GetTensorInfo().GetDataType())) + { + return reinterpret_cast<const T*>(m_Memory); + } + else + { + throw armnn::Exception("Attempting to get not compatible type tensor!"); + } } const TensorInfo& GetTensorInfo() const @@ -79,8 +85,14 @@ public: template <typename T> T* GetTensor() const { - ARMNN_ASSERT(CompatibleTypes<T>(GetTensorInfo().GetDataType())); - return reinterpret_cast<T*>(m_MutableMemory); + if (armnnUtils::CompatibleTypes<T>(GetTensorInfo().GetDataType())) + { + return reinterpret_cast<T*>(m_MutableMemory); + } + else + { + throw armnn::Exception("Attempting to get not compatible type tensor!"); + } } protected: |