15 #include <fmt/format.h> 21 if (option ==
nullptr)
27 return ((result.count(option)) ?
true :
false);
35 if (option ==
nullptr || required ==
nullptr)
37 throw cxxopts::OptionParseException(
"Invalid option to check dependency for");
41 if (
CheckOption(result, option) && !result[option].has_default())
43 if (
CheckOption(result, required) == 0 || result[required].has_default())
45 throw cxxopts::OptionParseException(
46 std::string(
"Option '") + option +
"' requires option '" + required +
"'.");
59 for (
auto i = computeDevices.begin(); i != computeDevices.end(); ++i)
61 for (
auto j = std::next(i); j != computeDevices.end(); ++j)
72 computeDevices.end());
78 std::vector<armnn::BackendId>
GetBackendIDs(
const std::vector<std::string>& backendStringsVec)
80 std::vector<armnn::BackendId> backendIDs;
81 for (
const auto& backendStrings : backendStringsVec)
84 std::vector<std::string> backendStringVec =
ParseStringList(backendStrings,
",");
85 for (
const auto& b : backendStringVec)
98 template<
typename optionType>
99 optionType
GetOptionValue(std::string&& optionName,
const cxxopts::ParseResult& result)
102 if(result.count(optionName))
104 out = result[optionName].as<optionType>();
118 std::vector<std::string> requiredOptions{
"compute",
122 bool requiredMissing =
false;
123 for(
auto const& str : requiredOptions)
125 if(!(result.count(str) > 0))
127 ARMNN_LOG(error) << fmt::format(
"The program option '{}' is mandatory but wasn't provided.", str);
128 requiredMissing =
true;
139 if(result.count(
"armnn-tflite-delegate") > 0)
141 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'armnn-tflite-delegate' is deprecated and will be " 142 "removed soon. Please use the option 'tflite-executor' instead.";
144 if(result.count(
"concurrent") > 0)
146 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'concurrent' is deprecated and will be " 147 "removed soon. Please use the option '\"P, thread-pool-size\"' instead.";
149 if(result.count(
"input-type") > 0)
151 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'input-type' is deprecated and will be " 152 "removed soon. The input-types are now automatically set.";
154 if(result.count(
"input-name") > 0)
156 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'input-name' is deprecated and will be " 157 "removed soon. The input-names are now automatically set.";
159 if(result.count(
"output-type") > 0)
161 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'output-type' is deprecated and will be " 162 "removed soon. The output-types are now automatically set.";
164 if(result.count(
"output-name") > 0)
166 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'output-name' is deprecated and will be " 167 "removed soon. The output-names are now automatically set.";
169 if(result.count(
"model-format") > 0)
171 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'model-format' is deprecated and will be " 172 "removed soon. The model-format is now automatically set.";
187 LogAndThrowFatal(
"Timeline profiling requires external profiling to be turned on");
193 "Executes a neural network model using the provided input " 194 "tensor. Prints the resulting output tensor."}
202 "Which device to run layers on by default. If a single device doesn't support all layers in the model " 203 "you can specify a second or third to fall back on. Possible choices: " 205 +
" NOTE: Multiple compute devices need to be passed as a comma separated list without whitespaces " 206 "e.g. GpuAcc,CpuAcc,CpuRef or by repeating the program option e.g. '-c CpuAcc -c CpuRef'. " 207 "Duplicates are ignored.",
208 cxxopts::value<std::vector<std::string>>())
211 "armnn-binary, onnx-binary, onnx-text, tflite-binary" 212 "DEPRECATED: The program option 'model-format' is deprecated and will be " 213 "removed soon. The model-format is now automatically set.",
214 cxxopts::value<std::string>())
217 "Path to model file, e.g. .armnn, , .prototxt, .tflite, .onnx",
221 "Identifier of the input tensors in the network separated by comma." 222 "This option is not required, but can be used to set the order of inputs",
223 cxxopts::value<std::string>())
226 "Identifier of the output tensors in the network separated by comma." 227 "This option is not required, but can be used to set the order of outputs",
228 cxxopts::value<std::string>());
231 (
"b,dynamic-backends-path",
232 "Path where to load any available dynamic backend from. " 233 "If left empty (the default), dynamic backends will not be used.",
236 (
"P, thread-pool-size",
237 "Run the network using the Arm NN thread pool with the number of threads provided. ",
241 "This option is for Arm NN internal asynchronous testing purposes. " 242 "False by default. If set to true will use std::launch::async or the Arm NN thread pool, " 243 "if 'thread-pool-size' is greater than 0, for asynchronous execution." 244 "DEPRECATED: The program option 'concurrent' is deprecated and will be " 245 "removed soon. Please use the option '\"P, thread-pool-size\"' instead.",
248 (
"d,input-tensor-data",
249 "Path to files containing the input data as a flat array separated by whitespace. " 250 "Several paths can be passed by separating them with a comma if the network has multiple inputs " 251 "or you wish to run the model multiple times with different input data using the 'iterations' option. " 252 "If not specified, the network will be run with dummy data (useful for profiling).",
253 cxxopts::value<std::string>()->default_value(
""))
255 (
"h,help",
"Display usage information")
257 (
"infer-output-shape",
258 "Infers output tensor shape from input tensor shape and validate where applicable (where supported by " 262 (
"allow-expanded-dims",
263 "If true will disregard dimensions with a size of 1 when validating tensor shapes. Tensor sizes must " 264 "still match. This is an Experimental parameter that is incompatible with infer-output-shape. " 265 "This parameter may be removed in a later update. ",
267 ->implicit_value(
"true"))
270 "Number of iterations to run the network for, default is set to 1. " 271 "If you wish to run the model with different input data for every execution you can do so by " 272 "supplying more input file paths to the 'input-tensor-data' option. " 273 "Note: The number of input files provided must be divisible by the number of inputs of the model. " 274 "e.g. Your model has 2 inputs and you supply 4 input files. If you set 'iterations' to 6 the first " 275 "run will consume the first two inputs, the second the next two and the last will begin from the " 276 "start and use the first two inputs again. " 277 "Note: If the 'concurrent' option is enabled all iterations will be run asynchronously.",
280 (
"l,dequantize-output",
281 "If this option is enabled, all quantized outputs will be dequantized to float. " 282 "If unset, default to not get dequantized. " 283 "Accepted values (true or false)" 284 " (Not available when executing ArmNNTfLiteDelegate or TfliteInterpreter)",
287 (
"p,print-intermediate-layers",
288 "If this option is enabled, the output of every graph layer will be printed.",
290 ->implicit_value(
"true"))
292 (
"parse-unsupported",
293 "Add unsupported operators as stand-in layers (where supported by parser)",
296 (
"N,do-not-print-output",
297 "The default behaviour of ExecuteNetwork is to print the resulting outputs on the console. " 298 "This behaviour can be changed by adding this flag to your command.",
302 "If this option is enabled, all float inputs will be quantized as appropriate for the model's inputs. " 303 "If unset, default to not quantized. Accepted values (true or false)" 304 " (Not available when executing ArmNNTfLiteDelegate or TfliteInterpreter)",
308 "Threshold time is the maximum allowed time for inference measured in milliseconds. If the actual " 309 "inference time is greater than the threshold time, the test will fail. By default, no threshold " 313 (
"s,input-tensor-shape",
314 "The shape of the input tensors in the network as a flat array of integers separated by comma." 315 "Several shapes can be passed by separating them with a colon (:).",
316 cxxopts::value<std::string>())
318 (
"v,visualize-optimized-model",
319 "Enables built optimized model visualizer. If unset, defaults to off.",
321 ->implicit_value(
"true"))
323 (
"w,write-outputs-to-file",
324 "Comma-separated list of output file paths keyed with the binding-id of the output slot. " 325 "If left empty (the default), the output tensors will not be written to a file.",
326 cxxopts::value<std::string>())
328 (
"x,subgraph-number",
329 "Id of the subgraph to be executed. Defaults to 0." 330 " (Not available when executing ArmNNTfLiteDelegate or TfliteInterpreter)",
334 "The type of the input tensors in the network separated by comma. " 335 "If unset, defaults to \"float\" for all defined inputs. " 336 "Accepted values (float, int, qasymms8 or qasymmu8)." 337 "DEPRECATED: The program option 'input-type' is deprecated and will be " 338 "removed soon. The input-types are now automatically set.",
339 cxxopts::value<std::string>())
342 "The type of the output tensors in the network separated by comma. " 343 "If unset, defaults to \"float\" for all defined outputs. " 344 "Accepted values (float, int, qasymms8 or qasymmu8)." 345 "DEPRECATED: The program option 'output-type' is deprecated and will be " 346 "removed soon. The output-types are now automatically set.",
347 cxxopts::value<std::string>())
349 (
"T,tflite-executor",
350 "Set the executor for the tflite model: parser, delegate, tflite" 351 "parser is the ArmNNTfLiteParser, " 352 "delegate is the ArmNNTfLiteDelegate, " 353 "tflite is the TfliteInterpreter",
354 cxxopts::value<std::string>()->default_value(
"parser"))
356 (
"C, compare-output",
357 "Number of Arm NN threads to use when running the network asynchronously via the Arm NN thread pool. " 358 "The default is set to 0 which equals disabled. If 'thread-pool-size' is greater than 0 the " 359 "'concurrent' option is automatically set to true.",
362 (
"B, compare-output-with-backend",
363 "Compare the output of the network with a different backend.",
364 cxxopts::value<std::vector<std::string>>())
366 (
"A, compare-with-tflite",
367 "Compare the output of the network with the tflite ref model.",
369 ->implicit_value(
"true"));
373 "If this option is enabled, FP32 layers, " 374 "weights and biases will be converted to BFloat16 where the backend supports it",
376 ->default_value(
"false")->implicit_value(
"true"))
379 "Enables fast_math options in backends that support it. Using the fast_math flag can lead to " 380 "performance improvements but may result in reduced or different precision.",
383 (
"number-of-threads",
384 "Assign the number of threads used by the CpuAcc backend. " 385 "Input value must be between 1 and 64. " 386 "Default is set to 0 (Backend will decide number of threads to use).",
389 (
"save-cached-network",
390 "Enables saving of the cached network to a file given with the cached-network-filepath option. " 391 "See also --cached-network-filepath",
393 ->default_value(
"false")->implicit_value(
"true"))
395 (
"cached-network-filepath",
396 "If non-empty, the given file will be used to load/save the cached network. " 397 "If save-cached-network is given then the cached network will be saved to the given file. " 398 "To save the cached network a file must already exist. " 399 "If save-cached-network is not given then the cached network will be loaded from the given file. " 400 "This will remove initial compilation time of kernels and speed up the first execution.",
404 "If this option is enabled, FP32 layers, " 405 "weights and biases will be converted to FP16 where the backend supports it",
407 ->default_value(
"false")->implicit_value(
"true"))
410 "Sets the tuning level which enables a tuning run which will update/create a tuning file. " 411 "Available options are: 1 (Rapid), 2 (Normal), 3 (Exhaustive). " 412 "Requires tuning-path to be set, default is set to 0 (No tuning run)",
416 "Path to tuning file. Enables use of CL tuning",
419 (
"MLGOTuningFilePath",
420 "Path to tuning file. Enables use of CL MLGO tuning",
424 "If enabled then the IO buffers will be reused for each inference",
428 (
"a,enable-external-profiling",
429 "If enabled external profiling will be switched on",
431 ->default_value(
"false")->implicit_value(
"true"))
433 (
"e,event-based-profiling",
434 "Enables built in profiler. If unset, defaults to off.",
437 (
"g,file-only-external-profiling",
438 "If enabled then the 'file-only' test mode of external profiling will be enabled",
440 ->default_value(
"false")->implicit_value(
"true"))
443 "If profiling is enabled specifies the output file format",
446 (
"j,outgoing-capture-file",
447 "If specified the outgoing external profiling packets will be captured in this binary file",
450 (
"k,incoming-capture-file",
451 "If specified the incoming external profiling packets will be captured in this binary file",
454 (
"timeline-profiling",
455 "If enabled timeline profiling will be switched on, requires external profiling",
457 ->default_value(
"false")->implicit_value(
"true"))
459 (
"u,counter-capture-period",
460 "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test",
463 (
"output-network-details",
464 "Outputs layer tensor infos and descriptors to std out along with profiling events. Defaults to off.",
466 ->implicit_value(
"true"))
468 (
"output-network-details-only",
469 "Outputs layer tensor infos and descriptors to std out without profiling events. Defaults to off.",
471 ->implicit_value(
"true"))
473 (
"import-inputs-if-aligned",
474 "In & Out tensors will be imported per inference if the memory alignment allows. Defaults to false.",
476 ->implicit_value(
"true"));
478 catch (
const std::exception& e)
481 ARMNN_LOG(fatal) <<
"Fatal internal error: " << e.what();
510 throw cxxopts::OptionParseException(
"You must enable profiling if you would like to output layer details");
514 auto computeDevices = GetOptionValue<std::vector<std::string>>(
"compute",
m_CxxResult);
529 std::string tfliteExecutor = GetOptionValue<std::string>(
"tflite-executor",
m_CxxResult);
531 if (tfliteExecutor.size() == 0 || tfliteExecutor ==
"parser")
535 else if (tfliteExecutor ==
"delegate")
539 else if (tfliteExecutor ==
"tflite")
545 ARMNN_LOG(info) << fmt::format(
"Invalid tflite-executor option '{}'.", tfliteExecutor);
567 std::vector<std::string> inputTensorShapesVector =
570 if (!inputTensorShapesVector.empty())
574 for(
const std::string& shape : inputTensorShapesVector)
576 std::stringstream ss(shape);
577 std::vector<unsigned int> dims =
ParseArray(ss);
606 auto comparisonComputDevices = GetOptionValue<std::vector<std::string>>(
"compare-output-with-backend",
m_CxxResult);
608 if (!comparisonComputDevices.empty())
ExecuteNetworkParams m_ExNetParams
cxxopts::Options m_CxxOptions
void ValidateExecuteNetworkParams()
Ensures that the parameters for ExecuteNetwork fit together.
std::string m_MLGOTuningFilePath
optionType GetOptionValue(std::string &&optionName, const cxxopts::ParseResult &result)
Provides a segfault safe way to get cxxopts option values by checking if the option was defined...
std::string m_OutgoingCaptureFile
Path to a file in which outgoing timeline profiling messages will be stored.
std::vector< unsigned int > ParseArray(std::istream &stream)
void RemoveDuplicateDevices(std::vector< armnn::BackendId > &computeDevices)
bool m_OutputDetailsOnlyToStdOut
bool m_EnableFp16TurboMode
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.
std::string m_DynamicBackendsPath
std::vector< armnn::TensorShape > m_InputTensorShapes
armnn::IRuntime::CreationOptions m_RuntimeOptions
#define ARMNN_LOG(severity)
BackendRegistry & BackendRegistryInstance()
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
TfLiteExecutor m_TfLiteExecutor
std::string GetBackendIdsAsString() const
std::string m_IncomingCaptureFile
Path to a file in which incoming timeline profiling messages will be stored.
std::vector< std::string > m_OutputTensorFiles
bool m_EnableProfiling
Indicates whether external profiling is enabled or not.
bool m_FileOnly
Enable profiling output to file only.
std::vector< armnn::BackendId > m_ComparisonComputeDevices
bool m_OutputDetailsToStdOut
std::string m_CachedNetworkFilePath
bool CheckOption(const cxxopts::ParseResult &result, const char *option)
std::vector< armnn::BackendId > m_ComputeDevices
std::vector< BackendOptions > m_BackendOptions
Pass backend specific options.
ProgramOptions()
Initializes ProgramOptions by adding options to the underlying cxxopts::options object.
bool m_GenerateTensorData
#define ARMNN_ASSERT_MSG(COND, MSG)
unsigned int m_NumberOfThreads
std::vector< std::string > m_InputNames
bool m_EnableBf16TurboMode
std::vector< std::string > m_InputTensorDataFilePaths
void ParseOptions(int ac, const char *av[])
Parses program options from the command line or another source and stores the values in member variab...
void CheckForDeprecatedOptions(const cxxopts::ParseResult &result)
Struct for the users to pass backend specific options.
void LogAndThrowFatal(std::string errorMessage)
std::string m_DynamicBackendsPath
Setting this value will override the paths set by the DYNAMIC_BACKEND_PATHS compiler directive Only a...
Holds and parses program options for the ExecuteNetwork application.
bool m_EnableGpuProfiling
Setting this flag will allow the user to obtain GPU profiling information from the runtime...
void CheckOptionDependency(const cxxopts::ParseResult &result, const char *option, const char *required)
bool m_ImportInputsIfAligned
bool m_EnableLayerDetails
void ValidateRuntimeOptions()
Ensures that the runtime options are valid.
uint32_t m_CapturePeriod
The duration at which captured profiling messages will be flushed.
void CheckOptionDependencies(const cxxopts::ParseResult &result)
bool m_TimelineEnabled
Indicates whether external timeline profiling is enabled or not.
cxxopts::ParseResult m_CxxResult
void CheckRequiredOptions(const cxxopts::ParseResult &result)
ExternalProfilingOptions m_ProfilingOptions
std::string m_ComparisonFile
std::string m_FileFormat
The format of the file used for outputting profiling data.