blob: a3264f55eff82fbd57d65eaecb3f605730ad89de [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
Colm Donelan0c479742021-12-10 12:43:54 +00007#include <armnn/backends/TensorHandle.hpp>
Matthew Bentham4cefc412019-06-18 16:14:34 +01008
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
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010020 RefTensorHandle(const TensorInfo& tensorInfo, MemorySourceFlags importFlags);
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010021
Matthew Bentham4cefc412019-06-18 16:14:34 +010022 ~RefTensorHandle();
23
Matthew Bentham7c1603a2019-06-21 17:22:23 +010024 virtual void Manage() override;
25
26 virtual void Allocate() override;
Matthew Bentham4cefc412019-06-18 16:14:34 +010027
28 virtual ITensorHandle* GetParent() const override
29 {
30 return nullptr;
31 }
32
Matthew Bentham7c1603a2019-06-21 17:22:23 +010033 virtual const void* Map(bool /* blocking = true */) const override;
34 using ITensorHandle::Map;
Matthew Bentham4cefc412019-06-18 16:14:34 +010035
36 virtual void Unmap() const override
37 {}
38
Matthew Bentham4cefc412019-06-18 16:14:34 +010039 TensorShape GetStrides() const override
40 {
41 return GetUnpaddedTensorStrides(m_TensorInfo);
42 }
43
44 TensorShape GetShape() const override
45 {
46 return m_TensorInfo.GetShape();
47 }
48
49 const TensorInfo& GetTensorInfo() const
50 {
51 return m_TensorInfo;
52 }
53
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010054 virtual MemorySourceFlags GetImportFlags() const override
55 {
56 return m_ImportFlags;
57 }
58
59 virtual bool Import(void* memory, MemorySource source) override;
60
Matthew Bentham4cefc412019-06-18 16:14:34 +010061private:
62 // Only used for testing
63 void CopyOutTo(void*) const override;
64 void CopyInFrom(const void*) override;
65
Matthew Bentham7c1603a2019-06-21 17:22:23 +010066 void* GetPointer() const;
Matthew Bentham4cefc412019-06-18 16:14:34 +010067
Matthew Bentham7c1603a2019-06-21 17:22:23 +010068 RefTensorHandle(const RefTensorHandle& other) = delete; // noncopyable
69 RefTensorHandle& operator=(const RefTensorHandle& other) = delete; //noncopyable
Matthew Bentham4cefc412019-06-18 16:14:34 +010070
71 TensorInfo m_TensorInfo;
Matthew Bentham7c1603a2019-06-21 17:22:23 +010072
73 std::shared_ptr<RefMemoryManager> m_MemoryManager;
74 RefMemoryManager::Pool* m_Pool;
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010075 mutable void* m_UnmanagedMemory;
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010076 MemorySourceFlags m_ImportFlags;
77 bool m_Imported;
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010078 bool m_IsImportEnabled;
Matthew Bentham4cefc412019-06-18 16:14:34 +010079};
80
Matthew Bentham7c1603a2019-06-21 17:22:23 +010081}