blob: a7eab034b293091a14cdde67b4e57367214c401f [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;
Nikhil Raj53e06592022-01-05 16:04:08 +000060 virtual bool CanBeImported(void* memory, MemorySource source) override;
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010061
Matthew Bentham4cefc412019-06-18 16:14:34 +010062private:
63 // Only used for testing
64 void CopyOutTo(void*) const override;
65 void CopyInFrom(const void*) override;
66
Matthew Bentham7c1603a2019-06-21 17:22:23 +010067 void* GetPointer() const;
Matthew Bentham4cefc412019-06-18 16:14:34 +010068
Matthew Bentham7c1603a2019-06-21 17:22:23 +010069 RefTensorHandle(const RefTensorHandle& other) = delete; // noncopyable
70 RefTensorHandle& operator=(const RefTensorHandle& other) = delete; //noncopyable
Matthew Bentham4cefc412019-06-18 16:14:34 +010071
72 TensorInfo m_TensorInfo;
Matthew Bentham7c1603a2019-06-21 17:22:23 +010073
74 std::shared_ptr<RefMemoryManager> m_MemoryManager;
75 RefMemoryManager::Pool* m_Pool;
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010076 mutable void* m_UnmanagedMemory;
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010077 MemorySourceFlags m_ImportFlags;
78 bool m_Imported;
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010079 bool m_IsImportEnabled;
Matthew Bentham4cefc412019-06-18 16:14:34 +010080};
81
Matthew Bentham7c1603a2019-06-21 17:22:23 +010082}