ArmNN
 20.02
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 "ITensorHandle.hpp"
9 
10 #include <armnn/IRuntime.hpp>
11 #include <armnn/MemorySources.hpp>
12 #include <armnn/Types.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  IgnoreUnused(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  IgnoreUnused(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, /// No strategy has been defined. Used internally to verify integrity of optimizations.
67  DirectCompatibility, /// Destination backend can work directly with tensors on source backend.
68  ExportToTarget, /// Source backends tensor data can be exported to destination backend tensor without copy.
69  CopyToTarget /// Copy contents from source backend tensor to destination backend tensor.
70 };
71 
72 } //namespace armnn
static const FactoryId DeferredFactoryId
Use the workload factory to create the tensor handle.
virtual bool SupportsMapUnmap() const final
DataLayout
Definition: Types.hpp:49
No strategy has been defined. Used internally to verify integrity of optimizations.
Source backends tensor data can be exported to destination backend tensor without copy...
virtual std::unique_ptr< ITensorHandle > CreateSubTensorHandle(ITensorHandle &parent, TensorShape const &subTensorShape, unsigned int const *subTensorOrigin) const =0
unsigned int MemorySourceFlags
Copyright (c) 2020 ARM Limited.
void IgnoreUnused(Ts &&...)
virtual const FactoryId & GetId() const =0
Destination backend can work directly with tensors on source backend.
virtual bool SupportsSubTensors() const =0
virtual MemorySourceFlags GetExportFlags() const
virtual ~ITensorHandleFactory()
Some TensorHandleFactory decisions are deferred to run-time.
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, DataLayout dataLayout, const bool IsMemoryManaged) const
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo, const bool IsMemoryManaged) const
Utility Functions for backends which require TensorHandles to have unmanaged memory.
virtual MemorySourceFlags GetImportFlags() const
virtual std::unique_ptr< ITensorHandle > CreateTensorHandle(const TensorInfo &tensorInfo) const =0
static const FactoryId LegacyFactoryId