ArmNN
 22.08
EthosnRefTensorHandle.hpp
Go to the documentation of this file.
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 
10 
11 namespace armnn
12 {
13 
14 // An implementation of ITensorHandle with simple "bump the pointer" memory-management behaviour
16 {
17 public:
18  EthosnRefTensorHandle(const TensorInfo& tensorInfo, std::shared_ptr<EthosnRefMemoryManager> &memoryManager);
19 
20  EthosnRefTensorHandle(const TensorInfo& tensorInfo, std::shared_ptr<EthosnRefMemoryManager> &memoryManager,
21  MemorySourceFlags importFlags);
22 
24 
25  virtual void Manage() override;
26 
27  virtual void Allocate() override;
28 
29  virtual ITensorHandle* GetParent() const override
30  {
31  return nullptr;
32  }
33 
34  virtual const void* Map(bool /* blocking = true */) const override;
35  using ITensorHandle::Map;
36 
37  virtual void Unmap() const override
38  {}
39 
40  TensorShape GetStrides() const override
41  {
42  return GetUnpaddedTensorStrides(m_TensorInfo);
43  }
44 
45  TensorShape GetShape() const override
46  {
47  return m_TensorInfo.GetShape();
48  }
49 
50  const TensorInfo& GetTensorInfo() const
51  {
52  return m_TensorInfo;
53  }
54 
55  virtual MemorySourceFlags GetImportFlags() const override
56  {
57  return m_ImportFlags;
58  }
59 
60  virtual bool Import(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  EthosnRefTensorHandle(const EthosnRefTensorHandle& other) = delete; // noncopyable
70  EthosnRefTensorHandle& operator=(const EthosnRefTensorHandle& other) = delete; //noncopyable
71 
72  TensorInfo m_TensorInfo;
73 
74  std::shared_ptr<EthosnRefMemoryManager> m_MemoryManager;
76  mutable void *m_UnmanagedMemory;
77  MemorySourceFlags m_ImportFlags;
78  bool m_Imported;
79 };
80 
81 }
const TensorInfo & GetTensorInfo() const
virtual void Unmap() const override
Unmap the tensor data.
virtual void Manage() override
Indicate to the memory manager that this resource is active.
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
virtual void Allocate() override
Indicate to the memory manager that this resource is no longer active.
unsigned int MemorySourceFlags
Copyright (c) 2021 ARM Limited and Contributors.
virtual bool Import(void *memory, MemorySource source) override
Import externally allocated memory.
TensorShape GetStrides() const override
Get the strides for each dimension ordered from largest to smallest where the smallest value is the s...
virtual const void * Map(bool) const override
Map the tensor data for access.
TensorShape GetUnpaddedTensorStrides(const TensorInfo &tensorInfo)
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
virtual ITensorHandle * GetParent() const override
Get the parent tensor if this is a subtensor.
EthosnRefTensorHandle(const TensorInfo &tensorInfo, std::shared_ptr< EthosnRefMemoryManager > &memoryManager)
virtual MemorySourceFlags GetImportFlags() const override
Get flags describing supported import sources.
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:230
TensorShape GetShape() const override
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...