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