blob: bdfd9b224b77d978a9014081aabed5896f6d802d [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
telsoa014fcda012018-03-09 14:13:49 +00002// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#pragma once
6
Derek Lamberti836b27b2019-11-20 10:51:57 +00007#include "BackendOptions.hpp"
telsoa014fcda012018-03-09 14:13:49 +00008#include "INetwork.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01009#include "IProfiler.hpp"
Mike Kelly55a8ffd2021-04-07 20:10:49 +010010#include "IWorkingMemHandle.hpp"
Keith Davise813d672021-04-22 10:10:34 +010011#include "IAsyncExecutionCallback.hpp"
Matthew Bentham313e1c82019-03-25 17:37:47 +000012#include "Tensor.hpp"
13#include "Types.hpp"
telsoa014fcda012018-03-09 14:13:49 +000014#include "TypesUtils.hpp"
Jim Flynn4e755a52020-03-29 17:48:26 +010015#include "profiling/ILocalPacketHandler.hpp"
telsoa014fcda012018-03-09 14:13:49 +000016
David Monahan801e2d52021-07-19 17:06:30 +010017#include <armnn/backends/ICustomAllocator.hpp>
Sadik Armaganb8a26d82021-10-04 15:13:11 +010018#include <armnn/backends/IMemoryOptimizerStrategy.hpp>
Matthew Bentham313e1c82019-03-25 17:37:47 +000019#include <memory>
Jan Eilersc1c872f2021-07-22 13:17:04 +010020#include <map>
Matthew Bentham313e1c82019-03-25 17:37:47 +000021
telsoa014fcda012018-03-09 14:13:49 +000022namespace armnn
23{
24
25using NetworkId = int;
26
telsoa01c577f2c2018-08-31 09:22:23 +010027class IGpuAccTunedParameters;
telsoa014fcda012018-03-09 14:13:49 +000028
Kevin Mayd92a6e42021-02-04 10:27:41 +000029struct RuntimeImpl;
telsoa014fcda012018-03-09 14:13:49 +000030class IRuntime;
31using IRuntimePtr = std::unique_ptr<IRuntime, void(*)(IRuntime* runtime)>;
32
David Monahan4f1e8e42019-09-04 09:22:10 +010033struct INetworkProperties
34{
Jan Eilers1b2654f2021-09-24 15:45:46 +010035 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Please use INetworkProperties constructor with MemorySource argument", "22.02")
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010036 INetworkProperties(bool importEnabled = false,
37 bool exportEnabled = false,
Keith Davis554fa092021-07-20 11:25:22 +010038 bool asyncEnabled = false,
39 bool profilingEnabled = false)
40 : m_ImportEnabled(importEnabled),
41 m_ExportEnabled(exportEnabled),
42 m_AsyncEnabled(asyncEnabled),
43 m_ProfilingEnabled(profilingEnabled),
Keith Davis4914d0c2021-08-18 17:14:05 +010044 m_OutputNetworkDetailsMethod(ProfilingDetailsMethod::Undefined),
Keith Davis554fa092021-07-20 11:25:22 +010045 m_InputSource(m_ImportEnabled ? MemorySource::Malloc : MemorySource::Undefined),
Finn Williamsb1aad422021-10-28 19:07:32 +010046 m_OutputSource(m_ExportEnabled ? MemorySource::Malloc : MemorySource::Undefined),
47 m_ExternalMemoryManagementEnabled(false)
Narumol Prangnawarate5f0b242021-05-07 17:52:36 +010048 {}
David Monahan4f1e8e42019-09-04 09:22:10 +010049
Jan Eilers1b2654f2021-09-24 15:45:46 +010050 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Please use INetworkProperties constructor without numThreads argument", "22.02")
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010051 INetworkProperties(bool asyncEnabled,
Keith Davisf4874862021-08-09 16:49:18 +010052 MemorySource inputSource,
53 MemorySource outputSource,
Keith Davis554fa092021-07-20 11:25:22 +010054 size_t numThreads,
55 bool profilingEnabled = false)
Keith Davisf4874862021-08-09 16:49:18 +010056 : m_ImportEnabled(inputSource != MemorySource::Undefined),
57 m_ExportEnabled(outputSource != MemorySource::Undefined),
Keith Davis554fa092021-07-20 11:25:22 +010058 m_AsyncEnabled(asyncEnabled),
59 m_ProfilingEnabled(profilingEnabled),
Keith Davis4914d0c2021-08-18 17:14:05 +010060 m_OutputNetworkDetailsMethod(ProfilingDetailsMethod::Undefined),
Keith Davisf4874862021-08-09 16:49:18 +010061 m_InputSource(inputSource),
Finn Williamsb1aad422021-10-28 19:07:32 +010062 m_OutputSource(outputSource),
63 m_ExternalMemoryManagementEnabled(false)
Finn Williamsf364d532021-06-09 17:07:33 +010064 {
65 armnn::IgnoreUnused(numThreads);
66 }
67
68 INetworkProperties(bool asyncEnabled,
Keith Davisf4874862021-08-09 16:49:18 +010069 MemorySource inputSource,
70 MemorySource outputSource,
71 bool profilingEnabled = false,
Finn Williamsb1aad422021-10-28 19:07:32 +010072 ProfilingDetailsMethod detailsMethod = ProfilingDetailsMethod::Undefined,
73 bool externalMemoryManagementEnabled = false)
Keith Davisf4874862021-08-09 16:49:18 +010074 : m_ImportEnabled(inputSource != MemorySource::Undefined),
75 m_ExportEnabled(outputSource != MemorySource::Undefined),
Keith Davis554fa092021-07-20 11:25:22 +010076 m_AsyncEnabled(asyncEnabled),
77 m_ProfilingEnabled(profilingEnabled),
Keith Davis4914d0c2021-08-18 17:14:05 +010078 m_OutputNetworkDetailsMethod(detailsMethod),
Keith Davisf4874862021-08-09 16:49:18 +010079 m_InputSource(inputSource),
Finn Williamsb1aad422021-10-28 19:07:32 +010080 m_OutputSource(outputSource),
81 m_ExternalMemoryManagementEnabled(externalMemoryManagementEnabled)
Keith Davis554fa092021-07-20 11:25:22 +010082 {}
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010083
84 /// Deprecated and will be removed in future release.
David Monahan4f1e8e42019-09-04 09:22:10 +010085 const bool m_ImportEnabled;
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010086 /// Deprecated and will be removed in future release.
David Monahan4f1e8e42019-09-04 09:22:10 +010087 const bool m_ExportEnabled;
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010088
Keith Davis554fa092021-07-20 11:25:22 +010089 const bool m_AsyncEnabled;
90
91 const bool m_ProfilingEnabled;
Keith Davise813d672021-04-22 10:10:34 +010092
Keith Davis4914d0c2021-08-18 17:14:05 +010093 const ProfilingDetailsMethod m_OutputNetworkDetailsMethod;
Keith Davisf4874862021-08-09 16:49:18 +010094
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010095 const MemorySource m_InputSource;
96 const MemorySource m_OutputSource;
David Monahan4f1e8e42019-09-04 09:22:10 +010097
Finn Williamsb1aad422021-10-28 19:07:32 +010098 const bool m_ExternalMemoryManagementEnabled;
99
David Monahan4f1e8e42019-09-04 09:22:10 +0100100 virtual ~INetworkProperties() {}
101};
102
Mike Kelly386ff1a2021-03-29 15:04:50 +0100103using namespace armnn::experimental;
104
telsoa014fcda012018-03-09 14:13:49 +0000105class IRuntime
106{
107public:
108 struct CreationOptions
109 {
telsoa01c577f2c2018-08-31 09:22:23 +0100110 CreationOptions()
111 : m_GpuAccTunedParameters(nullptr)
112 , m_EnableGpuProfiling(false)
Matteo Martincighe7d44982019-08-05 12:16:47 +0100113 , m_DynamicBackendsPath("")
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100114 , m_ProtectedMode(false)
Jan Eilersc1c872f2021-07-22 13:17:04 +0100115 , m_CustomAllocatorMap()
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100116 , m_MemoryOptimizerStrategyMap()
telsoa01c577f2c2018-08-31 09:22:23 +0100117 {}
telsoa014fcda012018-03-09 14:13:49 +0000118
telsoa01c577f2c2018-08-31 09:22:23 +0100119 /// If set, uses the GpuAcc tuned parameters from the given object when executing GPU workloads.
120 /// It will also be updated with new tuned parameters if it is configured to do so.
121 std::shared_ptr<IGpuAccTunedParameters> m_GpuAccTunedParameters;
122
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000123 /// Setting this flag will allow the user to obtain GPU profiling information from the runtime.
telsoa01c577f2c2018-08-31 09:22:23 +0100124 bool m_EnableGpuProfiling;
Matteo Martincighe7d44982019-08-05 12:16:47 +0100125
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000126 /// Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive
127 /// Only a single path is allowed for the override
Jan Eilersb1c62f12021-10-26 14:56:47 +0100128 /// It defines the path to search for any [dynamic backend libraries](src/dynamic/README.md).
Matteo Martincighe7d44982019-08-05 12:16:47 +0100129 std::string m_DynamicBackendsPath;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100130
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100131 /// Setting this flag will allow the user to create the Runtime in protected mode.
132 /// It will run all the inferences on protected memory and will make sure that
133 /// INetworkProperties::m_ImportEnabled set to true with MemorySource::DmaBufProtected option
Jan Eilersc1c872f2021-07-22 13:17:04 +0100134 /// This requires that the backend supports Protected Memory and has an allocator capable of
135 /// allocating Protected Memory associated with it.
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100136 bool m_ProtectedMode;
137
Jan Eilersc1c872f2021-07-22 13:17:04 +0100138 /// @brief A map to define a custom memory allocator for specific backend Ids.
139 ///
140 /// @details A Custom Allocator is used for allocation of working memory in the backends.
141 /// Set this if you need to take control of how memory is allocated on a backend. Required for
142 /// Protected Mode in order to correctly allocate Protected Memory
143 ///
144 /// @note Only supported for GpuAcc
145 std::map<BackendId, std::shared_ptr<ICustomAllocator>> m_CustomAllocatorMap;
146
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100147 /// @brief A map to define a custom memory optimizer strategy for specific backend Ids.
148 ///
149 /// @details A Memory Optimizer Strategy provides a solution to an abstract representation of
150 /// a network's memory requirements. This can also be used to return a pre-computed solution
151 /// for a specific network. Set this if you want to implement a Custom Memory Optimizer Strategy
152 /// for a given backend.
153 std::map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>> m_MemoryOptimizerStrategyMap;
154
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100155 struct ExternalProfilingOptions
156 {
157 ExternalProfilingOptions()
158 : m_EnableProfiling(false)
Jim Flynn4e755a52020-03-29 17:48:26 +0100159 , m_TimelineEnabled(false)
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100160 , m_OutgoingCaptureFile("")
161 , m_IncomingCaptureFile("")
162 , m_FileOnly(false)
Colm Donelan02705242019-11-14 14:19:07 +0000163 , m_CapturePeriod(LOWEST_CAPTURE_PERIOD)
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000164 , m_FileFormat("binary")
Jim Flynn4e755a52020-03-29 17:48:26 +0100165 , m_LocalPacketHandlers()
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100166 {}
167
Jan Eilersb1c62f12021-10-26 14:56:47 +0100168 /// Indicates whether external profiling is enabled or not.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100169 bool m_EnableProfiling;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100170 /// Indicates whether external timeline profiling is enabled or not.
Jim Flynn4e755a52020-03-29 17:48:26 +0100171 bool m_TimelineEnabled;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100172 /// Path to a file in which outgoing timeline profiling messages will be stored.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100173 std::string m_OutgoingCaptureFile;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100174 /// Path to a file in which incoming timeline profiling messages will be stored.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100175 std::string m_IncomingCaptureFile;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100176 /// Enable profiling output to file only.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100177 bool m_FileOnly;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100178 /// The duration at which captured profiling messages will be flushed.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100179 uint32_t m_CapturePeriod;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100180 /// The format of the file used for outputting profiling data.
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000181 std::string m_FileFormat;
Jim Flynn4e755a52020-03-29 17:48:26 +0100182 std::vector<armnn::profiling::ILocalPacketHandlerSharedPtr> m_LocalPacketHandlers;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100183 };
Jim Flynn4951b8c2019-10-03 10:04:30 -0700184 ExternalProfilingOptions m_ProfilingOptions;
Derek Lamberti836b27b2019-11-20 10:51:57 +0000185
186 /// Pass backend specific options.
187 ///
188 /// For example, to enable GpuAcc tuning add the following
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000189 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp
Derek Lamberti836b27b2019-11-20 10:51:57 +0000190 /// m_BackendOption.emplace_back(
191 /// BackendOptions{"GpuAcc",
192 /// {
193 /// {"TuningLevel", 2},
194 /// {"TuningFile", filename}
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100195 /// {"MemoryOptimizerStrategy", strategyname}
Derek Lamberti836b27b2019-11-20 10:51:57 +0000196 /// }
197 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000198 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000199 /// Execute representative workloads through the runtime to generate tuning data.
200 /// The tuning file is written once the runtime is destroyed
201
202 /// To execute with the tuning data, start up with just the tuning file specified.
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000203 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp
Derek Lamberti836b27b2019-11-20 10:51:57 +0000204 /// m_BackendOption.emplace_back(
205 /// BackendOptions{"GpuAcc",
206 /// {
207 /// {"TuningFile", filename}
208 /// }
209 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000210 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000211
212 /// The following backend options are available:
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100213 /// AllBackends:
214 /// "MemoryOptimizerStrategy" : string [stategynameString]
Jim Flynne1fdd282021-10-26 21:26:10 +0100215 /// (Existing Memory Optimizer Strategies: ConstantMemoryStrategy)
Derek Lamberti836b27b2019-11-20 10:51:57 +0000216 /// GpuAcc:
217 /// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning)
218 /// "TuningFile" : string [filenameString]
219 /// "KernelProfilingEnabled" : bool [true | false]
220 std::vector<BackendOptions> m_BackendOptions;
telsoa014fcda012018-03-09 14:13:49 +0000221 };
222
223 static IRuntime* CreateRaw(const CreationOptions& options);
224 static IRuntimePtr Create(const CreationOptions& options);
225 static void Destroy(IRuntime* runtime);
226
telsoa01c577f2c2018-08-31 09:22:23 +0100227 /// Loads a complete network into the IRuntime.
228 /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference.
229 /// @param [in] network - Complete network to load into the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +0000230 /// The runtime takes ownership of the network once passed in.
231 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000232 Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network);
telsoa014fcda012018-03-09 14:13:49 +0000233
telsoa01c577f2c2018-08-31 09:22:23 +0100234 /// Load a complete network into the IRuntime.
235 /// @param [out] networkIdOut Unique identifier for the network is returned in this reference.
236 /// @param [in] network Complete network to load into the IRuntime.
237 /// @param [out] errorMessage Error message if there were any errors.
238 /// The runtime takes ownership of the network once passed in.
239 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000240 Status LoadNetwork(NetworkId& networkIdOut,
241 IOptimizedNetworkPtr network,
242 std::string& errorMessage);
David Monahan4f1e8e42019-09-04 09:22:10 +0100243
Kevin Mayd92a6e42021-02-04 10:27:41 +0000244 Status LoadNetwork(NetworkId& networkIdOut,
245 IOptimizedNetworkPtr network,
246 std::string& errorMessage,
247 const INetworkProperties& networkProperties);
telsoa01c577f2c2018-08-31 09:22:23 +0100248
Kevin Mayd92a6e42021-02-04 10:27:41 +0000249 TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
250 TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
telsoa014fcda012018-03-09 14:13:49 +0000251
Finn Williamsf37b9702021-09-01 18:06:04 +0100252
253 /// ImportInputs separates the importing and mapping of InputTensors from network execution.
254 /// Allowing for a set of InputTensors to be imported and mapped once, but used in execution many times.
255 /// This function is not thread safe and must not be used while other threads are calling Execute().
256 /// Only compatible with AsyncEnabled networks
257 std::vector<ImportedInputId> ImportInputs(NetworkId networkId, const InputTensors& inputTensors);
258
Finn Williams8636bc72021-10-02 15:06:39 +0100259 /// ImportOutputs separates the importing and mapping of OutputTensors from network execution.
260 /// Allowing for a set of OutputTensors to be imported and mapped once, but used in execution many times.
261 /// This function is not thread safe and must not be used while other threads are calling Execute().
262 /// Only compatible with AsyncEnabled networks
Francis Murtaghb87f5442021-09-23 13:20:53 +0100263 std::vector<ImportedOutputId> ImportOutputs(NetworkId networkId, const OutputTensors& outputTensors);
Finn Williams8636bc72021-10-02 15:06:39 +0100264
265 /// Un-import and delete the imported InputTensor/s
266 /// This function is not thread safe and must not be used while other threads are calling Execute().
267 /// Only compatible with AsyncEnabled networks
268 void ClearImportedInputs(NetworkId networkId, const std::vector<ImportedInputId> inputIds);
269
270 /// Un-import and delete the imported OutputTensor/s
271 /// This function is not thread safe and must not be used while other threads are calling Execute().
272 /// Only compatible with AsyncEnabled networks
273 void ClearImportedOutputs(NetworkId networkId, const std::vector<ImportedOutputId> outputIds);
Finn Williamsf37b9702021-09-01 18:06:04 +0100274
telsoa01c577f2c2018-08-31 09:22:23 +0100275 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
Kevin Mayd92a6e42021-02-04 10:27:41 +0000276 Status EnqueueWorkload(NetworkId networkId,
277 const InputTensors& inputTensors,
278 const OutputTensors& outputTensors);
telsoa014fcda012018-03-09 14:13:49 +0000279
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100280 /// This is an experimental function.
281 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors.
282 /// This function performs a thread safe execution of the network. Returns once execution is complete.
283 /// Will block until this and any other thread using the same workingMem object completes.
284 Status Execute(IWorkingMemHandle& workingMemHandle,
285 const InputTensors& inputTensors,
Finn Williamsf37b9702021-09-01 18:06:04 +0100286 const OutputTensors& outputTensors,
Finn Williams8636bc72021-10-02 15:06:39 +0100287 std::vector<ImportedInputId> preImportedInputs = {},
288 std::vector<ImportedOutputId> preImportedOutputs = {});
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100289
telsoa01c577f2c2018-08-31 09:22:23 +0100290 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +0000291 /// At the moment this only removes the network from the m_Impl->m_Network.
292 /// This might need more work in the future to be AndroidNN compliant.
telsoa01c577f2c2018-08-31 09:22:23 +0100293 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +0000294 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000295 Status UnloadNetwork(NetworkId networkId);
telsoa014fcda012018-03-09 14:13:49 +0000296
Kevin Mayd92a6e42021-02-04 10:27:41 +0000297 const IDeviceSpec& GetDeviceSpec() const;
telsoa01c577f2c2018-08-31 09:22:23 +0100298
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100299 /// Create a new unique WorkingMemHandle object. Create multiple handles if you wish to have
300 /// overlapped Execution by calling this function from different threads.
301 std::unique_ptr<IWorkingMemHandle> CreateWorkingMemHandle(NetworkId networkId);
302
telsoa01c577f2c2018-08-31 09:22:23 +0100303 /// Gets the profiler corresponding to the given network id.
304 /// @param networkId The id of the network for which to get the profile.
305 /// @return A pointer to the requested profiler, or nullptr if not found.
Kevin Mayd92a6e42021-02-04 10:27:41 +0000306 const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const;
telsoa014fcda012018-03-09 14:13:49 +0000307
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000308 /// Registers a callback function to debug layers performing custom computations on intermediate tensors.
309 /// @param networkId The id of the network to register the callback.
310 /// @param func callback function to pass to the debug layer.
Kevin Mayd92a6e42021-02-04 10:27:41 +0000311 void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func);
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000312
telsoa014fcda012018-03-09 14:13:49 +0000313protected:
Kevin Mayd92a6e42021-02-04 10:27:41 +0000314 IRuntime();
315 IRuntime(const IRuntime::CreationOptions& options);
316 ~IRuntime();
317
318 std::unique_ptr<RuntimeImpl> pRuntimeImpl;
telsoa014fcda012018-03-09 14:13:49 +0000319};
320
Derek Lamberti836b27b2019-11-20 10:51:57 +0000321
322/// The following API is replaced by the backend options API.
telsoa01c577f2c2018-08-31 09:22:23 +0100323using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +0000324
telsoa01c577f2c2018-08-31 09:22:23 +0100325/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
326/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
327/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +0000328///
329/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100330/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
331/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +0000332/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
333///
telsoa01c577f2c2018-08-31 09:22:23 +0100334/// The parameters can be loaded from and saved to a file so that you can first run a slow initial read-write
telsoa014fcda012018-03-09 14:13:49 +0000335/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100336class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000337{
338public:
339 enum class Mode
340 {
341 UseTunedParameters,
342 UpdateTunedParameters
343 };
344
Ruomei Yan49937f32019-04-25 14:24:05 +0100345 enum class TuningLevel
346 {
Inki Dae23dbe3d2021-03-16 16:24:09 +0900347 Rapid = 1,
348 Normal = 2,
349 Exhaustive = 3
Ruomei Yan49937f32019-04-25 14:24:05 +0100350 };
351
telsoa014fcda012018-03-09 14:13:49 +0000352 /// Creates an IClTunedParameters with the given mode.
353 /// @{
Ruomei Yan49937f32019-04-25 14:24:05 +0100354 static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
355 static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
telsoa014fcda012018-03-09 14:13:49 +0000356 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100357 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000358
359 /// Loads an existing set of tuned parameters from the given file.
360 /// If there is an error loading the file, an armnn::Exception is thrown.
361 virtual void Load(const char* filename) = 0;
362
363 /// Saves the current set of tuned parameters to the given file.
364 /// If there is an error saving to the file, an armnn::Exception is thrown.
365 virtual void Save(const char* filename) const = 0;
366
367protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100368 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000369};
370
David Monahan4f1e8e42019-09-04 09:22:10 +0100371} // namespace armnn