Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 8 | #include <armnn/IRuntime.hpp> |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 9 | #include <armnn/MemorySources.hpp> |
| 10 | #include <armnn/Types.hpp> |
David Monahan | c6e5a6e | 2019-10-02 09:33:57 +0100 | [diff] [blame] | 11 | #include "ITensorHandle.hpp" |
| 12 | |
| 13 | #include <boost/core/ignore_unused.hpp> |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 14 | |
| 15 | namespace armnn |
| 16 | { |
| 17 | |
| 18 | class ITensorHandleFactory |
| 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 | |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 27 | virtual std::unique_ptr<ITensorHandle> CreateSubTensorHandle(ITensorHandle& parent, |
| 28 | TensorShape const& subTensorShape, |
| 29 | unsigned int const* subTensorOrigin) const = 0; |
| 30 | |
David Monahan | c6e5a6e | 2019-10-02 09:33:57 +0100 | [diff] [blame] | 31 | virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo) const = 0; |
| 32 | |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 33 | virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo, |
David Monahan | c6e5a6e | 2019-10-02 09:33:57 +0100 | [diff] [blame] | 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 | } |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 45 | |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 46 | virtual std::unique_ptr<ITensorHandle> CreateTensorHandle(const TensorInfo& tensorInfo, |
David Monahan | 3fb7e10 | 2019-08-20 11:25:29 +0100 | [diff] [blame] | 47 | DataLayout dataLayout, |
David Monahan | c6e5a6e | 2019-10-02 09:33:57 +0100 | [diff] [blame] | 48 | const bool IsMemoryManaged) const |
| 49 | { |
| 50 | boost::ignore_unused(IsMemoryManaged); |
| 51 | return CreateTensorHandle(tensorInfo, dataLayout); |
| 52 | } |
Narumol Prangnawarat | 4e3e818 | 2019-08-14 12:25:50 +0100 | [diff] [blame] | 53 | |
Ferran Balaguer | bfeb271 | 2019-08-07 15:14:56 +0100 | [diff] [blame] | 54 | virtual const FactoryId& GetId() const = 0; |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 55 | |
| 56 | virtual bool SupportsSubTensors() const = 0; |
| 57 | |
| 58 | virtual bool SupportsMapUnmap() const final { return true; } |
| 59 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 60 | virtual MemorySourceFlags GetExportFlags() const { return 0; } |
| 61 | virtual MemorySourceFlags GetImportFlags() const { return 0; } |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 62 | }; |
| 63 | |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 64 | enum class EdgeStrategy |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 65 | { |
Derek Lamberti | f674aa0 | 2019-08-01 15:56:25 +0100 | [diff] [blame] | 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. |
Derek Lamberti | 84da38b | 2019-06-13 11:40:08 +0100 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | } //namespace armnn |