Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 7 | #include "BackendOptions.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 8 | #include "INetwork.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 9 | #include "IProfiler.hpp" |
Mike Kelly | 55a8ffd | 2021-04-07 20:10:49 +0100 | [diff] [blame] | 10 | #include "IWorkingMemHandle.hpp" |
Keith Davis | e813d67 | 2021-04-22 10:10:34 +0100 | [diff] [blame] | 11 | #include "IAsyncExecutionCallback.hpp" |
Matthew Bentham | 313e1c8 | 2019-03-25 17:37:47 +0000 | [diff] [blame] | 12 | #include "Tensor.hpp" |
| 13 | #include "Types.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 14 | #include "TypesUtils.hpp" |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 15 | #include "profiling/ILocalPacketHandler.hpp" |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 16 | |
David Monahan | 801e2d5 | 2021-07-19 17:06:30 +0100 | [diff] [blame] | 17 | #include <armnn/backends/ICustomAllocator.hpp> |
Sadik Armagan | b8a26d8 | 2021-10-04 15:13:11 +0100 | [diff] [blame] | 18 | #include <armnn/backends/IMemoryOptimizerStrategy.hpp> |
Matthew Bentham | 313e1c8 | 2019-03-25 17:37:47 +0000 | [diff] [blame] | 19 | #include <memory> |
Jan Eilers | c1c872f | 2021-07-22 13:17:04 +0100 | [diff] [blame] | 20 | #include <map> |
Matthew Bentham | 313e1c8 | 2019-03-25 17:37:47 +0000 | [diff] [blame] | 21 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 22 | namespace armnn |
| 23 | { |
| 24 | |
| 25 | using NetworkId = int; |
| 26 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | class IGpuAccTunedParameters; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 28 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 29 | struct RuntimeImpl; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 30 | class IRuntime; |
| 31 | using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>; |
| 32 | |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 33 | struct INetworkProperties |
Jan Eilers | 446707f | 2021-12-16 11:28:37 +0000 | [diff] [blame] | 34 | { |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 35 | INetworkProperties(bool asyncEnabled, |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 36 | MemorySource inputSource, |
| 37 | MemorySource outputSource, |
| 38 | bool profilingEnabled = false, |
Finn Williams | b1aad42 | 2021-10-28 19:07:32 +0100 | [diff] [blame] | 39 | ProfilingDetailsMethod detailsMethod = ProfilingDetailsMethod::Undefined, |
| 40 | bool externalMemoryManagementEnabled = false) |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 41 | : m_ImportEnabled(inputSource != MemorySource::Undefined), |
| 42 | m_ExportEnabled(outputSource != MemorySource::Undefined), |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 43 | m_AsyncEnabled(asyncEnabled), |
| 44 | m_ProfilingEnabled(profilingEnabled), |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 45 | m_OutputNetworkDetailsMethod(detailsMethod), |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 46 | m_InputSource(inputSource), |
Finn Williams | b1aad42 | 2021-10-28 19:07:32 +0100 | [diff] [blame] | 47 | m_OutputSource(outputSource), |
| 48 | m_ExternalMemoryManagementEnabled(externalMemoryManagementEnabled) |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 49 | {} |
Francis Murtagh | 73d3e2e | 2021-04-29 14:23:04 +0100 | [diff] [blame] | 50 | |
| 51 | /// Deprecated and will be removed in future release. |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 52 | const bool m_ImportEnabled; |
Francis Murtagh | 73d3e2e | 2021-04-29 14:23:04 +0100 | [diff] [blame] | 53 | /// Deprecated and will be removed in future release. |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 54 | const bool m_ExportEnabled; |
Francis Murtagh | 73d3e2e | 2021-04-29 14:23:04 +0100 | [diff] [blame] | 55 | |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 56 | const bool m_AsyncEnabled; |
| 57 | |
| 58 | const bool m_ProfilingEnabled; |
Keith Davis | e813d67 | 2021-04-22 10:10:34 +0100 | [diff] [blame] | 59 | |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 60 | const ProfilingDetailsMethod m_OutputNetworkDetailsMethod; |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 61 | |
Francis Murtagh | 73d3e2e | 2021-04-29 14:23:04 +0100 | [diff] [blame] | 62 | const MemorySource m_InputSource; |
| 63 | const MemorySource m_OutputSource; |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 64 | |
Finn Williams | b1aad42 | 2021-10-28 19:07:32 +0100 | [diff] [blame] | 65 | const bool m_ExternalMemoryManagementEnabled; |
| 66 | |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 67 | virtual ~INetworkProperties() {} |
| 68 | }; |
| 69 | |
Mike Kelly | 386ff1a | 2021-03-29 15:04:50 +0100 | [diff] [blame] | 70 | using namespace armnn::experimental; |
| 71 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 72 | class IRuntime |
| 73 | { |
| 74 | public: |
| 75 | struct CreationOptions |
| 76 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 77 | CreationOptions() |
| 78 | : m_GpuAccTunedParameters(nullptr) |
| 79 | , m_EnableGpuProfiling(false) |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 80 | , m_DynamicBackendsPath("") |
Jan Eilers | 15fcc7e | 2021-07-14 13:50:15 +0100 | [diff] [blame] | 81 | , m_ProtectedMode(false) |
Jan Eilers | c1c872f | 2021-07-22 13:17:04 +0100 | [diff] [blame] | 82 | , m_CustomAllocatorMap() |
Sadik Armagan | b8a26d8 | 2021-10-04 15:13:11 +0100 | [diff] [blame] | 83 | , m_MemoryOptimizerStrategyMap() |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 84 | {} |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | /// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads. |
| 87 | /// It will also be updated with new tuned parameters if it is configured to do so. |
| 88 | std::shared_ptr<IGpuAccTunedParameters> m_GpuAccTunedParameters; |
| 89 | |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 90 | /// Setting this flag will allow the user to obtain GPU profiling information from the runtime. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 91 | bool m_EnableGpuProfiling; |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 92 | |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 93 | /// Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive |
| 94 | /// Only a single path is allowed for the override |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 95 | /// It defines the path to search for any [dynamic backend libraries](src/dynamic/README.md). |
Matteo Martincigh | e7d4498 | 2019-08-05 12:16:47 +0100 | [diff] [blame] | 96 | std::string m_DynamicBackendsPath; |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 97 | |
Jan Eilers | 15fcc7e | 2021-07-14 13:50:15 +0100 | [diff] [blame] | 98 | /// Setting this flag will allow the user to create the Runtime in protected mode. |
| 99 | /// It will run all the inferences on protected memory and will make sure that |
| 100 | /// INetworkProperties::m_ImportEnabled set to true with MemorySource::DmaBufProtected option |
Jan Eilers | c1c872f | 2021-07-22 13:17:04 +0100 | [diff] [blame] | 101 | /// This requires that the backend supports Protected Memory and has an allocator capable of |
| 102 | /// allocating Protected Memory associated with it. |
Jan Eilers | 15fcc7e | 2021-07-14 13:50:15 +0100 | [diff] [blame] | 103 | bool m_ProtectedMode; |
| 104 | |
Jan Eilers | c1c872f | 2021-07-22 13:17:04 +0100 | [diff] [blame] | 105 | /// @brief A map to define a custom memory allocator for specific backend Ids. |
| 106 | /// |
| 107 | /// @details A Custom Allocator is used for allocation of working memory in the backends. |
| 108 | /// Set this if you need to take control of how memory is allocated on a backend. Required for |
| 109 | /// Protected Mode in order to correctly allocate Protected Memory |
| 110 | /// |
| 111 | /// @note Only supported for GpuAcc |
| 112 | std::map<BackendId, std::shared_ptr<ICustomAllocator>> m_CustomAllocatorMap; |
| 113 | |
Sadik Armagan | b8a26d8 | 2021-10-04 15:13:11 +0100 | [diff] [blame] | 114 | /// @brief A map to define a custom memory optimizer strategy for specific backend Ids. |
| 115 | /// |
| 116 | /// @details A Memory Optimizer Strategy provides a solution to an abstract representation of |
| 117 | /// a network's memory requirements. This can also be used to return a pre-computed solution |
| 118 | /// for a specific network. Set this if you want to implement a Custom Memory Optimizer Strategy |
| 119 | /// for a given backend. |
| 120 | std::map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>> m_MemoryOptimizerStrategyMap; |
| 121 | |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 122 | struct ExternalProfilingOptions |
| 123 | { |
| 124 | ExternalProfilingOptions() |
| 125 | : m_EnableProfiling(false) |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 126 | , m_TimelineEnabled(false) |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 127 | , m_OutgoingCaptureFile("") |
| 128 | , m_IncomingCaptureFile("") |
| 129 | , m_FileOnly(false) |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 130 | , m_CapturePeriod(LOWEST_CAPTURE_PERIOD) |
Isabella Gottardi | a0687ee | 2020-03-11 18:04:20 +0000 | [diff] [blame] | 131 | , m_FileFormat("binary") |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 132 | , m_LocalPacketHandlers() |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 133 | {} |
| 134 | |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 135 | /// Indicates whether external profiling is enabled or not. |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 136 | bool m_EnableProfiling; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 137 | /// Indicates whether external timeline profiling is enabled or not. |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 138 | bool m_TimelineEnabled; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 139 | /// Path to a file in which outgoing timeline profiling messages will be stored. |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 140 | std::string m_OutgoingCaptureFile; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 141 | /// Path to a file in which incoming timeline profiling messages will be stored. |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 142 | std::string m_IncomingCaptureFile; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 143 | /// Enable profiling output to file only. |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 144 | bool m_FileOnly; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 145 | /// The duration at which captured profiling messages will be flushed. |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 146 | uint32_t m_CapturePeriod; |
Jan Eilers | b1c62f1 | 2021-10-26 14:56:47 +0100 | [diff] [blame] | 147 | /// The format of the file used for outputting profiling data. |
Isabella Gottardi | a0687ee | 2020-03-11 18:04:20 +0000 | [diff] [blame] | 148 | std::string m_FileFormat; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 149 | std::vector<arm::pipe::ILocalPacketHandlerSharedPtr> m_LocalPacketHandlers; |
Aron Virginas-Tar | 1a0f691 | 2019-08-23 15:18:44 +0100 | [diff] [blame] | 150 | }; |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 151 | ExternalProfilingOptions m_ProfilingOptions; |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 152 | |
| 153 | /// Pass backend specific options. |
| 154 | /// |
| 155 | /// For example, to enable GpuAcc tuning add the following |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 156 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 157 | /// m_BackendOption.emplace_back( |
| 158 | /// BackendOptions{"GpuAcc", |
| 159 | /// { |
| 160 | /// {"TuningLevel", 2}, |
| 161 | /// {"TuningFile", filename} |
Sadik Armagan | b8a26d8 | 2021-10-04 15:13:11 +0100 | [diff] [blame] | 162 | /// {"MemoryOptimizerStrategy", strategyname} |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 163 | /// } |
| 164 | /// }); |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 165 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 166 | /// Execute representative workloads through the runtime to generate tuning data. |
| 167 | /// The tuning file is written once the runtime is destroyed |
| 168 | |
| 169 | /// To execute with the tuning data, start up with just the tuning file specified. |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 170 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 171 | /// m_BackendOption.emplace_back( |
| 172 | /// BackendOptions{"GpuAcc", |
| 173 | /// { |
| 174 | /// {"TuningFile", filename} |
| 175 | /// } |
| 176 | /// }); |
Ryan OShea | 2bbfaa7 | 2020-02-12 16:15:27 +0000 | [diff] [blame] | 177 | /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 178 | |
| 179 | /// The following backend options are available: |
Sadik Armagan | b8a26d8 | 2021-10-04 15:13:11 +0100 | [diff] [blame] | 180 | /// AllBackends: |
| 181 | /// "MemoryOptimizerStrategy" : string [stategynameString] |
Jim Flynn | e1fdd28 | 2021-10-26 21:26:10 +0100 | [diff] [blame] | 182 | /// (Existing Memory Optimizer Strategies: ConstantMemoryStrategy) |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 183 | /// GpuAcc: |
| 184 | /// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning) |
| 185 | /// "TuningFile" : string [filenameString] |
| 186 | /// "KernelProfilingEnabled" : bool [true | false] |
| 187 | std::vector<BackendOptions> m_BackendOptions; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | static IRuntime* CreateRaw(const CreationOptions& options); |
| 191 | static IRuntimePtr Create(const CreationOptions& options); |
| 192 | static void Destroy(IRuntime* runtime); |
| 193 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 194 | /// Loads a complete network into the IRuntime. |
| 195 | /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference. |
| 196 | /// @param [in] network - Complete network to load into the IRuntime. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 197 | /// The runtime takes ownership of the network once passed in. |
| 198 | /// @return armnn::Status |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 199 | Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 200 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 201 | /// Load a complete network into the IRuntime. |
| 202 | /// @param [out] networkIdOut Unique identifier for the network is returned in this reference. |
| 203 | /// @param [in] network Complete network to load into the IRuntime. |
| 204 | /// @param [out] errorMessage Error message if there were any errors. |
| 205 | /// The runtime takes ownership of the network once passed in. |
| 206 | /// @return armnn::Status |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 207 | Status LoadNetwork(NetworkId& networkIdOut, |
| 208 | IOptimizedNetworkPtr network, |
| 209 | std::string& errorMessage); |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 210 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 211 | Status LoadNetwork(NetworkId& networkIdOut, |
| 212 | IOptimizedNetworkPtr network, |
| 213 | std::string& errorMessage, |
| 214 | const INetworkProperties& networkProperties); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 215 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 216 | TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const; |
| 217 | TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 218 | |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 219 | /// ImportInputs separates the importing and mapping of InputTensors from network execution. |
| 220 | /// Allowing for a set of InputTensors to be imported and mapped once, but used in execution many times. |
| 221 | /// This function is not thread safe and must not be used while other threads are calling Execute(). |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 222 | /// Only compatible with AsyncEnabled networks and aligned memory import |
| 223 | std::vector<ImportedInputId> ImportInputs(NetworkId networkId, const InputTensors& inputTensors, |
| 224 | MemorySource forceImportMemorySource = MemorySource::Undefined); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 225 | |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 226 | /// ImportOutputs separates the importing and mapping of OutputTensors from network execution. |
| 227 | /// Allowing for a set of OutputTensors to be imported and mapped once, but used in execution many times. |
| 228 | /// This function is not thread safe and must not be used while other threads are calling Execute(). |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 229 | /// Only compatible with AsyncEnabled networks and aligned memory import |
| 230 | std::vector<ImportedOutputId> ImportOutputs(NetworkId networkId, const OutputTensors& outputTensors, |
| 231 | MemorySource forceImportMemorySource = MemorySource::Undefined); |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 232 | |
| 233 | /// Un-import and delete the imported InputTensor/s |
| 234 | /// This function is not thread safe and must not be used while other threads are calling Execute(). |
| 235 | /// Only compatible with AsyncEnabled networks |
| 236 | void ClearImportedInputs(NetworkId networkId, const std::vector<ImportedInputId> inputIds); |
| 237 | |
| 238 | /// Un-import and delete the imported OutputTensor/s |
| 239 | /// This function is not thread safe and must not be used while other threads are calling Execute(). |
| 240 | /// Only compatible with AsyncEnabled networks |
| 241 | void ClearImportedOutputs(NetworkId networkId, const std::vector<ImportedOutputId> outputIds); |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 242 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 243 | /// Evaluates a network using input in inputTensors and outputs filled into outputTensors |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 244 | Status EnqueueWorkload(NetworkId networkId, |
| 245 | const InputTensors& inputTensors, |
Narumol Prangnawarat | e2af6f4 | 2022-01-28 17:59:18 +0000 | [diff] [blame] | 246 | const OutputTensors& outputTensors, |
| 247 | std::vector<ImportedInputId> preImportedInputIds = {}, |
| 248 | std::vector<ImportedOutputId> preImportedOutputIds = {}); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 249 | |
Mike Kelly | 55a8ffd | 2021-04-07 20:10:49 +0100 | [diff] [blame] | 250 | /// This is an experimental function. |
| 251 | /// Evaluates a network using input in inputTensors and outputs filled into outputTensors. |
| 252 | /// This function performs a thread safe execution of the network. Returns once execution is complete. |
| 253 | /// Will block until this and any other thread using the same workingMem object completes. |
| 254 | Status Execute(IWorkingMemHandle& workingMemHandle, |
| 255 | const InputTensors& inputTensors, |
Finn Williams | f37b970 | 2021-09-01 18:06:04 +0100 | [diff] [blame] | 256 | const OutputTensors& outputTensors, |
Finn Williams | 8636bc7 | 2021-10-02 15:06:39 +0100 | [diff] [blame] | 257 | std::vector<ImportedInputId> preImportedInputs = {}, |
| 258 | std::vector<ImportedOutputId> preImportedOutputs = {}); |
Mike Kelly | 55a8ffd | 2021-04-07 20:10:49 +0100 | [diff] [blame] | 259 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 260 | /// Unloads a network from the IRuntime. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 261 | /// At the moment this only removes the network from the m_Impl->m_Network. |
| 262 | /// This might need more work in the future to be AndroidNN compliant. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 263 | /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork(). |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 264 | /// @return armnn::Status |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 265 | Status UnloadNetwork(NetworkId networkId); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 266 | |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 267 | const IDeviceSpec& GetDeviceSpec() const; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 268 | |
Mike Kelly | 55a8ffd | 2021-04-07 20:10:49 +0100 | [diff] [blame] | 269 | /// Create a new unique WorkingMemHandle object. Create multiple handles if you wish to have |
| 270 | /// overlapped Execution by calling this function from different threads. |
| 271 | std::unique_ptr<IWorkingMemHandle> CreateWorkingMemHandle(NetworkId networkId); |
| 272 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 273 | /// Gets the profiler corresponding to the given network id. |
| 274 | /// @param networkId The id of the network for which to get the profile. |
| 275 | /// @return A pointer to the requested profiler, or nullptr if not found. |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 276 | const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 277 | |
Nattapat Chaimanowong | 6e94820 | 2019-03-22 14:01:46 +0000 | [diff] [blame] | 278 | /// Registers a callback function to debug layers performing custom computations on intermediate tensors. |
| 279 | /// @param networkId The id of the network to register the callback. |
| 280 | /// @param func callback function to pass to the debug layer. |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 281 | void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func); |
Nattapat Chaimanowong | 6e94820 | 2019-03-22 14:01:46 +0000 | [diff] [blame] | 282 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 283 | protected: |
Kevin May | d92a6e4 | 2021-02-04 10:27:41 +0000 | [diff] [blame] | 284 | IRuntime(); |
| 285 | IRuntime(const IRuntime::CreationOptions& options); |
| 286 | ~IRuntime(); |
| 287 | |
| 288 | std::unique_ptr<RuntimeImpl> pRuntimeImpl; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 289 | }; |
| 290 | |
Derek Lamberti | 836b27b | 2019-11-20 10:51:57 +0000 | [diff] [blame] | 291 | |
| 292 | /// The following API is replaced by the backend options API. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 293 | using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 294 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 295 | /// Manages a set of GpuAcc parameters which have been tuned for maximum performance. |
| 296 | /// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it |
| 297 | /// for all GPU workload execution. |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 298 | /// |
| 299 | /// Can be created in two modes: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 300 | /// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads. |
| 301 | /// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 302 | /// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow. |
| 303 | /// |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 304 | /// The parameters can be loaded from and saved to a file so that you can first run a slow initial read-write |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 305 | /// execution, save the parameters for later and then run fast read-only executions using the optimised parameters. |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 306 | class IGpuAccTunedParameters |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 307 | { |
| 308 | public: |
| 309 | enum class Mode |
| 310 | { |
| 311 | UseTunedParameters, |
| 312 | UpdateTunedParameters |
| 313 | }; |
| 314 | |
Ruomei Yan | 49937f3 | 2019-04-25 14:24:05 +0100 | [diff] [blame] | 315 | enum class TuningLevel |
| 316 | { |
Inki Dae | 23dbe3d | 2021-03-16 16:24:09 +0900 | [diff] [blame] | 317 | Rapid = 1, |
| 318 | Normal = 2, |
| 319 | Exhaustive = 3 |
Ruomei Yan | 49937f3 | 2019-04-25 14:24:05 +0100 | [diff] [blame] | 320 | }; |
| 321 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 322 | /// Creates an IClTunedParameters with the given mode. |
| 323 | /// @{ |
Ruomei Yan | 49937f3 | 2019-04-25 14:24:05 +0100 | [diff] [blame] | 324 | static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode); |
| 325 | static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 326 | /// @} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 327 | static void Destroy(IGpuAccTunedParameters* params); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 328 | |
| 329 | /// Loads an existing set of tuned parameters from the given file. |
| 330 | /// If there is an error loading the file, an armnn::Exception is thrown. |
| 331 | virtual void Load(const char* filename) = 0; |
| 332 | |
| 333 | /// Saves the current set of tuned parameters to the given file. |
| 334 | /// If there is an error saving to the file, an armnn::Exception is thrown. |
| 335 | virtual void Save(const char* filename) const = 0; |
| 336 | |
| 337 | protected: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 338 | virtual ~IGpuAccTunedParameters() {}; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 339 | }; |
| 340 | |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 341 | } // namespace armnn |