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