Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 1 | // |
| 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 Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 9 | #include "RefMemoryManager.hpp" |
| 10 | |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 11 | namespace armnn |
| 12 | { |
| 13 | |
| 14 | // An implementation of ITensorHandle with simple "bump the pointer" memory-management behaviour |
| 15 | class RefTensorHandle : public ITensorHandle |
| 16 | { |
| 17 | public: |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 18 | RefTensorHandle(const TensorInfo& tensorInfo, std::shared_ptr<RefMemoryManager> &memoryManager); |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 19 | |
Narumol Prangnawarat | 3b90af6 | 2020-06-26 11:00:21 +0100 | [diff] [blame] | 20 | RefTensorHandle(const TensorInfo& tensorInfo, MemorySourceFlags importFlags); |
Ferran Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 21 | |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 22 | ~RefTensorHandle(); |
| 23 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 24 | virtual void Manage() override; |
| 25 | |
| 26 | virtual void Allocate() override; |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 27 | |
| 28 | virtual ITensorHandle* GetParent() const override |
| 29 | { |
| 30 | return nullptr; |
| 31 | } |
| 32 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 33 | virtual const void* Map(bool /* blocking = true */) const override; |
| 34 | using ITensorHandle::Map; |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 35 | |
| 36 | virtual void Unmap() const override |
| 37 | {} |
| 38 | |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 39 | 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 Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 54 | virtual MemorySourceFlags GetImportFlags() const override |
| 55 | { |
| 56 | return m_ImportFlags; |
| 57 | } |
| 58 | |
| 59 | virtual bool Import(void* memory, MemorySource source) override; |
| 60 | |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 61 | private: |
| 62 | // Only used for testing |
| 63 | void CopyOutTo(void*) const override; |
| 64 | void CopyInFrom(const void*) override; |
| 65 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 66 | void* GetPointer() const; |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 67 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 68 | RefTensorHandle(const RefTensorHandle& other) = delete; // noncopyable |
| 69 | RefTensorHandle& operator=(const RefTensorHandle& other) = delete; //noncopyable |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 70 | |
| 71 | TensorInfo m_TensorInfo; |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 72 | |
| 73 | std::shared_ptr<RefMemoryManager> m_MemoryManager; |
| 74 | RefMemoryManager::Pool* m_Pool; |
Narumol Prangnawarat | 3b90af6 | 2020-06-26 11:00:21 +0100 | [diff] [blame] | 75 | mutable void* m_UnmanagedMemory; |
Ferran Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 76 | MemorySourceFlags m_ImportFlags; |
| 77 | bool m_Imported; |
Narumol Prangnawarat | 3b90af6 | 2020-06-26 11:00:21 +0100 | [diff] [blame] | 78 | bool m_IsImportEnabled; |
Matthew Bentham | 4cefc41 | 2019-06-18 16:14:34 +0100 | [diff] [blame] | 79 | }; |
| 80 | |
Matthew Bentham | 7c1603a | 2019-06-21 17:22:23 +0100 | [diff] [blame] | 81 | } |