blob: 93f8b0fd5bfcb58ffd514bee74398dcccff9cb9b [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),
46 m_OutputSource(m_ExportEnabled ? MemorySource::Malloc : MemorySource::Undefined)
Narumol Prangnawarate5f0b242021-05-07 17:52:36 +010047 {}
David Monahan4f1e8e42019-09-04 09:22:10 +010048
Jan Eilers1b2654f2021-09-24 15:45:46 +010049 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Please use INetworkProperties constructor without numThreads argument", "22.02")
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010050 INetworkProperties(bool asyncEnabled,
Keith Davisf4874862021-08-09 16:49:18 +010051 MemorySource inputSource,
52 MemorySource outputSource,
Keith Davis554fa092021-07-20 11:25:22 +010053 size_t numThreads,
54 bool profilingEnabled = false)
Keith Davisf4874862021-08-09 16:49:18 +010055 : m_ImportEnabled(inputSource != MemorySource::Undefined),
56 m_ExportEnabled(outputSource != MemorySource::Undefined),
Keith Davis554fa092021-07-20 11:25:22 +010057 m_AsyncEnabled(asyncEnabled),
58 m_ProfilingEnabled(profilingEnabled),
Keith Davis4914d0c2021-08-18 17:14:05 +010059 m_OutputNetworkDetailsMethod(ProfilingDetailsMethod::Undefined),
Keith Davisf4874862021-08-09 16:49:18 +010060 m_InputSource(inputSource),
61 m_OutputSource(outputSource)
Finn Williamsf364d532021-06-09 17:07:33 +010062 {
63 armnn::IgnoreUnused(numThreads);
64 }
65
66 INetworkProperties(bool asyncEnabled,
Keith Davisf4874862021-08-09 16:49:18 +010067 MemorySource inputSource,
68 MemorySource outputSource,
69 bool profilingEnabled = false,
Keith Davis4914d0c2021-08-18 17:14:05 +010070 ProfilingDetailsMethod detailsMethod = ProfilingDetailsMethod::Undefined)
Keith Davisf4874862021-08-09 16:49:18 +010071 : m_ImportEnabled(inputSource != MemorySource::Undefined),
72 m_ExportEnabled(outputSource != MemorySource::Undefined),
Keith Davis554fa092021-07-20 11:25:22 +010073 m_AsyncEnabled(asyncEnabled),
74 m_ProfilingEnabled(profilingEnabled),
Keith Davis4914d0c2021-08-18 17:14:05 +010075 m_OutputNetworkDetailsMethod(detailsMethod),
Keith Davisf4874862021-08-09 16:49:18 +010076 m_InputSource(inputSource),
77 m_OutputSource(outputSource)
Keith Davis554fa092021-07-20 11:25:22 +010078 {}
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010079
80 /// Deprecated and will be removed in future release.
David Monahan4f1e8e42019-09-04 09:22:10 +010081 const bool m_ImportEnabled;
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010082 /// Deprecated and will be removed in future release.
David Monahan4f1e8e42019-09-04 09:22:10 +010083 const bool m_ExportEnabled;
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010084
Keith Davis554fa092021-07-20 11:25:22 +010085 const bool m_AsyncEnabled;
86
87 const bool m_ProfilingEnabled;
Keith Davise813d672021-04-22 10:10:34 +010088
Keith Davis4914d0c2021-08-18 17:14:05 +010089 const ProfilingDetailsMethod m_OutputNetworkDetailsMethod;
Keith Davisf4874862021-08-09 16:49:18 +010090
Francis Murtagh73d3e2e2021-04-29 14:23:04 +010091 const MemorySource m_InputSource;
92 const MemorySource m_OutputSource;
David Monahan4f1e8e42019-09-04 09:22:10 +010093
94 virtual ~INetworkProperties() {}
95};
96
Mike Kelly386ff1a2021-03-29 15:04:50 +010097using namespace armnn::experimental;
98
telsoa014fcda012018-03-09 14:13:49 +000099class IRuntime
100{
101public:
102 struct CreationOptions
103 {
telsoa01c577f2c2018-08-31 09:22:23 +0100104 CreationOptions()
105 : m_GpuAccTunedParameters(nullptr)
106 , m_EnableGpuProfiling(false)
Matteo Martincighe7d44982019-08-05 12:16:47 +0100107 , m_DynamicBackendsPath("")
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100108 , m_ProtectedMode(false)
Jan Eilersc1c872f2021-07-22 13:17:04 +0100109 , m_CustomAllocatorMap()
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100110 , m_MemoryOptimizerStrategyMap()
telsoa01c577f2c2018-08-31 09:22:23 +0100111 {}
telsoa014fcda012018-03-09 14:13:49 +0000112
telsoa01c577f2c2018-08-31 09:22:23 +0100113 /// 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 OShea2bbfaa72020-02-12 16:15:27 +0000117 /// Setting this flag will allow the user to obtain GPU profiling information from the runtime.
telsoa01c577f2c2018-08-31 09:22:23 +0100118 bool m_EnableGpuProfiling;
Matteo Martincighe7d44982019-08-05 12:16:47 +0100119
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000120 /// 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
Jan Eilersb1c62f12021-10-26 14:56:47 +0100122 /// It defines the path to search for any [dynamic backend libraries](src/dynamic/README.md).
Matteo Martincighe7d44982019-08-05 12:16:47 +0100123 std::string m_DynamicBackendsPath;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100124
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100125 /// Setting this flag will allow the user to create the Runtime in protected mode.
126 /// It will run all the inferences on protected memory and will make sure that
127 /// INetworkProperties::m_ImportEnabled set to true with MemorySource::DmaBufProtected option
Jan Eilersc1c872f2021-07-22 13:17:04 +0100128 /// This requires that the backend supports Protected Memory and has an allocator capable of
129 /// allocating Protected Memory associated with it.
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100130 bool m_ProtectedMode;
131
Jan Eilersc1c872f2021-07-22 13:17:04 +0100132 /// @brief A map to define a custom memory allocator for specific backend Ids.
133 ///
134 /// @details A Custom Allocator is used for allocation of working memory in the backends.
135 /// Set this if you need to take control of how memory is allocated on a backend. Required for
136 /// Protected Mode in order to correctly allocate Protected Memory
137 ///
138 /// @note Only supported for GpuAcc
139 std::map<BackendId, std::shared_ptr<ICustomAllocator>> m_CustomAllocatorMap;
140
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100141 /// @brief A map to define a custom memory optimizer strategy for specific backend Ids.
142 ///
143 /// @details A Memory Optimizer Strategy provides a solution to an abstract representation of
144 /// a network's memory requirements. This can also be used to return a pre-computed solution
145 /// for a specific network. Set this if you want to implement a Custom Memory Optimizer Strategy
146 /// for a given backend.
147 std::map<BackendId, std::shared_ptr<IMemoryOptimizerStrategy>> m_MemoryOptimizerStrategyMap;
148
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100149 struct ExternalProfilingOptions
150 {
151 ExternalProfilingOptions()
152 : m_EnableProfiling(false)
Jim Flynn4e755a52020-03-29 17:48:26 +0100153 , m_TimelineEnabled(false)
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100154 , m_OutgoingCaptureFile("")
155 , m_IncomingCaptureFile("")
156 , m_FileOnly(false)
Colm Donelan02705242019-11-14 14:19:07 +0000157 , m_CapturePeriod(LOWEST_CAPTURE_PERIOD)
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000158 , m_FileFormat("binary")
Jim Flynn4e755a52020-03-29 17:48:26 +0100159 , m_LocalPacketHandlers()
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100160 {}
161
Jan Eilersb1c62f12021-10-26 14:56:47 +0100162 /// Indicates whether external profiling is enabled or not.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100163 bool m_EnableProfiling;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100164 /// Indicates whether external timeline profiling is enabled or not.
Jim Flynn4e755a52020-03-29 17:48:26 +0100165 bool m_TimelineEnabled;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100166 /// Path to a file in which outgoing timeline profiling messages will be stored.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100167 std::string m_OutgoingCaptureFile;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100168 /// Path to a file in which incoming timeline profiling messages will be stored.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100169 std::string m_IncomingCaptureFile;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100170 /// Enable profiling output to file only.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100171 bool m_FileOnly;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100172 /// The duration at which captured profiling messages will be flushed.
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100173 uint32_t m_CapturePeriod;
Jan Eilersb1c62f12021-10-26 14:56:47 +0100174 /// The format of the file used for outputting profiling data.
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000175 std::string m_FileFormat;
Jim Flynn4e755a52020-03-29 17:48:26 +0100176 std::vector<armnn::profiling::ILocalPacketHandlerSharedPtr> m_LocalPacketHandlers;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100177 };
Jim Flynn4951b8c2019-10-03 10:04:30 -0700178 ExternalProfilingOptions m_ProfilingOptions;
Derek Lamberti836b27b2019-11-20 10:51:57 +0000179
180 /// Pass backend specific options.
181 ///
182 /// For example, to enable GpuAcc tuning add the following
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000183 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp
Derek Lamberti836b27b2019-11-20 10:51:57 +0000184 /// m_BackendOption.emplace_back(
185 /// BackendOptions{"GpuAcc",
186 /// {
187 /// {"TuningLevel", 2},
188 /// {"TuningFile", filename}
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100189 /// {"MemoryOptimizerStrategy", strategyname}
Derek Lamberti836b27b2019-11-20 10:51:57 +0000190 /// }
191 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000192 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000193 /// Execute representative workloads through the runtime to generate tuning data.
194 /// The tuning file is written once the runtime is destroyed
195
196 /// To execute with the tuning data, start up with just the tuning file specified.
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000197 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp
Derek Lamberti836b27b2019-11-20 10:51:57 +0000198 /// m_BackendOption.emplace_back(
199 /// BackendOptions{"GpuAcc",
200 /// {
201 /// {"TuningFile", filename}
202 /// }
203 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000204 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000205
206 /// The following backend options are available:
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100207 /// AllBackends:
208 /// "MemoryOptimizerStrategy" : string [stategynameString]
Jim Flynne1fdd282021-10-26 21:26:10 +0100209 /// (Existing Memory Optimizer Strategies: ConstantMemoryStrategy)
Derek Lamberti836b27b2019-11-20 10:51:57 +0000210 /// GpuAcc:
211 /// "TuningLevel" : int [0..3] (0=UseOnly(default) | 1=RapidTuning | 2=NormalTuning | 3=ExhaustiveTuning)
212 /// "TuningFile" : string [filenameString]
213 /// "KernelProfilingEnabled" : bool [true | false]
214 std::vector<BackendOptions> m_BackendOptions;
telsoa014fcda012018-03-09 14:13:49 +0000215 };
216
217 static IRuntime* CreateRaw(const CreationOptions& options);
218 static IRuntimePtr Create(const CreationOptions& options);
219 static void Destroy(IRuntime* runtime);
220
telsoa01c577f2c2018-08-31 09:22:23 +0100221 /// Loads a complete network into the IRuntime.
222 /// @param [out] networkIdOut - Unique identifier for the network is returned in this reference.
223 /// @param [in] network - Complete network to load into the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +0000224 /// The runtime takes ownership of the network once passed in.
225 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000226 Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network);
telsoa014fcda012018-03-09 14:13:49 +0000227
telsoa01c577f2c2018-08-31 09:22:23 +0100228 /// Load a complete network into the IRuntime.
229 /// @param [out] networkIdOut Unique identifier for the network is returned in this reference.
230 /// @param [in] network Complete network to load into the IRuntime.
231 /// @param [out] errorMessage Error message if there were any errors.
232 /// The runtime takes ownership of the network once passed in.
233 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000234 Status LoadNetwork(NetworkId& networkIdOut,
235 IOptimizedNetworkPtr network,
236 std::string& errorMessage);
David Monahan4f1e8e42019-09-04 09:22:10 +0100237
Kevin Mayd92a6e42021-02-04 10:27:41 +0000238 Status LoadNetwork(NetworkId& networkIdOut,
239 IOptimizedNetworkPtr network,
240 std::string& errorMessage,
241 const INetworkProperties& networkProperties);
telsoa01c577f2c2018-08-31 09:22:23 +0100242
Kevin Mayd92a6e42021-02-04 10:27:41 +0000243 TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
244 TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
telsoa014fcda012018-03-09 14:13:49 +0000245
Finn Williamsf37b9702021-09-01 18:06:04 +0100246
247 /// ImportInputs separates the importing and mapping of InputTensors from network execution.
248 /// Allowing for a set of InputTensors to be imported and mapped once, but used in execution many times.
249 /// This function is not thread safe and must not be used while other threads are calling Execute().
250 /// Only compatible with AsyncEnabled networks
251 std::vector<ImportedInputId> ImportInputs(NetworkId networkId, const InputTensors& inputTensors);
252
Finn Williams8636bc72021-10-02 15:06:39 +0100253 /// ImportOutputs separates the importing and mapping of OutputTensors from network execution.
254 /// Allowing for a set of OutputTensors 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
Francis Murtaghb87f5442021-09-23 13:20:53 +0100257 std::vector<ImportedOutputId> ImportOutputs(NetworkId networkId, const OutputTensors& outputTensors);
Finn Williams8636bc72021-10-02 15:06:39 +0100258
259 /// Un-import and delete the imported InputTensor/s
260 /// This function is not thread safe and must not be used while other threads are calling Execute().
261 /// Only compatible with AsyncEnabled networks
262 void ClearImportedInputs(NetworkId networkId, const std::vector<ImportedInputId> inputIds);
263
264 /// Un-import and delete the imported OutputTensor/s
265 /// This function is not thread safe and must not be used while other threads are calling Execute().
266 /// Only compatible with AsyncEnabled networks
267 void ClearImportedOutputs(NetworkId networkId, const std::vector<ImportedOutputId> outputIds);
Finn Williamsf37b9702021-09-01 18:06:04 +0100268
telsoa01c577f2c2018-08-31 09:22:23 +0100269 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
Kevin Mayd92a6e42021-02-04 10:27:41 +0000270 Status EnqueueWorkload(NetworkId networkId,
271 const InputTensors& inputTensors,
272 const OutputTensors& outputTensors);
telsoa014fcda012018-03-09 14:13:49 +0000273
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100274 /// This is an experimental function.
275 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors.
276 /// This function performs a thread safe execution of the network. Returns once execution is complete.
277 /// Will block until this and any other thread using the same workingMem object completes.
278 Status Execute(IWorkingMemHandle& workingMemHandle,
279 const InputTensors& inputTensors,
Finn Williamsf37b9702021-09-01 18:06:04 +0100280 const OutputTensors& outputTensors,
Finn Williams8636bc72021-10-02 15:06:39 +0100281 std::vector<ImportedInputId> preImportedInputs = {},
282 std::vector<ImportedOutputId> preImportedOutputs = {});
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100283
telsoa01c577f2c2018-08-31 09:22:23 +0100284 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +0000285 /// At the moment this only removes the network from the m_Impl->m_Network.
286 /// This might need more work in the future to be AndroidNN compliant.
telsoa01c577f2c2018-08-31 09:22:23 +0100287 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +0000288 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000289 Status UnloadNetwork(NetworkId networkId);
telsoa014fcda012018-03-09 14:13:49 +0000290
Kevin Mayd92a6e42021-02-04 10:27:41 +0000291 const IDeviceSpec& GetDeviceSpec() const;
telsoa01c577f2c2018-08-31 09:22:23 +0100292
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100293 /// Create a new unique WorkingMemHandle object. Create multiple handles if you wish to have
294 /// overlapped Execution by calling this function from different threads.
295 std::unique_ptr<IWorkingMemHandle> CreateWorkingMemHandle(NetworkId networkId);
296
telsoa01c577f2c2018-08-31 09:22:23 +0100297 /// Gets the profiler corresponding to the given network id.
298 /// @param networkId The id of the network for which to get the profile.
299 /// @return A pointer to the requested profiler, or nullptr if not found.
Kevin Mayd92a6e42021-02-04 10:27:41 +0000300 const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const;
telsoa014fcda012018-03-09 14:13:49 +0000301
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000302 /// Registers a callback function to debug layers performing custom computations on intermediate tensors.
303 /// @param networkId The id of the network to register the callback.
304 /// @param func callback function to pass to the debug layer.
Kevin Mayd92a6e42021-02-04 10:27:41 +0000305 void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func);
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000306
telsoa014fcda012018-03-09 14:13:49 +0000307protected:
Kevin Mayd92a6e42021-02-04 10:27:41 +0000308 IRuntime();
309 IRuntime(const IRuntime::CreationOptions& options);
310 ~IRuntime();
311
312 std::unique_ptr<RuntimeImpl> pRuntimeImpl;
telsoa014fcda012018-03-09 14:13:49 +0000313};
314
Derek Lamberti836b27b2019-11-20 10:51:57 +0000315
316/// The following API is replaced by the backend options API.
telsoa01c577f2c2018-08-31 09:22:23 +0100317using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +0000318
telsoa01c577f2c2018-08-31 09:22:23 +0100319/// Manages a set of GpuAcc parameters which have been tuned for maximum performance.
320/// Passes an instance of this object to the IRuntime::Create() method (via IRuntime::CreationOptions) to use it
321/// for all GPU workload execution.
telsoa014fcda012018-03-09 14:13:49 +0000322///
323/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100324/// - In UseTunedParameters mode, the parameters stored in this object are used to execute GPU workloads.
325/// - In UpdateTunedParameters mode, additionally, whenever a GPU workload is executed for the first time, the
telsoa014fcda012018-03-09 14:13:49 +0000326/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
327///
telsoa01c577f2c2018-08-31 09:22:23 +0100328/// 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 +0000329/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100330class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000331{
332public:
333 enum class Mode
334 {
335 UseTunedParameters,
336 UpdateTunedParameters
337 };
338
Ruomei Yan49937f32019-04-25 14:24:05 +0100339 enum class TuningLevel
340 {
Inki Dae23dbe3d2021-03-16 16:24:09 +0900341 Rapid = 1,
342 Normal = 2,
343 Exhaustive = 3
Ruomei Yan49937f32019-04-25 14:24:05 +0100344 };
345
telsoa014fcda012018-03-09 14:13:49 +0000346 /// Creates an IClTunedParameters with the given mode.
347 /// @{
Ruomei Yan49937f32019-04-25 14:24:05 +0100348 static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
349 static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
telsoa014fcda012018-03-09 14:13:49 +0000350 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100351 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000352
353 /// Loads an existing set of tuned parameters from the given file.
354 /// If there is an error loading the file, an armnn::Exception is thrown.
355 virtual void Load(const char* filename) = 0;
356
357 /// Saves the current set of tuned parameters to the given file.
358 /// If there is an error saving to the file, an armnn::Exception is thrown.
359 virtual void Save(const char* filename) const = 0;
360
361protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100362 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000363};
364
David Monahan4f1e8e42019-09-04 09:22:10 +0100365} // namespace armnn