From 4cefc4135f7fbf5c2ba532a4f5b14d2811f9ed9e Mon Sep 17 00:00:00 2001 From: Matthew Bentham Date: Tue, 18 Jun 2019 16:14:34 +0100 Subject: 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 --- .../reference/workloads/RefWorkloadUtils.hpp | 64 ++++------------------ 1 file changed, 10 insertions(+), 54 deletions(-) (limited to 'src/backends/reference/workloads/RefWorkloadUtils.hpp') diff --git a/src/backends/reference/workloads/RefWorkloadUtils.hpp b/src/backends/reference/workloads/RefWorkloadUtils.hpp index ce796160f2..c3260c8142 100644 --- a/src/backends/reference/workloads/RefWorkloadUtils.hpp +++ b/src/backends/reference/workloads/RefWorkloadUtils.hpp @@ -9,8 +9,10 @@ #include #include -#include +#include + +#include #include namespace armnn @@ -22,41 +24,24 @@ namespace armnn inline const TensorInfo& GetTensorInfo(const ITensorHandle* tensorHandle) { - // We know that reference workloads use CpuTensorHandles only, so this cast is legitimate. - const ConstCpuTensorHandle* cpuTensorHandle = - boost::polymorphic_downcast(tensorHandle); - return cpuTensorHandle->GetTensorInfo(); -} - -template -inline const DataType* GetConstCpuData(const ITensorHandle* tensorHandle) -{ - // We know that reference workloads use (Const)CpuTensorHandles only, so this cast is legitimate. - const ConstCpuTensorHandle* cpuTensorHandle = - boost::polymorphic_downcast(tensorHandle); - return cpuTensorHandle->GetConstTensor(); + // We know that reference workloads use RefTensorHandles for inputs and outputs + const RefTensorHandle* refTensorHandle = + boost::polymorphic_downcast(tensorHandle); + return refTensorHandle->GetTensorInfo(); } -template -inline DataType* GetCpuData(const ITensorHandle* tensorHandle) -{ - // We know that reference workloads use CpuTensorHandles only, so this cast is legitimate. - const CpuTensorHandle* cpuTensorHandle = boost::polymorphic_downcast(tensorHandle); - return cpuTensorHandle->GetTensor(); -}; - template const DataType* GetInputTensorData(unsigned int idx, const PayloadType& data) { const ITensorHandle* tensorHandle = data.m_Inputs[idx]; - return GetConstCpuData(tensorHandle); + return reinterpret_cast(tensorHandle->Map()); } template DataType* GetOutputTensorData(unsigned int idx, const PayloadType& data) { - const ITensorHandle* tensorHandle = data.m_Outputs[idx]; - return GetCpuData(tensorHandle); + ITensorHandle* tensorHandle = data.m_Outputs[idx]; + return reinterpret_cast(tensorHandle->Map()); } template @@ -87,35 +72,6 @@ Half* GetOutputTensorDataHalf(unsigned int idx, const PayloadType& data) /// u8 helpers //////////////////////////////////////////// -inline const uint8_t* GetConstCpuU8Data(const ITensorHandle* tensorHandle) -{ - // We know that reference workloads use (Const)CpuTensorHandles only, so this cast is legitimate. - const ConstCpuTensorHandle* cpuTensorHandle = - boost::polymorphic_downcast(tensorHandle); - return cpuTensorHandle->GetConstTensor(); -}; - -inline uint8_t* GetCpuU8Data(const ITensorHandle* tensorHandle) -{ - // We know that reference workloads use CpuTensorHandles only, so this cast is legitimate. - const CpuTensorHandle* cpuTensorHandle = boost::polymorphic_downcast(tensorHandle); - return cpuTensorHandle->GetTensor(); -}; - -template -const uint8_t* GetInputTensorDataU8(unsigned int idx, const PayloadType& data) -{ - const ITensorHandle* tensorHandle = data.m_Inputs[idx]; - return GetConstCpuU8Data(tensorHandle); -} - -template -uint8_t* GetOutputTensorDataU8(unsigned int idx, const PayloadType& data) -{ - const ITensorHandle* tensorHandle = data.m_Outputs[idx]; - return GetCpuU8Data(tensorHandle); -} - template std::vector Dequantize(const T* quant, const TensorInfo& info) { -- cgit v1.2.1