From 0c47974f1800e8770904aecaef15d6f105758c4e Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Fri, 10 Dec 2021 12:43:54 +0000 Subject: IVGCVSW-6626 Promote backend headers in backendCommon to armnn/backends Move the following header files from backendsCommon to armnn/backends. * MemCopyWorkload.hpp * TensorHandle.hpp * Workload.hpp * WorkloadData.hpp * WorkloadFactory.hpp Replace them with forwarding headers and a pragma deprecation message. Resolve the deprecation messages in Arm NN code. Signed-off-by: Colm Donelan Change-Id: I47f116b30f86e478c9057795bc518c391a8ae514 --- src/backends/backendsCommon/TensorHandle.hpp | 268 +-------------------------- 1 file changed, 3 insertions(+), 265 deletions(-) (limited to 'src/backends/backendsCommon/TensorHandle.hpp') diff --git a/src/backends/backendsCommon/TensorHandle.hpp b/src/backends/backendsCommon/TensorHandle.hpp index ba1fc16378..99aac0ad5d 100644 --- a/src/backends/backendsCommon/TensorHandle.hpp +++ b/src/backends/backendsCommon/TensorHandle.hpp @@ -3,268 +3,6 @@ // SPDX-License-Identifier: MIT // -#pragma once - -#include -#include - -#include - -#include - -#include - -#include - -namespace armnn -{ - -// Get a TensorShape representing the strides (in bytes) for each dimension -// of a tensor, assuming fully packed data with no padding -TensorShape GetUnpaddedTensorStrides(const TensorInfo& tensorInfo); - -// Abstract tensor handles wrapping a readable region of memory, interpreting it as tensor data. -class ConstTensorHandle : public ITensorHandle -{ -public: - template - const T* GetConstTensor() const - { - if (armnnUtils::CompatibleTypes(GetTensorInfo().GetDataType())) - { - return reinterpret_cast(m_Memory); - } - else - { - throw armnn::Exception("Attempting to get not compatible type tensor!"); - } - } - - const TensorInfo& GetTensorInfo() const - { - return m_TensorInfo; - } - - virtual void Manage() override {} - - virtual ITensorHandle* GetParent() const override { return nullptr; } - - virtual const void* Map(bool /* blocking = true */) const override { return m_Memory; } - virtual void Unmap() const override {} - - TensorShape GetStrides() const override - { - return GetUnpaddedTensorStrides(m_TensorInfo); - } - TensorShape GetShape() const override { return m_TensorInfo.GetShape(); } - -protected: - ConstTensorHandle(const TensorInfo& tensorInfo); - - void SetConstMemory(const void* mem) { m_Memory = mem; } - -private: - // Only used for testing - void CopyOutTo(void *) const override { ARMNN_ASSERT_MSG(false, "Unimplemented"); } - void CopyInFrom(const void*) override { ARMNN_ASSERT_MSG(false, "Unimplemented"); } - - ConstTensorHandle(const ConstTensorHandle& other) = delete; - ConstTensorHandle& operator=(const ConstTensorHandle& other) = delete; - - TensorInfo m_TensorInfo; - const void* m_Memory; -}; - -template<> -const void* ConstTensorHandle::GetConstTensor() const; - -// Abstract specialization of ConstTensorHandle that allows write access to the same data. -class TensorHandle : public ConstTensorHandle -{ -public: - template - T* GetTensor() const - { - if (armnnUtils::CompatibleTypes(GetTensorInfo().GetDataType())) - { - return reinterpret_cast(m_MutableMemory); - } - else - { - throw armnn::Exception("Attempting to get not compatible type tensor!"); - } - } - -protected: - TensorHandle(const TensorInfo& tensorInfo); - - void SetMemory(void* mem) - { - m_MutableMemory = mem; - SetConstMemory(m_MutableMemory); - } - -private: - - TensorHandle(const TensorHandle& other) = delete; - TensorHandle& operator=(const TensorHandle& other) = delete; - void* m_MutableMemory; -}; - -template <> -void* TensorHandle::GetTensor() const; - -// A TensorHandle that owns the wrapped memory region. -class ScopedTensorHandle : public TensorHandle -{ -public: - explicit ScopedTensorHandle(const TensorInfo& tensorInfo); - - // Copies contents from Tensor. - explicit ScopedTensorHandle(const ConstTensor& tensor); - - // Copies contents from ConstTensorHandle - explicit ScopedTensorHandle(const ConstTensorHandle& tensorHandle); - - ScopedTensorHandle(const ScopedTensorHandle& other); - ScopedTensorHandle& operator=(const ScopedTensorHandle& other); - ~ScopedTensorHandle(); - - virtual void Allocate() override; - -private: - // Only used for testing - void CopyOutTo(void* memory) const override; - void CopyInFrom(const void* memory) override; - - void CopyFrom(const ScopedTensorHandle& other); - void CopyFrom(const void* srcMemory, unsigned int numBytes); -}; - -// A TensorHandle that wraps an already allocated memory region. -// -// Clients must make sure the passed in memory region stays alive for the lifetime of -// the PassthroughTensorHandle instance. -// -// Note there is no polymorphism to/from ConstPassthroughTensorHandle. -class PassthroughTensorHandle : public TensorHandle -{ -public: - PassthroughTensorHandle(const TensorInfo& tensorInfo, void* mem) - : TensorHandle(tensorInfo) - { - SetMemory(mem); - } - - virtual void Allocate() override; -}; - -// A ConstTensorHandle that wraps an already allocated memory region. -// -// This allows users to pass in const memory to a network. -// Clients must make sure the passed in memory region stays alive for the lifetime of -// the PassthroughTensorHandle instance. -// -// Note there is no polymorphism to/from PassthroughTensorHandle. -class ConstPassthroughTensorHandle : public ConstTensorHandle -{ -public: - ConstPassthroughTensorHandle(const TensorInfo& tensorInfo, const void* mem) - : ConstTensorHandle(tensorInfo) - { - SetConstMemory(mem); - } - - virtual void Allocate() override; -}; - - -// Template specializations. - -template <> -const void* ConstTensorHandle::GetConstTensor() const; - -template <> -void* TensorHandle::GetTensor() const; - -class ManagedConstTensorHandle -{ - -public: - explicit ManagedConstTensorHandle(std::shared_ptr ptr) - : m_Mapped(false) - , m_TensorHandle(std::move(ptr)) {}; - - /// RAII Managed resource Unmaps MemoryArea once out of scope - const void* Map(bool blocking = true) - { - if (m_TensorHandle) - { - auto pRet = m_TensorHandle->Map(blocking); - m_Mapped = true; - return pRet; - } - else - { - throw armnn::Exception("Attempting to Map null TensorHandle"); - } - - } - - // Delete copy constructor as it's unnecessary - ManagedConstTensorHandle(const ConstTensorHandle& other) = delete; - - // Delete copy assignment as it's unnecessary - ManagedConstTensorHandle& operator=(const ManagedConstTensorHandle& other) = delete; - - // Delete move assignment as it's unnecessary - ManagedConstTensorHandle& operator=(ManagedConstTensorHandle&& other) noexcept = delete; - - ~ManagedConstTensorHandle() - { - // Bias tensor handles need to be initialized empty before entering scope of if statement checking if enabled - if (m_TensorHandle) - { - Unmap(); - } - } - - void Unmap() - { - // Only unmap if mapped and TensorHandle exists. - if (m_Mapped && m_TensorHandle) - { - m_TensorHandle->Unmap(); - m_Mapped = false; - } - } - - const TensorInfo& GetTensorInfo() const - { - return m_TensorHandle->GetTensorInfo(); - } - - bool IsMapped() const - { - return m_Mapped; - } - -private: - bool m_Mapped; - std::shared_ptr m_TensorHandle; -}; - -using ConstCpuTensorHandle ARMNN_DEPRECATED_MSG_REMOVAL_DATE("ConstCpuTensorHandle is deprecated, " - "use ConstTensorHandle instead", "22.05") = ConstTensorHandle; -using CpuTensorHandle ARMNN_DEPRECATED_MSG_REMOVAL_DATE("CpuTensorHandle is deprecated, " - "use TensorHandle instead", "22.05") = TensorHandle; -using ScopedCpuTensorHandle ARMNN_DEPRECATED_MSG_REMOVAL_DATE("ScopedCpuTensorHandle is deprecated, " - "use ScopedTensorHandle instead", "22.05") = ScopedTensorHandle; -using PassthroughCpuTensorHandle ARMNN_DEPRECATED_MSG_REMOVAL_DATE("PassthroughCpuTensorHandle is deprecated, use " - "PassthroughTensorHandle instead", - "22.05") = PassthroughTensorHandle; -using ConstPassthroughCpuTensorHandle ARMNN_DEPRECATED_MSG_REMOVAL_DATE("ConstPassthroughCpuTensorHandle is " - "deprecated, use ConstPassthroughTensorHandle " - "instead", "22.05") = ConstPassthroughTensorHandle; - -} // namespace armnn +#include +#pragma message("src/backends/backendsCommon/TensorHandle.hpp has been deprecated, it is due for removal in"\ + " 22.08 release. Please use public interface include/armnn/backends/TensorHandle.hpp") -- cgit v1.2.1