blob: ad47ee597f3b46892bf4fb29147fff7e15643161 [file] [log] [blame]
Matthew Bentham4cefc412019-06-18 16:14:34 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
7#include <backendsCommon/CpuTensorHandle.hpp>
8
Matthew Bentham7c1603a2019-06-21 17:22:23 +01009#include "RefMemoryManager.hpp"
10
Matthew Bentham4cefc412019-06-18 16:14:34 +010011namespace armnn
12{
13
14// An implementation of ITensorHandle with simple "bump the pointer" memory-management behaviour
15class RefTensorHandle : public ITensorHandle
16{
17public:
Matthew Bentham7c1603a2019-06-21 17:22:23 +010018 RefTensorHandle(const TensorInfo& tensorInfo, std::shared_ptr<RefMemoryManager> &memoryManager);
Matthew Bentham4cefc412019-06-18 16:14:34 +010019
20 ~RefTensorHandle();
21
Matthew Bentham7c1603a2019-06-21 17:22:23 +010022 virtual void Manage() override;
23
24 virtual void Allocate() override;
Matthew Bentham4cefc412019-06-18 16:14:34 +010025
26 virtual ITensorHandle* GetParent() const override
27 {
28 return nullptr;
29 }
30
Matthew Bentham7c1603a2019-06-21 17:22:23 +010031 virtual const void* Map(bool /* blocking = true */) const override;
32 using ITensorHandle::Map;
Matthew Bentham4cefc412019-06-18 16:14:34 +010033
34 virtual void Unmap() const override
35 {}
36
Matthew Bentham4cefc412019-06-18 16:14:34 +010037 TensorShape GetStrides() const override
38 {
39 return GetUnpaddedTensorStrides(m_TensorInfo);
40 }
41
42 TensorShape GetShape() const override
43 {
44 return m_TensorInfo.GetShape();
45 }
46
47 const TensorInfo& GetTensorInfo() const
48 {
49 return m_TensorInfo;
50 }
51
52private:
53 // Only used for testing
54 void CopyOutTo(void*) const override;
55 void CopyInFrom(const void*) override;
56
Matthew Bentham7c1603a2019-06-21 17:22:23 +010057 void* GetPointer() const;
Matthew Bentham4cefc412019-06-18 16:14:34 +010058
Matthew Bentham7c1603a2019-06-21 17:22:23 +010059 RefTensorHandle(const RefTensorHandle& other) = delete; // noncopyable
60 RefTensorHandle& operator=(const RefTensorHandle& other) = delete; //noncopyable
Matthew Bentham4cefc412019-06-18 16:14:34 +010061
62 TensorInfo m_TensorInfo;
Matthew Bentham7c1603a2019-06-21 17:22:23 +010063
64 std::shared_ptr<RefMemoryManager> m_MemoryManager;
65 RefMemoryManager::Pool* m_Pool;
66 mutable void *m_UnmanagedMemory;
Matthew Bentham4cefc412019-06-18 16:14:34 +010067};
68
Matthew Bentham7c1603a2019-06-21 17:22:23 +010069}