diff options
Diffstat (limited to 'shim/sl/canonical/DriverOptions.cpp')
-rw-r--r-- | shim/sl/canonical/DriverOptions.cpp | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/shim/sl/canonical/DriverOptions.cpp b/shim/sl/canonical/DriverOptions.cpp index 3e26959dc1..5c73edfaa6 100644 --- a/shim/sl/canonical/DriverOptions.cpp +++ b/shim/sl/canonical/DriverOptions.cpp @@ -71,7 +71,10 @@ DriverOptions::DriverOptions(const std::vector<armnn::BackendId>& backends, bool { } -DriverOptions::DriverOptions(int argc, char** argv) +// This default constructor will example an environment variable called +// ARMNN_SL_OPTIONS. It will parse the parameters using the existing cxx +// opts mechanism. +DriverOptions::DriverOptions() : m_VerboseLogging(false) , m_RequestInputsAndOutputsDumpDir(std::string("")) , m_ServiceName(std::string("armnn_sl")) @@ -91,11 +94,37 @@ DriverOptions::DriverOptions(int argc, char** argv) std::string clTunedParametersModeAsString; std::string clTuningLevelAsString; std::vector<std::string> backends; - bool showHelp; - bool showVersion; + bool showHelp = false; + bool showVersion = false; - cxxopts::Options optionsDesc(argv[0], "ArmNN Android NN driver for the Android Neural Networks API." - "The Android NN driver will convert Android NNAPI requests " + const char* rawEnv = std::getenv("ARMNN_SL_OPTIONS"); + // If the environment variable isn't set we'll continue as if it were an empty string. + if (!rawEnv) + { + rawEnv = ""; + } + string optionsAsString(rawEnv); + regex whiteSpaceRegex("\\s+"); + // Tokienize the string based on whitespace. + sregex_token_iterator iter(optionsAsString.begin(), optionsAsString.end(), whiteSpaceRegex, -1); + sregex_token_iterator end; + vector<string> cliAsVector(iter, end); + // As we're pretending to be a command line, argv[0] should be an executable name. + cliAsVector.insert(cliAsVector.begin(), "ARMNN_SL_OPTIONS"); + // Convert the vector of string to a vector of char* backed by the existing vector. + std::vector<char*> argVector; + for (const auto& arg : cliAsVector) + { + argVector.push_back((char*)arg.data()); + } + // Terminate the array. + argVector.push_back(nullptr); + // Create usable variables. + int argc = argVector.size() - 1; // Ignore the null pointer at the end. + char** argv = argVector.data(); + + cxxopts::Options optionsDesc(argv[0], "Arm NN Support Library for the Android Neural Networks API." + "The support library will convert Android NNAPI requests " "and delegate them to available ArmNN backends."); try { @@ -118,7 +147,7 @@ DriverOptions::DriverOptions(int argc, char** argv) cxxopts::value<bool>(m_fp16Enabled)->default_value("false")) ("h,help", "Show this help", - cxxopts::value<bool>(showHelp)->default_value("false")) + cxxopts::value<bool>(showHelp)->default_value("false")->implicit_value("true")) ("m,cl-tuned-parameters-mode", "If 'UseTunedParameters' (the default), will read CL tuned parameters from the file specified by " @@ -131,10 +160,6 @@ DriverOptions::DriverOptions(int argc, char** argv) "If non-empty, the given file will be used to load/save MLGO CL tuned parameters. ", cxxopts::value<std::string>(m_ClMLGOTunedParametersFile)->default_value("")) - ("n,service-name", - "If non-empty, the driver service name to be registered", - cxxopts::value<std::string>(m_ServiceName)->default_value("armnn_sl")) - ("o,cl-tuning-level", "exhaustive: all lws values are tested " "normal: reduced number of lws values but enough to still have the performance really close to the " @@ -173,19 +198,11 @@ DriverOptions::DriverOptions(int argc, char** argv) cxxopts::value<std::string>(unsupportedOperationsAsString)->default_value("")) ("v,verbose-logging", "Turns verbose logging on", - cxxopts::value<bool>(m_VerboseLogging)->default_value("false")) + cxxopts::value<bool>(m_VerboseLogging)->default_value("false")->implicit_value("true")) ("V,version", "Show version information", - cxxopts::value<bool>(showVersion)->default_value("false")) - - ("A,asyncModelExecution", "Enable AsynModel Execution", - cxxopts::value<bool>(m_EnableAsyncModelExecution)->default_value("false")) - - ("T,armnn-threads", - "Assign the number of threads used by ArmNN. " - "Input value must be at least 1. " - "Default is set to 1.", - cxxopts::value<unsigned int>(m_ArmnnNumberOfThreads)->default_value("1")); + cxxopts::value<bool>(showVersion)->default_value("false")->implicit_value("true")) + ; } catch (const std::exception& e) { |