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