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