ArmNN
 21.05
ProgramOptions Struct Reference

Holds and parses program options for the ExecuteNetwork application. More...

#include <ExecuteNetworkProgramOptions.hpp>

Public Member Functions

 ProgramOptions ()
 Initializes ProgramOptions by adding options to the underlying cxxopts::options object. More...
 
 ProgramOptions (int ac, const char *av[])
 Runs ParseOptions() on initialization. More...
 
void ParseOptions (int ac, const char *av[])
 Parses program options from the command line or another source and stores the values in member variables. More...
 
void ValidateExecuteNetworkParams ()
 Ensures that the parameters for ExecuteNetwork fit together. More...
 
void ValidateRuntimeOptions ()
 Ensures that the runtime options are valid. More...
 

Public Attributes

cxxopts::Options m_CxxOptions
 
cxxopts::ParseResult m_CxxResult
 
ExecuteNetworkParams m_ExNetParams
 
armnn::IRuntime::CreationOptions m_RuntimeOptions
 

Detailed Description

Holds and parses program options for the ExecuteNetwork application.

Definition at line 21 of file ExecuteNetworkProgramOptions.hpp.

Constructor & Destructor Documentation

◆ ProgramOptions() [1/2]

Initializes ProgramOptions by adding options to the underlying cxxopts::options object.

(Does not parse any options)

Definition at line 157 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_ASSERT_MSG, ARMNN_LOG, armnn::BackendRegistryInstance(), BackendRegistry::GetBackendIdsAsString(), ExecuteNetworkParams::m_CachedNetworkFilePath, IRuntime::CreationOptions::ExternalProfilingOptions::m_CapturePeriod, ExecuteNetworkParams::m_Concurrent, m_CxxOptions, ExecuteNetworkParams::m_DequantizeOutput, IRuntime::CreationOptions::m_DynamicBackendsPath, ExecuteNetworkParams::m_EnableBf16TurboMode, ExecuteNetworkParams::m_EnableDelegate, ExecuteNetworkParams::m_EnableFastMath, ExecuteNetworkParams::m_EnableFp16TurboMode, ExecuteNetworkParams::m_EnableLayerDetails, ExecuteNetworkParams::m_EnableProfiling, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, m_ExNetParams, IRuntime::CreationOptions::ExternalProfilingOptions::m_FileFormat, IRuntime::CreationOptions::ExternalProfilingOptions::m_FileOnly, IRuntime::CreationOptions::ExternalProfilingOptions::m_IncomingCaptureFile, ExecuteNetworkParams::m_InferOutputShape, ExecuteNetworkParams::m_Iterations, ExecuteNetworkParams::m_MLGOTuningFilePath, ExecuteNetworkParams::m_ModelPath, ExecuteNetworkParams::m_NumberOfThreads, IRuntime::CreationOptions::ExternalProfilingOptions::m_OutgoingCaptureFile, ExecuteNetworkParams::m_ParseUnsupported, ExecuteNetworkParams::m_PrintIntermediate, IRuntime::CreationOptions::m_ProfilingOptions, ExecuteNetworkParams::m_QuantizeInput, m_RuntimeOptions, ExecuteNetworkParams::m_SaveCachedNetwork, ExecuteNetworkParams::m_SimultaneousIterations, ExecuteNetworkParams::m_SubgraphId, ExecuteNetworkParams::m_ThresholdTime, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, ExecuteNetworkParams::m_TuningLevel, and ExecuteNetworkParams::m_TuningPath.

157  : m_CxxOptions{"ExecuteNetwork",
158  "Executes a neural network model using the provided input "
159  "tensor. Prints the resulting output tensor."}
160 {
161  try
162  {
163  // cxxopts doesn't provide a mechanism to ensure required options are given. There is a
164  // separate function CheckRequiredOptions() for that.
165  m_CxxOptions.add_options("a) Required")
166  ("c,compute",
167  "Which device to run layers on by default. If a single device doesn't support all layers in the model "
168  "you can specify a second or third to fall back on. Possible choices: "
170  + " NOTE: Multiple compute devices need to be passed as a comma separated list without whitespaces "
171  "e.g. GpuAcc,CpuAcc,CpuRef or by repeating the program option e.g. '-c Cpuacc -c CpuRef'. "
172  "Duplicates are ignored.",
173  cxxopts::value<std::vector<std::string>>())
174 
175  ("f,model-format",
176  "armnn-binary, onnx-binary, onnx-text, tflite-binary",
177  cxxopts::value<std::string>())
178 
179  ("m,model-path",
180  "Path to model file, e.g. .armnn, , .prototxt, .tflite, .onnx",
181  cxxopts::value<std::string>(m_ExNetParams.m_ModelPath))
182 
183  ("i,input-name",
184  "Identifier of the input tensors in the network separated by comma.",
185  cxxopts::value<std::string>())
186 
187  ("o,output-name",
188  "Identifier of the output tensors in the network separated by comma.",
189  cxxopts::value<std::string>());
190 
191  m_CxxOptions.add_options("b) General")
192  ("b,dynamic-backends-path",
193  "Path where to load any available dynamic backend from. "
194  "If left empty (the default), dynamic backends will not be used.",
195  cxxopts::value<std::string>(m_RuntimeOptions.m_DynamicBackendsPath))
196 
197  ("n,concurrent",
198  "If this option is enabled inferences will be executed in parallel asynchronously.",
199  cxxopts::value<bool>(m_ExNetParams.m_Concurrent)->default_value("false")->implicit_value("true"))
200 
201  ("d,input-tensor-data",
202  "Path to files containing the input data as a flat array separated by whitespace. "
203  "Several paths can be passed by separating them with a comma. If not specified, the network will be "
204  "run with dummy data (useful for profiling).",
205  cxxopts::value<std::string>()->default_value(""))
206 
207  ("h,help", "Display usage information")
208 
209  ("infer-output-shape",
210  "Infers output tensor shape from input tensor shape and validate where applicable (where supported by "
211  "parser)",
212  cxxopts::value<bool>(m_ExNetParams.m_InferOutputShape)->default_value("false")->implicit_value("true"))
213 
214  ("iterations",
215  "Number of iterations to run the network for, default is set to 1",
216  cxxopts::value<size_t>(m_ExNetParams.m_Iterations)->default_value("1"))
217 
218  ("l,dequantize-output",
219  "If this option is enabled, all quantized outputs will be dequantized to float. "
220  "If unset, default to not get dequantized. "
221  "Accepted values (true or false)",
222  cxxopts::value<bool>(m_ExNetParams.m_DequantizeOutput)->default_value("false")->implicit_value("true"))
223 
224  ("p,print-intermediate-layers",
225  "If this option is enabled, the output of every graph layer will be printed.",
226  cxxopts::value<bool>(m_ExNetParams.m_PrintIntermediate)->default_value("false")
227  ->implicit_value("true"))
228 
229  ("parse-unsupported",
230  "Add unsupported operators as stand-in layers (where supported by parser)",
231  cxxopts::value<bool>(m_ExNetParams.m_ParseUnsupported)->default_value("false")->implicit_value("true"))
232 
233  ("q,quantize-input",
234  "If this option is enabled, all float inputs will be quantized to qasymm8. "
235  "If unset, default to not quantized. Accepted values (true or false)",
236  cxxopts::value<bool>(m_ExNetParams.m_QuantizeInput)->default_value("false")->implicit_value("true"))
237 
238  ("r,threshold-time",
239  "Threshold time is the maximum allowed time for inference measured in milliseconds. If the actual "
240  "inference time is greater than the threshold time, the test will fail. By default, no threshold "
241  "time is used.",
242  cxxopts::value<double>(m_ExNetParams.m_ThresholdTime)->default_value("0.0"))
243 
244  ("s,input-tensor-shape",
245  "The shape of the input tensors in the network as a flat array of integers separated by comma."
246  "Several shapes can be passed by separating them with a colon (:).",
247  cxxopts::value<std::string>())
248 
249  ("v,visualize-optimized-model",
250  "Enables built optimized model visualizer. If unset, defaults to off.",
251  cxxopts::value<bool>(m_ExNetParams.m_EnableLayerDetails)->default_value("false")
252  ->implicit_value("true"))
253 
254  ("w,write-outputs-to-file",
255  "Comma-separated list of output file paths keyed with the binding-id of the output slot. "
256  "If left empty (the default), the output tensors will not be written to a file.",
257  cxxopts::value<std::string>())
258 
259  ("x,subgraph-number",
260  "Id of the subgraph to be executed. Defaults to 0.",
261  cxxopts::value<size_t>(m_ExNetParams.m_SubgraphId)->default_value("0"))
262 
263  ("y,input-type",
264  "The type of the input tensors in the network separated by comma. "
265  "If unset, defaults to \"float\" for all defined inputs. "
266  "Accepted values (float, int or qasymm8).",
267  cxxopts::value<std::string>())
268 
269  ("z,output-type",
270  "The type of the output tensors in the network separated by comma. "
271  "If unset, defaults to \"float\" for all defined outputs. "
272  "Accepted values (float, int or qasymm8).",
273  cxxopts::value<std::string>())
274 
275  ("T,tflite-executor",
276  "Set the executor for the tflite model: parser, delegate, tflite"
277  "parser is the ArmNNTfLiteParser, "
278  "delegate is the ArmNNTfLiteDelegate, "
279  "tflite is the TfliteInterpreter",
280  cxxopts::value<std::string>()->default_value("parser"))
281 
282  ("D,armnn-tflite-delegate",
283  "Enable Arm NN TfLite delegate. "
284  "This option is depreciated please use tflite-executor instead",
285  cxxopts::value<bool>(m_ExNetParams.m_EnableDelegate)->default_value("false")->implicit_value("true"))
286 
287  ("simultaneous-iterations",
288  "Number of simultaneous iterations to async-run the network for, default is set to 1",
289  cxxopts::value<size_t>(m_ExNetParams.m_SimultaneousIterations)->default_value("1"));
290 
291  m_CxxOptions.add_options("c) Optimization")
292  ("bf16-turbo-mode",
293  "If this option is enabled, FP32 layers, "
294  "weights and biases will be converted to BFloat16 where the backend supports it",
295  cxxopts::value<bool>(m_ExNetParams.m_EnableBf16TurboMode)
296  ->default_value("false")->implicit_value("true"))
297 
298  ("enable-fast-math",
299  "Enables fast_math options in backends that support it. Using the fast_math flag can lead to "
300  "performance improvements but may result in reduced or different precision.",
301  cxxopts::value<bool>(m_ExNetParams.m_EnableFastMath)->default_value("false")->implicit_value("true"))
302 
303  ("number-of-threads",
304  "Assign the number of threads used by the CpuAcc backend. "
305  "Input value must be between 1 and 64. "
306  "Default is set to 0 (Backend will decide number of threads to use).",
307  cxxopts::value<unsigned int>(m_ExNetParams.m_NumberOfThreads)->default_value("0"))
308 
309  ("save-cached-network",
310  "Enables saving of the cached network to a file given with the cached-network-filepath option. "
311  "See also --cached-network-filepath",
312  cxxopts::value<bool>(m_ExNetParams.m_SaveCachedNetwork)
313  ->default_value("false")->implicit_value("true"))
314 
315  ("cached-network-filepath",
316  "If non-empty, the given file will be used to load/save the cached network. "
317  "If save-cached-network is given then the cached network will be saved to the given file. "
318  "To save the cached network a file must already exist. "
319  "If save-cached-network is not given then the cached network will be loaded from the given file. "
320  "This will remove initial compilation time of kernels and speed up the first execution.",
321  cxxopts::value<std::string>(m_ExNetParams.m_CachedNetworkFilePath)->default_value(""))
322 
323  ("fp16-turbo-mode",
324  "If this option is enabled, FP32 layers, "
325  "weights and biases will be converted to FP16 where the backend supports it",
326  cxxopts::value<bool>(m_ExNetParams.m_EnableFp16TurboMode)
327  ->default_value("false")->implicit_value("true"))
328 
329  ("tuning-level",
330  "Sets the tuning level which enables a tuning run which will update/create a tuning file. "
331  "Available options are: 1 (Rapid), 2 (Normal), 3 (Exhaustive). "
332  "Requires tuning-path to be set, default is set to 0 (No tuning run)",
333  cxxopts::value<int>(m_ExNetParams.m_TuningLevel)->default_value("0"))
334 
335  ("tuning-path",
336  "Path to tuning file. Enables use of CL tuning",
337  cxxopts::value<std::string>(m_ExNetParams.m_TuningPath))
338 
339  ("MLGOTuningFilePath",
340  "Path to tuning file. Enables use of CL MLGO tuning",
341  cxxopts::value<std::string>(m_ExNetParams.m_MLGOTuningFilePath));
342 
343  m_CxxOptions.add_options("d) Profiling")
344  ("a,enable-external-profiling",
345  "If enabled external profiling will be switched on",
347  ->default_value("false")->implicit_value("true"))
348 
349  ("e,event-based-profiling",
350  "Enables built in profiler. If unset, defaults to off.",
351  cxxopts::value<bool>(m_ExNetParams.m_EnableProfiling)->default_value("false")->implicit_value("true"))
352 
353  ("g,file-only-external-profiling",
354  "If enabled then the 'file-only' test mode of external profiling will be enabled",
355  cxxopts::value<bool>(m_RuntimeOptions.m_ProfilingOptions.m_FileOnly)
356  ->default_value("false")->implicit_value("true"))
357 
358  ("file-format",
359  "If profiling is enabled specifies the output file format",
360  cxxopts::value<std::string>(m_RuntimeOptions.m_ProfilingOptions.m_FileFormat)->default_value("binary"))
361 
362  ("j,outgoing-capture-file",
363  "If specified the outgoing external profiling packets will be captured in this binary file",
364  cxxopts::value<std::string>(m_RuntimeOptions.m_ProfilingOptions.m_OutgoingCaptureFile))
365 
366  ("k,incoming-capture-file",
367  "If specified the incoming external profiling packets will be captured in this binary file",
368  cxxopts::value<std::string>(m_RuntimeOptions.m_ProfilingOptions.m_IncomingCaptureFile))
369 
370  ("timeline-profiling",
371  "If enabled timeline profiling will be switched on, requires external profiling",
373  ->default_value("false")->implicit_value("true"))
374 
375  ("u,counter-capture-period",
376  "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test",
377  cxxopts::value<uint32_t>(m_RuntimeOptions.m_ProfilingOptions.m_CapturePeriod)->default_value("150"));
378  }
379  catch (const std::exception& e)
380  {
381  ARMNN_ASSERT_MSG(false, "Caught unexpected exception");
382  ARMNN_LOG(fatal) << "Fatal internal error: " << e.what();
383  exit(EXIT_FAILURE);
384  }
385 }
ExecuteNetworkParams m_ExNetParams
armnn::IRuntime::CreationOptions m_RuntimeOptions
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
BackendRegistry & BackendRegistryInstance()
std::string GetBackendIdsAsString() const
#define ARMNN_ASSERT_MSG(COND, MSG)
Definition: Assert.hpp:15
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
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:117

◆ ProgramOptions() [2/2]

ProgramOptions ( int  ac,
const char *  av[] 
)

Runs ParseOptions() on initialization.

Definition at line 387 of file ExecuteNetworkProgramOptions.cpp.

References ParseOptions().

387  : ProgramOptions()
388 {
389  ParseOptions(ac, av);
390 }
ProgramOptions()
Initializes ProgramOptions by adding options to the underlying cxxopts::options object.
void ParseOptions(int ac, const char *av[])
Parses program options from the command line or another source and stores the values in member variab...

Member Function Documentation

◆ ParseOptions()

void ParseOptions ( int  ac,
const char *  av[] 
)

Parses program options from the command line or another source and stores the values in member variables.

It also checks the validity of the parsed parameters. Throws a cxxopts exception if parsing fails or an armnn exception if parameters are not valid.

Definition at line 392 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG, ExecuteNetworkParams::ArmNNTfLiteDelegate, ExecuteNetworkParams::ArmNNTfLiteParser, CheckOptionDependencies(), CheckRequiredOptions(), GetBackendIDs(), IRuntime::CreationOptions::m_BackendOptions, ExecuteNetworkParams::m_ComputeDevices, m_CxxOptions, m_CxxResult, ExecuteNetworkParams::m_DynamicBackendsPath, IRuntime::CreationOptions::m_DynamicBackendsPath, ExecuteNetworkParams::m_EnableDelegate, IRuntime::CreationOptions::m_EnableGpuProfiling, ExecuteNetworkParams::m_EnableProfiling, m_ExNetParams, ExecuteNetworkParams::m_GenerateTensorData, ExecuteNetworkParams::m_InputNames, ExecuteNetworkParams::m_InputTensorDataFilePaths, ExecuteNetworkParams::m_InputTensorShapes, ExecuteNetworkParams::m_InputTypes, ExecuteNetworkParams::m_MLGOTuningFilePath, ExecuteNetworkParams::m_ModelFormat, ExecuteNetworkParams::m_OutputNames, ExecuteNetworkParams::m_OutputTensorFiles, ExecuteNetworkParams::m_OutputTypes, m_RuntimeOptions, ExecuteNetworkParams::m_TfLiteExecutor, ExecuteNetworkParams::m_TuningLevel, ExecuteNetworkParams::m_TuningPath, ParseArray(), ParseStringList(), armnn::stringUtils::StringTrimCopy(), ExecuteNetworkParams::TfliteInterpreter, ValidateExecuteNetworkParams(), and ValidateRuntimeOptions().

Referenced by ProgramOptions().

393 {
394  // Parses the command-line.
395  m_CxxResult = m_CxxOptions.parse(ac, av);
396 
397  if (m_CxxResult.count("help") || ac <= 1)
398  {
399  std::cout << m_CxxOptions.help() << std::endl;
400  exit(EXIT_SUCCESS);
401  }
402 
405 
406  // Some options can't be assigned directly because they need some post-processing:
407  auto computeDevices = GetOptionValue<std::vector<std::string>>("compute", m_CxxResult);
408  m_ExNetParams.m_ComputeDevices = GetBackendIDs(computeDevices);
410  armnn::stringUtils::StringTrimCopy(GetOptionValue<std::string>("model-format", m_CxxResult));
412  ParseStringList(GetOptionValue<std::string>("input-name", m_CxxResult), ",");
414  ParseStringList(GetOptionValue<std::string>("input-tensor-data", m_CxxResult), ",");
416  ParseStringList(GetOptionValue<std::string>("output-name", m_CxxResult), ",");
418  ParseStringList(GetOptionValue<std::string>("input-type", m_CxxResult), ",");
420  ParseStringList(GetOptionValue<std::string>("output-type", m_CxxResult), ",");
422  ParseStringList(GetOptionValue<std::string>("write-outputs-to-file", m_CxxResult), ",");
426 
428 
429  std::string tfliteExecutor = GetOptionValue<std::string>("tflite-executor", m_CxxResult);
430 
431  if (tfliteExecutor.size() == 0 || tfliteExecutor == "parser")
432  {
434  }
435  else if (tfliteExecutor == "delegate")
436  {
438  }
439  else if (tfliteExecutor == "tflite")
440  {
442  }
443  else
444  {
445  ARMNN_LOG(info) << fmt::format("Invalid tflite-executor option '{}'.", tfliteExecutor);
446  throw armnn::InvalidArgumentException ("Invalid tflite-executor option");
447  }
448 
450  {
452  ARMNN_LOG(info) << fmt::format("armnn-tflite-delegate option is being depreciated, "
453  "please use tflite-executor instead.");
454  }
455 
456 
457 
458  // Parse input tensor shape from the string we got from the command-line.
459  std::vector<std::string> inputTensorShapesVector =
460  ParseStringList(GetOptionValue<std::string>("input-tensor-shape", m_CxxResult), ":");
461 
462  if (!inputTensorShapesVector.empty())
463  {
464  m_ExNetParams.m_InputTensorShapes.reserve(inputTensorShapesVector.size());
465 
466  for(const std::string& shape : inputTensorShapesVector)
467  {
468  std::stringstream ss(shape);
469  std::vector<unsigned int> dims = ParseArray(ss);
470 
472  std::make_unique<armnn::TensorShape>(static_cast<unsigned int>(dims.size()), dims.data()));
473  }
474  }
475 
476  // We have to validate ExecuteNetworkParams first so that the tuning path and level is validated
478 
479  // Parse CL tuning parameters to runtime options
480  if (!m_ExNetParams.m_TuningPath.empty())
481  {
482  m_RuntimeOptions.m_BackendOptions.emplace_back(
484  {
485  "GpuAcc",
486  {
487  {"TuningLevel", m_ExNetParams.m_TuningLevel},
488  {"TuningFile", m_ExNetParams.m_TuningPath.c_str()},
489  {"KernelProfilingEnabled", m_ExNetParams.m_EnableProfiling},
490  {"MLGOTuningFilePath", m_ExNetParams.m_MLGOTuningFilePath}
491  }
492  }
493  );
494  }
495 
497 }
ExecuteNetworkParams m_ExNetParams
std::vector< std::string > m_InputTypes
void ValidateExecuteNetworkParams()
Ensures that the parameters for ExecuteNetwork fit together.
std::vector< TensorShapePtr > m_InputTensorShapes
std::vector< unsigned int > ParseArray(std::istream &stream)
std::vector< std::string > ParseStringList(const std::string &inputString, const char *delimiter)
Splits a given string at every accurance of delimiter into a vector of string.
armnn::IRuntime::CreationOptions m_RuntimeOptions
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
std::vector< armnn::BackendId > GetBackendIDs(const std::vector< std::string > &backendStringsVec)
Takes a vector of backend strings and returns a vector of backendIDs.
std::vector< std::string > m_OutputNames
std::vector< std::string > m_OutputTensorFiles
std::vector< armnn::BackendId > m_ComputeDevices
std::vector< std::string > m_OutputTypes
std::string StringTrimCopy(const std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string, returns a trimmed copy of the string.
Definition: StringUtils.hpp:85
std::vector< BackendOptions > m_BackendOptions
Pass backend specific options.
Definition: IRuntime.hpp:149
std::vector< std::string > m_InputNames
std::vector< std::string > m_InputTensorDataFilePaths
Struct for the users to pass backend specific options.
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
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
Definition: IRuntime.hpp:89
void ValidateRuntimeOptions()
Ensures that the runtime options are valid.
void CheckOptionDependencies(const cxxopts::ParseResult &result)
cxxopts::ParseResult m_CxxResult
void CheckRequiredOptions(const cxxopts::ParseResult &result)

◆ ValidateExecuteNetworkParams()

void ValidateExecuteNetworkParams ( )

Ensures that the parameters for ExecuteNetwork fit together.

Definition at line 142 of file ExecuteNetworkProgramOptions.cpp.

References m_ExNetParams, and ExecuteNetworkParams::ValidateParams().

Referenced by ParseOptions().

143 {
145 }
ExecuteNetworkParams m_ExNetParams

◆ ValidateRuntimeOptions()

void ValidateRuntimeOptions ( )

Member Data Documentation

◆ m_CxxOptions

cxxopts::Options m_CxxOptions

Definition at line 41 of file ExecuteNetworkProgramOptions.hpp.

Referenced by ParseOptions(), and ProgramOptions().

◆ m_CxxResult

cxxopts::ParseResult m_CxxResult

Definition at line 42 of file ExecuteNetworkProgramOptions.hpp.

Referenced by ParseOptions().

◆ m_ExNetParams

◆ m_RuntimeOptions


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