blob: d179d653cc67ff9a5b5c8467b0b33a885863b25f [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
16#include <boost/algorithm/string/predicate.hpp>
17#include <boost/program_options.hpp>
18
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010019#include <algorithm>
telsoa01ce3e84a2018-08-31 09:31:35 +010020#include <cassert>
21#include <functional>
22#include <string>
23#include <sstream>
24
25using namespace android;
26using namespace std;
27
28namespace armnn_driver
29{
30
Nikhil Raj77605822018-09-03 11:25:56 +010031DriverOptions::DriverOptions(armnn::Compute computeDevice, bool fp16Enabled)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010032 : m_Backends({computeDevice})
33 , m_VerboseLogging(false)
34 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010035 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010036 , m_EnableGpuProfiling(false)
37 , m_fp16Enabled(fp16Enabled)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010038 , m_FastMathEnabled(false)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010039{
40}
41
42DriverOptions::DriverOptions(const std::vector<armnn::BackendId>& backends, bool fp16Enabled)
43 : m_Backends(backends)
telsoa01ce3e84a2018-08-31 09:31:35 +010044 , m_VerboseLogging(false)
45 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010046 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
telsoa01ce3e84a2018-08-31 09:31:35 +010047 , m_EnableGpuProfiling(false)
Nikhil Raj77605822018-09-03 11:25:56 +010048 , m_fp16Enabled(fp16Enabled)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010049 , m_FastMathEnabled(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010050{
51}
52
53DriverOptions::DriverOptions(int argc, char** argv)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010054 : m_VerboseLogging(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010055 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010056 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
telsoa01ce3e84a2018-08-31 09:31:35 +010057 , m_EnableGpuProfiling(false)
58 , m_fp16Enabled(false)
Mike Kelly7ed56dd2020-09-30 20:22:56 +010059 , m_FastMathEnabled(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010060{
61 namespace po = boost::program_options;
62
telsoa01ce3e84a2018-08-31 09:31:35 +010063 std::string unsupportedOperationsAsString;
64 std::string clTunedParametersModeAsString;
Ruomei Yan689c6ee2019-04-25 17:48:41 +010065 std::string clTuningLevelAsString;
telsoa01ce3e84a2018-08-31 09:31:35 +010066
67 po::options_description optionsDesc("Options");
68 optionsDesc.add_options()
69 ("compute,c",
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010070 po::value<std::vector<std::string>>()->
71 multitoken()->default_value(std::vector<std::string>{"GpuAcc"}, "{GpuAcc}"),
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +010072 "Which backend to run layers on. Examples of possible values are: CpuRef, CpuAcc, GpuAcc")
telsoa01ce3e84a2018-08-31 09:31:35 +010073
74 ("verbose-logging,v",
75 po::bool_switch(&m_VerboseLogging),
76 "Turns verbose logging on")
77
78 ("request-inputs-and-outputs-dump-dir,d",
79 po::value<std::string>(&m_RequestInputsAndOutputsDumpDir)->default_value(""),
80 "If non-empty, the directory where request inputs and outputs should be dumped")
81
Kevin Mayabc95d02020-05-15 15:34:03 +010082 ("service-name,n",
83 po::value<std::string>(&m_ServiceName)->default_value("armnn"),
84 "If non-empty, the driver service name to be registered")
85
telsoa01ce3e84a2018-08-31 09:31:35 +010086 ("unsupported-operations,u",
87 po::value<std::string>(&unsupportedOperationsAsString)->default_value(""),
88 "If non-empty, a comma-separated list of operation indices which the driver will forcibly "
89 "consider unsupported")
90
91 ("cl-tuned-parameters-file,t",
92 po::value<std::string>(&m_ClTunedParametersFile)->default_value(""),
93 "If non-empty, the given file will be used to load/save CL tuned parameters. "
94 "See also --cl-tuned-parameters-mode")
95
96 ("cl-tuned-parameters-mode,m",
97 po::value<std::string>(&clTunedParametersModeAsString)->default_value("UseTunedParameters"),
98 "If 'UseTunedParameters' (the default), will read CL tuned parameters from the file specified by "
99 "--cl-tuned-parameters-file. "
100 "If 'UpdateTunedParameters', will also find the optimum parameters when preparing new networks and update "
101 "the file accordingly.")
102
Ruomei Yan689c6ee2019-04-25 17:48:41 +0100103 ("cl-tuning-level,o",
104 po::value<std::string>(&clTuningLevelAsString)->default_value("rapid"),
105 "exhaustive: all lws values are tested "
106 "normal: reduced number of lws values but enough to still have the performance really close to the "
107 "exhaustive approach "
108 "rapid: only 3 lws values should be tested for each kernel ")
109
Mike Kelly7ed56dd2020-09-30 20:22:56 +0100110 ("fast-math,a",
111 po::bool_switch(&m_FastMathEnabled),
112 "Turns FastMath on")
113
telsoa01ce3e84a2018-08-31 09:31:35 +0100114 ("gpu-profiling,p",
115 po::bool_switch(&m_EnableGpuProfiling),
surmeh01205bb992018-09-11 12:41:24 +0100116 "Turns GPU profiling on")
telsoa01ce3e84a2018-08-31 09:31:35 +0100117
118 ("fp16-enabled,f",
119 po::bool_switch(&m_fp16Enabled),
120 "Enables support for relaxed computation from Float32 to Float16");
121
122 po::variables_map variablesMap;
123 try
124 {
125 po::store(po::parse_command_line(argc, argv, optionsDesc), variablesMap);
126 po::notify(variablesMap);
127 }
128 catch (const po::error& e)
129 {
130 ALOGW("An error occurred attempting to parse program options: %s", e.what());
131 }
132
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100133 const std::vector<std::string> backends = variablesMap["compute"].as<std::vector<std::string>>();
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100134 m_Backends.reserve(backends.size());
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100135 for (auto&& backend : backends)
telsoa01ce3e84a2018-08-31 09:31:35 +0100136 {
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100137 m_Backends.emplace_back(backend);
telsoa01ce3e84a2018-08-31 09:31:35 +0100138 }
139
140 if (!unsupportedOperationsAsString.empty())
141 {
142 std::istringstream argStream(unsupportedOperationsAsString);
143
144 std::string s;
145 while (!argStream.eof())
146 {
147 std::getline(argStream, s, ',');
148 try
149 {
150 unsigned int operationIdx = std::stoi(s);
151 m_ForcedUnsupportedOperations.insert(operationIdx);
152 }
153 catch (const std::invalid_argument&)
154 {
155 ALOGW("Ignoring invalid integer argument in -u/--unsupported-operations value: %s", s.c_str());
156 }
157 }
158 }
159
160 if (!m_ClTunedParametersFile.empty())
161 {
162 // The mode is only relevant if the file path has been provided
163 if (clTunedParametersModeAsString == "UseTunedParameters")
164 {
165 m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UseTunedParameters;
166 }
167 else if (clTunedParametersModeAsString == "UpdateTunedParameters")
168 {
169 m_ClTunedParametersMode = armnn::IGpuAccTunedParameters::Mode::UpdateTunedParameters;
170 }
171 else
172 {
173 ALOGW("Requested unknown cl-tuned-parameters-mode '%s'. Defaulting to UseTunedParameters",
174 clTunedParametersModeAsString.c_str());
175 }
Ruomei Yan689c6ee2019-04-25 17:48:41 +0100176
177 if (clTuningLevelAsString == "exhaustive")
178 {
179 m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Exhaustive;
180 }
181 else if (clTuningLevelAsString == "normal")
182 {
183 m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Normal;
184 }
185 else if (clTuningLevelAsString == "rapid")
186 {
187 m_ClTuningLevel = armnn::IGpuAccTunedParameters::TuningLevel::Rapid;
188 }
189 else
190 {
191 ALOGW("Requested unknown cl-tuner-mode '%s'. Defaulting to rapid",
192 clTuningLevelAsString.c_str());
193 }
telsoa01ce3e84a2018-08-31 09:31:35 +0100194 }
195}
196
197} // namespace armnn_driver