blob: f7b00f8c46bed7f982a32944ade6d37a73dc103a [file] [log] [blame]
telsoa01ce3e84a2018-08-31 09:31:35 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
telsoa01ce3e84a2018-08-31 09:31:35 +01004//
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 Donelan0cc61782020-10-06 21:02:21 +010016#include <cxxopts/cxxopts.hpp>
telsoa01ce3e84a2018-08-31 09:31:35 +010017
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010018#include <algorithm>
telsoa01ce3e84a2018-08-31 09:31:35 +010019#include <cassert>
20#include <functional>
21#include <string>
22#include <sstream>
23
24using namespace android;
25using namespace std;
26
27namespace armnn_driver
28{
29
Nikhil Raj77605822018-09-03 11:25:56 +010030DriverOptions::DriverOptions(armnn::Compute computeDevice, bool fp16Enabled)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010031 : m_Backends({computeDevice})
32 , m_VerboseLogging(false)
33 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010034 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010035 , m_EnableGpuProfiling(false)
36 , m_fp16Enabled(fp16Enabled)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010037 , m_FastMathEnabled(false)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010038{
39}
40
41DriverOptions::DriverOptions(const std::vector<armnn::BackendId>& backends, bool fp16Enabled)
42 : m_Backends(backends)
telsoa01ce3e84a2018-08-31 09:31:35 +010043 , m_VerboseLogging(false)
44 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010045 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
telsoa01ce3e84a2018-08-31 09:31:35 +010046 , m_EnableGpuProfiling(false)
Nikhil Raj77605822018-09-03 11:25:56 +010047 , m_fp16Enabled(fp16Enabled)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010048 , m_FastMathEnabled(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010049{
50}
51
52DriverOptions::DriverOptions(int argc, char** argv)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010053 : m_VerboseLogging(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010054 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010055 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
telsoa01ce3e84a2018-08-31 09:31:35 +010056 , m_EnableGpuProfiling(false)
57 , m_fp16Enabled(false)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010058 , m_FastMathEnabled(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010059{
telsoa01ce3e84a2018-08-31 09:31:35 +010060 std::string unsupportedOperationsAsString;
61 std::string clTunedParametersModeAsString;
Ruomei Yan689c6ee2019-04-25 17:48:41 +010062 std::string clTuningLevelAsString;
Colm Donelan0cc61782020-10-06 21:02:21 +010063 std::vector<std::string> backends;
telsoa01ce3e84a2018-08-31 09:31:35 +010064
Colm Donelan0cc61782020-10-06 21:02:21 +010065 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))
telsoa01ce3e84a2018-08-31 09:31:35 +010072
Colm Donelan0cc61782020-10-06 21:02:21 +010073 ("v,verbose-logging", "Turns verbose logging on",
74 cxxopts::value<bool>(m_VerboseLogging)->default_value("false"))
telsoa01ce3e84a2018-08-31 09:31:35 +010075
Colm Donelan0cc61782020-10-06 21:02:21 +010076 ("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(""))
telsoa01ce3e84a2018-08-31 09:31:35 +010079
Colm Donelan0cc61782020-10-06 21:02:21 +010080 ("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 Mayabc95d02020-05-15 15:34:03 +010083
Colm Donelan0cc61782020-10-06 21:02:21 +010084 ("u,unsupported-operations",
telsoa01ce3e84a2018-08-31 09:31:35 +010085 "If non-empty, a comma-separated list of operation indices which the driver will forcibly "
Colm Donelan0cc61782020-10-06 21:02:21 +010086 "consider unsupported",
87 cxxopts::value<std::string>(unsupportedOperationsAsString)->default_value(""))
telsoa01ce3e84a2018-08-31 09:31:35 +010088
Colm Donelan0cc61782020-10-06 21:02:21 +010089 ("t,cl-tuned-parameters-file",
telsoa01ce3e84a2018-08-31 09:31:35 +010090 "If non-empty, the given file will be used to load/save CL tuned parameters. "
Colm Donelan0cc61782020-10-06 21:02:21 +010091 "See also --cl-tuned-parameters-mode",
92 cxxopts::value<std::string>(m_ClTunedParametersFile)->default_value(""))
telsoa01ce3e84a2018-08-31 09:31:35 +010093
Colm Donelan0cc61782020-10-06 21:02:21 +010094 ("m,cl-tuned-parameters-mode",
telsoa01ce3e84a2018-08-31 09:31:35 +010095 "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 Donelan0cc61782020-10-06 21:02:21 +010098 "the file accordingly.",
99 cxxopts::value<std::string>(clTunedParametersModeAsString)->default_value("UseTunedParameters"))
telsoa01ce3e84a2018-08-31 09:31:35 +0100100
Colm Donelan0cc61782020-10-06 21:02:21 +0100101 ("o,cl-tuning-level",
Ruomei Yan689c6ee2019-04-25 17:48:41 +0100102 "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 Donelan0cc61782020-10-06 21:02:21 +0100105 "rapid: only 3 lws values should be tested for each kernel ",
106 cxxopts::value<std::string>(clTuningLevelAsString)->default_value("rapid"))
Ruomei Yan689c6ee2019-04-25 17:48:41 +0100107
Colm Donelan0cc61782020-10-06 21:02:21 +0100108 ("a,fast-math", "Turns FastMath on",
109 cxxopts::value<bool>(m_FastMathEnabled)->default_value("false"))
Mike Kelly7ed56dd2020-09-30 20:22:56 +0100110
Colm Donelan0cc61782020-10-06 21:02:21 +0100111 ("p,gpu-profiling", "Turns GPU profiling on",
112 cxxopts::value<bool>(m_EnableGpuProfiling)->default_value("false"))
telsoa01ce3e84a2018-08-31 09:31:35 +0100113
Colm Donelan9bf0d322020-10-08 17:39:13 +0100114 ("f,fp16-enabled", "Enables support for relaxed computation from Float32 to Float16",
Colm Donelan0cc61782020-10-06 21:02:21 +0100115 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 }
telsoa01ce3e84a2018-08-31 09:31:35 +0100121
Colm Donelan0cc61782020-10-06 21:02:21 +0100122
telsoa01ce3e84a2018-08-31 09:31:35 +0100123 try
124 {
Colm Donelan0cc61782020-10-06 21:02:21 +0100125 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 }
telsoa01ce3e84a2018-08-31 09:31:35 +0100131 }
Colm Donelan0cc61782020-10-06 21:02:21 +0100132 catch (const cxxopts::OptionException& e)
telsoa01ce3e84a2018-08-31 09:31:35 +0100133 {
134 ALOGW("An error occurred attempting to parse program options: %s", e.what());
135 }
136
Colm Donelan0cc61782020-10-06 21:02:21 +0100137 // Convert the string backend names into backendId's.
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100138 m_Backends.reserve(backends.size());
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100139 for (auto&& backend : backends)
telsoa01ce3e84a2018-08-31 09:31:35 +0100140 {
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100141 m_Backends.emplace_back(backend);
telsoa01ce3e84a2018-08-31 09:31:35 +0100142 }
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 Yan689c6ee2019-04-25 17:48:41 +0100180
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 }
telsoa01ce3e84a2018-08-31 09:31:35 +0100198 }
199}
200
201} // namespace armnn_driver