ArmNN
 25.02
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ITensorHandle.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
9 #include <armnn/Tensor.hpp>
10 
11 namespace armnn
12 {
13 
14 class TensorShape;
15 
17 {
18 public:
19  virtual ~ITensorHandle(){}
20 
21  /// Indicate to the memory manager that this resource is active.
22  /// This is used to compute overlapping lifetimes of resources.
23  virtual void Manage() = 0;
24 
25  /// Indicate to the memory manager that this resource is no longer active.
26  /// This is used to compute overlapping lifetimes of resources.
27  virtual void Allocate() = 0;
28 
29  /// Get the parent tensor if this is a subtensor.
30  /// \return a pointer to the parent tensor. Otherwise nullptr if not a subtensor.
31  virtual ITensorHandle* GetParent() const = 0;
32 
33  /// Map the tensor data for access.
34  /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent)
35  /// \return pointer to the first element of the mapped data.
36  virtual const void* Map(bool blocking=true) const = 0;
37 
38  /// Unmap the tensor data
39  virtual void Unmap() const = 0;
40 
41  /// Map the tensor data for access. Must be paired with call to Unmap().
42  /// \param blocking hint to block the calling thread until all other accesses are complete. (backend dependent)
43  /// \return pointer to the first element of the mapped data.
44  void* Map(bool blocking=true)
45  {
46  return const_cast<void*>(static_cast<const ITensorHandle*>(this)->Map(blocking));
47  }
48 
49  /// Unmap the tensor data that was previously mapped with call to Map().
50  void Unmap()
51  {
52  return static_cast<const ITensorHandle*>(this)->Unmap();
53  }
54 
55  /// Get the strides for each dimension ordered from largest to smallest where
56  /// the smallest value is the same as the size of a single element in the tensor.
57  /// \return a TensorShape filled with the strides for each dimension
58  virtual TensorShape GetStrides() const = 0;
59 
60  /// Get the number of elements for each dimension ordered from slowest iterating dimension
61  /// to fastest iterating dimension.
62  /// \return a TensorShape filled with the number of elements for each dimension.
63  virtual TensorShape GetShape() const = 0;
64 
65  /// Testing support to be able to verify and set tensor data content
66  virtual void CopyOutTo(void* memory) const = 0;
67  virtual void CopyInFrom(const void* memory) = 0;
68 
69  /// Get flags describing supported import sources.
70  virtual unsigned int GetImportFlags() const { return 0; }
71 
72  /// Import externally allocated memory
73  /// \param memory base address of the memory being imported.
74  /// \param source source of the allocation for the memory being imported.
75  /// \return true on success or false on failure
76  virtual bool Import(void* memory, MemorySource source)
77  {
78  IgnoreUnused(memory, source);
79  return false;
80  };
81 
82  /// Implementations must determine if this memory block can be imported.
83  /// This might be based on alignment or memory source type.
84  /// \return true if this memory can be imported.
85  /// \return false by default, cannot be imported.
86  virtual bool CanBeImported(void* memory, MemorySource source)
87  {
88  IgnoreUnused(memory, source);
89  return false;
90  };
91 
92  /// Unimport externally allocated memory
93  virtual void Unimport()
94  {};
95 
96  /// Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it
97  /// \param tensorInfo the overidden TensorInfo.
98  virtual std::shared_ptr<ITensorHandle> DecorateTensorHandle(const TensorInfo& tensorInfo)
99  {
100  IgnoreUnused(tensorInfo);
101  return nullptr;
102  }
103 };
104 
105 }
virtual void Manage()=0
Indicate to the memory manager that this resource is active.
void * Map(bool blocking=true)
Map the tensor data for access.
virtual TensorShape GetStrides() const =0
Get the strides for each dimension ordered from largest to smallest where the smallest value is the s...
virtual ITensorHandle * GetParent() const =0
Get the parent tensor if this is a subtensor.
virtual void CopyOutTo(void *memory) const =0
Testing support to be able to verify and set tensor data content.
virtual bool Import(void *memory, MemorySource source)
Import externally allocated memory.
virtual unsigned int GetImportFlags() const
Get flags describing supported import sources.
virtual void Unmap() const =0
Unmap the tensor data.
virtual void Allocate()=0
Indicate to the memory manager that this resource is no longer active.
virtual bool CanBeImported(void *memory, MemorySource source)
Implementations must determine if this memory block can be imported.
virtual std::shared_ptr< ITensorHandle > DecorateTensorHandle(const TensorInfo &tensorInfo)
Returns a decorated version of this TensorHandle allowing us to override the TensorInfo for it.
virtual const void * Map(bool blocking=true) const =0
Map the tensor data for access.
virtual void Unimport()
Unimport externally allocated memory.
void Unmap()
Unmap the tensor data that was previously mapped with call to Map().
virtual void CopyInFrom(const void *memory)=0
virtual TensorShape GetShape() const =0
Get the number of elements for each dimension ordered from slowest iterating dimension to fastest ite...
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
Definition: Types.hpp:246
void IgnoreUnused(Ts &&...)