ArmNN
 22.02
ExecuteNetworkProgramOptions.cpp File Reference

Go to the source code of this file.

Functions

bool CheckOption (const cxxopts::ParseResult &result, const char *option)
 
void CheckOptionDependency (const cxxopts::ParseResult &result, const char *option, const char *required)
 
void CheckOptionDependencies (const cxxopts::ParseResult &result)
 
void RemoveDuplicateDevices (std::vector< armnn::BackendId > &computeDevices)
 
std::vector< armnn::BackendIdGetBackendIDs (const std::vector< std::string > &backendStringsVec)
 Takes a vector of backend strings and returns a vector of backendIDs. More...
 
template<typename optionType >
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. More...
 
void LogAndThrowFatal (std::string errorMessage)
 
void CheckRequiredOptions (const cxxopts::ParseResult &result)
 
void CheckForDeprecatedOptions (const cxxopts::ParseResult &result)
 

Function Documentation

◆ CheckForDeprecatedOptions()

void CheckForDeprecatedOptions ( const cxxopts::ParseResult &  result)

Definition at line 142 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG.

Referenced by ProgramOptions::ParseOptions().

143 {
144  if(result.count("simultaneous-iterations") > 0)
145  {
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.";
148  }
149  if(result.count("armnn-tflite-delegate") > 0)
150  {
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.";
153  }
154 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205

◆ CheckOption()

bool CheckOption ( const cxxopts::ParseResult &  result,
const char *  option 
)

Definition at line 18 of file ExecuteNetworkProgramOptions.cpp.

Referenced by CheckOptionDependency().

20 {
21  // Check that the given option is valid.
22  if (option == nullptr)
23  {
24  return false;
25  }
26 
27  // Check whether 'option' is provided.
28  return ((result.count(option)) ? true : false);
29 }

◆ CheckOptionDependencies()

void CheckOptionDependencies ( const cxxopts::ParseResult &  result)

Definition at line 52 of file ExecuteNetworkProgramOptions.cpp.

References CheckOptionDependency().

Referenced by ProgramOptions::ParseOptions().

53 {
54  CheckOptionDependency(result, "model-path", "model-format");
55  CheckOptionDependency(result, "input-tensor-shape", "model-path");
56  CheckOptionDependency(result, "tuning-level", "tuning-path");
57 }
void CheckOptionDependency(const cxxopts::ParseResult &result, const char *option, const char *required)

◆ CheckOptionDependency()

void CheckOptionDependency ( const cxxopts::ParseResult &  result,
const char *  option,
const char *  required 
)

Definition at line 31 of file ExecuteNetworkProgramOptions.cpp.

References CheckOption().

Referenced by CheckOptionDependencies().

34 {
35  // Check that the given options are valid.
36  if (option == nullptr || required == nullptr)
37  {
38  throw cxxopts::OptionParseException("Invalid option to check dependency for");
39  }
40 
41  // Check that if 'option' is provided, 'required' is also provided.
42  if (CheckOption(result, option) && !result[option].has_default())
43  {
44  if (CheckOption(result, required) == 0 || result[required].has_default())
45  {
46  throw cxxopts::OptionParseException(
47  std::string("Option '") + option + "' requires option '" + required + "'.");
48  }
49  }
50 }
bool CheckOption(const cxxopts::ParseResult &result, const char *option)

◆ CheckRequiredOptions()

void CheckRequiredOptions ( const cxxopts::ParseResult &  result)

Definition at line 117 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG.

Referenced by ProgramOptions::ParseOptions().

118 {
119 
120  // For each option in option-group "a) Required
121  std::vector<std::string> requiredOptions{"compute",
122  "model-format",
123  "model-path",
124  "input-name",
125  "output-name"};
126 
127  bool requiredMissing = false;
128  for(auto const& str : requiredOptions)
129  {
130  if(!(result.count(str) > 0))
131  {
132  ARMNN_LOG(error) << fmt::format("The program option '{}' is mandatory but wasn't provided.", str);
133  requiredMissing = true;
134  }
135  }
136  if(requiredMissing)
137  {
138  throw armnn::InvalidArgumentException ("Some required arguments are missing");
139  }
140 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205

◆ GetBackendIDs()

std::vector<armnn::BackendId> GetBackendIDs ( const std::vector< std::string > &  backendStringsVec)

Takes a vector of backend strings and returns a vector of backendIDs.

Removes duplicate entries. Can handle backend strings that contain multiple backends separated by comma e.g "CpuRef,CpuAcc"

Definition at line 81 of file ExecuteNetworkProgramOptions.cpp.

References ParseStringList(), and RemoveDuplicateDevices().

Referenced by CheckAccuracy(), and ProgramOptions::ParseOptions().

82 {
83  std::vector<armnn::BackendId> backendIDs;
84  for (const auto& backendStrings : backendStringsVec)
85  {
86  // Each backendStrings might contain multiple backends separated by comma e.g "CpuRef,CpuAcc"
87  std::vector<std::string> backendStringVec = ParseStringList(backendStrings, ",");
88  for (const auto& b : backendStringVec)
89  {
90  backendIDs.push_back(armnn::BackendId(b));
91  }
92  }
93 
94  RemoveDuplicateDevices(backendIDs);
95 
96  return backendIDs;
97 }
void RemoveDuplicateDevices(std::vector< armnn::BackendId > &computeDevices)
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.

◆ GetOptionValue()

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.

If the option wasn't defined it returns an empty object.

Definition at line 102 of file ExecuteNetworkProgramOptions.cpp.

103 {
104  optionType out;
105  if(result.count(optionName))
106  {
107  out = result[optionName].as<optionType>();
108  }
109  return out;
110 }

◆ LogAndThrowFatal()

void LogAndThrowFatal ( std::string  errorMessage)

◆ RemoveDuplicateDevices()

void RemoveDuplicateDevices ( std::vector< armnn::BackendId > &  computeDevices)

Definition at line 59 of file ExecuteNetworkProgramOptions.cpp.

References armnn::Undefined.

Referenced by GetBackendIDs().

60 {
61  // Mark the duplicate devices as 'Undefined'.
62  for (auto i = computeDevices.begin(); i != computeDevices.end(); ++i)
63  {
64  for (auto j = std::next(i); j != computeDevices.end(); ++j)
65  {
66  if (*j == *i)
67  {
69  }
70  }
71  }
72 
73  // Remove 'Undefined' devices.
74  computeDevices.erase(std::remove(computeDevices.begin(), computeDevices.end(), armnn::Compute::Undefined),
75  computeDevices.end());
76 }