IVGCVSW-3307 Introduce RefTensorHandle
Use it for intermediate tensors on reference backend.
Lays the groundwork for memory management in the reference backend.
Change-Id: I7d3ee132cac31bde70ae6e1b815f4f0b03d550a6
Signed-off-by: Matthew Bentham <Matthew.Bentham@arm.com>
diff --git a/src/backends/reference/RefTensorHandle.cpp b/src/backends/reference/RefTensorHandle.cpp
new file mode 100644
index 0000000..b7670f6
--- /dev/null
+++ b/src/backends/reference/RefTensorHandle.cpp
@@ -0,0 +1,45 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+#include "RefTensorHandle.hpp"
+
+namespace armnn
+{
+
+RefTensorHandle::RefTensorHandle(const TensorInfo &tensorInfo):
+ m_TensorInfo(tensorInfo),
+ m_Memory(nullptr)
+{
+
+}
+
+RefTensorHandle::~RefTensorHandle()
+{
+ ::operator delete(m_Memory);
+}
+
+void RefTensorHandle::Allocate()
+{
+ if (m_Memory == nullptr)
+ {
+ m_Memory = ::operator new(m_TensorInfo.GetNumBytes());
+ }
+ else
+ {
+ throw InvalidArgumentException("RefTensorHandle::Allocate Trying to allocate a RefTensorHandle"
+ "that already has allocated memory.");
+ }
+}
+
+void RefTensorHandle::CopyOutTo(void* memory) const
+{
+ memcpy(memory, m_Memory, m_TensorInfo.GetNumBytes());
+}
+
+void RefTensorHandle::CopyInFrom(const void* memory)
+{
+ memcpy(m_Memory, memory, m_TensorInfo.GetNumBytes());
+}
+
+}
\ No newline at end of file