ArmNN
 21.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 > &backendStrings)
 Takes a vector of backend strings and returns a vector of backendIDs. Removes duplicate entries. 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)
 

Function Documentation

◆ 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 110 of file ExecuteNetworkProgramOptions.cpp.

References ARMNN_LOG.

Referenced by ProgramOptions::ParseOptions().

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

◆ GetBackendIDs()

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

Takes a vector of backend strings and returns a vector of backendIDs. Removes duplicate entries.

Definition at line 79 of file ExecuteNetworkProgramOptions.cpp.

References RemoveDuplicateDevices().

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

80 {
81  std::vector<armnn::BackendId> backendIDs;
82  for (const auto& b : backendStrings)
83  {
84  backendIDs.push_back(armnn::BackendId(b));
85  }
86 
87  RemoveDuplicateDevices(backendIDs);
88 
89  return backendIDs;
90 }
void RemoveDuplicateDevices(std::vector< armnn::BackendId > &computeDevices)

◆ 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 95 of file ExecuteNetworkProgramOptions.cpp.

96 {
97  optionType out;
98  if(result.count(optionName))
99  {
100  out = result[optionName].as<optionType>();
101  }
102  return out;
103 }

◆ 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 }