aboutsummaryrefslogtreecommitdiff
path: root/src/backends/backendsCommon/CpuTensorHandle.cpp
diff options
context:
space:
mode:
authorJames Conroy <james.conroy@arm.com>2021-04-27 17:13:27 +0100
committerNarumol Prangnawarat <narumol.prangnawarat@arm.com>2021-05-06 14:40:40 +0000
commit1f58f03d82c482626b1b4673b6c0e25da4338fb5 (patch)
treee92451e00d459a2fc0d870694460f482aa4c77ae /src/backends/backendsCommon/CpuTensorHandle.cpp
parenta7a12f5c3654da554ad6197beff0f0fc54681c92 (diff)
downloadarmnn-1f58f03d82c482626b1b4673b6c0e25da4338fb5.tar.gz
IVGCVSW-5815 Generalise ConstCpuTensorHandle
* Generalises ConstCpuTensorHandle and inherited classes by removing 'Cpu' from aliases. * New renamed classes: ConstTensorHandle, TensorHandle, ScopedTensorHandle, PassthroughTensorHandle, ConstPassthroughTensorHandle. Signed-off-by: James Conroy <james.conroy@arm.com> Change-Id: I1824e0e134202735fb77051f20a7252f161dfe16
Diffstat (limited to 'src/backends/backendsCommon/CpuTensorHandle.cpp')
-rw-r--r--src/backends/backendsCommon/CpuTensorHandle.cpp141
1 files changed, 0 insertions, 141 deletions
diff --git a/src/backends/backendsCommon/CpuTensorHandle.cpp b/src/backends/backendsCommon/CpuTensorHandle.cpp
deleted file mode 100644
index 192469a633..0000000000
--- a/src/backends/backendsCommon/CpuTensorHandle.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-//
-// Copyright © 2017 Arm Ltd. All rights reserved.
-// SPDX-License-Identifier: MIT
-//
-#include <armnn/Exceptions.hpp>
-#include <armnn/utility/IgnoreUnused.hpp>
-
-#include <backendsCommon/CpuTensorHandle.hpp>
-
-#include <cstring>
-
-namespace armnn
-{
-
-TensorShape GetUnpaddedTensorStrides(const TensorInfo& tensorInfo)
-{
- TensorShape shape(tensorInfo.GetShape());
- auto size = GetDataTypeSize(tensorInfo.GetDataType());
- auto runningSize = size;
- std::vector<unsigned int> strides(shape.GetNumDimensions());
- auto lastIdx = shape.GetNumDimensions()-1;
- for (unsigned int i=0; i < lastIdx ; i++)
- {
- strides[lastIdx-i] = runningSize;
- runningSize *= shape[lastIdx-i];
- }
- strides[0] = runningSize;
- return TensorShape(shape.GetNumDimensions(), strides.data());
-}
-
-ConstCpuTensorHandle::ConstCpuTensorHandle(const TensorInfo& tensorInfo)
-: m_TensorInfo(tensorInfo)
-, m_Memory(nullptr)
-{
-}
-
-template <>
-const void* ConstCpuTensorHandle::GetConstTensor<void>() const
-{
- return m_Memory;
-}
-
-CpuTensorHandle::CpuTensorHandle(const TensorInfo& tensorInfo)
-: ConstCpuTensorHandle(tensorInfo)
-, m_MutableMemory(nullptr)
-{
-}
-
-template <>
-void* CpuTensorHandle::GetTensor<void>() const
-{
- return m_MutableMemory;
-}
-
-ScopedCpuTensorHandle::ScopedCpuTensorHandle(const TensorInfo& tensorInfo)
-: CpuTensorHandle(tensorInfo)
-{
-}
-
-ScopedCpuTensorHandle::ScopedCpuTensorHandle(const ConstTensor& tensor)
-: ScopedCpuTensorHandle(tensor.GetInfo())
-{
- CopyFrom(tensor.GetMemoryArea(), tensor.GetNumBytes());
-}
-
-ScopedCpuTensorHandle::ScopedCpuTensorHandle(const ConstCpuTensorHandle& tensorHandle)
-: ScopedCpuTensorHandle(tensorHandle.GetTensorInfo())
-{
- CopyFrom(tensorHandle.GetConstTensor<void>(), tensorHandle.GetTensorInfo().GetNumBytes());
-}
-
-ScopedCpuTensorHandle::ScopedCpuTensorHandle(const ScopedCpuTensorHandle& other)
-: CpuTensorHandle(other.GetTensorInfo())
-{
- CopyFrom(other);
-}
-
-ScopedCpuTensorHandle& ScopedCpuTensorHandle::operator=(const ScopedCpuTensorHandle& other)
-{
- ::operator delete(GetTensor<void>());
- SetMemory(nullptr);
- CopyFrom(other);
- return *this;
-}
-
-ScopedCpuTensorHandle::~ScopedCpuTensorHandle()
-{
- ::operator delete(GetTensor<void>());
-}
-
-void ScopedCpuTensorHandle::Allocate()
-{
- if (GetTensor<void>() == nullptr)
- {
- SetMemory(::operator new(GetTensorInfo().GetNumBytes()));
- }
- else
- {
- throw InvalidArgumentException("CpuTensorHandle::Allocate Trying to allocate a CpuTensorHandle"
- "that already has allocated memory.");
- }
-}
-
-void ScopedCpuTensorHandle::CopyOutTo(void* memory) const
-{
- memcpy(memory, GetTensor<void>(), GetTensorInfo().GetNumBytes());
-}
-
-void ScopedCpuTensorHandle::CopyInFrom(const void* memory)
-{
- memcpy(GetTensor<void>(), memory, GetTensorInfo().GetNumBytes());
-}
-
-void ScopedCpuTensorHandle::CopyFrom(const ScopedCpuTensorHandle& other)
-{
- CopyFrom(other.GetTensor<void>(), other.GetTensorInfo().GetNumBytes());
-}
-
-void ScopedCpuTensorHandle::CopyFrom(const void* srcMemory, unsigned int numBytes)
-{
- ARMNN_ASSERT(GetTensor<void>() == nullptr);
- ARMNN_ASSERT(GetTensorInfo().GetNumBytes() == numBytes);
-
- if (srcMemory)
- {
- Allocate();
- memcpy(GetTensor<void>(), srcMemory, numBytes);
- }
-}
-
-void PassthroughCpuTensorHandle::Allocate()
-{
- throw InvalidArgumentException("PassthroughCpuTensorHandle::Allocate() should never be called");
-}
-
-void ConstPassthroughCpuTensorHandle::Allocate()
-{
- throw InvalidArgumentException("ConstPassthroughCpuTensorHandle::Allocate() should never be called");
-}
-
-} // namespace armnn