ArmNN  NotReleased
ITensorHandleFactory.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/IRuntime.hpp>
10 #include <armnn/Types.hpp>
11 #include "ITensorHandle.hpp"
12 
13 #include <boost/core/ignore_unused.hpp>
14 
15 namespace armnn
16 {
17 
19 {
20 public:
21  using FactoryId = std::string;
22  static const FactoryId LegacyFactoryId; // Use the workload factory to create the tensor handle
23  static const FactoryId DeferredFactoryId; // Some TensorHandleFactory decisions are deferred to run-time
24 
25  virtual ~ITensorHandleFactory() {}
26 
27  virtual std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent,
28  TensorShape const& subTensorShape,
29  unsigned int const* subTensorOrigin) const = 0;
30 
31  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo) const = 0;
32 
33  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
34  DataLayout dataLayout) const = 0;
35 
36  // Utility Functions for backends which require TensorHandles to have unmanaged memory.
37  // These should be overloaded if required to facilitate direct import of input tensors
38  // and direct export of output tensors.
39  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
40  const bool IsMemoryManaged) const
41  {
42  boost::ignore_unused(IsMemoryManaged);
43  return CreateTensorHandle(tensorInfo);
44  }
45 
46  virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
47  DataLayout dataLayout,
48  const bool IsMemoryManaged) const
49  {
50  boost::ignore_unused(IsMemoryManaged);
51  return CreateTensorHandle(tensorInfo, dataLayout);
52  }
53 
54  virtual const FactoryId& GetId() const = 0;
55 
56  virtual bool SupportsSubTensors() const = 0;
57 
58  virtual bool SupportsMapUnmap() const final { return true; }
59 
60  virtual MemorySourceFlags GetExportFlags() const { return 0; }
61  virtual MemorySourceFlags GetImportFlags() const { return 0; }
62 };
63 
64 enum class EdgeStrategy
65 {
66  Undefined,
70 };
71 
72 } //namespace armnn
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, DataLayout dataLayout, const bool IsMemoryManaged) const
virtual bool SupportsMapUnmap() const final
No strategy has been defined. Used internally to verify integrity of optimizations.
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
Source backends tensor data can be exported to destination backend tensor without copy...
static const FactoryId LegacyFactoryId
static const FactoryId DeferredFactoryId
virtual MemorySourceFlags GetExportFlags() const
virtual bool SupportsSubTensors() const =0
unsigned int MemorySourceFlags
Destination backend can work directly with tensors on source backend.
virtual const FactoryId & GetId() const =0
DataLayout
Definition: Types.hpp:48
virtual std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, TensorShape const &subTensorShape, unsigned int const *subTensorOrigin) const =0
virtual MemorySourceFlags GetImportFlags() const
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged) const