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