ArmNN
 21.05
RuntimeImpl Struct Referencefinal

#include <Runtime.hpp>

Inheritance diagram for RuntimeImpl:
IReportStructure

Public Member Functions

Status LoadNetwork (NetworkId &networkIdOut, IOptimizedNetworkPtr network)
 Loads a complete network into the Runtime. More...
 
Status LoadNetwork (NetworkId &networkIdOut, IOptimizedNetworkPtr network, std::string &errorMessage)
 Load a complete network into the IRuntime. More...
 
Status LoadNetwork (NetworkId &networkIdOut, IOptimizedNetworkPtr network, std::string &errorMessage, const INetworkProperties &networkProperties)
 
TensorInfo GetInputTensorInfo (NetworkId networkId, LayerBindingId layerId) const
 
TensorInfo GetOutputTensorInfo (NetworkId networkId, LayerBindingId layerId) const
 
Status EnqueueWorkload (NetworkId networkId, const InputTensors &inputTensors, const OutputTensors &outputTensors)
 
void Schedule (NetworkId networkId, const InputTensors &inputTensors, const OutputTensors &outputTensors, const QosExecPriority priority, std::shared_ptr< IAsyncExecutionCallback > callback)
 This is an experimental function. More...
 
Status Execute (IWorkingMemHandle &workingMemHandle, const InputTensors &inputTensors, const OutputTensors &outputTensors)
 This is an experimental function. More...
 
Status UnloadNetwork (NetworkId networkId)
 Unloads a network from the Runtime. More...
 
const IDeviceSpecGetDeviceSpec () const
 
const std::shared_ptr< IProfilerGetProfiler (NetworkId networkId) const
 Gets the profiler corresponding to the given network id. More...
 
std::unique_ptr< IWorkingMemHandleCreateWorkingMemHandle (NetworkId networkId)
 Create a new unique WorkingMemHandle object. More...
 
void RegisterDebugCallback (NetworkId networkId, const DebugCallbackFunction &func)
 Registers a callback function to debug layers performing custom computations on intermediate tensors. More...
 
 RuntimeImpl (const IRuntime::CreationOptions &options)
 Creates a runtime for workload execution. More...
 
 ~RuntimeImpl ()
 
void ReportStructure ()
 
- Public Member Functions inherited from IReportStructure
virtual ~IReportStructure ()
 

Friends

void RuntimeLoadedNetworksReserve (RuntimeImpl *runtime)
 
profiling::ProfilingServiceGetProfilingService (RuntimeImpl *runtime)
 

Detailed Description

Definition at line 30 of file Runtime.hpp.

Constructor & Destructor Documentation

◆ RuntimeImpl()

RuntimeImpl ( const IRuntime::CreationOptions options)

Creates a runtime for workload execution.

Definition at line 269 of file Runtime.cpp.

References ProfilingService::AddBackendProfilingContext(), DeviceSpec::AddSupportedBackends(), ARMNN_ASSERT, ARMNN_LOG, ARMNN_VERSION, armnn::BackendRegistryInstance(), ProfilingService::ConfigureProfilingService(), BackendRegistry::GetFactory(), armnn::GetTimeDuration(), armnn::GetTimeNow(), armnn::info, IRuntime::CreationOptions::m_DynamicBackendsPath, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, BackendRegistry::SetProfilingService(), and ProfilingService::WaitForProfilingServiceActivation().

Referenced by RuntimeImpl::GetDeviceSpec().

270  : m_NetworkIdCounter(0),
271  m_ProfilingService(*this)
272 {
273  const auto start_time = armnn::GetTimeNow();
274  ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION << "\n";
275 
277  {
278  throw RuntimeException("It is not possible to enable timeline reporting without profiling being enabled");
279  }
280 
281  // Load any available/compatible dynamic backend before the runtime
282  // goes through the backend registry
283  LoadDynamicBackends(options.m_DynamicBackendsPath);
284 
285  BackendIdSet supportedBackends;
286  for (const auto& id : BackendRegistryInstance().GetBackendIds())
287  {
288  // Store backend contexts for the supported ones
289  try {
290  auto factoryFun = BackendRegistryInstance().GetFactory(id);
291  auto backend = factoryFun();
292  ARMNN_ASSERT(backend.get() != nullptr);
293 
294  auto context = backend->CreateBackendContext(options);
295 
296  // backends are allowed to return nullptrs if they
297  // don't wish to create a backend specific context
298  if (context)
299  {
300  m_BackendContexts.emplace(std::make_pair(id, std::move(context)));
301  }
302  supportedBackends.emplace(id);
303 
304  unique_ptr<armnn::profiling::IBackendProfiling> profilingIface =
305  std::make_unique<armnn::profiling::BackendProfiling>(armnn::profiling::BackendProfiling(
306  options, m_ProfilingService, id));
307 
308  // Backends may also provide a profiling context. Ask for it now.
309  auto profilingContext = backend->CreateBackendProfilingContext(options, profilingIface);
310  // Backends that don't support profiling will return a null profiling context.
311  if (profilingContext)
312  {
313  // Pass the context onto the profiling service.
314  m_ProfilingService.AddBackendProfilingContext(id, profilingContext);
315  }
316  }
317  catch (const BackendUnavailableException&)
318  {
319  // Ignore backends which are unavailable
320  }
321  }
322 
323  BackendRegistryInstance().SetProfilingService(m_ProfilingService);
324  // pass configuration info to the profiling service
325  m_ProfilingService.ConfigureProfilingService(options.m_ProfilingOptions);
327  {
328  // try to wait for the profiling service to initialise
329  m_ProfilingService.WaitForProfilingServiceActivation(3000);
330  }
331 
332  m_DeviceSpec.AddSupportedBackends(supportedBackends);
333 
334  ARMNN_LOG(info) << "Initialization time: " << std::setprecision(2)
335  << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n";
336 }
void AddSupportedBackends(const BackendIdSet &backendIds, bool isDynamic=false)
Definition: DeviceSpec.hpp:30
void WaitForProfilingServiceActivation(unsigned int timeout) override
FactoryFunction GetFactory(const BackendId &id) const
std::chrono::duration< double, std::milli > GetTimeDuration(std::chrono::high_resolution_clock::time_point start_time)
Definition: Timer.hpp:19
std::unordered_set< BackendId > BackendIdSet
Definition: BackendId.hpp:191
#define ARMNN_VERSION
ARMNN_VERSION: "X.Y.Z" where: X = Major version number Y = Minor version number Z = Patch version num...
Definition: Version.hpp:22
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
BackendRegistry & BackendRegistryInstance()
std::chrono::high_resolution_clock::time_point GetTimeNow()
Definition: Timer.hpp:14
void SetProfilingService(armnn::Optional< profiling::ProfilingService &> profilingService)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
std::string m_DynamicBackendsPath
Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive Only a...
Definition: IRuntime.hpp:93
void AddBackendProfilingContext(const BackendId backendId, std::shared_ptr< armnn::profiling::IBackendProfilingContext > profilingContext)
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:117
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
Class for non-fatal exceptions raised while initialising a backend.
Definition: Exceptions.hpp:68

◆ ~RuntimeImpl()

Definition at line 338 of file Runtime.cpp.

References ARMNN_LOG, armnn::BackendRegistryInstance(), DeviceSpec::ClearDynamicBackends(), DynamicBackendUtils::DeregisterDynamicBackends(), DeviceSpec::GetDynamicBackends(), armnn::GetTimeDuration(), armnn::GetTimeNow(), armnn::info, BackendRegistry::SetProfilingService(), and RuntimeImpl::UnloadNetwork().

Referenced by RuntimeImpl::GetDeviceSpec().

339 {
340  const auto start_time = armnn::GetTimeNow();
341  std::vector<int> networkIDs;
342  try
343  {
344  // Coverity fix: The following code may throw an exception of type std::length_error.
345  std::transform(m_LoadedNetworks.begin(), m_LoadedNetworks.end(),
346  std::back_inserter(networkIDs),
347  [](const auto &pair) { return pair.first; });
348  }
349  catch (const std::exception& e)
350  {
351  // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
352  // exception of type std::length_error.
353  // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
354  std::cerr << "WARNING: An error has occurred when getting the IDs of the networks to unload: " << e.what()
355  << "\nSome of the loaded networks may not be unloaded" << std::endl;
356  }
357  // We then proceed to unload all the networks which IDs have been appended to the list
358  // up to the point the exception was thrown (if any).
359 
360  for (auto networkID : networkIDs)
361  {
362  try
363  {
364  // Coverity fix: UnloadNetwork() may throw an exception of type std::length_error,
365  // boost::log::v2s_mt_posix::odr_violation or boost::log::v2s_mt_posix::system_error
366  UnloadNetwork(networkID);
367  }
368  catch (const std::exception& e)
369  {
370  // Coverity fix: BOOST_LOG_TRIVIAL (typically used to report errors) may throw an
371  // exception of type std::length_error.
372  // Using stderr instead in this context as there is no point in nesting try-catch blocks here.
373  std::cerr << "WARNING: An error has occurred when unloading network " << networkID << ": " << e.what()
374  << std::endl;
375  }
376  }
377 
378  // Clear all dynamic backends.
380  m_DeviceSpec.ClearDynamicBackends();
381  m_BackendContexts.clear();
382 
384  ARMNN_LOG(info) << "Shutdown time: " << std::setprecision(2)
385  << std::fixed << armnn::GetTimeDuration(start_time).count() << " ms\n";
386 }
std::chrono::duration< double, std::milli > GetTimeDuration(std::chrono::high_resolution_clock::time_point start_time)
Definition: Timer.hpp:19
static void DeregisterDynamicBackends(const BackendIdSet &dynamicBackends)
Status UnloadNetwork(NetworkId networkId)
Unloads a network from the Runtime.
Definition: Runtime.cpp:190
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
BackendRegistry & BackendRegistryInstance()
std::chrono::high_resolution_clock::time_point GetTimeNow()
Definition: Timer.hpp:14
void SetProfilingService(armnn::Optional< profiling::ProfilingService &> profilingService)
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
const BackendIdSet & GetDynamicBackends() const
Definition: DeviceSpec.hpp:48
void ClearDynamicBackends()
Definition: DeviceSpec.hpp:39

Member Function Documentation

◆ CreateWorkingMemHandle()

std::unique_ptr< IWorkingMemHandle > CreateWorkingMemHandle ( NetworkId  networkId)

Create a new unique WorkingMemHandle object.

Create multiple handles if you wish to have overlapped Execution by calling this function from different threads.

Definition at line 492 of file Runtime.cpp.

References ARMNN_LOG, ARMNN_SCOPED_PROFILING_EVENT, LoadedNetwork::CreateWorkingMemHandle(), armnn::error, LoadedNetwork::FreeWorkingMemory(), ProfilerManager::GetInstance(), LoadedNetwork::GetProfiler(), LoadedNetwork::IsAsyncEnabled(), ProfilerManager::RegisterProfiler(), and armnn::Undefined.

Referenced by RuntimeImpl::GetDeviceSpec().

493 {
494  LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
495 
496  if (!loadedNetwork)
497  {
498  ARMNN_LOG(error) << "A Network with an id of " << networkId << " does not exist.\n";
499  return nullptr;
500  }
501  if (!loadedNetwork->IsAsyncEnabled())
502  {
503  ARMNN_LOG(error) << "Network " << networkId << " is not async enabled.\n";
504  return nullptr;
505  }
507 
508  ARMNN_SCOPED_PROFILING_EVENT(Compute::Undefined, "CreateWorkingMemHandle");
509 
510  static thread_local NetworkId lastId = networkId;
511  if (lastId != networkId)
512  {
513  LoadedNetworkFuncSafe(lastId, [](LoadedNetwork* network)
514  {
515  network->FreeWorkingMemory();
516  });
517  }
518  lastId=networkId;
519 
520  return loadedNetwork->CreateWorkingMemHandle(networkId);
521 }
std::unique_ptr< IWorkingMemHandle > CreateWorkingMemHandle(NetworkId networkId)
Create a new unique WorkingMemHandle object.
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:489
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
int NetworkId
Definition: IRuntime.hpp:22
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:496
const std::shared_ptr< IProfiler > & GetProfiler() const

◆ EnqueueWorkload()

Status EnqueueWorkload ( NetworkId  networkId,
const InputTensors inputTensors,
const OutputTensors outputTensors 
)

Definition at line 405 of file Runtime.cpp.

References ARMNN_LOG, ARMNN_SCOPED_PROFILING_EVENT, LoadedNetwork::EnqueueWorkload(), armnn::error, armnn::Failure, LoadedNetwork::FreeWorkingMemory(), ProfilerManager::GetInstance(), LoadedNetwork::GetProfiler(), LoadedNetwork::IsAsyncEnabled(), ProfilerManager::RegisterProfiler(), and armnn::Undefined.

Referenced by BOOST_AUTO_TEST_CASE(), and VerifyPostOptimisationStructureTestImpl().

408 {
409  LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
410 
411  if (!loadedNetwork)
412  {
413  ARMNN_LOG(error) << "A Network with an id of " << networkId << " does not exist.\n";
414  return Status::Failure;
415  }
416  if (loadedNetwork->IsAsyncEnabled())
417  {
418  ARMNN_LOG(error) << "Network " << networkId << " is async enabled.\n";
419  return Status::Failure;
420  }
422 
424 
425  static thread_local NetworkId lastId = networkId;
426  if (lastId != networkId)
427  {
428  LoadedNetworkFuncSafe(lastId, [](LoadedNetwork* network)
429  {
430  network->FreeWorkingMemory();
431  });
432  }
433  lastId=networkId;
434 
435  return loadedNetwork->EnqueueWorkload(inputTensors, outputTensors);
436 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:489
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
int NetworkId
Definition: IRuntime.hpp:22
Status EnqueueWorkload(const InputTensors &inputTensors, const OutputTensors &outputTensors)
Single thread execution of the loaded network.
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:496
const std::shared_ptr< IProfiler > & GetProfiler() const

◆ Execute()

Status Execute ( IWorkingMemHandle workingMemHandle,
const InputTensors inputTensors,
const OutputTensors outputTensors 
)

This is an experimental function.

Evaluates a network using input in inputTensors and outputs filled into outputTensors. This function performs a thread safe execution of the network. Returns once execution is complete. Will block until this and any other thread using the same workingMem object completes.

Definition at line 438 of file Runtime.cpp.

References ARMNN_LOG, ARMNN_SCOPED_PROFILING_EVENT, armnn::error, LoadedNetwork::Execute(), armnn::Failure, ProfilerManager::GetInstance(), IWorkingMemHandle::GetNetworkId(), LoadedNetwork::GetProfiler(), LoadedNetwork::IsAsyncEnabled(), ProfilerManager::RegisterProfiler(), and armnn::Undefined.

441 {
442  NetworkId networkId = iWorkingMemHandle.GetNetworkId();
443  LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
444 
445  if (!loadedNetwork)
446  {
447  ARMNN_LOG(error) << "A Network with an id of " << networkId << " does not exist.\n";
448  return Status::Failure;
449  }
450  if (!loadedNetwork->IsAsyncEnabled())
451  {
452  ARMNN_LOG(error) << "Attempting execute " << networkId << " when it is not async enabled.\n";
453  return Status::Failure;
454  }
456 
458 
459  return loadedNetwork->Execute(inputTensors, outputTensors, iWorkingMemHandle);
460 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:489
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
Status Execute(const InputTensors &inputTensors, const OutputTensors &outputTensors, IWorkingMemHandle &workingMemHandle)
Thread safe execution of the loaded network.
int NetworkId
Definition: IRuntime.hpp:22
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:496
const std::shared_ptr< IProfiler > & GetProfiler() const

◆ GetDeviceSpec()

◆ GetInputTensorInfo()

TensorInfo GetInputTensorInfo ( NetworkId  networkId,
LayerBindingId  layerId 
) const

Definition at line 394 of file Runtime.cpp.

References LoadedNetwork::GetInputTensorInfo().

Referenced by BOOST_AUTO_TEST_CASE(), and VerifyPostOptimisationStructureTestImpl().

395 {
396  return GetLoadedNetworkPtr(networkId)->GetInputTensorInfo(layerId);
397 }
TensorInfo GetInputTensorInfo(LayerBindingId layerId) const

◆ GetOutputTensorInfo()

TensorInfo GetOutputTensorInfo ( NetworkId  networkId,
LayerBindingId  layerId 
) const

Definition at line 399 of file Runtime.cpp.

References LoadedNetwork::GetOutputTensorInfo().

Referenced by BOOST_AUTO_TEST_CASE(), and VerifyPostOptimisationStructureTestImpl().

400 {
401  return GetLoadedNetworkPtr(networkId)->GetOutputTensorInfo(layerId);
402 }
TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const

◆ GetProfiler()

const std::shared_ptr< IProfiler > GetProfiler ( NetworkId  networkId) const

Gets the profiler corresponding to the given network id.

Parameters
networkIdThe id of the network for which to get the profile.
Returns
A pointer to the requested profiler, or nullptr if not found.

Definition at line 242 of file Runtime.cpp.

Referenced by RuntimeImpl::GetDeviceSpec().

243 {
244  auto it = m_LoadedNetworks.find(networkId);
245  if (it != m_LoadedNetworks.end())
246  {
247  auto& loadedNetwork = it->second;
248  return loadedNetwork->GetProfiler();
249  }
250 
251  return nullptr;
252 }

◆ LoadNetwork() [1/3]

Status LoadNetwork ( NetworkId networkIdOut,
IOptimizedNetworkPtr  network 
)

Loads a complete network into the Runtime.

Parameters
[out]networkIdOut- Unique identifier for the network is returned in this reference.
[in]network- Complete network to load into the Runtime. The runtime takes ownership of the network once passed in.
Returns
armnn::Status

Definition at line 130 of file Runtime.cpp.

References IRuntime::LoadNetwork().

Referenced by BOOST_AUTO_TEST_CASE(), and VerifyPostOptimisationStructureTestImpl().

131 {
132  std::string ignoredErrorMessage;
133  return LoadNetwork(networkIdOut, std::move(inNetwork), ignoredErrorMessage);
134 }
Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network)
Loads a complete network into the Runtime.
Definition: Runtime.cpp:130

◆ LoadNetwork() [2/3]

Status LoadNetwork ( NetworkId networkIdOut,
IOptimizedNetworkPtr  network,
std::string &  errorMessage 
)

Load a complete network into the IRuntime.

Parameters
[out]networkIdOutUnique identifier for the network is returned in this reference.
[in]networkComplete network to load into the IRuntime.
[out]errorMessageError message if there were any errors. The runtime takes ownership of the network once passed in.
Returns
armnn::Status

Definition at line 136 of file Runtime.cpp.

References IRuntime::LoadNetwork(), and armnn::Undefined.

139 {
141  return LoadNetwork(networkIdOut, std::move(inNetwork), errorMessage, networkProperties);
142 }
Status LoadNetwork(NetworkId &networkIdOut, IOptimizedNetworkPtr network)
Loads a complete network into the Runtime.
Definition: Runtime.cpp:130

◆ LoadNetwork() [3/3]

Status LoadNetwork ( NetworkId networkIdOut,
IOptimizedNetworkPtr  network,
std::string &  errorMessage,
const INetworkProperties networkProperties 
)

Definition at line 144 of file Runtime.cpp.

References armnn::Failure, LoadedNetwork::MakeLoadedNetwork(), and armnn::Success.

148 {
149  IOptimizedNetwork* rawNetwork = inNetwork.release();
150 
151  networkIdOut = GenerateNetworkId();
152 
153  for (auto&& context : m_BackendContexts)
154  {
155  context.second->BeforeLoadNetwork(networkIdOut);
156  }
157 
158  unique_ptr<LoadedNetwork> loadedNetwork = LoadedNetwork::MakeLoadedNetwork(
159  std::unique_ptr<IOptimizedNetwork>(rawNetwork),
160  errorMessage,
161  networkProperties,
162  m_ProfilingService,
163  networkIdOut);
164 
165  if (!loadedNetwork)
166  {
167  return Status::Failure;
168  }
169 
170  {
171  std::lock_guard<std::mutex> lockGuard(m_Mutex);
172 
173  // Stores the network
174  m_LoadedNetworks[networkIdOut] = std::move(loadedNetwork);
175  }
176 
177  for (auto&& context : m_BackendContexts)
178  {
179  context.second->AfterLoadNetwork(networkIdOut);
180  }
181 
182  if (m_ProfilingService.IsProfilingEnabled())
183  {
184  m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_LOADS);
185  }
186 
187  return Status::Success;
188 }
uint32_t IncrementCounterValue(uint16_t counterUid) override
bool IsProfilingEnabled() const override
static std::unique_ptr< LoadedNetwork > MakeLoadedNetwork(std::unique_ptr< IOptimizedNetwork > net, std::string &errorMessage, const INetworkProperties &networkProperties, profiling::ProfilingService &profilingService, const NetworkId networkIdOut)

◆ RegisterDebugCallback()

void RegisterDebugCallback ( NetworkId  networkId,
const DebugCallbackFunction func 
)

Registers a callback function to debug layers performing custom computations on intermediate tensors.

Parameters
networkIdThe id of the network to register the callback.
funccallback function to pass to the debug layer.

Definition at line 523 of file Runtime.cpp.

References DeviceSpec::AddSupportedBackends(), DynamicBackendUtils::CreateDynamicBackends(), DynamicBackendUtils::GetBackendPaths(), DynamicBackendUtils::GetSharedObjects(), LoadedNetwork::RegisterDebugCallback(), and DynamicBackendUtils::RegisterDynamicBackends().

Referenced by RuntimeImpl::GetDeviceSpec().

524 {
525  LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
526  loadedNetwork->RegisterDebugCallback(func);
527 }
void RegisterDebugCallback(const DebugCallbackFunction &func)

◆ ReportStructure()

void ReportStructure ( )
virtual

Implements IReportStructure.

Definition at line 254 of file Runtime.cpp.

Referenced by RuntimeImpl::GetDeviceSpec().

255 {
256  // No-op for the time being, but this may be useful in future to have the profilingService available
257  // if (profilingService.IsProfilingEnabled()){}
258 
259  LoadedNetworks::iterator it = m_LoadedNetworks.begin();
260  while (it != m_LoadedNetworks.end())
261  {
262  auto& loadedNetwork = it->second;
263  loadedNetwork->SendNetworkStructure();
264  // Increment the Iterator to point to next entry
265  it++;
266  }
267 }

◆ Schedule()

void Schedule ( NetworkId  networkId,
const InputTensors inputTensors,
const OutputTensors outputTensors,
const QosExecPriority  priority,
std::shared_ptr< IAsyncExecutionCallback callback 
)

This is an experimental function.

Schedule a thread safe execution by taking the input tensors and an execution priority for Quality of Service. The output tensors will then be filled and the callback object will notify that the execution has either succeeded or failed.

Definition at line 462 of file Runtime.cpp.

References ARMNN_SCOPED_PROFILING_EVENT, ProfilerManager::GetInstance(), LoadedNetwork::GetProfiler(), LoadedNetwork::IsAsyncEnabled(), ProfilerManager::RegisterProfiler(), LoadedNetwork::Schedule(), and armnn::Undefined.

467 {
468  LoadedNetwork* loadedNetwork = GetLoadedNetworkPtr(networkId);
469 
470  if (!loadedNetwork)
471  {
472  throw armnn::Exception(
473  "Network with ID of " + std::to_string(networkId) + " does not exist \n"
474  );
475  }
476  if (!loadedNetwork->IsAsyncEnabled())
477  {
478  throw armnn::Exception(
479  "Attempting to schedule Network " + std::to_string(networkId) + " when it is not async enabled \n"
480  );
481  }
482 
484 
486 
487  loadedNetwork->Schedule(inputTensors, outputTensors, priority, callback);
488 }
static ProfilerManager & GetInstance()
Definition: Profiling.cpp:489
#define ARMNN_SCOPED_PROFILING_EVENT(backendId, name)
Definition: Profiling.hpp:173
void Schedule(const InputTensors &inputTensors, const OutputTensors &outputTensors, const QosExecPriority priority, std::shared_ptr< IAsyncExecutionCallback > cb)
Schedule an asynchronous execution on the loaded network.
void RegisterProfiler(IProfiler *profiler)
Definition: Profiling.cpp:496
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
const std::shared_ptr< IProfiler > & GetProfiler() const

◆ UnloadNetwork()

Status UnloadNetwork ( NetworkId  networkId)

Unloads a network from the Runtime.

At the moment this only removes the network from the m_Impl->m_Network. This might need more work in the future to be AndroidNN compliant.

Parameters
[in]networkIdUnique identifier for the network to be unloaded. Generated in LoadNetwork().
Returns
armnn::Status

Definition at line 190 of file Runtime.cpp.

References ARMNN_LOG, LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, armnn::debug, armnn::Failure, TimelineUtilityMethods::GetTimelineUtils(), armnn::Success, and armnn::warning.

Referenced by BOOST_AUTO_TEST_CASE(), and RuntimeImpl::~RuntimeImpl().

191 {
192  bool unloadOk = true;
193  for (auto&& context : m_BackendContexts)
194  {
195  unloadOk &= context.second->BeforeUnloadNetwork(networkId);
196  }
197 
198  if (!unloadOk)
199  {
200  ARMNN_LOG(warning) << "RuntimeImpl::UnloadNetwork(): failed to unload "
201  "network with ID:" << networkId << " because BeforeUnloadNetwork failed";
202  return Status::Failure;
203  }
204 
205  std::unique_ptr<profiling::TimelineUtilityMethods> timelineUtils =
207  {
208  std::lock_guard<std::mutex> lockGuard(m_Mutex);
209 
210  // If timeline recording is on mark the Network end of life
211  if (timelineUtils)
212  {
213  auto search = m_LoadedNetworks.find(networkId);
214  if (search != m_LoadedNetworks.end())
215  {
216  profiling::ProfilingGuid networkGuid = search->second->GetNetworkGuid();
217  timelineUtils->RecordEvent(networkGuid,
219  }
220  }
221  if (m_LoadedNetworks.erase(networkId) == 0)
222  {
223  ARMNN_LOG(warning) << "WARNING: RuntimeImpl::UnloadNetwork(): " << networkId << " not found!";
224  return Status::Failure;
225  }
226 
227  if (m_ProfilingService.IsProfilingEnabled())
228  {
229  m_ProfilingService.IncrementCounterValue(armnn::profiling::NETWORK_UNLOADS);
230  }
231  }
232 
233  for (auto&& context : m_BackendContexts)
234  {
235  context.second->AfterUnloadNetwork(networkId);
236  }
237 
238  ARMNN_LOG(debug) << "RuntimeImpl::UnloadNetwork(): Unloaded network with ID: " << networkId;
239  return Status::Success;
240 }
static std::unique_ptr< TimelineUtilityMethods > GetTimelineUtils(ProfilingService &profilingService)
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
uint32_t IncrementCounterValue(uint16_t counterUid) override
static ARMNN_DLLEXPORT ProfilingStaticGuid ARMNN_PROFILING_EOL_EVENT_CLASS
bool IsProfilingEnabled() const override

Friends And Related Function Documentation

◆ GetProfilingService

profiling::ProfilingService& GetProfilingService ( RuntimeImpl runtime)
friend

Definition at line 35 of file TestUtils.cpp.

Referenced by RuntimeImpl::GetDeviceSpec().

36 {
37  return runtime->m_ProfilingService;
38 }

◆ RuntimeLoadedNetworksReserve

void RuntimeLoadedNetworksReserve ( RuntimeImpl runtime)
friend

Definition at line 30 of file RuntimeTests.cpp.

Referenced by RuntimeImpl::GetDeviceSpec().

31 {
32  runtime->m_LoadedNetworks.reserve(1);
33 }

The documentation for this struct was generated from the following files: