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