blob: b4dedd5e776fa3d3150a1eca3fcffb05a33aa9d2 [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
Matthew Benthamc30abd82022-11-23 12:11:32 +000020 RefTensorHandle(const TensorInfo& tensorInfo);
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
Matthew Benthamc30abd82022-11-23 12:11:32 +000054 virtual MemorySourceFlags GetImportFlags() const override;
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010055
56 virtual bool Import(void* memory, MemorySource source) override;
Nikhil Raj53e06592022-01-05 16:04:08 +000057 virtual bool CanBeImported(void* memory, MemorySource source) override;
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010058
Matthew Bentham4cefc412019-06-18 16:14:34 +010059private:
60 // Only used for testing
61 void CopyOutTo(void*) const override;
62 void CopyInFrom(const void*) override;
63
Matthew Bentham7c1603a2019-06-21 17:22:23 +010064 void* GetPointer() const;
Matthew Bentham4cefc412019-06-18 16:14:34 +010065
Matthew Bentham7c1603a2019-06-21 17:22:23 +010066 RefTensorHandle(const RefTensorHandle& other) = delete; // noncopyable
67 RefTensorHandle& operator=(const RefTensorHandle& other) = delete; //noncopyable
Matthew Bentham4cefc412019-06-18 16:14:34 +010068
69 TensorInfo m_TensorInfo;
Matthew Bentham7c1603a2019-06-21 17:22:23 +010070
71 std::shared_ptr<RefMemoryManager> m_MemoryManager;
72 RefMemoryManager::Pool* m_Pool;
Narumol Prangnawarat3b90af62020-06-26 11:00:21 +010073 mutable void* m_UnmanagedMemory;
Matthew Bentham6b5f6742022-11-23 18:17:48 +000074 void* m_ImportedMemory;
Matthew Bentham4cefc412019-06-18 16:14:34 +010075};
76
Matthew Bentham7c1603a2019-06-21 17:22:23 +010077}