78 : m_VerboseLogging(
false)
79 , m_RequestInputsAndOutputsDumpDir(std::string(
""))
80 , m_ServiceName(std::string(
"armnn_sl"))
81 , m_ForcedUnsupportedOperations({})
84 , m_EnableGpuProfiling(
false)
85 , m_fp16Enabled(
false)
86 , m_FastMathEnabled(
false)
88 , m_SaveCachedNetwork(
false)
89 , m_NumberOfThreads(0)
90 , m_EnableAsyncModelExecution(
false)
91 , m_ArmnnNumberOfThreads(1)
93 std::string unsupportedOperationsAsString;
94 std::string clTunedParametersModeAsString;
95 std::string clTuningLevelAsString;
96 std::vector<std::string> backends;
97 bool showHelp =
false;
98 bool showVersion =
false;
100 const char* rawEnv = std::getenv(
"ARMNN_SL_OPTIONS");
106 string optionsAsString(rawEnv);
107 regex whiteSpaceRegex(
"\\s+");
109 sregex_token_iterator iter(optionsAsString.begin(), optionsAsString.end(), whiteSpaceRegex, -1);
110 sregex_token_iterator end;
111 vector<string> cliAsVector(iter, end);
113 cliAsVector.insert(cliAsVector.begin(),
"ARMNN_SL_OPTIONS");
115 std::vector<char*> argVector;
116 for (
const auto& arg : cliAsVector)
118 argVector.push_back((
char*)arg.data());
121 argVector.push_back(
nullptr);
123 int argc = argVector.size() - 1;
124 char** argv = argVector.data();
126 cxxopts::Options optionsDesc(argv[0],
"Arm NN Support Library for the Android Neural Networks API."
127 "The support library will convert Android NNAPI requests "
128 "and delegate them to available ArmNN backends.");
131 optionsDesc.add_options()
133 (
"a,enable-fast-math",
134 "Enables fast_math options in backends that support it. Using the fast_math flag can "
135 "lead to performance improvements but may result in reduced or different precision.",
136 cxxopts::value<bool>(m_FastMathEnabled)->default_value(
"false"))
138 (
"c,compute",
"Comma separated list of backends to run layers on. "
139 "Examples of possible values are: CpuRef, CpuAcc, GpuAcc",
140 cxxopts::value<std::vector<std::string>>(backends))
142 (
"d,request-inputs-and-outputs-dump-dir",
143 "If non-empty, the directory where request inputs and outputs should be dumped",
144 cxxopts::value<std::string>(m_RequestInputsAndOutputsDumpDir)->default_value(
""))
146 (
"f,fp16-enabled",
"Enables support for relaxed computation from Float32 to Float16",
147 cxxopts::value<bool>(m_fp16Enabled)->default_value(
"false"))
149 (
"h,help",
"Show this help",
150 cxxopts::value<bool>(showHelp)->default_value(
"false")->implicit_value(
"true"))
152 (
"m,cl-tuned-parameters-mode",
153 "If 'UseTunedParameters' (the default), will read CL tuned parameters from the file specified by "
154 "--cl-tuned-parameters-file. "
155 "If 'UpdateTunedParameters', will also find the optimum parameters when preparing new networks and update "
156 "the file accordingly.",
157 cxxopts::value<std::string>(clTunedParametersModeAsString)->default_value(
"UseTunedParameters"))
159 (
"g,mlgo-cl-tuned-parameters-file",
160 "If non-empty, the given file will be used to load/save MLGO CL tuned parameters. ",
161 cxxopts::value<std::string>(m_ClMLGOTunedParametersFile)->default_value(
""))
163 (
"o,cl-tuning-level",
164 "exhaustive: all lws values are tested "
165 "normal: reduced number of lws values but enough to still have the performance really close to the "
166 "exhaustive approach "
167 "rapid: only 3 lws values should be tested for each kernel ",
168 cxxopts::value<std::string>(clTuningLevelAsString)->default_value(
"rapid"))
170 (
"p,gpu-profiling",
"Turns GPU profiling on",
171 cxxopts::value<bool>(m_EnableGpuProfiling)->default_value(
"false"))
173 (
"q,cached-network-file",
"If non-empty, the given file will be used to load/save cached network. "
174 "If save-cached-network option is given will save the cached network to given file."
175 "If save-cached-network option is not given will load the cached network from given "
177 cxxopts::value<std::string>(m_CachedNetworkFilePath)->default_value(
""))
179 (
"s,save-cached-network",
180 "Enables saving the cached network to the file given with cached-network-file option."
181 " See also --cached-network-file",
182 cxxopts::value<bool>(m_SaveCachedNetwork)->default_value(
"false"))
184 (
"number-of-threads",
185 "Assign the number of threads used by the CpuAcc backend. "
186 "Input value must be between 1 and 64. "
187 "Default is set to 0 (Backend will decide number of threads to use).",
188 cxxopts::value<unsigned int>(m_NumberOfThreads)->default_value(
"0"))
190 (
"t,cl-tuned-parameters-file",
191 "If non-empty, the given file will be used to load/save CL tuned parameters. "
192 "See also --cl-tuned-parameters-mode",
193 cxxopts::value<std::string>(m_ClTunedParametersFile)->default_value(
""))
195 (
"u,unsupported-operations",
196 "If non-empty, a comma-separated list of operation indices which the driver will forcibly "
197 "consider unsupported",
198 cxxopts::value<std::string>(unsupportedOperationsAsString)->default_value(
""))
200 (
"v,verbose-logging",
"Turns verbose logging on",
201 cxxopts::value<bool>(m_VerboseLogging)->default_value(
"false")->implicit_value(
"true"))
203 (
"V,version",
"Show version information",
204 cxxopts::value<bool>(showVersion)->default_value(
"false")->implicit_value(
"true"))
207 catch (
const std::exception& e)
209 VLOG(DRIVER) <<
"An error occurred attempting to construct options: " << e.what();
210 std::cout <<
"An error occurred attempting to construct options: %s" << std::endl;
211 m_ExitCode = EXIT_FAILURE;
217 cxxopts::ParseResult result = optionsDesc.parse(argc, argv);
219 catch (
const cxxopts::exceptions::exception& e)
221 VLOG(DRIVER) <<
"An exception occurred attempting to parse program options: " << e.what();
222 std::cout << optionsDesc.help() << std::endl
223 <<
"An exception occurred while parsing program options: " << std::endl
224 << e.what() << std::endl;
226 m_ExitCode = EXIT_FAILURE;
231 VLOG(DRIVER) <<
"Showing help and exiting";
232 std::cout << optionsDesc.help() << std::endl;
234 m_ExitCode = EXIT_SUCCESS;
239 VLOG(DRIVER) <<
"Showing version and exiting";
240 std::cout <<
"ArmNN Android NN driver for the Android Neural Networks API.\n"
243 m_ExitCode = EXIT_SUCCESS;
248 m_Backends.reserve(backends.size());
249 for (
auto&& backend : backends)
251 m_Backends.emplace_back(backend);
255 if (backends.empty())
257 VLOG(DRIVER) <<
"No backends have been specified:";
258 std::cout << optionsDesc.help() << std::endl
259 <<
"Unable to start:" << std::endl
260 <<
"No backends have been specified" << std::endl;
262 m_ExitCode = EXIT_FAILURE;
266 if (!unsupportedOperationsAsString.empty())
268 std::istringstream argStream(unsupportedOperationsAsString);
271 while (!argStream.eof())
273 std::getline(argStream, s,
',');
276 unsigned int operationIdx = std::stoi(s);
277 m_ForcedUnsupportedOperations.insert(operationIdx);
279 catch (
const std::invalid_argument&)
281 VLOG(DRIVER) <<
"Ignoring invalid integer argument in -u/--unsupported-operations value: " << s.c_str();
286 if (!m_ClTunedParametersFile.empty())
289 if (clTunedParametersModeAsString ==
"UseTunedParameters")
293 else if (clTunedParametersModeAsString ==
"UpdateTunedParameters")
299 VLOG(DRIVER) <<
"Requested unknown cl-tuned-parameters-mode "
300 << clTunedParametersModeAsString.c_str() <<
". Defaulting to UseTunedParameters";
303 if (clTuningLevelAsString ==
"exhaustive")
307 else if (clTuningLevelAsString ==
"normal")
311 else if (clTuningLevelAsString ==
"rapid")
317 VLOG(DRIVER) <<
"Requested unknown cl-tuner-mode '%s'. "
318 "Defaulting to rapid" << clTuningLevelAsString.c_str();