Laurent Carlier | 749294b | 2020-06-01 09:03:17 +0100 | [diff] [blame] | 1 | // |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 2 | // Copyright © 2017 Arm Ltd and Contributors. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 5 | |
Francis Murtagh | bee4bc9 | 2019-06-18 12:30:37 +0100 | [diff] [blame] | 6 | #include "../NetworkExecutionUtils/NetworkExecutionUtils.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 8 | // MAIN |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 9 | int main(int argc, const char* argv[]) |
| 10 | { |
| 11 | // Configures logging for both the ARMNN library and this test program. |
| 12 | #ifdef NDEBUG |
| 13 | armnn::LogSeverity level = armnn::LogSeverity::Info; |
| 14 | #else |
| 15 | armnn::LogSeverity level = armnn::LogSeverity::Debug; |
| 16 | #endif |
| 17 | armnn::ConfigureLogging(true, true, level); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 18 | |
| 19 | std::string testCasesFile; |
| 20 | |
| 21 | std::string modelFormat; |
| 22 | std::string modelPath; |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 23 | std::string inputNames; |
| 24 | std::string inputTensorShapes; |
| 25 | std::string inputTensorDataFilePaths; |
| 26 | std::string outputNames; |
| 27 | std::string inputTypes; |
Éanna Ó Catháin | b3d481a | 2019-02-26 11:26:24 +0000 | [diff] [blame] | 28 | std::string outputTypes; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 29 | std::string dynamicBackendsPath; |
Sadik Armagan | 7708628 | 2019-09-02 11:46:28 +0100 | [diff] [blame] | 30 | std::string outputTensorFiles; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 31 | |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 32 | // external profiling parameters |
| 33 | std::string outgoingCaptureFile; |
| 34 | std::string incomingCaptureFile; |
| 35 | uint32_t counterCapturePeriod; |
Isabella Gottardi | a0687ee | 2020-03-11 18:04:20 +0000 | [diff] [blame] | 36 | std::string fileFormat; |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 37 | |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 38 | size_t iterations = 1; |
| 39 | int tuningLevel = 0; |
| 40 | std::string tuningPath; |
| 41 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 42 | double thresholdTime = 0.0; |
| 43 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 44 | size_t subgraphId = 0; |
| 45 | |
Matthew Jackson | 07882f1 | 2019-09-05 15:55:55 +0100 | [diff] [blame] | 46 | const std::string backendsMessage = "REQUIRED: Which device to run layers on by default. Possible choices: " |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 47 | + armnn::BackendRegistryInstance().GetBackendIdsAsString(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 48 | po::options_description desc("Options"); |
| 49 | try |
| 50 | { |
| 51 | desc.add_options() |
| 52 | ("help", "Display usage information") |
Matthew Jackson | 07882f1 | 2019-09-05 15:55:55 +0100 | [diff] [blame] | 53 | ("compute,c", po::value<std::vector<std::string>>()->multitoken()->required(), |
| 54 | backendsMessage.c_str()) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 55 | ("test-cases,t", po::value(&testCasesFile), "Path to a CSV file containing test cases to run. " |
| 56 | "If set, further parameters -- with the exception of compute device and concurrency -- will be ignored, " |
| 57 | "as they are expected to be defined in the file for each test in particular.") |
| 58 | ("concurrent,n", po::bool_switch()->default_value(false), |
| 59 | "Whether or not the test cases should be executed in parallel") |
Matteo Martincigh | 4912402 | 2019-01-11 13:25:59 +0000 | [diff] [blame] | 60 | ("model-format,f", po::value(&modelFormat)->required(), |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 61 | "armnn-binary, caffe-binary, caffe-text, onnx-binary, onnx-text, tflite-binary, tensorflow-binary or " |
| 62 | "tensorflow-text.") |
| 63 | ("model-path,m", po::value(&modelPath)->required(), "Path to model file, e.g. .armnn, .caffemodel, " |
| 64 | ".prototxt, .tflite, .onnx") |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 65 | ("dynamic-backends-path,b", po::value(&dynamicBackendsPath), |
| 66 | "Path where to load any available dynamic backend from. " |
| 67 | "If left empty (the default), dynamic backends will not be used.") |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 68 | ("input-name,i", po::value(&inputNames), |
| 69 | "Identifier of the input tensors in the network separated by comma.") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 70 | ("subgraph-number,x", po::value<size_t>(&subgraphId)->default_value(0), "Id of the subgraph to be executed." |
| 71 | "Defaults to 0") |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 72 | ("input-tensor-shape,s", po::value(&inputTensorShapes), |
Francis Murtagh | 1555cbd | 2019-10-08 14:47:46 +0100 | [diff] [blame] | 73 | "The shape of the input tensors in the network as a flat array of integers separated by comma." |
| 74 | "Several shapes can be passed by separating them with a colon (:)." |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 75 | "This parameter is optional, depending on the network.") |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 76 | ("input-tensor-data,d", po::value(&inputTensorDataFilePaths)->default_value(""), |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 77 | "Path to files containing the input data as a flat array separated by whitespace. " |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 78 | "Several paths can be passed by separating them with a comma. If not specified, the network will be run " |
| 79 | "with dummy data (useful for profiling).") |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 80 | ("input-type,y",po::value(&inputTypes), "The type of the input tensors in the network separated by comma. " |
| 81 | "If unset, defaults to \"float\" for all defined inputs. " |
Éanna Ó Catháin | b3d481a | 2019-02-26 11:26:24 +0000 | [diff] [blame] | 82 | "Accepted values (float, int or qasymm8)") |
Narumol Prangnawarat | 610256f | 2019-06-26 15:10:46 +0100 | [diff] [blame] | 83 | ("quantize-input,q",po::bool_switch()->default_value(false), |
| 84 | "If this option is enabled, all float inputs will be quantized to qasymm8. " |
| 85 | "If unset, default to not quantized. " |
| 86 | "Accepted values (true or false)") |
Éanna Ó Catháin | b3d481a | 2019-02-26 11:26:24 +0000 | [diff] [blame] | 87 | ("output-type,z",po::value(&outputTypes), |
| 88 | "The type of the output tensors in the network separated by comma. " |
| 89 | "If unset, defaults to \"float\" for all defined outputs. " |
| 90 | "Accepted values (float, int or qasymm8).") |
Georgios Pinitas | 50311ba | 2020-02-18 13:25:23 +0000 | [diff] [blame] | 91 | ("dequantize-output,l",po::bool_switch()->default_value(false), |
| 92 | "If this option is enabled, all quantized outputs will be dequantized to float. " |
| 93 | "If unset, default to not get dequantized. " |
| 94 | "Accepted values (true or false)") |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 95 | ("output-name,o", po::value(&outputNames), |
| 96 | "Identifier of the output tensors in the network separated by comma.") |
Sadik Armagan | 7708628 | 2019-09-02 11:46:28 +0100 | [diff] [blame] | 97 | ("write-outputs-to-file,w", po::value(&outputTensorFiles), |
| 98 | "Comma-separated list of output file paths keyed with the binding-id of the output slot. " |
| 99 | "If left empty (the default), the output tensors will not be written to a file.") |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 100 | ("event-based-profiling,e", po::bool_switch()->default_value(false), |
Ruomei Yan | 2fcce08 | 2019-04-02 16:47:34 +0100 | [diff] [blame] | 101 | "Enables built in profiler. If unset, defaults to off.") |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 102 | ("visualize-optimized-model,v", po::bool_switch()->default_value(false), |
| 103 | "Enables built optimized model visualizer. If unset, defaults to off.") |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 104 | ("bf16-turbo-mode", po::bool_switch()->default_value(false), "If this option is enabled, FP32 layers, " |
| 105 | "weights and biases will be converted to BFloat16 where the backend supports it") |
Ruomei Yan | 2fcce08 | 2019-04-02 16:47:34 +0100 | [diff] [blame] | 106 | ("fp16-turbo-mode,h", po::bool_switch()->default_value(false), "If this option is enabled, FP32 layers, " |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 107 | "weights and biases will be converted to FP16 where the backend supports it") |
| 108 | ("threshold-time,r", po::value<double>(&thresholdTime)->default_value(0.0), |
| 109 | "Threshold time is the maximum allowed time for inference measured in milliseconds. If the actual " |
| 110 | "inference time is greater than the threshold time, the test will fail. By default, no threshold " |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 111 | "time is used.") |
| 112 | ("print-intermediate-layers,p", po::bool_switch()->default_value(false), |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 113 | "If this option is enabled, the output of every graph layer will be printed.") |
| 114 | ("enable-external-profiling,a", po::bool_switch()->default_value(false), |
| 115 | "If enabled external profiling will be switched on") |
Finn Williams | d7fcafa | 2020-04-23 17:55:18 +0100 | [diff] [blame] | 116 | ("timeline-profiling", po::bool_switch()->default_value(false), |
| 117 | "If enabled timeline profiling will be switched on, requires external profiling") |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 118 | ("outgoing-capture-file,j", po::value(&outgoingCaptureFile), |
| 119 | "If specified the outgoing external profiling packets will be captured in this binary file") |
| 120 | ("incoming-capture-file,k", po::value(&incomingCaptureFile), |
| 121 | "If specified the incoming external profiling packets will be captured in this binary file") |
| 122 | ("file-only-external-profiling,g", po::bool_switch()->default_value(false), |
| 123 | "If enabled then the 'file-only' test mode of external profiling will be enabled") |
| 124 | ("counter-capture-period,u", po::value<uint32_t>(&counterCapturePeriod)->default_value(150u), |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 125 | "If profiling is enabled in 'file-only' mode this is the capture period that will be used in the test") |
Finn Williams | 5061601 | 2020-05-13 17:19:14 +0100 | [diff] [blame] | 126 | ("file-format", po::value(&fileFormat)->default_value("binary"), |
Isabella Gottardi | a0687ee | 2020-03-11 18:04:20 +0000 | [diff] [blame] | 127 | "If profiling is enabled specifies the output file format") |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 128 | ("iterations", po::value<size_t>(&iterations)->default_value(1), |
| 129 | "Number of iterations to run the network for, default is set to 1") |
| 130 | ("tuning-path", po::value(&tuningPath), |
| 131 | "Path to tuning file. Enables use of CL tuning") |
| 132 | ("tuning-level", po::value<int>(&tuningLevel)->default_value(0), |
| 133 | "Sets the tuning level which enables a tuning run which will update/create a tuning file. " |
| 134 | "Available options are: 1 (Rapid), 2 (Normal), 3 (Exhaustive). " |
| 135 | "Requires tuning-path to be set, default is set to 0 (No tuning run)") |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 136 | ("parse-unsupported", po::bool_switch()->default_value(false), |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 137 | "Add unsupported operators as stand-in layers (where supported by parser)") |
| 138 | ("infer-output-shape", po::bool_switch()->default_value(false), |
| 139 | "Infers output tensor shape from input tensor shape and validate where applicable (where supported by " |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 140 | "parser)") |
Sadik Armagan | 283a8b4 | 2020-09-22 14:35:19 +0100 | [diff] [blame] | 141 | ("enable-fast-math", po::bool_switch()->default_value(false), |
Mike Kelly | fc6ab47 | 2020-10-08 12:19:01 +0100 | [diff] [blame] | 142 | "Enables fast_math options in backends that support it. Using the fast_math flag can lead to " |
| 143 | "performance improvements but may result in reduced or different precision."); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 144 | } |
| 145 | catch (const std::exception& e) |
| 146 | { |
| 147 | // Coverity points out that default_value(...) can throw a bad_lexical_cast, |
| 148 | // and that desc.add_options() can throw boost::io::too_few_args. |
| 149 | // They really won't in any of these cases. |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 150 | ARMNN_ASSERT_MSG(false, "Caught unexpected exception"); |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 151 | ARMNN_LOG(fatal) << "Fatal internal error: " << e.what(); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 152 | return EXIT_FAILURE; |
| 153 | } |
| 154 | |
| 155 | // Parses the command-line. |
| 156 | po::variables_map vm; |
| 157 | try |
| 158 | { |
| 159 | po::store(po::parse_command_line(argc, argv, desc), vm); |
| 160 | |
| 161 | if (CheckOption(vm, "help") || argc <= 1) |
| 162 | { |
| 163 | std::cout << "Executes a neural network model using the provided input tensor. " << std::endl; |
| 164 | std::cout << "Prints the resulting output tensor." << std::endl; |
| 165 | std::cout << std::endl; |
| 166 | std::cout << desc << std::endl; |
| 167 | return EXIT_SUCCESS; |
| 168 | } |
| 169 | |
| 170 | po::notify(vm); |
| 171 | } |
| 172 | catch (const po::error& e) |
| 173 | { |
| 174 | std::cerr << e.what() << std::endl << std::endl; |
| 175 | std::cerr << desc << std::endl; |
| 176 | return EXIT_FAILURE; |
| 177 | } |
| 178 | |
| 179 | // Get the value of the switch arguments. |
| 180 | bool concurrent = vm["concurrent"].as<bool>(); |
| 181 | bool enableProfiling = vm["event-based-profiling"].as<bool>(); |
Andre Ghattas | 23ae2ea | 2019-08-07 12:18:38 +0100 | [diff] [blame] | 182 | bool enableLayerDetails = vm["visualize-optimized-model"].as<bool>(); |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 183 | bool enableBf16TurboMode = vm["bf16-turbo-mode"].as<bool>(); |
Ruomei Yan | 2fcce08 | 2019-04-02 16:47:34 +0100 | [diff] [blame] | 184 | bool enableFp16TurboMode = vm["fp16-turbo-mode"].as<bool>(); |
Narumol Prangnawarat | 610256f | 2019-06-26 15:10:46 +0100 | [diff] [blame] | 185 | bool quantizeInput = vm["quantize-input"].as<bool>(); |
Georgios Pinitas | 50311ba | 2020-02-18 13:25:23 +0000 | [diff] [blame] | 186 | bool dequantizeOutput = vm["dequantize-output"].as<bool>(); |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 187 | bool printIntermediate = vm["print-intermediate-layers"].as<bool>(); |
Jim Flynn | 4951b8c | 2019-10-03 10:04:30 -0700 | [diff] [blame] | 188 | bool enableExternalProfiling = vm["enable-external-profiling"].as<bool>(); |
| 189 | bool fileOnlyExternalProfiling = vm["file-only-external-profiling"].as<bool>(); |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 190 | bool parseUnsupported = vm["parse-unsupported"].as<bool>(); |
Finn Williams | d7fcafa | 2020-04-23 17:55:18 +0100 | [diff] [blame] | 191 | bool timelineEnabled = vm["timeline-profiling"].as<bool>(); |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 192 | bool inferOutputShape = vm["infer-output-shape"].as<bool>(); |
Sadik Armagan | 283a8b4 | 2020-09-22 14:35:19 +0100 | [diff] [blame] | 193 | bool enableFastMath = vm["enable-fast-math"].as<bool>(); |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 194 | |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 195 | if (enableBf16TurboMode && enableFp16TurboMode) |
| 196 | { |
| 197 | ARMNN_LOG(fatal) << "BFloat16 and Float16 turbo mode cannot be enabled at the same time."; |
| 198 | return EXIT_FAILURE; |
| 199 | } |
| 200 | |
Finn Williams | d7fcafa | 2020-04-23 17:55:18 +0100 | [diff] [blame] | 201 | // Create runtime |
| 202 | armnn::IRuntime::CreationOptions options; |
| 203 | options.m_EnableGpuProfiling = enableProfiling; |
| 204 | options.m_DynamicBackendsPath = dynamicBackendsPath; |
| 205 | options.m_ProfilingOptions.m_EnableProfiling = enableExternalProfiling; |
| 206 | options.m_ProfilingOptions.m_IncomingCaptureFile = incomingCaptureFile; |
| 207 | options.m_ProfilingOptions.m_OutgoingCaptureFile = outgoingCaptureFile; |
| 208 | options.m_ProfilingOptions.m_FileOnly = fileOnlyExternalProfiling; |
| 209 | options.m_ProfilingOptions.m_CapturePeriod = counterCapturePeriod; |
| 210 | options.m_ProfilingOptions.m_FileFormat = fileFormat; |
| 211 | options.m_ProfilingOptions.m_TimelineEnabled = timelineEnabled; |
| 212 | |
| 213 | if (timelineEnabled && !enableExternalProfiling) |
| 214 | { |
| 215 | ARMNN_LOG(fatal) << "Timeline profiling requires external profiling to be turned on"; |
| 216 | return EXIT_FAILURE; |
| 217 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 218 | |
| 219 | // Check whether we have to load test cases from a file. |
| 220 | if (CheckOption(vm, "test-cases")) |
| 221 | { |
| 222 | // Check that the file exists. |
Francis Murtagh | 532a29d | 2020-06-29 11:50:01 +0100 | [diff] [blame] | 223 | if (!fs::exists(testCasesFile)) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 224 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 225 | ARMNN_LOG(fatal) << "Given file \"" << testCasesFile << "\" does not exist"; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 226 | return EXIT_FAILURE; |
| 227 | } |
| 228 | |
| 229 | // Parse CSV file and extract test cases |
| 230 | armnnUtils::CsvReader reader; |
| 231 | std::vector<armnnUtils::CsvRow> testCases = reader.ParseFile(testCasesFile); |
| 232 | |
| 233 | // Check that there is at least one test case to run |
| 234 | if (testCases.empty()) |
| 235 | { |
Derek Lamberti | 0844697 | 2019-11-26 16:38:31 +0000 | [diff] [blame] | 236 | ARMNN_LOG(fatal) << "Given file \"" << testCasesFile << "\" has no test cases"; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 237 | return EXIT_FAILURE; |
| 238 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 239 | // Create runtime |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 240 | std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options)); |
| 241 | |
| 242 | const std::string executableName("ExecuteNetwork"); |
| 243 | |
| 244 | // Check whether we need to run the test cases concurrently |
| 245 | if (concurrent) |
| 246 | { |
| 247 | std::vector<std::future<int>> results; |
| 248 | results.reserve(testCases.size()); |
| 249 | |
| 250 | // Run each test case in its own thread |
| 251 | for (auto& testCase : testCases) |
| 252 | { |
| 253 | testCase.values.insert(testCase.values.begin(), executableName); |
Nina Drozd | 549ae37 | 2018-09-10 14:26:44 +0100 | [diff] [blame] | 254 | results.push_back(std::async(std::launch::async, RunCsvTest, std::cref(testCase), std::cref(runtime), |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 255 | enableProfiling, enableFp16TurboMode, enableBf16TurboMode, thresholdTime, |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 256 | printIntermediate, enableLayerDetails, parseUnsupported, |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 257 | inferOutputShape, enableFastMath)); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Check results |
| 261 | for (auto& result : results) |
| 262 | { |
| 263 | if (result.get() != EXIT_SUCCESS) |
| 264 | { |
| 265 | return EXIT_FAILURE; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | else |
| 270 | { |
| 271 | // Run tests sequentially |
| 272 | for (auto& testCase : testCases) |
| 273 | { |
| 274 | testCase.values.insert(testCase.values.begin(), executableName); |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 275 | if (RunCsvTest(testCase, runtime, enableProfiling, |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 276 | enableFp16TurboMode, enableBf16TurboMode, thresholdTime, printIntermediate, |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 277 | enableLayerDetails, parseUnsupported, inferOutputShape, enableFastMath) != EXIT_SUCCESS) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 278 | { |
| 279 | return EXIT_FAILURE; |
| 280 | } |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | return EXIT_SUCCESS; |
| 285 | } |
| 286 | else // Run single test |
| 287 | { |
Aron Virginas-Tar | 382e21c | 2019-01-22 14:10:39 +0000 | [diff] [blame] | 288 | // Get the preferred order of compute devices. If none are specified, default to using CpuRef |
| 289 | const std::string computeOption("compute"); |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 290 | std::vector<std::string> computeDevicesAsStrings = |
| 291 | CheckOption(vm, computeOption.c_str()) ? |
| 292 | vm[computeOption].as<std::vector<std::string>>() : |
| 293 | std::vector<std::string>(); |
Matteo Martincigh | 067112f | 2018-10-29 11:01:09 +0000 | [diff] [blame] | 294 | std::vector<armnn::BackendId> computeDevices(computeDevicesAsStrings.begin(), computeDevicesAsStrings.end()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 295 | |
| 296 | // Remove duplicates from the list of compute devices. |
| 297 | RemoveDuplicateDevices(computeDevices); |
| 298 | |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 299 | #if defined(ARMCOMPUTECL_ENABLED) |
| 300 | std::shared_ptr<armnn::IGpuAccTunedParameters> tuned_params; |
| 301 | |
| 302 | if (tuningPath != "") |
| 303 | { |
| 304 | if (tuningLevel != 0) |
| 305 | { |
| 306 | RunCLTuning(tuningPath, tuningLevel, modelFormat, inputTensorShapes, computeDevices, |
| 307 | dynamicBackendsPath, modelPath, inputNames, inputTensorDataFilePaths, inputTypes, quantizeInput, |
| 308 | outputTypes, outputNames, outputTensorFiles, dequantizeOutput, enableProfiling, |
| 309 | enableFp16TurboMode, enableBf16TurboMode, thresholdTime, printIntermediate, subgraphId, |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 310 | enableLayerDetails, parseUnsupported, inferOutputShape, enableFastMath); |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 311 | } |
| 312 | ARMNN_LOG(info) << "Using tuning params: " << tuningPath << "\n"; |
| 313 | options.m_BackendOptions.emplace_back( |
| 314 | armnn::BackendOptions |
| 315 | { |
| 316 | "GpuAcc", |
| 317 | { |
| 318 | {"TuningLevel", 0}, |
| 319 | {"TuningFile", tuningPath.c_str()}, |
| 320 | {"KernelProfilingEnabled", enableProfiling} |
| 321 | } |
| 322 | } |
| 323 | ); |
| 324 | } |
| 325 | #endif |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 326 | try |
| 327 | { |
| 328 | CheckOptionDependencies(vm); |
| 329 | } |
| 330 | catch (const po::error& e) |
| 331 | { |
| 332 | std::cerr << e.what() << std::endl << std::endl; |
| 333 | std::cerr << desc << std::endl; |
| 334 | return EXIT_FAILURE; |
| 335 | } |
Colm Donelan | b682d84 | 2019-10-16 12:24:20 +0100 | [diff] [blame] | 336 | // Create runtime |
Colm Donelan | b682d84 | 2019-10-16 12:24:20 +0100 | [diff] [blame] | 337 | std::shared_ptr<armnn::IRuntime> runtime(armnn::IRuntime::Create(options)); |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 338 | |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 339 | return RunTest(modelFormat, inputTensorShapes, computeDevices, dynamicBackendsPath, modelPath, |
| 340 | inputNames, inputTensorDataFilePaths, inputTypes, quantizeInput, outputTypes, outputNames, |
| 341 | outputTensorFiles, dequantizeOutput, enableProfiling, enableFp16TurboMode, enableBf16TurboMode, |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 342 | thresholdTime, printIntermediate, subgraphId, enableLayerDetails, parseUnsupported, inferOutputShape, |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 343 | enableFastMath, iterations, runtime); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 344 | } |
| 345 | } |