ArmNN
 22.08
ArmNNExecutor Class Reference

#include <ArmNNExecutor.hpp>

Inheritance diagram for ArmNNExecutor:
IExecutor

Public Member Functions

 ArmNNExecutor (const ExecuteNetworkParams &params, armnn::IRuntime::CreationOptions runtimeOptions)
 
std::vector< const void *> Execute () override
 Execute the given network. More...
 
void PrintNetworkInfo () override
 Print available information about the network. More...
 
void CompareAndPrintResult (std::vector< const void *> otherOutput) override
 Compare the output with the result of another IExecutor. More...
 
- Public Member Functions inherited from IExecutor
virtual ~IExecutor ()
 

Detailed Description

Definition at line 37 of file ArmNNExecutor.hpp.

Constructor & Destructor Documentation

◆ ArmNNExecutor()

ArmNNExecutor ( const ExecuteNetworkParams params,
armnn::IRuntime::CreationOptions  runtimeOptions 
)

Definition at line 17 of file ArmNNExecutor.cpp.

References ARMNN_LOG, CheckInferenceTimeThreshold(), IRuntime::Create(), armnn::DetailsOnly, armnn::DetailsWithEvents, armnn::Failure, AsyncCallbackManager::GetNewCallback(), AsyncCallbackManager::GetNotifiedCallback(), armnn::GetTimeDuration(), armnn::GetTimeNow(), armnn::info, ExecuteNetworkParams::m_Concurrent, ExecuteNetworkParams::m_DontPrintOutputs, ExecuteNetworkParams::m_DynamicBackendsPath, IRuntime::CreationOptions::m_DynamicBackendsPath, IRuntime::CreationOptions::m_EnableGpuProfiling, ExecuteNetworkParams::m_EnableProfiling, ExecuteNetworkParams::m_GenerateTensorData, ExecuteNetworkParams::m_ImportInputsIfAligned, ExecuteNetworkParams::m_Iterations, ExecuteNetworkParams::m_OutputDetailsOnlyToStdOut, ExecuteNetworkParams::m_OutputDetailsToStdOut, ExecuteNetworkParams::m_ThreadPoolSize, ExecuteNetworkParams::m_ThresholdTime, armnn::Medium, and armnn::warning.

18 : m_Params(params)
19 {
20  runtimeOptions.m_EnableGpuProfiling = params.m_EnableProfiling;
21  runtimeOptions.m_DynamicBackendsPath = params.m_DynamicBackendsPath;
22  m_Runtime = armnn::IRuntime::Create(runtimeOptions);
23 
24  auto parser = CreateParser();
25  auto network = parser->CreateNetwork(m_Params);
26  auto optNet = OptimizeNetwork(network.get());
27 
28  m_IOInfo = GetIOInfo(optNet.get());
29  SetupInputsAndOutputs();
30 
31  std::string errorMsg;
32 
33  armnn::ProfilingDetailsMethod profilingDetailsMethod = ProfilingDetailsMethod::Undefined;
34  if (params.m_OutputDetailsOnlyToStdOut)
35  {
36  profilingDetailsMethod = armnn::ProfilingDetailsMethod::DetailsOnly;
37  }
38  else if (params.m_OutputDetailsToStdOut)
39  {
40  profilingDetailsMethod = armnn::ProfilingDetailsMethod::DetailsWithEvents;
41  }
42 
43  INetworkProperties networkProperties{m_Params.m_Concurrent,
44  MemorySource::Undefined,
45  MemorySource::Undefined,
46  params.m_EnableProfiling,
47  profilingDetailsMethod};
48 
49  m_Runtime->LoadNetwork(m_NetworkId, std::move(optNet), errorMsg, networkProperties);
50 
51  if (m_Params.m_Iterations > 1)
52  {
53  std::stringstream msg;
54  msg << "Network will be executed " << m_Params.m_Iterations;
55  if (m_Params.m_Concurrent)
56  {
57  msg << " times in an asynchronous manner. ";
58  }
59  else
60  {
61  msg << " times successively. ";
62  }
63  msg << "The input-tensor-data files will be reused recursively if the user didn't provide enough to "
64  "cover each execution.";
65  ARMNN_LOG(info) << msg.str();
66  }
67 
68  if (m_Params.m_GenerateTensorData)
69  {
70  ARMNN_LOG(warning) << "The input data was generated, note that the output will not be useful";
71  }
72 
73  if (m_Params.m_DontPrintOutputs)
74  {
75  ARMNN_LOG(info) << "Printing outputs to console is disabled.";
76  }
77 }
static IRuntimePtr Create(const CreationOptions &options)
Definition: Runtime.cpp:49
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
ProfilingDetailsMethod
Define the behaviour of the internal profiler when outputting network details.
Definition: Types.hpp:71
std::string m_DynamicBackendsPath
Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive Only a...
Definition: IRuntime.hpp:98
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
Definition: IRuntime.hpp:93

Member Function Documentation

◆ CompareAndPrintResult()

void CompareAndPrintResult ( std::vector< const void *>  otherOutput)
overridevirtual

Compare the output with the result of another IExecutor.

Implements IExecutor.

Definition at line 671 of file ArmNNExecutor.cpp.

References IOnnxParser::Create(), IDeserializer::Create(), ITfLiteParser::Create(), armnn::Float32, LogAndThrow(), BindingPointInfo::m_BindingId, ITfLiteParser::TfLiteParserOptions::m_InferAndValidate, ExecuteNetworkParams::m_InferOutputShape, ExecuteNetworkParams::m_InputNames, ExecuteNetworkParams::m_InputTensorShapes, ExecuteNetworkParams::m_IsModelBinary, ExecuteNetworkParams::m_ModelPath, ExecuteNetworkParams::m_ParseUnsupported, ITfLiteParser::TfLiteParserOptions::m_StandInLayerForUnsupported, BindingPointInfo::m_TensorInfo, armnn::QAsymmS8, armnn::QAsymmU8, armnn::QSymmS16, and armnn::QSymmS8.

672 {
673  unsigned int index = 0;
674 
675  for (const auto& outputTensors: m_OutputTensorsVec)
676  {
677  for (const auto& outputTensor: outputTensors)
678  {
679  float result = 0;
680  size_t size = outputTensor.second.GetNumBytes();
681 
682  switch (outputTensor.second.GetDataType())
683  {
685  {
686  result = ComputeRMSE<float>(outputTensor.second.GetMemoryArea(), otherOutput[index++], size);
687  break;
688  }
690  {
691  result = ComputeRMSE<int16_t>(outputTensor.second.GetMemoryArea(), otherOutput[index++], size);
692  break;
693  }
696  {
697  result = ComputeRMSE<int8_t>(outputTensor.second.GetMemoryArea(), otherOutput[index++], size);
698  break;
699  }
701  {
702  result = ComputeRMSE<uint8_t>(outputTensor.second.GetMemoryArea(), otherOutput[index++], size);
703  break;
704  }
705  default:
706  {
707  LogAndThrow("Unexpected DataType");
708  }
709  }
710  std::cout << "RMSE: of " << result << "\n";
711  }
712  }
713 }
void LogAndThrow(std::string eMsg)

◆ Execute()

std::vector< const void * > Execute ( )
overridevirtual

Execute the given network.

Returns
std::vector<const void*> A type erased vector of the outputs, that can be compared with the output of another IExecutor

Implements IExecutor.

Definition at line 198 of file ArmNNExecutor.cpp.

References ExecuteNetworkParams::m_ThreadPoolSize.

199 {
200  if(m_Params.m_ThreadPoolSize == 0)
201  {
202  ExecuteSync();
203  }
204  else
205  {
206  ExecuteAsync();
207  }
208  std::vector<const void*> results;
209  for (auto& output : m_OutputStorage)
210  {
211  results.push_back(output.m_Mem);
212  }
213 
214  return results;
215 }

◆ PrintNetworkInfo()

void PrintNetworkInfo ( )
overridevirtual

Print available information about the network.

Implements IExecutor.

Definition at line 217 of file ArmNNExecutor.cpp.

References ARMNN_LOG, armnn::BFloat16, armnn::Boolean, IOptimizedNetwork::ExecuteStrategy(), armnn::Float16, armnn::Float32, IInputSlot::GetConnection(), TensorInfo::GetDataType(), armnn::GetDataTypeName(), IConnectableLayer::GetInputSlot(), TensorInfo::GetNumBytes(), TensorInfo::GetNumElements(), IConnectableLayer::GetOutputSlot(), TensorInfo::GetQuantizationOffset(), TensorInfo::GetQuantizationScale(), TensorInfo::GetShape(), IOutputSlot::GetTensorInfo(), armnn::GetTimeDuration(), armnn::GetTimeNow(), IConnectableLayer::GetType(), armnn::IgnoreUnused(), armnn::InferAndValidate, armnn::info, armnn::Input, LogAndThrow(), OptimizerOptions::m_Debug, ExecuteNetworkParams::m_GenerateTensorData, ExecuteNetworkParams::m_ImportInputsIfAligned, ExecuteNetworkParams::m_InputNames, ExecuteNetworkParams::m_InputTensorDataFilePaths, ExecuteNetworkParams::m_Iterations, OptimizerOptions::m_ModelOptions, ExecuteNetworkParams::m_OutputTensorFiles, OptimizerOptions::m_ProfilingEnabled, OptimizerOptions::m_ReduceFp32ToBf16, OptimizerOptions::m_ReduceFp32ToFp16, ExecuteNetworkParams::m_ReuseBuffers, OptimizerOptions::m_shapeInferenceMethod, ExecuteNetworkParams::m_ThreadPoolSize, armnn::Malloc, armnn::Optimize(), armnn::Output, armnn::QAsymmS8, armnn::QAsymmU8, armnn::QSymmS16, armnn::QSymmS8, IOptimizedNetwork::SerializeToDot(), armnn::Signed32, armnn::Signed64, and armnn::ValidateOnly.

218 {
219  const std::vector<std::string>& inputNames = m_Params.m_InputNames.size() != 0 ?
220  m_Params.m_InputNames :
221  m_IOInfo.m_InputNames;
222  std::stringstream ss;
223  ss << "===== Network Info =====\n";
224  ss << "Inputs in order:\n";
225  for (const auto& inputName : inputNames)
226  {
227  const auto inputInfo = m_IOInfo.m_InputInfoMap[inputName].second;
228  ss << inputName << ", " << inputInfo.GetShape() << ", " << GetDataTypeName(inputInfo.GetDataType());
229  if (inputInfo.IsQuantized())
230  {
231  ss << " Quantization Offset: " << inputInfo.GetQuantizationOffset();
232  if (inputInfo.HasMultipleQuantizationScales())
233  {
234  ss << " Quantization scales: ";
235  for (const auto scale: inputInfo.GetQuantizationScales())
236  {
237  ss << scale << ", ";
238  }
239  }
240  else
241  {
242  ss << " Quantization scale: " << inputInfo.GetQuantizationScale();
243  }
244  }
245  ss << "\n";
246  }
247 
248  ss << "Outputs in order:\n";
249  for (const auto& outputName : m_IOInfo.m_OutputNames)
250  {
251  const auto outputInfo = m_IOInfo.m_OutputInfoMap[outputName].second;
252  ss << outputName << ", " << outputInfo.GetShape() << ", " << GetDataTypeName(outputInfo.GetDataType());
253  if (outputInfo.IsQuantized())
254  {
255  ss << " Quantization Offset: " << outputInfo.GetQuantizationOffset();
256  if (outputInfo.HasMultipleQuantizationScales())
257  {
258  ss << " Quantization scales: ";
259  for (const auto scale: outputInfo.GetQuantizationScales())
260  {
261  ss << scale << ", ";
262  }
263  }
264  else
265  {
266  ss << " Quantization scale: " << outputInfo.GetQuantizationScale();
267  }
268  }
269  ss << "\n";
270  }
271 
272  std::cout << ss.str() << std::endl;
273 }
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:202
std::vector< std::string > m_InputNames

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