blob: 47bfef588aea96f4fe172148521c942ae7844352 [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
Matteo Martincighe7d44982019-08-05 12:16:47 +0100122 std::string m_DynamicBackendsPath;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100123
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100124 /// 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 Eilersc1c872f2021-07-22 13:17:04 +0100127 /// This requires that the backend supports Protected Memory and has an allocator capable of
128 /// allocating Protected Memory associated with it.
Jan Eilers15fcc7e2021-07-14 13:50:15 +0100129 bool m_ProtectedMode;
130
Jan Eilersc1c872f2021-07-22 13:17:04 +0100131 /// @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 Armaganb8a26d82021-10-04 15:13:11 +0100140 /// @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-Tar1a0f6912019-08-23 15:18:44 +0100148 struct ExternalProfilingOptions
149 {
150 ExternalProfilingOptions()
151 : m_EnableProfiling(false)
Jim Flynn4e755a52020-03-29 17:48:26 +0100152 , m_TimelineEnabled(false)
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100153 , m_OutgoingCaptureFile("")
154 , m_IncomingCaptureFile("")
155 , m_FileOnly(false)
Colm Donelan02705242019-11-14 14:19:07 +0000156 , m_CapturePeriod(LOWEST_CAPTURE_PERIOD)
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000157 , m_FileFormat("binary")
Jim Flynn4e755a52020-03-29 17:48:26 +0100158 , m_LocalPacketHandlers()
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100159 {}
160
161 bool m_EnableProfiling;
Jim Flynn4e755a52020-03-29 17:48:26 +0100162 bool m_TimelineEnabled;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100163 std::string m_OutgoingCaptureFile;
164 std::string m_IncomingCaptureFile;
165 bool m_FileOnly;
166 uint32_t m_CapturePeriod;
Isabella Gottardia0687ee2020-03-11 18:04:20 +0000167 std::string m_FileFormat;
Jim Flynn4e755a52020-03-29 17:48:26 +0100168 std::vector<armnn::profiling::ILocalPacketHandlerSharedPtr> m_LocalPacketHandlers;
Aron Virginas-Tar1a0f6912019-08-23 15:18:44 +0100169 };
Jim Flynn4951b8c2019-10-03 10:04:30 -0700170 ExternalProfilingOptions m_ProfilingOptions;
Derek Lamberti836b27b2019-11-20 10:51:57 +0000171
172 /// Pass backend specific options.
173 ///
174 /// For example, to enable GpuAcc tuning add the following
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000175 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.cpp
Derek Lamberti836b27b2019-11-20 10:51:57 +0000176 /// m_BackendOption.emplace_back(
177 /// BackendOptions{"GpuAcc",
178 /// {
179 /// {"TuningLevel", 2},
180 /// {"TuningFile", filename}
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100181 /// {"MemoryOptimizerStrategy", strategyname}
Derek Lamberti836b27b2019-11-20 10:51:57 +0000182 /// }
183 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000184 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000185 /// 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 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 /// {"TuningFile", filename}
194 /// }
195 /// });
Ryan OShea2bbfaa72020-02-12 16:15:27 +0000196 /// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Derek Lamberti836b27b2019-11-20 10:51:57 +0000197
198 /// The following backend options are available:
Sadik Armaganb8a26d82021-10-04 15:13:11 +0100199 /// AllBackends:
200 /// "MemoryOptimizerStrategy" : string [stategynameString]
201 /// (Existing Memory Optimizer Strategies: ConstLayerMemoryOptimizerStrategy)
Derek Lamberti836b27b2019-11-20 10:51:57 +0000202 /// 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;
telsoa014fcda012018-03-09 14:13:49 +0000207 };
208
209 static IRuntime* CreateRaw(const CreationOptions& options);
210 static IRuntimePtr Create(const CreationOptions& options);
211 static void Destroy(IRuntime* runtime);
212
telsoa01c577f2c2018-08-31 09:22:23 +0100213 /// 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.
telsoa014fcda012018-03-09 14:13:49 +0000216 /// The runtime takes ownership of the network once passed in.
217 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000218 Status LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network);
telsoa014fcda012018-03-09 14:13:49 +0000219
telsoa01c577f2c2018-08-31 09:22:23 +0100220 /// 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 Mayd92a6e42021-02-04 10:27:41 +0000226 Status LoadNetwork(NetworkId& networkIdOut,
227 IOptimizedNetworkPtr network,
228 std::string& errorMessage);
David Monahan4f1e8e42019-09-04 09:22:10 +0100229
Kevin Mayd92a6e42021-02-04 10:27:41 +0000230 Status LoadNetwork(NetworkId& networkIdOut,
231 IOptimizedNetworkPtr network,
232 std::string& errorMessage,
233 const INetworkProperties& networkProperties);
telsoa01c577f2c2018-08-31 09:22:23 +0100234
Kevin Mayd92a6e42021-02-04 10:27:41 +0000235 TensorInfo GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
236 TensorInfo GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const;
telsoa014fcda012018-03-09 14:13:49 +0000237
Finn Williamsf37b9702021-09-01 18:06:04 +0100238
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 Williams8636bc72021-10-02 15:06:39 +0100245 /// 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
249 std::vector<ImportedInputId> ImportOutputs(NetworkId networkId, const OutputTensors& outputTensors);
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 Williamsf37b9702021-09-01 18:06:04 +0100260
telsoa01c577f2c2018-08-31 09:22:23 +0100261 /// Evaluates a network using input in inputTensors and outputs filled into outputTensors
Kevin Mayd92a6e42021-02-04 10:27:41 +0000262 Status EnqueueWorkload(NetworkId networkId,
263 const InputTensors& inputTensors,
264 const OutputTensors& outputTensors);
telsoa014fcda012018-03-09 14:13:49 +0000265
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100266 /// 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 Williamsf37b9702021-09-01 18:06:04 +0100272 const OutputTensors& outputTensors,
Finn Williams8636bc72021-10-02 15:06:39 +0100273 std::vector<ImportedInputId> preImportedInputs = {},
274 std::vector<ImportedOutputId> preImportedOutputs = {});
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100275
telsoa01c577f2c2018-08-31 09:22:23 +0100276 /// Unloads a network from the IRuntime.
telsoa014fcda012018-03-09 14:13:49 +0000277 /// 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.
telsoa01c577f2c2018-08-31 09:22:23 +0100279 /// @param [in] networkId - Unique identifier for the network to be unloaded. Generated in LoadNetwork().
telsoa014fcda012018-03-09 14:13:49 +0000280 /// @return armnn::Status
Kevin Mayd92a6e42021-02-04 10:27:41 +0000281 Status UnloadNetwork(NetworkId networkId);
telsoa014fcda012018-03-09 14:13:49 +0000282
Kevin Mayd92a6e42021-02-04 10:27:41 +0000283 const IDeviceSpec& GetDeviceSpec() const;
telsoa01c577f2c2018-08-31 09:22:23 +0100284
Mike Kelly55a8ffd2021-04-07 20:10:49 +0100285 /// 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
telsoa01c577f2c2018-08-31 09:22:23 +0100289 /// 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 Mayd92a6e42021-02-04 10:27:41 +0000292 const std::shared_ptr<IProfiler> GetProfiler(NetworkId networkId) const;
telsoa014fcda012018-03-09 14:13:49 +0000293
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000294 /// 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 Mayd92a6e42021-02-04 10:27:41 +0000297 void RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func);
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000298
telsoa014fcda012018-03-09 14:13:49 +0000299protected:
Kevin Mayd92a6e42021-02-04 10:27:41 +0000300 IRuntime();
301 IRuntime(const IRuntime::CreationOptions& options);
302 ~IRuntime();
303
304 std::unique_ptr<RuntimeImpl> pRuntimeImpl;
telsoa014fcda012018-03-09 14:13:49 +0000305};
306
Derek Lamberti836b27b2019-11-20 10:51:57 +0000307
308/// The following API is replaced by the backend options API.
telsoa01c577f2c2018-08-31 09:22:23 +0100309using IGpuAccTunedParametersPtr = std::shared_ptr<IGpuAccTunedParameters>;
telsoa014fcda012018-03-09 14:13:49 +0000310
telsoa01c577f2c2018-08-31 09:22:23 +0100311/// 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.
telsoa014fcda012018-03-09 14:13:49 +0000314///
315/// Can be created in two modes:
telsoa01c577f2c2018-08-31 09:22:23 +0100316/// - 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
telsoa014fcda012018-03-09 14:13:49 +0000318/// optimum parameters will be found and stored in this object. WARNING - This tuning can be slow.
319///
telsoa01c577f2c2018-08-31 09:22:23 +0100320/// 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 +0000321/// execution, save the parameters for later and then run fast read-only executions using the optimised parameters.
telsoa01c577f2c2018-08-31 09:22:23 +0100322class IGpuAccTunedParameters
telsoa014fcda012018-03-09 14:13:49 +0000323{
324public:
325 enum class Mode
326 {
327 UseTunedParameters,
328 UpdateTunedParameters
329 };
330
Ruomei Yan49937f32019-04-25 14:24:05 +0100331 enum class TuningLevel
332 {
Inki Dae23dbe3d2021-03-16 16:24:09 +0900333 Rapid = 1,
334 Normal = 2,
335 Exhaustive = 3
Ruomei Yan49937f32019-04-25 14:24:05 +0100336 };
337
telsoa014fcda012018-03-09 14:13:49 +0000338 /// Creates an IClTunedParameters with the given mode.
339 /// @{
Ruomei Yan49937f32019-04-25 14:24:05 +0100340 static IGpuAccTunedParameters* CreateRaw(Mode mode, TuningLevel tunerMode);
341 static IGpuAccTunedParametersPtr Create(Mode mode, TuningLevel tunerMode);
telsoa014fcda012018-03-09 14:13:49 +0000342 /// @}
telsoa01c577f2c2018-08-31 09:22:23 +0100343 static void Destroy(IGpuAccTunedParameters* params);
telsoa014fcda012018-03-09 14:13:49 +0000344
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
353protected:
telsoa01c577f2c2018-08-31 09:22:23 +0100354 virtual ~IGpuAccTunedParameters() {};
telsoa014fcda012018-03-09 14:13:49 +0000355};
356
David Monahan4f1e8e42019-09-04 09:22:10 +0100357} // namespace armnn