blob: 4247b2d3e5fcdfe59d1b78e1477e32f543202fbb [file] [log] [blame]
Georgios Pinitas12be7ab2018-07-03 12:06:23 +01001/*
2 * Copyright (c) 2018 ARM Limited.
3 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24#include "CommonGraphOptions.h"
25
26#include "arm_compute/graph/TypeLoader.h"
27#include "arm_compute/graph/TypePrinter.h"
28
29#include "support/ToolchainSupport.h"
30
31#include <map>
32
33using namespace arm_compute::graph;
34
35namespace
36{
37std::pair<unsigned int, unsigned int> parse_validation_range(const std::string &validation_range)
38{
39 std::pair<unsigned int /* start */, unsigned int /* end */> range = { 0, std::numeric_limits<unsigned int>::max() };
40 if(!validation_range.empty())
41 {
42 std::string str;
43 std::stringstream stream(validation_range);
44
45 // Get first value
46 std::getline(stream, str, ',');
47 if(stream.fail())
48 {
49 return range;
50 }
51 else
52 {
53 range.first = arm_compute::support::cpp11::stoi(str);
54 }
55
56 // Get second value
57 std::getline(stream, str);
58 if(stream.fail())
59 {
60 range.second = range.first;
61 return range;
62 }
63 else
64 {
65 range.second = arm_compute::support::cpp11::stoi(str);
66 }
67 }
68 return range;
69}
70} // namespace
71
72namespace arm_compute
73{
74namespace utils
75{
76::std::ostream &operator<<(::std::ostream &os, const CommonGraphParams &common_params)
77{
78 std::string false_str = std::string("false");
79 std::string true_str = std::string("true");
80
81 os << "Threads : " << common_params.threads << std::endl;
82 os << "Target : " << common_params.target << std::endl;
83 os << "Data type : " << common_params.data_type << std::endl;
84 os << "Data layout : " << common_params.data_layout << std::endl;
85 os << "Tuner enabled? : " << (common_params.enable_tuner ? true_str : false_str) << std::endl;
Anthony Barbier7b607dc2018-07-13 15:55:24 +010086 os << "Tuner file : " << common_params.tuner_file << std::endl;
Georgios Pinitase2220552018-07-20 13:23:44 +010087 os << "Fast math enabled? : " << (common_params.fast_math_hint == FastMathHint::Enabled ? true_str : false_str) << std::endl;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +010088 if(!common_params.data_path.empty())
89 {
90 os << "Data path : " << common_params.data_path << std::endl;
91 }
92 if(!common_params.image.empty())
93 {
94 os << "Image file : " << common_params.image << std::endl;
95 }
96 if(!common_params.labels.empty())
97 {
98 os << "Labels file : " << common_params.labels << std::endl;
99 }
100 if(!common_params.validation_file.empty())
101 {
102 os << "Validation range : " << common_params.validation_range_start << "-" << common_params.validation_range_end << std::endl;
103 os << "Validation file : " << common_params.validation_file << std::endl;
104 if(!common_params.validation_path.empty())
105 {
106 os << "Validation path : " << common_params.validation_path << std::endl;
107 }
108 }
109
110 return os;
111}
112
113CommonGraphOptions::CommonGraphOptions(CommandLineParser &parser)
114 : help(parser.add_option<ToggleOption>("help")),
115 threads(parser.add_option<SimpleOption<int>>("threads", 1)),
116 target(),
117 data_type(),
118 data_layout(),
119 enable_tuner(parser.add_option<ToggleOption>("enable-tuner")),
120 fast_math_hint(parser.add_option<ToggleOption>("fast-math")),
121 data_path(parser.add_option<SimpleOption<std::string>>("data")),
122 image(parser.add_option<SimpleOption<std::string>>("image")),
123 labels(parser.add_option<SimpleOption<std::string>>("labels")),
124 validation_file(parser.add_option<SimpleOption<std::string>>("validation-file")),
125 validation_path(parser.add_option<SimpleOption<std::string>>("validation-path")),
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100126 validation_range(parser.add_option<SimpleOption<std::string>>("validation-range")),
127 tuner_file(parser.add_option<SimpleOption<std::string>>("tuner-file"))
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100128{
129 std::set<arm_compute::graph::Target> supported_targets
130 {
131 Target::NEON,
132 Target::CL,
133 Target::GC,
134 };
135
136 std::set<arm_compute::DataType> supported_data_types
137 {
138 DataType::F16,
139 DataType::F32,
140 DataType::QASYMM8,
141 };
142
143 std::set<DataLayout> supported_data_layouts
144 {
145 DataLayout::NHWC,
146 DataLayout::NCHW,
147 };
148
149 target = parser.add_option<EnumOption<Target>>("target", supported_targets, Target::NEON);
150 data_type = parser.add_option<EnumOption<DataType>>("type", supported_data_types, DataType::F32);
Georgios Pinitas415a2bf2018-07-30 12:05:25 +0100151 data_layout = parser.add_option<EnumOption<DataLayout>>("layout", supported_data_layouts);
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100152
153 help->set_help("Show this help message");
154 threads->set_help("Number of threads to use");
155 target->set_help("Target to execute on");
156 data_type->set_help("Data type to use");
157 data_layout->set_help("Data layout to use");
Anthony Barbier943a40b2018-07-12 18:03:54 +0100158 enable_tuner->set_help("Enable OpenCL dynamic tuner");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100159 fast_math_hint->set_help("Enable fast math");
160 data_path->set_help("Path where graph parameters reside");
161 image->set_help("Input image for the graph");
162 labels->set_help("File containing the output labels");
163 validation_file->set_help("File used to validate the graph");
164 validation_path->set_help("Path to the validation data");
165 validation_range->set_help("Range of the images to validate for (Format : start,end)");
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100166 tuner_file->set_help("File to load/save CLTuner values");
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100167}
168
169CommonGraphParams consume_common_graph_parameters(CommonGraphOptions &options)
170{
Georgios Pinitase2220552018-07-20 13:23:44 +0100171 FastMathHint fast_math_hint_value = options.fast_math_hint->value() ? FastMathHint::Enabled : FastMathHint::Disabled;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100172 auto validation_range = parse_validation_range(options.validation_range->value());
173
174 CommonGraphParams common_params;
Georgios Pinitas415a2bf2018-07-30 12:05:25 +0100175 common_params.help = options.help->is_set() ? options.help->value() : false;
176 common_params.threads = options.threads->value();
177 common_params.target = options.target->value();
178 common_params.data_type = options.data_type->value();
179 if(options.data_layout->is_set())
180 {
181 common_params.data_layout = options.data_layout->value();
182 }
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100183 common_params.enable_tuner = options.enable_tuner->is_set() ? options.enable_tuner->value() : false;
Georgios Pinitase2220552018-07-20 13:23:44 +0100184 common_params.fast_math_hint = options.fast_math_hint->is_set() ? fast_math_hint_value : FastMathHint::Disabled;
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100185 common_params.data_path = options.data_path->value();
186 common_params.image = options.image->value();
187 common_params.labels = options.labels->value();
188 common_params.validation_file = options.validation_file->value();
189 common_params.validation_path = options.validation_path->value();
190 common_params.validation_range_start = validation_range.first;
191 common_params.validation_range_end = validation_range.second;
Anthony Barbier7b607dc2018-07-13 15:55:24 +0100192 common_params.tuner_file = options.tuner_file->value();
Georgios Pinitas12be7ab2018-07-03 12:06:23 +0100193
194 return common_params;
195}
196} // namespace utils
197} // namespace arm_compute