ArmNN
 24.08
SampleTensorHandle.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
8 
10 
11 namespace sdb // sample dynamic backend
12 {
13 
14 // An implementation of ITensorHandle with simple "bump the pointer" memory-management behaviour
16 {
17 public:
18  SampleTensorHandle(const armnn::TensorInfo& tensorInfo, std::shared_ptr<SampleMemoryManager> &memoryManager);
19 
20  SampleTensorHandle(const armnn::TensorInfo& tensorInfo, armnn::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  armnn::TensorShape GetStrides() const override
40  {
41  return GetUnpaddedTensorStrides(m_TensorInfo);
42  }
43 
44  armnn::TensorShape GetShape() const override
45  {
46  return m_TensorInfo.GetShape();
47  }
48 
50  {
51  return m_TensorInfo;
52  }
53 
54  virtual armnn::MemorySourceFlags GetImportFlags() const override
55  {
56  return m_ImportFlags;
57  }
58 
59  virtual bool Import(void* memory, armnn::MemorySource source) override;
60 
61 private:
62  // Only used for testing
63  void CopyOutTo(void*) const override;
64  void CopyInFrom(const void*) override;
65 
66  void* GetPointer() const;
67 
68  SampleTensorHandle(const SampleTensorHandle& other) = delete; // noncopyable
69  SampleTensorHandle& operator=(const SampleTensorHandle& other) = delete; //noncopyable
70 
71  armnn::TensorInfo m_TensorInfo;
72 
73  std::shared_ptr<SampleMemoryManager> m_MemoryManager;
75  mutable void *m_UnmanagedMemory;
76  armnn::MemorySourceFlags m_ImportFlags;
77  bool m_Imported;
78 };
79 
80 } // namespace sdb
sdb::SampleTensorHandle::~SampleTensorHandle
~SampleTensorHandle()
Definition: SampleTensorHandle.cpp:35
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
SampleMemoryManager.hpp
armnn::ITensorHandle
Definition: ITensorHandle.hpp:16
sdb::SampleTensorHandle::Allocate
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
Definition: SampleTensorHandle.cpp:52
sdb
Definition: SampleDynamicAdditionWorkload.cpp:11
armnn::TensorShape
Definition: Tensor.hpp:20
sdb::SampleTensorHandle::GetParent
virtual ITensorHandle * GetParent() const override
Get the parent tensor if this is a subtensor.
Definition: SampleTensorHandle.hpp:28
sdb::SampleTensorHandle::GetImportFlags
virtual armnn::MemorySourceFlags GetImportFlags() const override
Get flags describing supported import sources.
Definition: SampleTensorHandle.hpp:54
sdb::SampleTensorHandle
Definition: SampleTensorHandle.hpp:15
sdb::SampleTensorHandle::Manage
virtual void Manage() override
Indicate to the memory manager that this resource is active.
Definition: SampleTensorHandle.cpp:47
TensorHandle.hpp
sdb::SampleTensorHandle::Map
virtual const void * Map(bool) const override
Map the tensor data for access.
Definition: SampleTensorHandle.cpp:74
sdb::SampleTensorHandle::GetStrides
armnn::TensorShape GetStrides() const override
Get the strides for each dimension ordered from largest to smallest where the smallest value is the s...
Definition: SampleTensorHandle.hpp:39
armnn::TensorInfo::GetShape
const TensorShape & GetShape() const
Definition: Tensor.hpp:193
sdb::SampleTensorHandle::GetShape
armnn::TensorShape GetShape() const override
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
Definition: SampleTensorHandle.hpp:44
armnn::MemorySource
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:244
sdb::SampleTensorHandle::Import
virtual bool Import(void *memory, armnn::MemorySource source) override
Import externally allocated memory.
Definition: SampleTensorHandle.cpp:91
sdb::SampleTensorHandle::GetTensorInfo
const armnn::TensorInfo & GetTensorInfo() const
Definition: SampleTensorHandle.hpp:49
sdb::SampleMemoryManager::Pool
Definition: SampleMemoryManager.hpp:33
sdb::SampleTensorHandle::SampleTensorHandle
SampleTensorHandle(const armnn::TensorInfo &tensorInfo, std::shared_ptr< SampleMemoryManager > &memoryManager)
Definition: SampleTensorHandle.cpp:11
sdb::SampleTensorHandle::Unmap
virtual void Unmap() const override
Unmap the tensor data.
Definition: SampleTensorHandle.hpp:36