telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #define LOG_TAG "ArmnnDriver" |
| 7 | |
| 8 | #include "DriverOptions.hpp" |
| 9 | #include "Utils.hpp" |
| 10 | |
| 11 | #include <log/log.h> |
| 12 | #include "SystemPropertiesUtils.hpp" |
| 13 | |
| 14 | #include <OperationsUtils.h> |
| 15 | |
| 16 | #include <boost/algorithm/string/predicate.hpp> |
| 17 | #include <boost/program_options.hpp> |
| 18 | |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 19 | #include <algorithm> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 20 | #include <cassert> |
| 21 | #include <functional> |
| 22 | #include <string> |
| 23 | #include <sstream> |
| 24 | |
| 25 | using namespace android; |
| 26 | using namespace std; |
| 27 | |
| 28 | namespace armnn_driver |
| 29 | { |
| 30 | |
Nikhil Raj | 7760582 | 2018-09-03 11:25:56 +0100 | [diff] [blame] | 31 | DriverOptions::DriverOptions(armnn::Compute computeDevice, bool fp16Enabled) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 32 | : m_Backends({computeDevice}) |
| 33 | , m_VerboseLogging(false) |
| 34 | , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 35 | , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 36 | , m_EnableGpuProfiling(false) |
| 37 | , m_fp16Enabled(fp16Enabled) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | DriverOptions::DriverOptions(const std::vector<armnn::BackendId>& backends, bool fp16Enabled) |
| 42 | : m_Backends(backends) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 43 | , m_VerboseLogging(false) |
| 44 | , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 45 | , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 46 | , m_EnableGpuProfiling(false) |
Nikhil Raj | 7760582 | 2018-09-03 11:25:56 +0100 | [diff] [blame] | 47 | , m_fp16Enabled(fp16Enabled) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 48 | { |
| 49 | } |
| 50 | |
| 51 | DriverOptions::DriverOptions(int argc, char** argv) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 52 | : m_VerboseLogging(false) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 53 | , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 54 | , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 55 | , m_EnableGpuProfiling(false) |
| 56 | , m_fp16Enabled(false) |
| 57 | { |
| 58 | namespace po = boost::program_options; |
| 59 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 60 | std::string unsupportedOperationsAsString; |
| 61 | std::string clTunedParametersModeAsString; |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 62 | std::string clTuningLevelAsString; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 63 | |
| 64 | po::options_description optionsDesc("Options"); |
| 65 | optionsDesc.add_options() |
| 66 | ("compute,c", |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 67 | po::value<std::vector<std::string>>()-> |
| 68 | multitoken()->default_value(std::vector<std::string>{"GpuAcc"}, "{GpuAcc}"), |
Narumol Prangnawarat | 856d1c9 | 2019-05-03 16:42:52 +0100 | [diff] [blame] | 69 | "Which backend to run layers on. Examples of possible values are: CpuRef, CpuAcc, GpuAcc") |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 70 | |
| 71 | ("verbose-logging,v", |
| 72 | po::bool_switch(&m_VerboseLogging), |
| 73 | "Turns verbose logging on") |
| 74 | |
| 75 | ("request-inputs-and-outputs-dump-dir,d", |
| 76 | po::value<std::string>(&m_RequestInputsAndOutputsDumpDir)->default_value(""), |
| 77 | "If non-empty, the directory where request inputs and outputs should be dumped") |
| 78 | |
Kevin May | abc95d0 | 2020-05-15 15:34:03 +0100 | [diff] [blame] | 79 | ("service-name,n", |
| 80 | po::value<std::string>(&m_ServiceName)->default_value("armnn"), |
| 81 | "If non-empty, the driver service name to be registered") |
| 82 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 83 | ("unsupported-operations,u", |
| 84 | po::value<std::string>(&unsupportedOperationsAsString)->default_value(""), |
| 85 | "If non-empty, a comma-separated list of operation indices which the driver will forcibly " |
| 86 | "consider unsupported") |
| 87 | |
| 88 | ("cl-tuned-parameters-file,t", |
| 89 | po::value<std::string>(&m_ClTunedParametersFile)->default_value(""), |
| 90 | "If non-empty, the given file will be used to load/save CL tuned parameters. " |
| 91 | "See also --cl-tuned-parameters-mode") |
| 92 | |
| 93 | ("cl-tuned-parameters-mode,m", |
| 94 | po::value<std::string>(&clTunedParametersModeAsString)->default_value("UseTunedParameters"), |
| 95 | "If 'UseTunedParameters' (the default), will read CL tuned parameters from the file specified by " |
| 96 | "--cl-tuned-parameters-file. " |
| 97 | "If 'UpdateTunedParameters', will also find the optimum parameters when preparing new networks and update " |
| 98 | "the file accordingly.") |
| 99 | |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 100 | ("cl-tuning-level,o", |
| 101 | po::value<std::string>(&clTuningLevelAsString)->default_value("rapid"), |
| 102 | "exhaustive: all lws values are tested " |
| 103 | "normal: reduced number of lws values but enough to still have the performance really close to the " |
| 104 | "exhaustive approach " |
| 105 | "rapid: only 3 lws values should be tested for each kernel ") |
| 106 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 107 | ("gpu-profiling,p", |
| 108 | po::bool_switch(&m_EnableGpuProfiling), |
surmeh01 | 205bb99 | 2018-09-11 12:41:24 +0100 | [diff] [blame] | 109 | "Turns GPU profiling on") |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 110 | |
| 111 | ("fp16-enabled,f", |
| 112 | po::bool_switch(&m_fp16Enabled), |
| 113 | "Enables support for relaxed computation from Float32 to Float16"); |
| 114 | |
| 115 | po::variables_map variablesMap; |
| 116 | try |
| 117 | { |
| 118 | po::store(po::parse_command_line(argc, argv, optionsDesc), variablesMap); |
| 119 | po::notify(variablesMap); |
| 120 | } |
| 121 | catch (const po::error& e) |
| 122 | { |
| 123 | ALOGW("An error occurred attempting to parse program options: %s", e.what()); |
| 124 | } |
| 125 | |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 126 | const std::vector<std::string> backends = variablesMap["compute"].as<std::vector<std::string>>(); |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 127 | m_Backends.reserve(backends.size()); |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 128 | for (auto&& backend : backends) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 129 | { |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 130 | m_Backends.emplace_back(backend); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | if (!unsupportedOperationsAsString.empty()) |
| 134 | { |
| 135 | std::istringstream argStream(unsupportedOperationsAsString); |
| 136 | |
| 137 | std::string s; |
| 138 | while (!argStream.eof()) |
| 139 | { |
| 140 | std::getline(argStream, s, ','); |
| 141 | try |
| 142 | { |
| 143 | unsigned int operationIdx = std::stoi(s); |
| 144 | m_ForcedUnsupportedOperations.insert(operationIdx); |
| 145 | } |
| 146 | catch (const std::invalid_argument&) |
| 147 | { |
| 148 | ALOGW("Ignoring invalid integer argument in -u/--unsupported-operations value: %s", s.c_str()); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | if (!m_ClTunedParametersFile.empty()) |
| 154 | { |
| 155 | // The mode is only relevant if the file path has been provided |
| 156 | if (clTunedParametersModeAsString == "UseTunedParameters") |
| 157 | { |
| 158 | m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UseTunedParameters; |
| 159 | } |
| 160 | else if (clTunedParametersModeAsString == "UpdateTunedParameters") |
| 161 | { |
| 162 | m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters; |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | ALOGW("Requested unknown cl-tuned-parameters-mode '%s'. Defaulting to UseTunedParameters", |
| 167 | clTunedParametersModeAsString.c_str()); |
| 168 | } |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 169 | |
| 170 | if (clTuningLevelAsString == "exhaustive") |
| 171 | { |
| 172 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Exhaustive; |
| 173 | } |
| 174 | else if (clTuningLevelAsString == "normal") |
| 175 | { |
| 176 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Normal; |
| 177 | } |
| 178 | else if (clTuningLevelAsString == "rapid") |
| 179 | { |
| 180 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Rapid; |
| 181 | } |
| 182 | else |
| 183 | { |
| 184 | ALOGW("Requested unknown cl-tuner-mode '%s'. Defaulting to rapid", |
| 185 | clTuningLevelAsString.c_str()); |
| 186 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
| 190 | } // namespace armnn_driver |