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 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 16 | #include <cxxopts/cxxopts.hpp> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 17 | |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 18 | #include <algorithm> |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 19 | #include <cassert> |
| 20 | #include <functional> |
| 21 | #include <string> |
| 22 | #include <sstream> |
| 23 | |
| 24 | using namespace android; |
| 25 | using namespace std; |
| 26 | |
| 27 | namespace armnn_driver |
| 28 | { |
| 29 | |
Nikhil Raj | 7760582 | 2018-09-03 11:25:56 +0100 | [diff] [blame] | 30 | DriverOptions::DriverOptions(armnn::Compute computeDevice, bool fp16Enabled) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 31 | : m_Backends({computeDevice}) |
| 32 | , m_VerboseLogging(false) |
| 33 | , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 34 | , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 35 | , m_EnableGpuProfiling(false) |
| 36 | , m_fp16Enabled(fp16Enabled) |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 37 | , m_FastMathEnabled(false) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 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) |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 48 | , m_FastMathEnabled(false) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
| 52 | DriverOptions::DriverOptions(int argc, char** argv) |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 53 | : m_VerboseLogging(false) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 54 | , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 55 | , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 56 | , m_EnableGpuProfiling(false) |
| 57 | , m_fp16Enabled(false) |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 58 | , m_FastMathEnabled(false) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 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; |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 63 | std::vector<std::string> backends; |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 64 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 65 | cxxopts::Options optionsDesc("Options"); |
| 66 | try |
| 67 | { |
| 68 | optionsDesc.add_options() |
| 69 | ("c,compute", |
| 70 | "Comma separated list of backends to run layers on. Examples of possible values are: CpuRef, CpuAcc, GpuAcc", |
| 71 | cxxopts::value<std::vector<std::string>>(backends)) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 72 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 73 | ("v,verbose-logging", "Turns verbose logging on", |
| 74 | cxxopts::value<bool>(m_VerboseLogging)->default_value("false")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 75 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 76 | ("d,request-inputs-and-outputs-dump-dir", |
| 77 | "If non-empty, the directory where request inputs and outputs should be dumped", |
| 78 | cxxopts::value<std::string>(m_RequestInputsAndOutputsDumpDir)->default_value("")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 79 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 80 | ("n,service-name", |
| 81 | "If non-empty, the driver service name to be registered", |
| 82 | cxxopts::value<std::string>(m_ServiceName)->default_value("armnn")) |
Kevin May | abc95d0 | 2020-05-15 15:34:03 +0100 | [diff] [blame] | 83 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 84 | ("u,unsupported-operations", |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 85 | "If non-empty, a comma-separated list of operation indices which the driver will forcibly " |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 86 | "consider unsupported", |
| 87 | cxxopts::value<std::string>(unsupportedOperationsAsString)->default_value("")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 88 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 89 | ("t,cl-tuned-parameters-file", |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 90 | "If non-empty, the given file will be used to load/save CL tuned parameters. " |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 91 | "See also --cl-tuned-parameters-mode", |
| 92 | cxxopts::value<std::string>(m_ClTunedParametersFile)->default_value("")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 93 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 94 | ("m,cl-tuned-parameters-mode", |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 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 " |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 98 | "the file accordingly.", |
| 99 | cxxopts::value<std::string>(clTunedParametersModeAsString)->default_value("UseTunedParameters")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 100 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 101 | ("o,cl-tuning-level", |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 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 " |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 105 | "rapid: only 3 lws values should be tested for each kernel ", |
| 106 | cxxopts::value<std::string>(clTuningLevelAsString)->default_value("rapid")) |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 107 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 108 | ("a,fast-math", "Turns FastMath on", |
| 109 | cxxopts::value<bool>(m_FastMathEnabled)->default_value("false")) |
Mike Kelly | 7ed56dd | 2020-09-30 20:22:56 +0100 | [diff] [blame] | 110 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 111 | ("p,gpu-profiling", "Turns GPU profiling on", |
| 112 | cxxopts::value<bool>(m_EnableGpuProfiling)->default_value("false")) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 113 | |
Colm Donelan | 9bf0d32 | 2020-10-08 17:39:13 +0100 | [diff] [blame] | 114 | ("f,fp16-enabled", "Enables support for relaxed computation from Float32 to Float16", |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 115 | cxxopts::value<bool>(m_fp16Enabled)->default_value("false")); |
| 116 | } |
| 117 | catch (const std::exception& e) |
| 118 | { |
| 119 | ALOGW("An error occurred attempting to construct options: %s", e.what()); |
| 120 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 121 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 122 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 123 | try |
| 124 | { |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 125 | cxxopts::ParseResult result = optionsDesc.parse(argc, argv); |
| 126 | // If no backends have been specified then the default value is GpuAcc. |
| 127 | if (backends.empty()) |
| 128 | { |
| 129 | backends.push_back("GpuAcc"); |
| 130 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 131 | } |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 132 | catch (const cxxopts::OptionException& e) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 133 | { |
| 134 | ALOGW("An error occurred attempting to parse program options: %s", e.what()); |
| 135 | } |
| 136 | |
Colm Donelan | 0cc6178 | 2020-10-06 21:02:21 +0100 | [diff] [blame] | 137 | // Convert the string backend names into backendId's. |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 138 | m_Backends.reserve(backends.size()); |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 139 | for (auto&& backend : backends) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 140 | { |
Nattapat Chaimanowong | d5fd976 | 2019-04-04 13:33:10 +0100 | [diff] [blame] | 141 | m_Backends.emplace_back(backend); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | if (!unsupportedOperationsAsString.empty()) |
| 145 | { |
| 146 | std::istringstream argStream(unsupportedOperationsAsString); |
| 147 | |
| 148 | std::string s; |
| 149 | while (!argStream.eof()) |
| 150 | { |
| 151 | std::getline(argStream, s, ','); |
| 152 | try |
| 153 | { |
| 154 | unsigned int operationIdx = std::stoi(s); |
| 155 | m_ForcedUnsupportedOperations.insert(operationIdx); |
| 156 | } |
| 157 | catch (const std::invalid_argument&) |
| 158 | { |
| 159 | ALOGW("Ignoring invalid integer argument in -u/--unsupported-operations value: %s", s.c_str()); |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | if (!m_ClTunedParametersFile.empty()) |
| 165 | { |
| 166 | // The mode is only relevant if the file path has been provided |
| 167 | if (clTunedParametersModeAsString == "UseTunedParameters") |
| 168 | { |
| 169 | m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UseTunedParameters; |
| 170 | } |
| 171 | else if (clTunedParametersModeAsString == "UpdateTunedParameters") |
| 172 | { |
| 173 | m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters; |
| 174 | } |
| 175 | else |
| 176 | { |
| 177 | ALOGW("Requested unknown cl-tuned-parameters-mode '%s'. Defaulting to UseTunedParameters", |
| 178 | clTunedParametersModeAsString.c_str()); |
| 179 | } |
Ruomei Yan | 689c6ee | 2019-04-25 17:48:41 +0100 | [diff] [blame] | 180 | |
| 181 | if (clTuningLevelAsString == "exhaustive") |
| 182 | { |
| 183 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Exhaustive; |
| 184 | } |
| 185 | else if (clTuningLevelAsString == "normal") |
| 186 | { |
| 187 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Normal; |
| 188 | } |
| 189 | else if (clTuningLevelAsString == "rapid") |
| 190 | { |
| 191 | m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Rapid; |
| 192 | } |
| 193 | else |
| 194 | { |
| 195 | ALOGW("Requested unknown cl-tuner-mode '%s'. Defaulting to rapid", |
| 196 | clTuningLevelAsString.c_str()); |
| 197 | } |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 198 | } |
| 199 | } |
| 200 | |
| 201 | } // namespace armnn_driver |