ArmNN
 22.08
ExecuteNetwork.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "ArmNNExecutor.hpp"
8 #if defined(ARMNN_TFLITE_DELEGATE)
9 #include "TfliteExecutor.hpp"
10 #endif
11 #include <armnn/Logging.hpp>
12 
13 
14 std::unique_ptr<IExecutor> BuildExecutor(ProgramOptions& programOptions)
15 {
18  {
19 #if defined(ARMNN_TFLITE_DELEGATE)
20  return std::make_unique<TfLiteExecutor>(programOptions.m_ExNetParams);
21 #else
22  ARMNN_LOG(fatal) << "Not built with Arm NN Tensorflow-Lite delegate support.";
23  return nullptr;
24 #endif
25  }
26  else
27  {
28  return std::make_unique<ArmNNExecutor>(programOptions.m_ExNetParams, programOptions.m_RuntimeOptions);
29  }
30 }
31 
32 // MAIN
33 int main(int argc, const char* argv[])
34 {
35  // Configures logging for both the ARMNN library and this test program.
36 #ifdef NDEBUG
38 #else
40 #endif
41  armnn::ConfigureLogging(true, true, level);
42 
43 
44  // Get ExecuteNetwork parameters and runtime options from command line
45  // This might throw an InvalidArgumentException if the user provided invalid inputs
46  ProgramOptions programOptions;
47  try
48  {
49  programOptions.ParseOptions(argc, argv);
50  }
51  catch (const std::exception& e)
52  {
53  ARMNN_LOG(fatal) << e.what();
54  return EXIT_FAILURE;
55  }
56 
57  std::vector<const void*> outputResults;
58 
59  auto executor = BuildExecutor(programOptions);
60  if (!executor)
61  {
62  return EXIT_FAILURE;
63  }
64 
65  executor->PrintNetworkInfo();
66  outputResults = executor->Execute();
67 
68  if (!programOptions.m_ExNetParams.m_ComparisonComputeDevices.empty() ||
69  programOptions.m_ExNetParams.m_CompareWithTflite)
70  {
71  ExecuteNetworkParams comparisonParams = programOptions.m_ExNetParams;
72  comparisonParams.m_ComputeDevices = programOptions.m_ExNetParams.m_ComparisonComputeDevices;
73 
74  if (programOptions.m_ExNetParams.m_CompareWithTflite)
75  {
77  }
78 
79  auto comparisonExecutor = BuildExecutor(programOptions);
80 
81  if (!comparisonExecutor)
82  {
83  return EXIT_FAILURE;
84  }
85 
86  comparisonExecutor->PrintNetworkInfo();
87  comparisonExecutor->Execute();
88 
89  comparisonExecutor->CompareAndPrintResult(outputResults);
90  }
91 }
ExecuteNetworkParams m_ExNetParams
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
Definition: Utils.cpp:18
armnn::IRuntime::CreationOptions m_RuntimeOptions
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
std::vector< armnn::BackendId > m_ComparisonComputeDevices
std::vector< armnn::BackendId > m_ComputeDevices
std::unique_ptr< IExecutor > BuildExecutor(ProgramOptions &programOptions)
Holds all parameters necessary to execute a network Check ExecuteNetworkProgramOptions.cpp for a description of each parameter.
void ParseOptions(int ac, const char *av[])
Parses program options from the command line or another source and stores the values in member variab...
Holds and parses program options for the ExecuteNetwork application.
int main(int argc, const char *argv[])
LogSeverity
Definition: Utils.hpp:14