blob: 1f534b6e6f90743cf3864c5c6a67537c33b6ed81 [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)
38{
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)
telsoa01ce3e84a2018-08-31 09:31:35 +010048{
49}
50
51DriverOptions::DriverOptions(int argc, char** argv)
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010052 : m_VerboseLogging(false)
telsoa01ce3e84a2018-08-31 09:31:35 +010053 , m_ClTunedParametersMode(armnn::IGpuAccTunedParameters::Mode::UseTunedParameters)
Ruomei Yan689c6ee2019-04-25 17:48:41 +010054 , m_ClTuningLevel(armnn::IGpuAccTunedParameters::TuningLevel::Rapid)
telsoa01ce3e84a2018-08-31 09:31:35 +010055 , m_EnableGpuProfiling(false)
56 , m_fp16Enabled(false)
57{
58 namespace po = boost::program_options;
59
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;
telsoa01ce3e84a2018-08-31 09:31:35 +010063
64 po::options_description optionsDesc("Options");
65 optionsDesc.add_options()
66 ("compute,c",
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +010067 po::value<std::vector<std::string>>()->
68 multitoken()->default_value(std::vector<std::string>{"GpuAcc"}, "{GpuAcc}"),
Narumol Prangnawarat856d1c92019-05-03 16:42:52 +010069 "Which backend to run layers on. Examples of possible values are: CpuRef, CpuAcc, GpuAcc")
telsoa01ce3e84a2018-08-31 09:31:35 +010070
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 Mayabc95d02020-05-15 15:34:03 +010079 ("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
telsoa01ce3e84a2018-08-31 09:31:35 +010083 ("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 Yan689c6ee2019-04-25 17:48:41 +0100100 ("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
telsoa01ce3e84a2018-08-31 09:31:35 +0100107 ("gpu-profiling,p",
108 po::bool_switch(&m_EnableGpuProfiling),
surmeh01205bb992018-09-11 12:41:24 +0100109 "Turns GPU profiling on")
telsoa01ce3e84a2018-08-31 09:31:35 +0100110
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 Chaimanowongd5fd9762019-04-04 13:33:10 +0100126 const std::vector<std::string> backends = variablesMap["compute"].as<std::vector<std::string>>();
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100127 m_Backends.reserve(backends.size());
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100128 for (auto&& backend : backends)
telsoa01ce3e84a2018-08-31 09:31:35 +0100129 {
Nattapat Chaimanowongd5fd9762019-04-04 13:33:10 +0100130 m_Backends.emplace_back(backend);
telsoa01ce3e84a2018-08-31 09:31:35 +0100131 }
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 Yan689c6ee2019-04-25 17:48:41 +0100169
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 }
telsoa01ce3e84a2018-08-31 09:31:35 +0100187 }
188}
189
190} // namespace armnn_driver