blob: 2e4742301b2f85feaa0c037e5b8cd9b956ff8f43 [file] [log] [blame]
Derek Lamberti84da38b2019-06-13 11:40:08 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#pragma once
7
Derek Lamberti84da38b2019-06-13 11:40:08 +01008#include <armnn/IRuntime.hpp>
Derek Lambertif674aa02019-08-01 15:56:25 +01009#include <armnn/MemorySources.hpp>
10#include <armnn/Types.hpp>
David Monahanc6e5a6e2019-10-02 09:33:57 +010011#include "ITensorHandle.hpp"
12
13#include <boost/core/ignore_unused.hpp>
Derek Lamberti84da38b2019-06-13 11:40:08 +010014
15namespace armnn
16{
17
18class ITensorHandleFactory
19{
20public:
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
Derek Lamberti84da38b2019-06-13 11:40:08 +010027 virtual std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent,
28 TensorShape const& subTensorShape,
29 unsigned int const* subTensorOrigin) const = 0;
30
David Monahanc6e5a6e2019-10-02 09:33:57 +010031 virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo) const = 0;
32
David Monahan3fb7e102019-08-20 11:25:29 +010033 virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
David Monahanc6e5a6e2019-10-02 09:33:57 +010034 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 }
Derek Lamberti84da38b2019-06-13 11:40:08 +010045
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010046 virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo,
David Monahan3fb7e102019-08-20 11:25:29 +010047 DataLayout dataLayout,
David Monahanc6e5a6e2019-10-02 09:33:57 +010048 const bool IsMemoryManaged) const
49 {
50 boost::ignore_unused(IsMemoryManaged);
51 return CreateTensorHandle(tensorInfo, dataLayout);
52 }
Narumol Prangnawarat4e3e8182019-08-14 12:25:50 +010053
Ferran Balaguerbfeb2712019-08-07 15:14:56 +010054 virtual const FactoryId& GetId() const = 0;
Derek Lamberti84da38b2019-06-13 11:40:08 +010055
56 virtual bool SupportsSubTensors() const = 0;
57
58 virtual bool SupportsMapUnmap() const final { return true; }
59
Derek Lambertif674aa02019-08-01 15:56:25 +010060 virtual MemorySourceFlags GetExportFlags() const { return 0; }
61 virtual MemorySourceFlags GetImportFlags() const { return 0; }
Derek Lamberti84da38b2019-06-13 11:40:08 +010062};
63
Derek Lambertif674aa02019-08-01 15:56:25 +010064enum class EdgeStrategy
Derek Lamberti84da38b2019-06-13 11:40:08 +010065{
Derek Lambertif674aa02019-08-01 15:56:25 +010066 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.
Derek Lamberti84da38b2019-06-13 11:40:08 +010070};
71
72} //namespace armnn