Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 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 | |
SiCong Li | e357a25 | 2020-08-09 20:05:52 +0100 | [diff] [blame] | 26 | #include "arm_compute/core/Utils.h" |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 27 | #include "arm_compute/graph/TypeLoader.h" |
| 28 | #include "arm_compute/graph/TypePrinter.h" |
| 29 | |
Matthew Bentham | 9204646 | 2020-03-07 22:15:55 +0000 | [diff] [blame] | 30 | #include "support/StringSupport.h" |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 31 | |
| 32 | #include <map> |
| 33 | |
| 34 | using namespace arm_compute::graph; |
| 35 | |
| 36 | namespace |
| 37 | { |
| 38 | std::pair<unsigned int, unsigned int> parse_validation_range(const std::string &validation_range) |
| 39 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 40 | std::pair<unsigned int /* start */, unsigned int /* end */> range = {0, std::numeric_limits<unsigned int>::max()}; |
| 41 | if (!validation_range.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 42 | { |
| 43 | std::string str; |
| 44 | std::stringstream stream(validation_range); |
| 45 | |
| 46 | // Get first value |
| 47 | std::getline(stream, str, ','); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 48 | if (stream.fail()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 49 | { |
| 50 | return range; |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | range.first = arm_compute::support::cpp11::stoi(str); |
| 55 | } |
| 56 | |
| 57 | // Get second value |
| 58 | std::getline(stream, str); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 59 | if (stream.fail()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 60 | { |
| 61 | range.second = range.first; |
| 62 | return range; |
| 63 | } |
| 64 | else |
| 65 | { |
| 66 | range.second = arm_compute::support::cpp11::stoi(str); |
| 67 | } |
| 68 | } |
| 69 | return range; |
| 70 | } |
| 71 | } // namespace |
| 72 | |
| 73 | namespace arm_compute |
| 74 | { |
| 75 | namespace utils |
| 76 | { |
| 77 | ::std::ostream &operator<<(::std::ostream &os, const CommonGraphParams &common_params) |
| 78 | { |
| 79 | std::string false_str = std::string("false"); |
| 80 | std::string true_str = std::string("true"); |
| 81 | |
| 82 | os << "Threads : " << common_params.threads << std::endl; |
| 83 | os << "Target : " << common_params.target << std::endl; |
| 84 | os << "Data type : " << common_params.data_type << std::endl; |
| 85 | os << "Data layout : " << common_params.data_layout << std::endl; |
| 86 | os << "Tuner enabled? : " << (common_params.enable_tuner ? true_str : false_str) << std::endl; |
Pablo Tello | db9116f | 2019-07-11 16:50:37 +0100 | [diff] [blame] | 87 | os << "Cache enabled? : " << (common_params.enable_cl_cache ? true_str : false_str) << std::endl; |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 88 | os << "Tuner mode : " << common_params.tuner_mode << std::endl; |
Anthony Barbier | 7b607dc | 2018-07-13 15:55:24 +0100 | [diff] [blame] | 89 | os << "Tuner file : " << common_params.tuner_file << std::endl; |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 90 | os << "MLGO file : " << common_params.mlgo_file << std::endl; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 91 | os << "Fast math enabled? : " << (common_params.fast_math_hint == FastMathHint::Enabled ? true_str : false_str) |
| 92 | << std::endl; |
| 93 | if (!common_params.data_path.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 94 | { |
| 95 | os << "Data path : " << common_params.data_path << std::endl; |
| 96 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 97 | if (!common_params.image.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 98 | { |
| 99 | os << "Image file : " << common_params.image << std::endl; |
| 100 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 101 | if (!common_params.labels.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 102 | { |
| 103 | os << "Labels file : " << common_params.labels << std::endl; |
| 104 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 105 | if (!common_params.validation_file.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 106 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 107 | os << "Validation range : " << common_params.validation_range_start << "-" << common_params.validation_range_end |
| 108 | << std::endl; |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 109 | os << "Validation file : " << common_params.validation_file << std::endl; |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 110 | if (!common_params.validation_path.empty()) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 111 | { |
| 112 | os << "Validation path : " << common_params.validation_path << std::endl; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return os; |
| 117 | } |
| 118 | |
| 119 | CommonGraphOptions::CommonGraphOptions(CommandLineParser &parser) |
| 120 | : help(parser.add_option<ToggleOption>("help")), |
| 121 | threads(parser.add_option<SimpleOption<int>>("threads", 1)), |
Georgios Pinitas | 450dfb1 | 2021-06-15 10:11:47 +0100 | [diff] [blame] | 122 | batches(parser.add_option<SimpleOption<int>>("batches", 1)), |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 123 | target(), |
| 124 | data_type(), |
| 125 | data_layout(), |
| 126 | enable_tuner(parser.add_option<ToggleOption>("enable-tuner")), |
Pablo Tello | db9116f | 2019-07-11 16:50:37 +0100 | [diff] [blame] | 127 | enable_cl_cache(parser.add_option<ToggleOption>("enable-cl-cache")), |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 128 | tuner_mode(), |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 129 | fast_math_hint(parser.add_option<ToggleOption>("fast-math")), |
| 130 | data_path(parser.add_option<SimpleOption<std::string>>("data")), |
| 131 | image(parser.add_option<SimpleOption<std::string>>("image")), |
| 132 | labels(parser.add_option<SimpleOption<std::string>>("labels")), |
| 133 | validation_file(parser.add_option<SimpleOption<std::string>>("validation-file")), |
| 134 | validation_path(parser.add_option<SimpleOption<std::string>>("validation-path")), |
Anthony Barbier | 7b607dc | 2018-07-13 15:55:24 +0100 | [diff] [blame] | 135 | validation_range(parser.add_option<SimpleOption<std::string>>("validation-range")), |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 136 | tuner_file(parser.add_option<SimpleOption<std::string>>("tuner-file")), |
| 137 | mlgo_file(parser.add_option<SimpleOption<std::string>>("mlgo-file")) |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 138 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 139 | std::set<arm_compute::graph::Target> supported_targets{ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 140 | Target::NEON, |
| 141 | Target::CL, |
Michalis Spyrou | 402740d | 2021-04-20 11:26:21 +0100 | [diff] [blame] | 142 | Target::CLVK, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 143 | }; |
| 144 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 145 | std::set<arm_compute::DataType> supported_data_types{ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 146 | DataType::F16, |
| 147 | DataType::F32, |
| 148 | DataType::QASYMM8, |
SiCongLi | f466d75 | 2021-03-01 15:26:18 +0000 | [diff] [blame] | 149 | DataType::QASYMM8_SIGNED, |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 150 | }; |
| 151 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 152 | std::set<DataLayout> supported_data_layouts{ |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 153 | DataLayout::NHWC, |
| 154 | DataLayout::NCHW, |
| 155 | }; |
| 156 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 157 | const std::set<CLTunerMode> supported_tuner_modes{CLTunerMode::EXHAUSTIVE, CLTunerMode::NORMAL, CLTunerMode::RAPID}; |
Vidhya Sudhan Loganathan | 050471e | 2019-04-25 09:27:24 +0100 | [diff] [blame] | 158 | |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 159 | target = parser.add_option<EnumOption<Target>>("target", supported_targets, Target::NEON); |
| 160 | data_type = parser.add_option<EnumOption<DataType>>("type", supported_data_types, DataType::F32); |
Georgios Pinitas | 415a2bf | 2018-07-30 12:05:25 +0100 | [diff] [blame] | 161 | data_layout = parser.add_option<EnumOption<DataLayout>>("layout", supported_data_layouts); |
Michalis Spyrou | 083a069 | 2019-05-13 15:35:50 +0100 | [diff] [blame] | 162 | tuner_mode = parser.add_option<EnumOption<CLTunerMode>>("tuner-mode", supported_tuner_modes, CLTunerMode::NORMAL); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 163 | |
| 164 | help->set_help("Show this help message"); |
| 165 | threads->set_help("Number of threads to use"); |
Georgios Pinitas | 450dfb1 | 2021-06-15 10:11:47 +0100 | [diff] [blame] | 166 | batches->set_help("Number of batches to use for the inputs"); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 167 | target->set_help("Target to execute on"); |
| 168 | data_type->set_help("Data type to use"); |
| 169 | data_layout->set_help("Data layout to use"); |
Anthony Barbier | 943a40b | 2018-07-12 18:03:54 +0100 | [diff] [blame] | 170 | enable_tuner->set_help("Enable OpenCL dynamic tuner"); |
Pablo Tello | db9116f | 2019-07-11 16:50:37 +0100 | [diff] [blame] | 171 | enable_cl_cache->set_help("Enable OpenCL program caches"); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 172 | tuner_mode->set_help("Configures the time taken by the tuner to tune. " |
| 173 | "Exhaustive: slowest but produces the most performant LWS configuration. " |
| 174 | "Normal: slow but produces the LWS configurations on par with Exhaustive most of the time. " |
| 175 | "Rapid: fast but produces less performant LWS configurations"); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 176 | fast_math_hint->set_help("Enable fast math"); |
| 177 | data_path->set_help("Path where graph parameters reside"); |
| 178 | image->set_help("Input image for the graph"); |
| 179 | labels->set_help("File containing the output labels"); |
| 180 | validation_file->set_help("File used to validate the graph"); |
| 181 | validation_path->set_help("Path to the validation data"); |
| 182 | validation_range->set_help("Range of the images to validate for (Format : start,end)"); |
Anthony Barbier | 7b607dc | 2018-07-13 15:55:24 +0100 | [diff] [blame] | 183 | tuner_file->set_help("File to load/save CLTuner values"); |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 184 | mlgo_file->set_help("File to load MLGO heuristics"); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | CommonGraphParams consume_common_graph_parameters(CommonGraphOptions &options) |
| 188 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 189 | FastMathHint fast_math_hint_value = |
| 190 | options.fast_math_hint->value() ? FastMathHint::Enabled : FastMathHint::Disabled; |
| 191 | auto validation_range = parse_validation_range(options.validation_range->value()); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 192 | |
| 193 | CommonGraphParams common_params; |
Georgios Pinitas | 415a2bf | 2018-07-30 12:05:25 +0100 | [diff] [blame] | 194 | common_params.help = options.help->is_set() ? options.help->value() : false; |
| 195 | common_params.threads = options.threads->value(); |
Georgios Pinitas | 450dfb1 | 2021-06-15 10:11:47 +0100 | [diff] [blame] | 196 | common_params.batches = options.batches->value(); |
Georgios Pinitas | 415a2bf | 2018-07-30 12:05:25 +0100 | [diff] [blame] | 197 | common_params.target = options.target->value(); |
| 198 | common_params.data_type = options.data_type->value(); |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 199 | if (options.data_layout->is_set()) |
Georgios Pinitas | 415a2bf | 2018-07-30 12:05:25 +0100 | [diff] [blame] | 200 | { |
| 201 | common_params.data_layout = options.data_layout->value(); |
| 202 | } |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 203 | common_params.enable_tuner = options.enable_tuner->is_set() ? options.enable_tuner->value() : false; |
| 204 | common_params.enable_cl_cache = common_params.target == arm_compute::graph::Target::NEON |
| 205 | ? false |
| 206 | : (options.enable_cl_cache->is_set() ? options.enable_cl_cache->value() : true); |
| 207 | common_params.tuner_mode = options.tuner_mode->value(); |
| 208 | common_params.fast_math_hint = options.fast_math_hint->is_set() ? fast_math_hint_value : FastMathHint::Disabled; |
| 209 | common_params.data_path = options.data_path->value(); |
| 210 | common_params.image = options.image->value(); |
| 211 | common_params.labels = options.labels->value(); |
| 212 | common_params.validation_file = options.validation_file->value(); |
| 213 | common_params.validation_path = options.validation_path->value(); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 214 | common_params.validation_range_start = validation_range.first; |
| 215 | common_params.validation_range_end = validation_range.second; |
Anthony Barbier | 7b607dc | 2018-07-13 15:55:24 +0100 | [diff] [blame] | 216 | common_params.tuner_file = options.tuner_file->value(); |
SiCong Li | 4841c97 | 2021-02-03 12:17:35 +0000 | [diff] [blame] | 217 | common_params.mlgo_file = options.mlgo_file->value(); |
Georgios Pinitas | 12be7ab | 2018-07-03 12:06:23 +0100 | [diff] [blame] | 218 | |
| 219 | return common_params; |
| 220 | } |
| 221 | } // namespace utils |
| 222 | } // namespace arm_compute |