16 #include <fmt/format.h> 22 if (option ==
nullptr)
28 return ((result.count(option)) ?
true :
false);
36 if (option ==
nullptr || required ==
nullptr)
38 throw cxxopts::OptionParseException(
"Invalid option to check dependency for");
42 if (
CheckOption(result, option) && !result[option].has_default())
44 if (
CheckOption(result, required) == 0 || result[required].has_default())
46 throw cxxopts::OptionParseException(
47 std::string(
"Option '") + option +
"' requires option '" + required +
"'.");
62 for (
auto i = computeDevices.begin(); i != computeDevices.end(); ++i)
64 for (
auto j = std::next(i); j != computeDevices.end(); ++j)
75 computeDevices.end());
81 std::vector<armnn::BackendId>
GetBackendIDs(
const std::vector<std::string>& backendStringsVec)
83 std::vector<armnn::BackendId> backendIDs;
84 for (
const auto& backendStrings : backendStringsVec)
87 std::vector<std::string> backendStringVec =
ParseStringList(backendStrings,
",");
88 for (
const auto& b : backendStringVec)
101 template<
typename optionType>
102 optionType
GetOptionValue(std::string&& optionName,
const cxxopts::ParseResult& result)
105 if(result.count(optionName))
107 out = result[optionName].as<optionType>();
121 std::vector<std::string> requiredOptions{
"compute",
127 bool requiredMissing =
false;
128 for(
auto const& str : requiredOptions)
130 if(!(result.count(str) > 0))
132 ARMNN_LOG(error) << fmt::format(
"The program option '{}' is mandatory but wasn't provided.", str);
133 requiredMissing =
true;
144 if(result.count(
"simultaneous-iterations") > 0)
146 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'simultaneous-iterations' is deprecated and will be " 147 "removed soon. Please use the option 'iterations' combined with 'concurrent' instead.";
149 if(result.count(
"armnn-tflite-delegate") > 0)
151 ARMNN_LOG(warning) <<
"DEPRECATED: The program option 'armnn-tflite-delegate' is deprecated and will be " 152 "removed soon. Please use the option 'tflite-executor' instead.";
166 LogAndThrowFatal(
"Timeline profiling requires external profiling to be turned on");
172 "Executes a neural network model using the provided input " 173 "tensor. Prints the resulting output tensor."}
181 "Which device to run layers on by default. If a single device doesn't support all layers in the model " 182 "you can specify a second or third to fall back on. Possible choices: " 184 +
" NOTE: Multiple compute devices need to be passed as a comma separated list without whitespaces " 185 "e.g. GpuAcc,CpuAcc,CpuRef or by repeating the program option e.g. '-c Cpuacc -c CpuRef'. " 186 "Duplicates are ignored.",
187 cxxopts::value<std::vector<std::string>>())
190 "armnn-binary, onnx-binary, onnx-text, tflite-binary",
191 cxxopts::value<std::string>())
194 "Path to model file, e.g. .armnn, , .prototxt, .tflite, .onnx",
198 "Identifier of the input tensors in the network separated by comma.",
199 cxxopts::value<std::string>())
202 "Identifier of the output tensors in the network separated by comma.",
203 cxxopts::value<std::string>());
206 (
"b,dynamic-backends-path",
207 "Path where to load any available dynamic backend from. " 208 "If left empty (the default), dynamic backends will not be used.",
212 "This option is for Arm NN internal asynchronous testing purposes. " 213 "False by default. If set to true will use std::launch::async or the Arm NN thread pool, " 214 "if 'thread-pool-size' is greater than 0, for asynchronous execution.",
217 (
"d,input-tensor-data",
218 "Path to files containing the input data as a flat array separated by whitespace. " 219 "Several paths can be passed by separating them with a comma if the network has multiple inputs " 220 "or you wish to run the model multiple times with different input data using the 'iterations' option. " 221 "If not specified, the network will be run with dummy data (useful for profiling).",
222 cxxopts::value<std::string>()->default_value(
""))
224 (
"h,help",
"Display usage information")
226 (
"infer-output-shape",
227 "Infers output tensor shape from input tensor shape and validate where applicable (where supported by " 232 "Number of iterations to run the network for, default is set to 1. " 233 "If you wish to run the model with different input data for every execution you can do so by " 234 "supplying more input file paths to the 'input-tensor-data' option. " 235 "Note: The number of input files provided must be divisible by the number of inputs of the model. " 236 "e.g. Your model has 2 inputs and you supply 4 input files. If you set 'iterations' to 6 the first " 237 "run will consume the first two inputs, the second the next two and the last will begin from the " 238 "start and use the first two inputs again. " 239 "Note: If the 'concurrent' option is enabled all iterations will be run asynchronously.",
242 (
"l,dequantize-output",
243 "If this option is enabled, all quantized outputs will be dequantized to float. " 244 "If unset, default to not get dequantized. " 245 "Accepted values (true or false)",
248 (
"p,print-intermediate-layers",
249 "If this option is enabled, the output of every graph layer will be printed.",
251 ->implicit_value(
"true"))
253 (
"parse-unsupported",
254 "Add unsupported operators as stand-in layers (where supported by parser)",
258 "If this option is enabled, all float inputs will be quantized as appropriate for the model's inputs. " 259 "If unset, default to not quantized. Accepted values (true or false)",
263 "Threshold time is the maximum allowed time for inference measured in milliseconds. If the actual " 264 "inference time is greater than the threshold time, the test will fail. By default, no threshold " 268 (
"s,input-tensor-shape",
269 "The shape of the input tensors in the network as a flat array of integers separated by comma." 270 "Several shapes can be passed by separating them with a colon (:).",
271 cxxopts::value<std::string>())
273 (
"v,visualize-optimized-model",
274 "Enables built optimized model visualizer. If unset, defaults to off.",
276 ->implicit_value(
"true"))
278 (
"w,write-outputs-to-file",
279 "Comma-separated list of output file paths keyed with the binding-id of the output slot. " 280 "If left empty (the default), the output tensors will not be written to a file.",
281 cxxopts::value<std::string>())
283 (
"x,subgraph-number",
284 "Id of the subgraph to be executed. Defaults to 0.",
288 "The type of the input tensors in the network separated by comma. " 289 "If unset, defaults to \"float\" for all defined inputs. " 290 "Accepted values (float, int, qasymms8 or qasymmu8).",
291 cxxopts::value<std::string>())
294 "The type of the output tensors in the network separated by comma. " 295 "If unset, defaults to \"float\" for all defined outputs. " 296 "Accepted values (float, int, qasymms8 or qasymmu8).",
297 cxxopts::value<std::string>())
299 (
"T,tflite-executor",
300 "Set the executor for the tflite model: parser, delegate, tflite" 301 "parser is the ArmNNTfLiteParser, " 302 "delegate is the ArmNNTfLiteDelegate, " 303 "tflite is the TfliteInterpreter",
304 cxxopts::value<std::string>()->default_value(
"parser"))
306 (
"D,armnn-tflite-delegate",
307 "Enable Arm NN TfLite delegate. " 308 "DEPRECATED: This option is deprecated please use tflite-executor instead",
311 (
"simultaneous-iterations",
312 "Number of simultaneous iterations to async-run the network for, default is set to 1 (disabled). " 313 "When thread-pool-size is set the Arm NN thread pool is used. Otherwise std::launch::async is used." 314 "DEPRECATED: This option is deprecated and will be removed soon. " 315 "Please use the option 'iterations' combined with 'concurrent' instead.",
319 "Number of Arm NN threads to use when running the network asynchronously via the Arm NN thread pool. " 320 "The default is set to 0 which equals disabled. If 'thread-pool-size' is greater than 0 the " 321 "'concurrent' option is automatically set to true.",
326 "If this option is enabled, FP32 layers, " 327 "weights and biases will be converted to BFloat16 where the backend supports it",
329 ->default_value(
"false")->implicit_value(
"true"))
332 "Enables fast_math options in backends that support it. Using the fast_math flag can lead to " 333 "performance improvements but may result in reduced or different precision.",
336 (
"number-of-threads",
337 "Assign the number of threads used by the CpuAcc backend. " 338 "Input value must be between 1 and 64. " 339 "Default is set to 0 (Backend will decide number of threads to use).",
342 (
"save-cached-network",
343 "Enables saving of the cached network to a file given with the cached-network-filepath option. " 344 "See also --cached-network-filepath",
346 ->default_value(
"false")->implicit_value(
"true"))
348 (
"cached-network-filepath",
349 "If non-empty, the given file will be used to load/save the cached network. " 350 "If save-cached-network is given then the cached network will be saved to the given file. " 351 "To save the cached network a file must already exist. " 352 "If save-cached-network is not given then the cached network will be loaded from the given file. " 353 "This will remove initial compilation time of kernels and speed up the first execution.",
357 "If this option is enabled, FP32 layers, " 358 "weights and biases will be converted to FP16 where the backend supports it",
360 ->default_value(
"false")->implicit_value(
"true"))
363 "Sets the tuning level which enables a tuning run which will update/create a tuning file. " 364 "Available options are: 1 (Rapid), 2 (Normal), 3 (Exhaustive). " 365 "Requires tuning-path to be set, default is set to 0 (No tuning run)",
369 "Path to tuning file. Enables use of CL tuning",
372 (
"MLGOTuningFilePath",
373 "Path to tuning file. Enables use of CL MLGO tuning",
377 (
"a,enable-external-profiling",
378 "If enabled external profiling will be switched on",
380 ->default_value(
"false")->implicit_value(
"true"))
382 (
"e,event-based-profiling",
383 "Enables built in profiler. If unset, defaults to off.",
386 (
"g,file-only-external-profiling",
387 "If enabled then the 'file-only' test mode of external profiling will be enabled",
389 ->default_value(
"false")->implicit_value(
"true"))
392 "If profiling is enabled specifies the output file format",
395 (
"j,outgoing-capture-file",
396 "If specified the outgoing external profiling packets will be captured in this binary file",
399 (
"k,incoming-capture-file",
400 "If specified the incoming external profiling packets will be captured in this binary file",
403 (
"timeline-profiling",
404 "If enabled timeline profiling will be switched on, requires external profiling",
406 ->default_value(
"false")->implicit_value(
"true"))
408 (
"u,counter-capture-period",
409 "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test",
412 (
"output-network-details",
413 "Outputs layer tensor infos and descriptors to std out. Defaults to off.",
415 ->implicit_value(
"true"));
417 catch (
const std::exception& e)
420 ARMNN_LOG(fatal) <<
"Fatal internal error: " << e.what();
446 auto computeDevices = GetOptionValue<std::vector<std::string>>(
"compute",
m_CxxResult);
468 std::string tfliteExecutor = GetOptionValue<std::string>(
"tflite-executor",
m_CxxResult);
470 if (tfliteExecutor.size() == 0 || tfliteExecutor ==
"parser")
474 else if (tfliteExecutor ==
"delegate")
478 else if (tfliteExecutor ==
"tflite")
484 ARMNN_LOG(info) << fmt::format(
"Invalid tflite-executor option '{}'.", tfliteExecutor);
506 std::vector<std::string> inputTensorShapesVector =
509 if (!inputTensorShapesVector.empty())
513 for(
const std::string& shape : inputTensorShapesVector)
515 std::stringstream ss(shape);
516 std::vector<unsigned int> dims =
ParseArray(ss);
519 std::make_unique<armnn::TensorShape>(static_cast<unsigned int>(dims.size()), dims.data()));
ExecuteNetworkParams m_ExNetParams
std::vector< std::string > m_InputTypes
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
std::vector< TensorShapePtr > m_InputTensorShapes
std::vector< unsigned int > ParseArray(std::istream &stream)
void RemoveDuplicateDevices(std::vector< armnn::BackendId > &computeDevices)
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
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
std::vector< std::string > m_OutputTensorFiles
size_t m_SimultaneousIterations
bool m_OutputDetailsToStdOut
std::string m_CachedNetworkFilePath
bool CheckOption(const cxxopts::ParseResult &result, const char *option)
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.
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_EnableLayerDetails
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)
ExternalProfilingOptions m_ProfilingOptions
std::string m_ModelFormat