blob: 8fdc4f1e0ac6196e250edf771bfe36c8a2765493 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Jim Flynn6398a982020-05-27 17:05:21 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
5#include "Runtime.hpp"
6
David Beck056be3c2018-10-22 13:16:00 +01007#include <armnn/Version.hpp>
Matteo Martincighc601aa62019-10-29 15:03:22 +00008#include <armnn/BackendRegistry.hpp>
Jim Flynnf7713212020-07-14 09:50:59 +01009#include <LabelsAndEventClasses.hpp>
Matthew Benthamf48afc62020-01-15 17:55:08 +000010#include <armnn/Logging.hpp>
alered01a7227ac2020-05-07 14:58:29 +010011#include <armnn/utility/Timer.hpp>
Matteo Martincighe54aa062019-08-05 14:12:11 +010012
Matteo Martincighe5b8eb92019-11-28 15:45:42 +000013#include <armnn/backends/IBackendContext.hpp>
Matteo Martincighe54aa062019-08-05 14:12:11 +010014#include <backendsCommon/DynamicBackendUtils.hpp>
Jan Eilersbb446e52020-04-02 13:56:54 +010015#include <armnn/utility/PolymorphicDowncast.hpp>
telsoa014fcda012018-03-09 14:13:49 +000016
surmeh013537c2c2018-05-18 16:31:43 +010017#include <iostream>
18
Colm Donelan1aff3932020-02-05 17:48:59 +000019#include <backends/BackendProfiling.hpp>
telsoa014fcda012018-03-09 14:13:49 +000020
21using namespace armnn;
22using namespace std;
23
24namespace armnn
25{
Kevin Mayd92a6e42021-02-04 10:27:41 +000026IRuntime::IRuntime() : pRuntimeImpl( new RuntimeImpl(armnn::IRuntime::CreationOptions())) {}
27
28IRuntime::IRuntime(const IRuntime::CreationOptions& options) : pRuntimeImpl(new RuntimeImpl(options)) {}
29
30IRuntime::~IRuntime() = default;
telsoa014fcda012018-03-09 14:13:49 +000031
32IRuntime* IRuntime::CreateRaw(const CreationOptions& options)
33{
Kevin Mayd92a6e42021-02-04 10:27:41 +000034 return new IRuntime(options);
telsoa014fcda012018-03-09 14:13:49 +000035}
36
37IRuntimePtr IRuntime::Create(const CreationOptions& options)
38{
39 return IRuntimePtr(CreateRaw(options), &IRuntime::Destroy);
40}
41
42void IRuntime::Destroy(IRuntime* runtime)
43{
Kevin Mayd92a6e42021-02-04 10:27:41 +000044 delete runtime;
telsoa014fcda012018-03-09 14:13:49 +000045}
46
Kevin Mayd92a6e42021-02-04 10:27:41 +000047Status IRuntime::LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr network)
48{
49 return pRuntimeImpl->LoadNetwork(networkIdOut, std::move(network));
50}
51
52Status IRuntime::LoadNetwork(NetworkId& networkIdOut,
53 IOptimizedNetworkPtr network,
54 std::string& errorMessage)
55{
56 return pRuntimeImpl->LoadNetwork(networkIdOut, std::move(network), errorMessage);
57}
58
59Status IRuntime::LoadNetwork(NetworkId& networkIdOut,
60 IOptimizedNetworkPtr network,
61 std::string& errorMessage,
62 const INetworkProperties& networkProperties)
63{
64 return pRuntimeImpl->LoadNetwork(networkIdOut, std::move(network), errorMessage, networkProperties);
65}
66
67TensorInfo IRuntime::GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const
68{
69 return pRuntimeImpl->GetInputTensorInfo(networkId, layerId);
70}
71
72TensorInfo IRuntime::GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const
73{
74 return pRuntimeImpl->GetOutputTensorInfo(networkId, layerId);
75}
76
77Status IRuntime::EnqueueWorkload(NetworkId networkId,
78 const InputTensors& inputTensors,
79 const OutputTensors& outputTensors)
80{
81 return pRuntimeImpl->EnqueueWorkload(networkId, inputTensors, outputTensors);
82}
83
84Status IRuntime::UnloadNetwork(NetworkId networkId)
85{
86 return pRuntimeImpl->UnloadNetwork(networkId);
87}
88
89const IDeviceSpec& IRuntime::GetDeviceSpec() const
90{
91 return pRuntimeImpl->GetDeviceSpec();
92}
93
94const std::shared_ptr<IProfiler> IRuntime::GetProfiler(NetworkId networkId) const
95{
96 return pRuntimeImpl->GetProfiler(networkId);
97}
98
99void IRuntime::RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func)
100{
101 return pRuntimeImpl->RegisterDebugCallback(networkId, func);
102}
103
104int RuntimeImpl::GenerateNetworkId()
telsoa014fcda012018-03-09 14:13:49 +0000105{
106 return m_NetworkIdCounter++;
107}
108
Kevin Mayd92a6e42021-02-04 10:27:41 +0000109Status RuntimeImpl::LoadNetwork(NetworkId& networkIdOut, IOptimizedNetworkPtr inNetwork)
telsoa014fcda012018-03-09 14:13:49 +0000110{
telsoa01c577f2c2018-08-31 09:22:23 +0100111 std::string ignoredErrorMessage;
112 return LoadNetwork(networkIdOut, std::move(inNetwork), ignoredErrorMessage);
113}
114
Kevin Mayd92a6e42021-02-04 10:27:41 +0000115Status RuntimeImpl::LoadNetwork(NetworkId& networkIdOut,
116 IOptimizedNetworkPtr inNetwork,
117 std::string& errorMessage)
David Monahan4f1e8e42019-09-04 09:22:10 +0100118{
119 INetworkProperties networkProperties;
120 return LoadNetwork(networkIdOut, std::move(inNetwork), errorMessage, networkProperties);
121}
122
Kevin Mayd92a6e42021-02-04 10:27:41 +0000123Status RuntimeImpl::LoadNetwork(NetworkId& networkIdOut,
124 IOptimizedNetworkPtr inNetwork,
125 std::string& errorMessage,
126 const INetworkProperties& networkProperties)
telsoa01c577f2c2018-08-31 09:22:23 +0100127{
telsoa014fcda012018-03-09 14:13:49 +0000128 IOptimizedNetwork* rawNetwork = inNetwork.release();
David Beck1b61be52018-11-08 09:19:14 +0000129
130 networkIdOut = GenerateNetworkId();
131
132 for (auto&& context : m_BackendContexts)
133 {
134 context.second->BeforeLoadNetwork(networkIdOut);
135 }
136
telsoa014fcda012018-03-09 14:13:49 +0000137 unique_ptr<LoadedNetwork> loadedNetwork = LoadedNetwork::MakeLoadedNetwork(
Jan Eilersbb446e52020-04-02 13:56:54 +0100138 std::unique_ptr<OptimizedNetwork>(PolymorphicDowncast<OptimizedNetwork*>(rawNetwork)),
David Monahan4f1e8e42019-09-04 09:22:10 +0100139 errorMessage,
Sadik Armagan3184c902020-03-18 10:57:30 +0000140 networkProperties,
141 m_ProfilingService);
telsoa014fcda012018-03-09 14:13:49 +0000142
143 if (!loadedNetwork)
144 {
145 return Status::Failure;
146 }
147
telsoa01c577f2c2018-08-31 09:22:23 +0100148 {
149 std::lock_guard<std::mutex> lockGuard(m_Mutex);
150
151 // Stores the network
152 m_LoadedNetworks[networkIdOut] = std::move(loadedNetwork);
153 }
telsoa014fcda012018-03-09 14:13:49 +0000154
David Beck1b61be52018-11-08 09:19:14 +0000155 for (auto&& context : m_BackendContexts)
156 {
157 context.second->AfterLoadNetwork(networkIdOut);
158 }
159
Sadik Armagan3184c902020-03-18 10:57:30 +0000160 if (m_ProfilingService.IsProfilingEnabled())
Keith Davise394bd92019-12-02 15:12:19 +0000161 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000162 m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_LOADS);
Keith Davise394bd92019-12-02 15:12:19 +0000163 }
164
telsoa014fcda012018-03-09 14:13:49 +0000165 return Status::Success;
telsoa014fcda012018-03-09 14:13:49 +0000166}
167
Kevin Mayd92a6e42021-02-04 10:27:41 +0000168Status RuntimeImpl::UnloadNetwork(NetworkId networkId)
telsoa014fcda012018-03-09 14:13:49 +0000169{
David Beck1b61be52018-11-08 09:19:14 +0000170 bool unloadOk = true;
171 for (auto&& context : m_BackendContexts)
David Beck9efb57d2018-11-05 13:40:33 +0000172 {
David Beck1b61be52018-11-08 09:19:14 +0000173 unloadOk &= context.second->BeforeUnloadNetwork(networkId);
David Beck9efb57d2018-11-05 13:40:33 +0000174 }
David Beck1b61be52018-11-08 09:19:14 +0000175
176 if (!unloadOk)
177 {
Kevin Mayd92a6e42021-02-04 10:27:41 +0000178 ARMNN_LOG(warning) << "RuntimeImpl::UnloadNetwork(): failed to unload "
Derek Lamberti08446972019-11-26 16:38:31 +0000179 "network with ID:" << networkId << " because BeforeUnloadNetwork failed";
David Beck1b61be52018-11-08 09:19:14 +0000180 return Status::Failure;
181 }
David Beck9efb57d2018-11-05 13:40:33 +0000182
Jim Flynnf7713212020-07-14 09:50:59 +0100183 std::unique_ptr<profiling::TimelineUtilityMethods> timelineUtils =
184 profiling::TimelineUtilityMethods::GetTimelineUtils(m_ProfilingService);
telsoa014fcda012018-03-09 14:13:49 +0000185 {
telsoa01c577f2c2018-08-31 09:22:23 +0100186 std::lock_guard<std::mutex> lockGuard(m_Mutex);
187
Jim Flynnf7713212020-07-14 09:50:59 +0100188 // If timeline recording is on mark the Network end of life
189 if (timelineUtils)
190 {
191 auto search = m_LoadedNetworks.find(networkId);
192 if (search != m_LoadedNetworks.end())
193 {
194 profiling::ProfilingGuid networkGuid = search->second->GetNetworkGuid();
195 timelineUtils->RecordEvent(networkGuid,
196 profiling::LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
197 }
198 }
telsoa01c577f2c2018-08-31 09:22:23 +0100199 if (m_LoadedNetworks.erase(networkId) == 0)
200 {
Kevin Mayd92a6e42021-02-04 10:27:41 +0000201 ARMNN_LOG(warning) << "WARNING: RuntimeImpl::UnloadNetwork(): " << networkId << " not found!";
telsoa01c577f2c2018-08-31 09:22:23 +0100202 return Status::Failure;
203 }
Sadik Armagan3184c902020-03-18 10:57:30 +0000204
205 if (m_ProfilingService.IsProfilingEnabled())
Keith Davise394bd92019-12-02 15:12:19 +0000206 {
Sadik Armagan3184c902020-03-18 10:57:30 +0000207 m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_UNLOADS);
Keith Davise394bd92019-12-02 15:12:19 +0000208 }
David Beck1b61be52018-11-08 09:19:14 +0000209 }
David Beck9efb57d2018-11-05 13:40:33 +0000210
David Beck1b61be52018-11-08 09:19:14 +0000211 for (auto&& context : m_BackendContexts)
212 {
213 context.second->AfterUnloadNetwork(networkId);
telsoa01c577f2c2018-08-31 09:22:23 +0100214 }
215
Kevin Mayd92a6e42021-02-04 10:27:41 +0000216 ARMNN_LOG(debug) << "RuntimeImpl::UnloadNetwork(): Unloaded network with ID: " << networkId;
telsoa014fcda012018-03-09 14:13:49 +0000217 return Status::Success;
218}
219
Kevin Mayd92a6e42021-02-04 10:27:41 +0000220const std::shared_ptr<IProfiler> RuntimeImpl::GetProfiler(NetworkId networkId) const
telsoa01c577f2c2018-08-31 09:22:23 +0100221{
222 auto it = m_LoadedNetworks.find(networkId);
223 if (it != m_LoadedNetworks.end())
224 {
225 auto& loadedNetwork = it->second;
226 return loadedNetwork->GetProfiler();
227 }
228
229 return nullptr;
230}
231
Kevin Mayd92a6e42021-02-04 10:27:41 +0000232void RuntimeImpl::ReportStructure() // armnn::profiling::IProfilingService& profilingService as param
Keith Davis33ed2212020-03-30 10:43:41 +0100233{
234 // No-op for the time being, but this may be useful in future to have the profilingService available
235 // if (profilingService.IsProfilingEnabled()){}
236
237 LoadedNetworks::iterator it = m_LoadedNetworks.begin();
238 while (it != m_LoadedNetworks.end())
239 {
240 auto& loadedNetwork = it->second;
241 loadedNetwork->SendNetworkStructure();
242 // Increment the Iterator to point to next entry
243 it++;
244 }
245}
246
Kevin Mayd92a6e42021-02-04 10:27:41 +0000247RuntimeImpl::RuntimeImpl(const IRuntime::CreationOptions& options)
Keith Davis33ed2212020-03-30 10:43:41 +0100248 : m_NetworkIdCounter(0),
249 m_ProfilingService(*this)
telsoa014fcda012018-03-09 14:13:49 +0000250{
alered01a7227ac2020-05-07 14:58:29 +0100251 const auto start_time = armnn::GetTimeNow();
Derek Lamberti08446972019-11-26 16:38:31 +0000252 ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION << "\n";
David Beck1b61be52018-11-08 09:19:14 +0000253
Keith Davis33ed2212020-03-30 10:43:41 +0100254 if ( options.m_ProfilingOptions.m_TimelineEnabled && !options.m_ProfilingOptions.m_EnableProfiling )
255 {
256 throw RuntimeException("It is not possible to enable timeline reporting without profiling being enabled");
257 }
258
Matteo Martincighe54aa062019-08-05 14:12:11 +0100259 // Load any available/compatible dynamic backend before the runtime
260 // goes through the backend registry
261 LoadDynamicBackends(options.m_DynamicBackendsPath);
262
Matthew Bentham9a61fa62020-02-04 10:03:55 +0000263 BackendIdSet supportedBackends;
David Beck1b61be52018-11-08 09:19:14 +0000264 for (const auto& id : BackendRegistryInstance().GetBackendIds())
265 {
266 // Store backend contexts for the supported ones
Matthew Bentham9a61fa62020-02-04 10:03:55 +0000267 try {
David Beck1b61be52018-11-08 09:19:14 +0000268 auto factoryFun = BackendRegistryInstance().GetFactory(id);
269 auto backend = factoryFun();
Narumol Prangnawaratac2770a2020-04-01 16:51:23 +0100270 ARMNN_ASSERT(backend.get() != nullptr);
David Beck1b61be52018-11-08 09:19:14 +0000271
272 auto context = backend->CreateBackendContext(options);
273
274 // backends are allowed to return nullptrs if they
275 // don't wish to create a backend specific context
276 if (context)
277 {
278 m_BackendContexts.emplace(std::make_pair(id, std::move(context)));
279 }
Matthew Bentham9a61fa62020-02-04 10:03:55 +0000280 supportedBackends.emplace(id);
Colm Donelan1aff3932020-02-05 17:48:59 +0000281
282 unique_ptr<armnn::profiling::IBackendProfiling> profilingIface =
283 std::make_unique<armnn::profiling::BackendProfiling>(armnn::profiling::BackendProfiling(
Sadik Armagan3184c902020-03-18 10:57:30 +0000284 options, m_ProfilingService, id));
Colm Donelan1aff3932020-02-05 17:48:59 +0000285
286 // Backends may also provide a profiling context. Ask for it now.
287 auto profilingContext = backend->CreateBackendProfilingContext(options, profilingIface);
288 // Backends that don't support profiling will return a null profiling context.
289 if (profilingContext)
290 {
Finn Williamsfe5a24b2020-04-09 16:05:28 +0100291 // Pass the context onto the profiling service.
292 m_ProfilingService.AddBackendProfilingContext(id, profilingContext);
Colm Donelan1aff3932020-02-05 17:48:59 +0000293 }
David Beck1b61be52018-11-08 09:19:14 +0000294 }
Matthew Bentham9a61fa62020-02-04 10:03:55 +0000295 catch (const BackendUnavailableException&)
296 {
297 // Ignore backends which are unavailable
298 }
David Beck1b61be52018-11-08 09:19:14 +0000299 }
Finn Williamsfe5a24b2020-04-09 16:05:28 +0100300
Finn Williams45a73622020-05-15 18:41:05 +0100301 BackendRegistryInstance().SetProfilingService(m_ProfilingService);
Finn Williamsfe5a24b2020-04-09 16:05:28 +0100302 // pass configuration info to the profiling service
303 m_ProfilingService.ConfigureProfilingService(options.m_ProfilingOptions);
Jim Flynn6398a982020-05-27 17:05:21 +0100304 if (options.m_ProfilingOptions.m_EnableProfiling)
305 {
306 // try to wait for the profiling service to initialise
307 m_ProfilingService.WaitForProfilingServiceActivation(3000);
308 }
Finn Williamsfe5a24b2020-04-09 16:05:28 +0100309
Matthew Bentham9a61fa62020-02-04 10:03:55 +0000310 m_DeviceSpec.AddSupportedBackends(supportedBackends);
alered01a7227ac2020-05-07 14:58:29 +0100311
312 ARMNN_LOG(info) << "Initialization time: " << std::setprecision(2)
313 << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n";
surmeh01bceff2f2018-03-29 16:29:27 +0100314}
315
Kevin Mayd92a6e42021-02-04 10:27:41 +0000316RuntimeImpl::~RuntimeImpl()
surmeh01bceff2f2018-03-29 16:29:27 +0100317{
alered01a7227ac2020-05-07 14:58:29 +0100318 const auto start_time = armnn::GetTimeNow();
surmeh01bceff2f2018-03-29 16:29:27 +0100319 std::vector<int> networkIDs;
surmeh013537c2c2018-05-18 16:31:43 +0100320 try
321 {
322 // Coverity fix: The following code may throw an exception of type std::length_error.
323 std::transform(m_LoadedNetworks.begin(), m_LoadedNetworks.end(),
324 std::back_inserter(networkIDs),
325 [](const auto &pair) { return pair.first; });
326 }
327 catch (const std::exception& e)
328 {
329 // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
330 // exception of type std::length_error.
331 // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
332 std::cerr << "WARNING: An error has occurred when getting the IDs of the networks to unload: " << e.what()
333 << "\nSome of the loaded networks may not be unloaded" << std::endl;
334 }
335 // We then proceed to unload all the networks which IDs have been appended to the list
336 // up to the point the exception was thrown (if any).
surmeh01bceff2f2018-03-29 16:29:27 +0100337
338 for (auto networkID : networkIDs)
339 {
surmeh013537c2c2018-05-18 16:31:43 +0100340 try
341 {
342 // Coverity fix: UnloadNetwork() may throw an exception of type std::length_error,
343 // boost::log::v2s_mt_posix::odr_violation or boost::log::v2s_mt_posix::system_error
344 UnloadNetwork(networkID);
345 }
346 catch (const std::exception& e)
347 {
348 // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
349 // exception of type std::length_error.
350 // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
351 std::cerr << "WARNING: An error has occurred when unloading network " << networkID << ": " << e.what()
352 << std::endl;
353 }
telsoa014fcda012018-03-09 14:13:49 +0000354 }
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000355
356 // Clear all dynamic backends.
357 DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
358 m_DeviceSpec.ClearDynamicBackends();
Colm Donelan1aff3932020-02-05 17:48:59 +0000359 m_BackendContexts.clear();
Finn Williams45a73622020-05-15 18:41:05 +0100360
361 BackendRegistryInstance().SetProfilingService(armnn::EmptyOptional());
alered01a7227ac2020-05-07 14:58:29 +0100362 ARMNN_LOG(info) << "Shutdown time: " << std::setprecision(2)
363 << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n";
telsoa014fcda012018-03-09 14:13:49 +0000364}
365
Kevin Mayd92a6e42021-02-04 10:27:41 +0000366LoadedNetwork* RuntimeImpl::GetLoadedNetworkPtr(NetworkId networkId) const
surmeh013537c2c2018-05-18 16:31:43 +0100367{
368 std::lock_guard<std::mutex> lockGuard(m_Mutex);
369 return m_LoadedNetworks.at(networkId).get();
370}
371
Kevin Mayd92a6e42021-02-04 10:27:41 +0000372TensorInfo RuntimeImpl::GetInputTensorInfo(NetworkId networkId, LayerBindingId layerId) const
telsoa014fcda012018-03-09 14:13:49 +0000373{
surmeh013537c2c2018-05-18 16:31:43 +0100374 return GetLoadedNetworkPtr(networkId)->GetInputTensorInfo(layerId);
telsoa014fcda012018-03-09 14:13:49 +0000375}
376
Kevin Mayd92a6e42021-02-04 10:27:41 +0000377TensorInfo RuntimeImpl::GetOutputTensorInfo(NetworkId networkId, LayerBindingId layerId) const
telsoa014fcda012018-03-09 14:13:49 +0000378{
surmeh013537c2c2018-05-18 16:31:43 +0100379 return GetLoadedNetworkPtr(networkId)->GetOutputTensorInfo(layerId);
telsoa014fcda012018-03-09 14:13:49 +0000380}
381
Derek Lamberti03614f62018-10-02 15:52:46 +0100382
Kevin Mayd92a6e42021-02-04 10:27:41 +0000383Status RuntimeImpl::EnqueueWorkload(NetworkId networkId,
telsoa01c577f2c2018-08-31 09:22:23 +0100384 const InputTensors& inputTensors,
385 const OutputTensors& outputTensors)
telsoa014fcda012018-03-09 14:13:49 +0000386{
surmeh013537c2c2018-05-18 16:31:43 +0100387 LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
Narumol Prangnawarat5b4d0d52020-06-23 11:45:56 +0100388 ProfilerManager::GetInstance().RegisterProfiler(loadedNetwork->GetProfiler().get());
389
390 ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "EnqueueWorkload");
Derek Lamberti03614f62018-10-02 15:52:46 +0100391
392 static thread_local NetworkId lastId = networkId;
393 if (lastId != networkId)
394 {
395 LoadedNetworkFuncSafe(lastId, [](LoadedNetwork* network)
396 {
397 network->FreeWorkingMemory();
398 });
399 }
400 lastId=networkId;
401
surmeh013537c2c2018-05-18 16:31:43 +0100402 return loadedNetwork->EnqueueWorkload(inputTensors, outputTensors);
telsoa014fcda012018-03-09 14:13:49 +0000403}
404
Kevin Mayd92a6e42021-02-04 10:27:41 +0000405void RuntimeImpl::RegisterDebugCallback(NetworkId networkId, const DebugCallbackFunction& func)
Nattapat Chaimanowong6e948202019-03-22 14:01:46 +0000406{
407 LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
408 loadedNetwork->RegisterDebugCallback(func);
409}
410
Kevin Mayd92a6e42021-02-04 10:27:41 +0000411void RuntimeImpl::LoadDynamicBackends(const std::string& overrideBackendPath)
Matteo Martincighe54aa062019-08-05 14:12:11 +0100412{
413 // Get the paths where to load the dynamic backends from
414 std::vector<std::string> backendPaths = DynamicBackendUtils::GetBackendPaths(overrideBackendPath);
415
416 // Get the shared objects to try to load as dynamic backends
417 std::vector<std::string> sharedObjects = DynamicBackendUtils::GetSharedObjects(backendPaths);
418
419 // Create a list of dynamic backends
Matteo Martincigh0c2b2892019-08-05 14:12:11 +0100420 m_DynamicBackends = DynamicBackendUtils::CreateDynamicBackends(sharedObjects);
421
422 // Register the dynamic backends in the backend registry
Matteo Martincigh89533902019-08-15 12:08:06 +0100423 BackendIdSet registeredBackendIds = DynamicBackendUtils::RegisterDynamicBackends(m_DynamicBackends);
424
425 // Add the registered dynamic backend ids to the list of supported backends
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000426 m_DeviceSpec.AddSupportedBackends(registeredBackendIds, true);
telsoa014fcda012018-03-09 14:13:49 +0000427}
Matteo Martincighe54aa062019-08-05 14:12:11 +0100428
429} // namespace armnn