ArmNN
 23.08
TosaRefTensorHandle.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
8 
10 
11 namespace armnn
12 {
13 
14 // An implementation of ITensorHandle with simple "bump the pointer" memory-management behaviour
16 {
17 public:
18  TosaRefTensorHandle(const TensorInfo& tensorInfo, std::shared_ptr<TosaRefMemoryManager> &memoryManager);
19 
20  TosaRefTensorHandle(const TensorInfo& tensorInfo, MemorySourceFlags importFlags);
21 
23 
24  virtual void Manage() override;
25 
26  virtual void Allocate() override;
27 
28  virtual ITensorHandle* GetParent() const override
29  {
30  return nullptr;
31  }
32 
33  virtual const void* Map(bool /* blocking = true */) const override;
34  using ITensorHandle::Map;
35 
36  virtual void Unmap() const override
37  {}
38 
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 
54  virtual MemorySourceFlags GetImportFlags() const override
55  {
56  return m_ImportFlags;
57  }
58 
59  virtual bool Import(void* memory, MemorySource source) override;
60  virtual bool CanBeImported(void* memory, MemorySource source) override;
61 
62 private:
63  // Only used for testing
64  void CopyOutTo(void*) const override;
65  void CopyInFrom(const void*) override;
66 
67  void* GetPointer() const;
68 
69  TosaRefTensorHandle(const TosaRefTensorHandle& other) = delete; // noncopyable
70  TosaRefTensorHandle& operator=(const TosaRefTensorHandle& other) = delete; //noncopyable
71 
72  TensorInfo m_TensorInfo;
73 
74  std::shared_ptr<TosaRefMemoryManager> m_MemoryManager;
76  mutable void* m_UnmanagedMemory;
77  MemorySourceFlags m_ImportFlags;
78  bool m_Imported;
79  bool m_IsImportEnabled;
80 };
81 
82 }
armnn::TosaRefTensorHandle::Map
virtual const void * Map(bool) const override
Map the tensor data for access.
Definition: TosaRefTensorHandle.cpp:80
armnn::TosaRefTensorHandle::GetStrides
TensorShape GetStrides() const override
Get the strides for each dimension ordered from largest to smallest where the smallest value is the s...
Definition: TosaRefTensorHandle.hpp:39
armnn::TosaRefTensorHandle::TosaRefTensorHandle
TosaRefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< TosaRefMemoryManager > &memoryManager)
Definition: TosaRefTensorHandle.cpp:10
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::MemorySourceFlags
unsigned int MemorySourceFlags
Definition: MemorySources.hpp:15
armnn::GetUnpaddedTensorStrides
TensorShape GetUnpaddedTensorStrides(const TensorInfo &tensorInfo)
Definition: TensorHandle.cpp:15
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
armnn::TosaRefTensorHandle::Allocate
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
Definition: TosaRefTensorHandle.cpp:54
armnn::TosaRefTensorHandle::CanBeImported
virtual bool CanBeImported(void *memory, MemorySource source) override
Implementations must determine if this memory block can be imported.
Definition: TosaRefTensorHandle.cpp:158
armnn::TosaRefTensorHandle
Definition: TosaRefTensorHandle.hpp:15
TosaRefMemoryManager.hpp
armnn::TosaRefMemoryManager::Pool
Definition: TosaRefMemoryManager.hpp:33
armnn::TosaRefTensorHandle::~TosaRefTensorHandle
~TosaRefTensorHandle()
Definition: TosaRefTensorHandle.cpp:31
armnn::TosaRefTensorHandle::Import
virtual bool Import(void *memory, MemorySource source) override
Import externally allocated memory.
Definition: TosaRefTensorHandle.cpp:115
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::TosaRefTensorHandle::GetImportFlags
virtual MemorySourceFlags GetImportFlags() const override
Get flags describing supported import sources.
Definition: TosaRefTensorHandle.hpp:54
armnn::TosaRefTensorHandle::Unmap
virtual void Unmap() const override
Unmap the tensor data.
Definition: TosaRefTensorHandle.hpp:36
armnn::TosaRefTensorHandle::GetShape
TensorShape GetShape() const override
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
Definition: TosaRefTensorHandle.hpp:44
TensorHandle.hpp
armnn::TosaRefTensorHandle::GetTensorInfo
const TensorInfo & GetTensorInfo() const
Definition: TosaRefTensorHandle.hpp:49
armnn::TosaRefTensorHandle::Manage
virtual void Manage() override
Indicate to the memory manager that this resource is active.
Definition: TosaRefTensorHandle.cpp:43
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
armnn::MemorySource
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:243
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::TosaRefTensorHandle::GetParent
virtual ITensorHandle * GetParent() const override
Get the parent tensor if this is a subtensor.
Definition: TosaRefTensorHandle.hpp:28
armnn::ITensorHandle::Map
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.