ArmNN
 22.08
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 137 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG.

Referenced by ProgramOptions::ParseOptions().

138 {
139  if(result.count("armnn-tflite-delegate") > 0)
140  {
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.";
143  }
144  if(result.count("concurrent") > 0)
145  {
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.";
148  }
149  if(result.count("input-type") > 0)
150  {
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.";
153  }
154  if(result.count("input-name") > 0)
155  {
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.";
158  }
159  if(result.count("output-type") > 0)
160  {
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.";
163  }
164  if(result.count("output-name") > 0)
165  {
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.";
168  }
169  if(result.count("model-format") > 0)
170  {
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.";
173  }
174 
175 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205

◆ CheckOption()

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

Definition at line 17 of file ExecuteNetworkProgramOptions.cpp.

Referenced by CheckOptionDependency().

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

◆ CheckOptionDependencies()

void CheckOptionDependencies ( const cxxopts::ParseResult &  result)

Definition at line 51 of file ExecuteNetworkProgramOptions.cpp.

References CheckOptionDependency().

Referenced by ProgramOptions::ParseOptions().

52 {
53  CheckOptionDependency(result, "tuning-level", "tuning-path");
54 }
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 30 of file ExecuteNetworkProgramOptions.cpp.

References CheckOption().

Referenced by CheckOptionDependencies().

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

◆ CheckRequiredOptions()

void CheckRequiredOptions ( const cxxopts::ParseResult &  result)

Definition at line 114 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG.

Referenced by ProgramOptions::ParseOptions().

115 {
116 
117  // For each option in option-group "a) Required
118  std::vector<std::string> requiredOptions{"compute",
119  "model-path"
120  };
121 
122  bool requiredMissing = false;
123  for(auto const& str : requiredOptions)
124  {
125  if(!(result.count(str) > 0))
126  {
127  ARMNN_LOG(error) << fmt::format("The program option '{}' is mandatory but wasn't provided.", str);
128  requiredMissing = true;
129  }
130  }
131  if(requiredMissing)
132  {
133  throw armnn::InvalidArgumentException ("Some required arguments are missing");
134  }
135 }
#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 78 of file ExecuteNetworkProgramOptions.cpp.

References ParseStringList(), and RemoveDuplicateDevices().

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

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

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

◆ LogAndThrowFatal()

void LogAndThrowFatal ( std::string  errorMessage)

◆ RemoveDuplicateDevices()

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

Definition at line 56 of file ExecuteNetworkProgramOptions.cpp.

References armnn::Undefined.

Referenced by GetBackendIDs().

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