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 | #include "Runtime.hpp" |
| 6 | |
David Beck | 056be3c | 2018-10-22 13:16:00 +0100 | [diff] [blame] | 7 | #include <armnn/Version.hpp> |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 8 | #include <armnn/BackendRegistry.hpp> |
Matthew Bentham | f48afc6 | 2020-01-15 17:55:08 +0000 | [diff] [blame] | 9 | #include <armnn/Logging.hpp> |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 10 | #include <armnn/utility/Timer.hpp> |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 11 | |
Matteo Martincigh | e5b8eb9 | 2019-11-28 15:45:42 +0000 | [diff] [blame] | 12 | #include <armnn/backends/IBackendContext.hpp> |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 13 | #include <backendsCommon/DynamicBackendUtils.hpp> |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 14 | #include <armnn/utility/PolymorphicDowncast.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 15 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 16 | #include <iostream> |
| 17 | |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 18 | #include <backends/BackendProfiling.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace armnn; |
| 21 | using namespace std; |
| 22 | |
| 23 | namespace armnn |
| 24 | { |
| 25 | |
| 26 | IRuntime* IRuntime::CreateRaw(const CreationOptions& options) |
| 27 | { |
| 28 | return new Runtime(options); |
| 29 | } |
| 30 | |
| 31 | IRuntimePtr IRuntime::Create(const CreationOptions& options) |
| 32 | { |
| 33 | return IRuntimePtr(CreateRaw(options), &IRuntime::Destroy); |
| 34 | } |
| 35 | |
| 36 | void IRuntime::Destroy(IRuntime* runtime) |
| 37 | { |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 38 | delete PolymorphicDowncast<Runtime*>(runtime); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int Runtime::GenerateNetworkId() |
| 42 | { |
| 43 | return m_NetworkIdCounter++; |
| 44 | } |
| 45 | |
| 46 | Status Runtime::LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr inNetwork) |
| 47 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 48 | std::string ignoredErrorMessage; |
| 49 | return LoadNetwork(networkIdOut, std::move(inNetwork), ignoredErrorMessage); |
| 50 | } |
| 51 | |
| 52 | Status Runtime::LoadNetwork(NetworkId& networkIdOut, |
| 53 | IOptimizedNetworkPtr inNetwork, |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 54 | std::string& errorMessage) |
| 55 | { |
| 56 | INetworkProperties networkProperties; |
| 57 | return LoadNetwork(networkIdOut, std::move(inNetwork), errorMessage, networkProperties); |
| 58 | } |
| 59 | |
| 60 | Status Runtime::LoadNetwork(NetworkId& networkIdOut, |
| 61 | IOptimizedNetworkPtr inNetwork, |
| 62 | std::string& errorMessage, |
| 63 | const INetworkProperties& networkProperties) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 64 | { |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 65 | IOptimizedNetwork* rawNetwork = inNetwork.release(); |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 66 | |
| 67 | networkIdOut = GenerateNetworkId(); |
| 68 | |
| 69 | for (auto&& context : m_BackendContexts) |
| 70 | { |
| 71 | context.second->BeforeLoadNetwork(networkIdOut); |
| 72 | } |
| 73 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 74 | unique_ptr<LoadedNetwork> loadedNetwork = LoadedNetwork::MakeLoadedNetwork( |
Jan Eilers | bb446e5 | 2020-04-02 13:56:54 +0100 | [diff] [blame] | 75 | std::unique_ptr<OptimizedNetwork>(PolymorphicDowncast<OptimizedNetwork*>(rawNetwork)), |
David Monahan | 4f1e8e4 | 2019-09-04 09:22:10 +0100 | [diff] [blame] | 76 | errorMessage, |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 77 | networkProperties, |
| 78 | m_ProfilingService); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 79 | |
| 80 | if (!loadedNetwork) |
| 81 | { |
| 82 | return Status::Failure; |
| 83 | } |
| 84 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 85 | { |
| 86 | std::lock_guard<std::mutex> lockGuard(m_Mutex); |
| 87 | |
| 88 | // Stores the network |
| 89 | m_LoadedNetworks[networkIdOut] = std::move(loadedNetwork); |
| 90 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 91 | |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 92 | for (auto&& context : m_BackendContexts) |
| 93 | { |
| 94 | context.second->AfterLoadNetwork(networkIdOut); |
| 95 | } |
| 96 | |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 97 | if (m_ProfilingService.IsProfilingEnabled()) |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 98 | { |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 99 | m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_LOADS); |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 100 | } |
| 101 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 102 | return Status::Success; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | Status Runtime::UnloadNetwork(NetworkId networkId) |
| 106 | { |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 107 | bool unloadOk = true; |
| 108 | for (auto&& context : m_BackendContexts) |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 109 | { |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 110 | unloadOk &= context.second->BeforeUnloadNetwork(networkId); |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 111 | } |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 112 | |
| 113 | if (!unloadOk) |
| 114 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 115 | ARMNN_LOG(warning) << "Runtime::UnloadNetwork(): failed to unload " |
| 116 | "network with ID:" << networkId << " because BeforeUnloadNetwork failed"; |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 117 | return Status::Failure; |
| 118 | } |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 119 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 120 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 121 | std::lock_guard<std::mutex> lockGuard(m_Mutex); |
| 122 | |
| 123 | if (m_LoadedNetworks.erase(networkId) == 0) |
| 124 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 125 | ARMNN_LOG(warning) << "WARNING: Runtime::UnloadNetwork(): " << networkId << " not found!"; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 126 | return Status::Failure; |
| 127 | } |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 128 | |
| 129 | if (m_ProfilingService.IsProfilingEnabled()) |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 130 | { |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 131 | m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_UNLOADS); |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 132 | } |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 133 | } |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 134 | |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 135 | for (auto&& context : m_BackendContexts) |
| 136 | { |
| 137 | context.second->AfterUnloadNetwork(networkId); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 140 | ARMNN_LOG(debug) << "Runtime::UnloadNetwork(): Unloaded network with ID: " << networkId; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 141 | return Status::Success; |
| 142 | } |
| 143 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 144 | const std::shared_ptr<IProfiler> Runtime::GetProfiler(NetworkId networkId) const |
| 145 | { |
| 146 | auto it = m_LoadedNetworks.find(networkId); |
| 147 | if (it != m_LoadedNetworks.end()) |
| 148 | { |
| 149 | auto& loadedNetwork = it->second; |
| 150 | return loadedNetwork->GetProfiler(); |
| 151 | } |
| 152 | |
| 153 | return nullptr; |
| 154 | } |
| 155 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 156 | void Runtime::ReportStructure() // armnn::profiling::IProfilingService& profilingService as param |
| 157 | { |
| 158 | // No-op for the time being, but this may be useful in future to have the profilingService available |
| 159 | // if (profilingService.IsProfilingEnabled()){} |
| 160 | |
| 161 | LoadedNetworks::iterator it = m_LoadedNetworks.begin(); |
| 162 | while (it != m_LoadedNetworks.end()) |
| 163 | { |
| 164 | auto& loadedNetwork = it->second; |
| 165 | loadedNetwork->SendNetworkStructure(); |
| 166 | // Increment the Iterator to point to next entry |
| 167 | it++; |
| 168 | } |
| 169 | } |
| 170 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 171 | Runtime::Runtime(const CreationOptions& options) |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 172 | : m_NetworkIdCounter(0), |
| 173 | m_ProfilingService(*this) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 174 | { |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 175 | const auto start_time = armnn::GetTimeNow(); |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 176 | ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION << "\n"; |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 177 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 178 | if ( options.m_ProfilingOptions.m_TimelineEnabled && !options.m_ProfilingOptions.m_EnableProfiling ) |
| 179 | { |
| 180 | throw RuntimeException("It is not possible to enable timeline reporting without profiling being enabled"); |
| 181 | } |
| 182 | |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 183 | // Load any available/compatible dynamic backend before the runtime |
| 184 | // goes through the backend registry |
| 185 | LoadDynamicBackends(options.m_DynamicBackendsPath); |
| 186 | |
Matthew Bentham | 9a61fa6 | 2020-02-04 10:03:55 +0000 | [diff] [blame] | 187 | BackendIdSet supportedBackends; |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 188 | for (const auto& id : BackendRegistryInstance().GetBackendIds()) |
| 189 | { |
| 190 | // Store backend contexts for the supported ones |
Matthew Bentham | 9a61fa6 | 2020-02-04 10:03:55 +0000 | [diff] [blame] | 191 | try { |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 192 | auto factoryFun = BackendRegistryInstance().GetFactory(id); |
| 193 | auto backend = factoryFun(); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 194 | ARMNN_ASSERT(backend.get() != nullptr); |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 195 | |
| 196 | auto context = backend->CreateBackendContext(options); |
| 197 | |
| 198 | // backends are allowed to return nullptrs if they |
| 199 | // don't wish to create a backend specific context |
| 200 | if (context) |
| 201 | { |
| 202 | m_BackendContexts.emplace(std::make_pair(id, std::move(context))); |
| 203 | } |
Matthew Bentham | 9a61fa6 | 2020-02-04 10:03:55 +0000 | [diff] [blame] | 204 | supportedBackends.emplace(id); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 205 | |
| 206 | unique_ptr<armnn::profiling::IBackendProfiling> profilingIface = |
| 207 | std::make_unique<armnn::profiling::BackendProfiling>(armnn::profiling::BackendProfiling( |
Sadik Armagan | 3184c90 | 2020-03-18 10:57:30 +0000 | [diff] [blame] | 208 | options, m_ProfilingService, id)); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 209 | |
| 210 | // Backends may also provide a profiling context. Ask for it now. |
| 211 | auto profilingContext = backend->CreateBackendProfilingContext(options, profilingIface); |
| 212 | // Backends that don't support profiling will return a null profiling context. |
| 213 | if (profilingContext) |
| 214 | { |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 215 | // Pass the context onto the profiling service. |
| 216 | m_ProfilingService.AddBackendProfilingContext(id, profilingContext); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 217 | } |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 218 | } |
Matthew Bentham | 9a61fa6 | 2020-02-04 10:03:55 +0000 | [diff] [blame] | 219 | catch (const BackendUnavailableException&) |
| 220 | { |
| 221 | // Ignore backends which are unavailable |
| 222 | } |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 223 | } |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 224 | |
Finn Williams | 45a7362 | 2020-05-15 18:41:05 +0100 | [diff] [blame] | 225 | BackendRegistryInstance().SetProfilingService(m_ProfilingService); |
Finn Williams | fe5a24b | 2020-04-09 16:05:28 +0100 | [diff] [blame] | 226 | // pass configuration info to the profiling service |
| 227 | m_ProfilingService.ConfigureProfilingService(options.m_ProfilingOptions); |
| 228 | |
Matthew Bentham | 9a61fa6 | 2020-02-04 10:03:55 +0000 | [diff] [blame] | 229 | m_DeviceSpec.AddSupportedBackends(supportedBackends); |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 230 | |
| 231 | ARMNN_LOG(info) << "Initialization time: " << std::setprecision(2) |
| 232 | << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n"; |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | Runtime::~Runtime() |
| 236 | { |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 237 | const auto start_time = armnn::GetTimeNow(); |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 238 | std::vector<int> networkIDs; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 239 | try |
| 240 | { |
| 241 | // Coverity fix: The following code may throw an exception of type std::length_error. |
| 242 | std::transform(m_LoadedNetworks.begin(), m_LoadedNetworks.end(), |
| 243 | std::back_inserter(networkIDs), |
| 244 | [](const auto &pair) { return pair.first; }); |
| 245 | } |
| 246 | catch (const std::exception& e) |
| 247 | { |
| 248 | // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an |
| 249 | // exception of type std::length_error. |
| 250 | // Using stderr instead in this context as there is no point in nesting try-catch blocks here. |
| 251 | std::cerr << "WARNING: An error has occurred when getting the IDs of the networks to unload: " << e.what() |
| 252 | << "\nSome of the loaded networks may not be unloaded" << std::endl; |
| 253 | } |
| 254 | // We then proceed to unload all the networks which IDs have been appended to the list |
| 255 | // up to the point the exception was thrown (if any). |
surmeh01 | bceff2f | 2018-03-29 16:29:27 +0100 | [diff] [blame] | 256 | |
| 257 | for (auto networkID : networkIDs) |
| 258 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 259 | try |
| 260 | { |
| 261 | // Coverity fix: UnloadNetwork() may throw an exception of type std::length_error, |
| 262 | // boost::log::v2s_mt_posix::odr_violation or boost::log::v2s_mt_posix::system_error |
| 263 | UnloadNetwork(networkID); |
| 264 | } |
| 265 | catch (const std::exception& e) |
| 266 | { |
| 267 | // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an |
| 268 | // exception of type std::length_error. |
| 269 | // Using stderr instead in this context as there is no point in nesting try-catch blocks here. |
| 270 | std::cerr << "WARNING: An error has occurred when unloading network " << networkID << ": " << e.what() |
| 271 | << std::endl; |
| 272 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 273 | } |
Narumol Prangnawarat | 60a20fb | 2019-12-09 17:24:41 +0000 | [diff] [blame] | 274 | |
| 275 | // Clear all dynamic backends. |
| 276 | DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends()); |
| 277 | m_DeviceSpec.ClearDynamicBackends(); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 278 | m_BackendContexts.clear(); |
Finn Williams | 45a7362 | 2020-05-15 18:41:05 +0100 | [diff] [blame] | 279 | |
| 280 | BackendRegistryInstance().SetProfilingService(armnn::EmptyOptional()); |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 281 | ARMNN_LOG(info) << "Shutdown time: " << std::setprecision(2) |
| 282 | << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n"; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 283 | } |
| 284 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 285 | LoadedNetwork* Runtime::GetLoadedNetworkPtr(NetworkId networkId) const |
| 286 | { |
| 287 | std::lock_guard<std::mutex> lockGuard(m_Mutex); |
| 288 | return m_LoadedNetworks.at(networkId).get(); |
| 289 | } |
| 290 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 291 | TensorInfo Runtime::GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const |
| 292 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 293 | return GetLoadedNetworkPtr(networkId)->GetInputTensorInfo(layerId); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | TensorInfo Runtime::GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const |
| 297 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 298 | return GetLoadedNetworkPtr(networkId)->GetOutputTensorInfo(layerId); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 299 | } |
| 300 | |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 301 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 302 | Status Runtime::EnqueueWorkload(NetworkId networkId, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 303 | const InputTensors& inputTensors, |
| 304 | const OutputTensors& outputTensors) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 305 | { |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 306 | LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId); |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 307 | |
| 308 | static thread_local NetworkId lastId = networkId; |
| 309 | if (lastId != networkId) |
| 310 | { |
| 311 | LoadedNetworkFuncSafe(lastId, [](LoadedNetwork* network) |
| 312 | { |
| 313 | network->FreeWorkingMemory(); |
| 314 | }); |
| 315 | } |
| 316 | lastId=networkId; |
| 317 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 318 | return loadedNetwork->EnqueueWorkload(inputTensors, outputTensors); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 319 | } |
| 320 | |
Nattapat Chaimanowong | 6e94820 | 2019-03-22 14:01:46 +0000 | [diff] [blame] | 321 | void Runtime::RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func) |
| 322 | { |
| 323 | LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId); |
| 324 | loadedNetwork->RegisterDebugCallback(func); |
| 325 | } |
| 326 | |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 327 | void Runtime::LoadDynamicBackends(const std::string& overrideBackendPath) |
| 328 | { |
| 329 | // Get the paths where to load the dynamic backends from |
| 330 | std::vector<std::string> backendPaths = DynamicBackendUtils::GetBackendPaths(overrideBackendPath); |
| 331 | |
| 332 | // Get the shared objects to try to load as dynamic backends |
| 333 | std::vector<std::string> sharedObjects = DynamicBackendUtils::GetSharedObjects(backendPaths); |
| 334 | |
| 335 | // Create a list of dynamic backends |
Matteo Martincigh | 0c2b289 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 336 | m_DynamicBackends = DynamicBackendUtils::CreateDynamicBackends(sharedObjects); |
| 337 | |
| 338 | // Register the dynamic backends in the backend registry |
Matteo Martincigh | 8953390 | 2019-08-15 12:08:06 +0100 | [diff] [blame] | 339 | BackendIdSet registeredBackendIds = DynamicBackendUtils::RegisterDynamicBackends(m_DynamicBackends); |
| 340 | |
| 341 | // Add the registered dynamic backend ids to the list of supported backends |
Narumol Prangnawarat | 60a20fb | 2019-12-09 17:24:41 +0000 | [diff] [blame] | 342 | m_DeviceSpec.AddSupportedBackends(registeredBackendIds, true); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 343 | } |
Matteo Martincigh | e54aa06 | 2019-08-05 14:12:11 +0100 | [diff] [blame] | 344 | |
| 345 | } // namespace armnn |