telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. 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 | // |
| 5 | #pragma once |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 6 | #include <armnn/ArmNN.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 7 | |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 8 | #if defined(ARMNN_SERIALIZER) |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 9 | #include "armnnDeserializer/IDeserializer.hpp" |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 10 | #endif |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 11 | #if defined(ARMNN_TF_LITE_PARSER) |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 12 | #include <armnnTfLiteParser/ITfLiteParser.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 13 | #endif |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 14 | #if defined(ARMNN_ONNX_PARSER) |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 15 | #include <armnnOnnxParser/IOnnxParser.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 16 | #endif |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 18 | #include <HeapProfiling.hpp> |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 19 | #include <TensorIOUtils.hpp> |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 20 | |
David Beck | 1b61be5 | 2018-11-08 09:19:14 +0000 | [diff] [blame] | 21 | #include <backendsCommon/BackendRegistry.hpp> |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 22 | |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 23 | #include <boost/algorithm/string/join.hpp> |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 24 | #include <boost/exception/exception.hpp> |
| 25 | #include <boost/exception/diagnostic_information.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 26 | #include <boost/log/trivial.hpp> |
| 27 | #include <boost/format.hpp> |
| 28 | #include <boost/program_options.hpp> |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 29 | #include <boost/filesystem.hpp> |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 30 | #include <boost/lexical_cast.hpp> |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 31 | #include <boost/variant.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 32 | |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 33 | #include <algorithm> |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 34 | #include <chrono> |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 35 | #include <iterator> |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 36 | #include <fstream> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | #include <map> |
| 38 | #include <string> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 39 | #include <vector> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 40 | #include <type_traits> |
| 41 | |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 42 | namespace |
| 43 | { |
| 44 | |
| 45 | inline bool CheckRequestedBackendsAreValid(const std::vector<armnn::BackendId>& backendIds, |
| 46 | armnn::Optional<std::string&> invalidBackendIds = armnn::EmptyOptional()) |
| 47 | { |
| 48 | if (backendIds.empty()) |
| 49 | { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | armnn::BackendIdSet validBackendIds = armnn::BackendRegistryInstance().GetBackendIds(); |
| 54 | |
| 55 | bool allValid = true; |
| 56 | for (const auto& backendId : backendIds) |
| 57 | { |
| 58 | if (std::find(validBackendIds.begin(), validBackendIds.end(), backendId) == validBackendIds.end()) |
| 59 | { |
| 60 | allValid = false; |
| 61 | if (invalidBackendIds) |
| 62 | { |
| 63 | if (!invalidBackendIds.value().empty()) |
| 64 | { |
| 65 | invalidBackendIds.value() += ", "; |
| 66 | } |
| 67 | invalidBackendIds.value() += backendId; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | return allValid; |
| 72 | } |
| 73 | |
| 74 | } // anonymous namespace |
| 75 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 76 | namespace InferenceModelInternal |
| 77 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 78 | using BindingPointInfo = armnn::BindingPointInfo; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 79 | |
| 80 | using QuantizationParams = std::pair<float,int32_t>; |
| 81 | |
| 82 | struct Params |
| 83 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 84 | std::string m_ModelPath; |
| 85 | std::vector<std::string> m_InputBindings; |
| 86 | std::vector<armnn::TensorShape> m_InputShapes; |
| 87 | std::vector<std::string> m_OutputBindings; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 88 | std::vector<armnn::BackendId> m_ComputeDevices; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 89 | std::string m_DynamicBackendsPath; |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 90 | size_t m_SubgraphId; |
| 91 | bool m_IsModelBinary; |
| 92 | bool m_VisualizePostOptimizationModel; |
| 93 | bool m_EnableFp16TurboMode; |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 94 | bool m_PrintIntermediateLayers; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 95 | |
| 96 | Params() |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 97 | : m_ComputeDevices{} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 98 | , m_SubgraphId(0) |
| 99 | , m_IsModelBinary(true) |
| 100 | , m_VisualizePostOptimizationModel(false) |
| 101 | , m_EnableFp16TurboMode(false) |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 102 | , m_PrintIntermediateLayers(false) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 103 | {} |
| 104 | }; |
| 105 | |
| 106 | } // namespace InferenceModelInternal |
| 107 | |
| 108 | template <typename IParser> |
| 109 | struct CreateNetworkImpl |
| 110 | { |
| 111 | public: |
| 112 | using Params = InferenceModelInternal::Params; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 113 | |
| 114 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 115 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 116 | std::vector<armnn::BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 117 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 118 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 119 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 120 | // Create a network from a file on disk |
| 121 | auto parser(IParser::Create()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 122 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 123 | std::map<std::string, armnn::TensorShape> inputShapes; |
| 124 | if (!params.m_InputShapes.empty()) |
| 125 | { |
| 126 | const size_t numInputShapes = params.m_InputShapes.size(); |
| 127 | const size_t numInputBindings = params.m_InputBindings.size(); |
| 128 | if (numInputShapes < numInputBindings) |
| 129 | { |
| 130 | throw armnn::Exception(boost::str(boost::format( |
| 131 | "Not every input has its tensor shape specified: expected=%1%, got=%2%") |
| 132 | % numInputBindings % numInputShapes)); |
| 133 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 134 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 135 | for (size_t i = 0; i < numInputShapes; i++) |
| 136 | { |
| 137 | inputShapes[params.m_InputBindings[i]] = params.m_InputShapes[i]; |
| 138 | } |
| 139 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 140 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 141 | std::vector<std::string> requestedOutputs = params.m_OutputBindings; |
| 142 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
| 143 | |
| 144 | { |
| 145 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 146 | // Handle text and binary input differently by calling the corresponding parser function |
| 147 | network = (params.m_IsModelBinary ? |
| 148 | parser->CreateNetworkFromBinaryFile(modelPath.c_str(), inputShapes, requestedOutputs) : |
| 149 | parser->CreateNetworkFromTextFile(modelPath.c_str(), inputShapes, requestedOutputs)); |
| 150 | } |
| 151 | |
| 152 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 153 | { |
| 154 | inputBindings.push_back(parser->GetNetworkInputBindingInfo(inputLayerName)); |
| 155 | } |
| 156 | |
| 157 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 158 | { |
| 159 | outputBindings.push_back(parser->GetNetworkOutputBindingInfo(outputLayerName)); |
| 160 | } |
| 161 | |
| 162 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 163 | } |
| 164 | }; |
| 165 | |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 166 | #if defined(ARMNN_SERIALIZER) |
| 167 | template <> |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 168 | struct CreateNetworkImpl<armnnDeserializer::IDeserializer> |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 169 | { |
| 170 | public: |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 171 | using IParser = armnnDeserializer::IDeserializer; |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 172 | using Params = InferenceModelInternal::Params; |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 173 | |
| 174 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 175 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 176 | std::vector<armnn::BindingPointInfo>& outputBindings) |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 177 | { |
| 178 | auto parser(IParser::Create()); |
| 179 | BOOST_ASSERT(parser); |
| 180 | |
| 181 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
| 182 | |
| 183 | { |
| 184 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
Derek Lamberti | 2b183fb | 2019-02-18 16:36:57 +0000 | [diff] [blame] | 185 | |
| 186 | boost::system::error_code errorCode; |
| 187 | boost::filesystem::path pathToFile(params.m_ModelPath); |
| 188 | if (!boost::filesystem::exists(pathToFile, errorCode)) |
| 189 | { |
| 190 | throw armnn::FileNotFoundException(boost::str( |
| 191 | boost::format("Cannot find the file (%1%) errorCode: %2% %3%") % |
| 192 | params.m_ModelPath % |
| 193 | errorCode % |
| 194 | CHECK_LOCATION().AsString())); |
| 195 | } |
| 196 | std::ifstream file(params.m_ModelPath, std::ios::binary); |
| 197 | |
| 198 | network = parser->CreateNetworkFromBinary(file); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Derek Lamberti | ff05cc5 | 2019-04-26 13:05:17 +0100 | [diff] [blame] | 201 | unsigned int subgraphId = boost::numeric_cast<unsigned int>(params.m_SubgraphId); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 202 | |
| 203 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 204 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 205 | armnnDeserializer::BindingPointInfo inputBinding = |
Derek Lamberti | ff05cc5 | 2019-04-26 13:05:17 +0100 | [diff] [blame] | 206 | parser->GetNetworkInputBindingInfo(subgraphId, inputLayerName); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 207 | inputBindings.push_back(std::make_pair(inputBinding.m_BindingId, inputBinding.m_TensorInfo)); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 211 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 212 | armnnDeserializer::BindingPointInfo outputBinding = |
Derek Lamberti | ff05cc5 | 2019-04-26 13:05:17 +0100 | [diff] [blame] | 213 | parser->GetNetworkOutputBindingInfo(subgraphId, outputLayerName); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 214 | outputBindings.push_back(std::make_pair(outputBinding.m_BindingId, outputBinding.m_TensorInfo)); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | return network; |
| 218 | } |
| 219 | }; |
| 220 | #endif |
| 221 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 222 | #if defined(ARMNN_TF_LITE_PARSER) |
| 223 | template <> |
| 224 | struct CreateNetworkImpl<armnnTfLiteParser::ITfLiteParser> |
| 225 | { |
| 226 | public: |
| 227 | using IParser = armnnTfLiteParser::ITfLiteParser; |
| 228 | using Params = InferenceModelInternal::Params; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 229 | |
| 230 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 231 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 232 | std::vector<armnn::BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 233 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 234 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 235 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 236 | // Create a network from a file on disk |
| 237 | auto parser(IParser::Create()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 238 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 239 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 240 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 241 | { |
| 242 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 243 | network = parser->CreateNetworkFromBinaryFile(modelPath.c_str()); |
| 244 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 245 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 246 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 247 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 248 | armnn::BindingPointInfo inputBinding = |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 249 | parser->GetNetworkInputBindingInfo(params.m_SubgraphId, inputLayerName); |
| 250 | inputBindings.push_back(inputBinding); |
| 251 | } |
| 252 | |
| 253 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 254 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 255 | armnn::BindingPointInfo outputBinding = |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 256 | parser->GetNetworkOutputBindingInfo(params.m_SubgraphId, outputLayerName); |
| 257 | outputBindings.push_back(outputBinding); |
| 258 | } |
| 259 | |
| 260 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 261 | } |
| 262 | }; |
| 263 | #endif |
| 264 | |
| 265 | #if defined(ARMNN_ONNX_PARSER) |
| 266 | template <> |
| 267 | struct CreateNetworkImpl<armnnOnnxParser::IOnnxParser> |
| 268 | { |
| 269 | public: |
| 270 | using IParser = armnnOnnxParser::IOnnxParser; |
| 271 | using Params = InferenceModelInternal::Params; |
| 272 | using BindingPointInfo = InferenceModelInternal::BindingPointInfo; |
| 273 | |
| 274 | static armnn::INetworkPtr Create(const Params& params, |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 275 | std::vector<BindingPointInfo>& inputBindings, |
| 276 | std::vector<BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 277 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 278 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 279 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 280 | // Create a network from a file on disk |
| 281 | auto parser(IParser::Create()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 282 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 283 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 284 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 285 | { |
| 286 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 287 | network = (params.m_IsModelBinary ? |
| 288 | parser->CreateNetworkFromBinaryFile(modelPath.c_str()) : |
| 289 | parser->CreateNetworkFromTextFile(modelPath.c_str())); |
| 290 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 291 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 292 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 293 | { |
| 294 | BindingPointInfo inputBinding = parser->GetNetworkInputBindingInfo(inputLayerName); |
| 295 | inputBindings.push_back(inputBinding); |
| 296 | } |
| 297 | |
| 298 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 299 | { |
| 300 | BindingPointInfo outputBinding = parser->GetNetworkOutputBindingInfo(outputLayerName); |
| 301 | outputBindings.push_back(outputBinding); |
| 302 | } |
| 303 | |
| 304 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 305 | } |
| 306 | }; |
| 307 | #endif |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 308 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 309 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 310 | |
| 311 | template <typename IParser, typename TDataType> |
| 312 | class InferenceModel |
| 313 | { |
| 314 | public: |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 315 | using DataType = TDataType; |
| 316 | using Params = InferenceModelInternal::Params; |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 317 | using QuantizationParams = InferenceModelInternal::QuantizationParams; |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 318 | using TContainer = boost::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>>; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 319 | |
| 320 | struct CommandLineOptions |
| 321 | { |
| 322 | std::string m_ModelDir; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 323 | std::vector<std::string> m_ComputeDevices; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 324 | std::string m_DynamicBackendsPath; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 325 | bool m_VisualizePostOptimizationModel; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 326 | bool m_EnableFp16TurboMode; |
Pablo Tello | 507f39d | 2019-04-15 15:44:39 +0100 | [diff] [blame] | 327 | std::string m_Labels; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 328 | |
| 329 | std::vector<armnn::BackendId> GetComputeDevicesAsBackendIds() |
| 330 | { |
| 331 | std::vector<armnn::BackendId> backendIds; |
| 332 | std::copy(m_ComputeDevices.begin(), m_ComputeDevices.end(), std::back_inserter(backendIds)); |
| 333 | return backendIds; |
| 334 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 335 | }; |
| 336 | |
| 337 | static void AddCommandLineOptions(boost::program_options::options_description& desc, CommandLineOptions& options) |
| 338 | { |
| 339 | namespace po = boost::program_options; |
| 340 | |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 341 | const std::vector<std::string> defaultComputes = { "CpuAcc", "CpuRef" }; |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 342 | |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 343 | const std::string backendsMessage = "Which device to run layers on by default. Possible choices: " |
| 344 | + armnn::BackendRegistryInstance().GetBackendIdsAsString(); |
| 345 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 346 | desc.add_options() |
| 347 | ("model-dir,m", po::value<std::string>(&options.m_ModelDir)->required(), |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 348 | "Path to directory containing model files (.caffemodel/.prototxt/.tflite)") |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 349 | ("compute,c", po::value<std::vector<std::string>>(&options.m_ComputeDevices)-> |
| 350 | default_value(defaultComputes, boost::algorithm::join(defaultComputes, ", "))-> |
| 351 | multitoken(), backendsMessage.c_str()) |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 352 | ("dynamic-backends-path,b", po::value(&options.m_DynamicBackendsPath), |
| 353 | "Path where to load any available dynamic backend from. " |
| 354 | "If left empty (the default), dynamic backends will not be used.") |
Pablo Tello | 507f39d | 2019-04-15 15:44:39 +0100 | [diff] [blame] | 355 | ("labels,l", po::value<std::string>(&options.m_Labels), |
| 356 | "Text file containing one image filename - correct label pair per line, " |
| 357 | "used to test the accuracy of the network.") |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 358 | ("visualize-optimized-model,v", |
| 359 | po::value<bool>(&options.m_VisualizePostOptimizationModel)->default_value(false), |
| 360 | "Produce a dot file useful for visualizing the graph post optimization." |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 361 | "The file will have the same name as the model with the .dot extention.") |
| 362 | ("fp16-turbo-mode", po::value<bool>(&options.m_EnableFp16TurboMode)->default_value(false), |
| 363 | "If this option is enabled FP32 layers, weights and biases will be converted " |
| 364 | "to FP16 where the backend supports it."); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 365 | } |
| 366 | |
Matthew Bentham | 3e68b97 | 2019-04-09 13:10:46 +0100 | [diff] [blame] | 367 | InferenceModel(const Params& params, |
| 368 | bool enableProfiling, |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 369 | const std::string& dynamicBackendsPath, |
Matthew Bentham | 3e68b97 | 2019-04-09 13:10:46 +0100 | [diff] [blame] | 370 | const std::shared_ptr<armnn::IRuntime>& runtime = nullptr) |
| 371 | : m_EnableProfiling(enableProfiling) |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 372 | , m_DynamicBackendsPath(dynamicBackendsPath) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 373 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 374 | if (runtime) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 375 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 376 | m_Runtime = runtime; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 377 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 378 | else |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 379 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 380 | armnn::IRuntime::CreationOptions options; |
Nina Drozd | 549ae37 | 2018-09-10 14:26:44 +0100 | [diff] [blame] | 381 | options.m_EnableGpuProfiling = m_EnableProfiling; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 382 | options.m_DynamicBackendsPath = m_DynamicBackendsPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 383 | m_Runtime = std::move(armnn::IRuntime::Create(options)); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 384 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 385 | |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 386 | std::string invalidBackends; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 387 | if (!CheckRequestedBackendsAreValid(params.m_ComputeDevices, armnn::Optional<std::string&>(invalidBackends))) |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 388 | { |
| 389 | throw armnn::Exception("Some backend IDs are invalid: " + invalidBackends); |
| 390 | } |
| 391 | |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 392 | armnn::INetworkPtr network = CreateNetworkImpl<IParser>::Create(params, m_InputBindings, m_OutputBindings); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 393 | |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 394 | armnn::IOptimizedNetworkPtr optNet{nullptr, [](armnn::IOptimizedNetwork*){}}; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 395 | { |
| 396 | ARMNN_SCOPED_HEAP_PROFILING("Optimizing"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 397 | |
| 398 | armnn::OptimizerOptions options; |
| 399 | options.m_ReduceFp32ToFp16 = params.m_EnableFp16TurboMode; |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 400 | options.m_Debug = params.m_PrintIntermediateLayers; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 401 | |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 402 | optNet = armnn::Optimize(*network, params.m_ComputeDevices, m_Runtime->GetDeviceSpec(), options); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 403 | if (!optNet) |
| 404 | { |
| 405 | throw armnn::Exception("Optimize returned nullptr"); |
| 406 | } |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 407 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 408 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 409 | if (params.m_VisualizePostOptimizationModel) |
| 410 | { |
| 411 | boost::filesystem::path filename = params.m_ModelPath; |
| 412 | filename.replace_extension("dot"); |
Rob Hughes | 9e10c2b | 2019-07-23 15:37:19 +0100 | [diff] [blame] | 413 | std::fstream file(filename.c_str(), std::ios_base::out); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 414 | optNet->SerializeToDot(file); |
| 415 | } |
| 416 | |
| 417 | armnn::Status ret; |
| 418 | { |
| 419 | ARMNN_SCOPED_HEAP_PROFILING("LoadNetwork"); |
| 420 | ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, std::move(optNet)); |
| 421 | } |
| 422 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 423 | if (ret == armnn::Status::Failure) |
| 424 | { |
| 425 | throw armnn::Exception("IRuntime::LoadNetwork failed"); |
| 426 | } |
| 427 | } |
| 428 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 429 | void CheckInputIndexIsValid(unsigned int inputIndex) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 430 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 431 | if (m_InputBindings.size() < inputIndex + 1) |
| 432 | { |
| 433 | throw armnn::Exception(boost::str(boost::format("Input index out of range: %1%") % inputIndex)); |
| 434 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 437 | void CheckOutputIndexIsValid(unsigned int outputIndex) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 438 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 439 | if (m_OutputBindings.size() < outputIndex + 1) |
| 440 | { |
| 441 | throw armnn::Exception(boost::str(boost::format("Output index out of range: %1%") % outputIndex)); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | unsigned int GetOutputSize(unsigned int outputIndex = 0u) const |
| 446 | { |
| 447 | CheckOutputIndexIsValid(outputIndex); |
| 448 | return m_OutputBindings[outputIndex].second.GetNumElements(); |
| 449 | } |
| 450 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 451 | std::chrono::duration<double, std::milli> Run( |
| 452 | const std::vector<TContainer>& inputContainers, |
| 453 | std::vector<TContainer>& outputContainers) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 454 | { |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 455 | for (unsigned int i = 0; i < outputContainers.size(); ++i) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 456 | { |
| 457 | const unsigned int expectedOutputDataSize = GetOutputSize(i); |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 458 | |
| 459 | boost::apply_visitor([expectedOutputDataSize, i](auto&& value) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 460 | { |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 461 | const unsigned int actualOutputDataSize = boost::numeric_cast<unsigned int>(value.size()); |
| 462 | if (actualOutputDataSize < expectedOutputDataSize) |
| 463 | { |
| 464 | unsigned int outputIndex = boost::numeric_cast<unsigned int>(i); |
| 465 | throw armnn::Exception( |
| 466 | boost::str(boost::format("Not enough data for output #%1%: expected " |
| 467 | "%2% elements, got %3%") % outputIndex % expectedOutputDataSize % actualOutputDataSize)); |
| 468 | } |
| 469 | }, |
| 470 | outputContainers[i]); |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 471 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 472 | |
| 473 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkIdentifier); |
| 474 | if (profiler) |
| 475 | { |
| 476 | profiler->EnableProfiling(m_EnableProfiling); |
| 477 | } |
| 478 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 479 | // Start timer to record inference time in EnqueueWorkload (in milliseconds) |
| 480 | const auto start_time = GetCurrentTime(); |
| 481 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 482 | armnn::Status ret = m_Runtime->EnqueueWorkload(m_NetworkIdentifier, |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 483 | MakeInputTensors(inputContainers), |
| 484 | MakeOutputTensors(outputContainers)); |
Sadik Armagan | 2b7a158 | 2018-09-05 16:33:58 +0100 | [diff] [blame] | 485 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 486 | const auto end_time = GetCurrentTime(); |
| 487 | |
Sadik Armagan | 2b7a158 | 2018-09-05 16:33:58 +0100 | [diff] [blame] | 488 | // if profiling is enabled print out the results |
| 489 | if (profiler && profiler->IsProfilingEnabled()) |
| 490 | { |
| 491 | profiler->Print(std::cout); |
| 492 | } |
| 493 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 494 | if (ret == armnn::Status::Failure) |
| 495 | { |
| 496 | throw armnn::Exception("IRuntime::EnqueueWorkload failed"); |
| 497 | } |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 498 | else |
| 499 | { |
| 500 | return std::chrono::duration<double, std::milli>(end_time - start_time); |
| 501 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 504 | const armnn::BindingPointInfo& GetInputBindingInfo(unsigned int inputIndex = 0u) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 505 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 506 | CheckInputIndexIsValid(inputIndex); |
| 507 | return m_InputBindings[inputIndex]; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 510 | const std::vector<armnn::BindingPointInfo>& GetInputBindingInfos() const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 511 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 512 | return m_InputBindings; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 515 | const armnn::BindingPointInfo& GetOutputBindingInfo(unsigned int outputIndex = 0u) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 516 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 517 | CheckOutputIndexIsValid(outputIndex); |
| 518 | return m_OutputBindings[outputIndex]; |
| 519 | } |
| 520 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 521 | const std::vector<armnn::BindingPointInfo>& GetOutputBindingInfos() const |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 522 | { |
| 523 | return m_OutputBindings; |
| 524 | } |
| 525 | |
| 526 | QuantizationParams GetQuantizationParams(unsigned int outputIndex = 0u) const |
| 527 | { |
| 528 | CheckOutputIndexIsValid(outputIndex); |
| 529 | return std::make_pair(m_OutputBindings[outputIndex].second.GetQuantizationScale(), |
| 530 | m_OutputBindings[outputIndex].second.GetQuantizationOffset()); |
| 531 | } |
| 532 | |
Narumol Prangnawarat | 4628d05 | 2019-02-25 17:26:05 +0000 | [diff] [blame] | 533 | QuantizationParams GetInputQuantizationParams(unsigned int inputIndex = 0u) const |
| 534 | { |
| 535 | CheckInputIndexIsValid(inputIndex); |
| 536 | return std::make_pair(m_InputBindings[inputIndex].second.GetQuantizationScale(), |
| 537 | m_InputBindings[inputIndex].second.GetQuantizationOffset()); |
| 538 | } |
| 539 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 540 | std::vector<QuantizationParams> GetAllQuantizationParams() const |
| 541 | { |
| 542 | std::vector<QuantizationParams> quantizationParams; |
| 543 | for (unsigned int i = 0u; i < m_OutputBindings.size(); i++) |
| 544 | { |
| 545 | quantizationParams.push_back(GetQuantizationParams(i)); |
| 546 | } |
| 547 | return quantizationParams; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 548 | } |
| 549 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 550 | private: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 551 | armnn::NetworkId m_NetworkIdentifier; |
| 552 | std::shared_ptr<armnn::IRuntime> m_Runtime; |
| 553 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 554 | std::vector<armnn::BindingPointInfo> m_InputBindings; |
| 555 | std::vector<armnn::BindingPointInfo> m_OutputBindings; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 556 | bool m_EnableProfiling; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 557 | std::string m_DynamicBackendsPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 558 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 559 | template<typename TContainer> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 560 | armnn::InputTensors MakeInputTensors(const std::vector<TContainer>& inputDataContainers) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 561 | { |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 562 | return armnnUtils::MakeInputTensors(m_InputBindings, inputDataContainers); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | template<typename TContainer> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 566 | armnn::OutputTensors MakeOutputTensors(std::vector<TContainer>& outputDataContainers) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 567 | { |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 568 | return armnnUtils::MakeOutputTensors(m_OutputBindings, outputDataContainers); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 569 | } |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 570 | |
| 571 | std::chrono::high_resolution_clock::time_point GetCurrentTime() |
| 572 | { |
| 573 | return std::chrono::high_resolution_clock::now(); |
| 574 | } |
| 575 | |
| 576 | std::chrono::duration<double, std::milli> GetTimeDuration( |
| 577 | std::chrono::high_resolution_clock::time_point& start_time, |
| 578 | std::chrono::high_resolution_clock::time_point& end_time) |
| 579 | { |
| 580 | return std::chrono::duration<double, std::milli>(end_time - start_time); |
| 581 | } |
| 582 | |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 583 | }; |