telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
Nikhil Raj Arm | 1a7f033 | 2022-07-05 09:29:18 +0000 | [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 | // |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 5 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 6 | #pragma once |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 7 | |
David Monahan | 6bb47a7 | 2021-10-22 12:57:28 +0100 | [diff] [blame] | 8 | |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 9 | #include <armnn/ArmNN.hpp> |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 10 | #include <armnn/Threadpool.hpp> |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 11 | #include <armnn/Logging.hpp> |
| 12 | #include <armnn/utility/Timer.hpp> |
Matteo Martincigh | c601aa6 | 2019-10-29 15:03:22 +0000 | [diff] [blame] | 13 | #include <armnn/BackendRegistry.hpp> |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 14 | #include <armnn/utility/Assert.hpp> |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 15 | #include <armnn/utility/NumericCast.hpp> |
Francis Murtagh | 40d2741 | 2021-10-28 11:11:35 +0100 | [diff] [blame] | 16 | |
| 17 | #include <armnnUtils/TContainer.hpp> |
| 18 | |
Nikhil Raj | 7dcc697 | 2021-04-30 15:44:24 +0100 | [diff] [blame] | 19 | #include <common/include/ProfilingGuid.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 20 | |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 21 | #if defined(ARMNN_SERIALIZER) |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 22 | #include "armnnDeserializer/IDeserializer.hpp" |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 23 | #endif |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 24 | #if defined(ARMNN_TF_LITE_PARSER) |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 25 | #include <armnnTfLiteParser/ITfLiteParser.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 26 | #endif |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 27 | #if defined(ARMNN_ONNX_PARSER) |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 28 | #include <armnnOnnxParser/IOnnxParser.hpp> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 29 | #endif |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 30 | |
Rob Hughes | 9542f90 | 2021-07-14 09:48:54 +0100 | [diff] [blame] | 31 | #include <armnnUtils/Filesystem.hpp> |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 32 | #include <HeapProfiling.hpp> |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 33 | #include <TensorIOUtils.hpp> |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 34 | |
David Monahan | a8837bf | 2020-04-16 10:01:56 +0100 | [diff] [blame] | 35 | #include "armnn/utility/StringUtils.hpp" |
James Ward | c89829f | 2020-10-12 14:17:36 +0100 | [diff] [blame] | 36 | #include <cxxopts/cxxopts.hpp> |
| 37 | #include "CxxoptsUtils.hpp" |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 38 | #include <fmt/format.h> |
James Ward | 6d9f5c5 | 2020-09-28 11:56:35 +0100 | [diff] [blame] | 39 | #include <mapbox/variant.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 40 | |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 41 | #include <algorithm> |
| 42 | #include <iterator> |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 43 | #include <fstream> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 44 | #include <map> |
| 45 | #include <string> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 46 | #include <vector> |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 47 | #include <type_traits> |
| 48 | |
Nikhil Raj Arm | 1a7f033 | 2022-07-05 09:29:18 +0000 | [diff] [blame] | 49 | namespace |
| 50 | { |
| 51 | |
| 52 | inline bool CheckRequestedBackendsAreValid(const std::vector<armnn::BackendId>& backendIds, |
| 53 | armnn::Optional<std::string&> invalidBackendIds = armnn::EmptyOptional()) |
| 54 | { |
| 55 | if (backendIds.empty()) |
| 56 | { |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | armnn::BackendIdSet validBackendIds = armnn::BackendRegistryInstance().GetBackendIds(); |
| 61 | |
| 62 | bool allValid = true; |
| 63 | for (const auto& backendId : backendIds) |
| 64 | { |
| 65 | if (std::find(validBackendIds.begin(), validBackendIds.end(), backendId) == validBackendIds.end()) |
| 66 | { |
| 67 | allValid = false; |
| 68 | if (invalidBackendIds) |
| 69 | { |
| 70 | if (!invalidBackendIds.value().empty()) |
| 71 | { |
| 72 | invalidBackendIds.value() += ", "; |
| 73 | } |
| 74 | invalidBackendIds.value() += backendId; |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | return allValid; |
| 79 | } |
| 80 | |
| 81 | } // anonymous namespace |
| 82 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 83 | namespace InferenceModelInternal |
| 84 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 85 | using BindingPointInfo = armnn::BindingPointInfo; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 86 | |
| 87 | using QuantizationParams = std::pair<float,int32_t>; |
| 88 | |
| 89 | struct Params |
| 90 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 91 | std::string m_ModelPath; |
| 92 | std::vector<std::string> m_InputBindings; |
| 93 | std::vector<armnn::TensorShape> m_InputShapes; |
| 94 | std::vector<std::string> m_OutputBindings; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 95 | std::vector<armnn::BackendId> m_ComputeDevices; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 96 | std::string m_DynamicBackendsPath; |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 97 | size_t m_SubgraphId; |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 98 | bool m_AllowExpandedDims; |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 99 | bool m_IsModelBinary; |
| 100 | bool m_VisualizePostOptimizationModel; |
| 101 | bool m_EnableFp16TurboMode; |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 102 | bool m_EnableBf16TurboMode; |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 103 | bool m_PrintIntermediateLayers; |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 104 | bool m_ParseUnsupported; |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 105 | bool m_InferOutputShape; |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 106 | bool m_EnableFastMath; |
Matthew Sloyan | 4243211 | 2021-01-08 10:30:51 +0000 | [diff] [blame] | 107 | bool m_SaveCachedNetwork; |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 108 | bool m_OutputDetailsToStdOut; |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 109 | bool m_OutputDetailsOnlyToStdOut; |
Matthew Sloyan | 4243211 | 2021-01-08 10:30:51 +0000 | [diff] [blame] | 110 | std::string m_CachedNetworkFilePath; |
Matthew Sloyan | 0a7dc6b | 2021-02-10 16:50:53 +0000 | [diff] [blame] | 111 | unsigned int m_NumberOfThreads; |
Finn Williams | 4064632 | 2021-02-11 16:16:42 +0000 | [diff] [blame] | 112 | std::string m_MLGOTuningFilePath; |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 113 | bool m_AsyncEnabled; |
Kevin May | b4b3ac9 | 2021-05-21 16:42:21 +0100 | [diff] [blame] | 114 | size_t m_ThreadPoolSize; |
Jim Flynn | 1542581 | 2022-02-15 16:53:13 +0000 | [diff] [blame] | 115 | bool m_ImportInputsIfAligned; |
Finn Williams | 4064632 | 2021-02-11 16:16:42 +0000 | [diff] [blame] | 116 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 117 | |
| 118 | Params() |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 119 | : m_ComputeDevices{} |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 120 | , m_SubgraphId(0) |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 121 | , m_AllowExpandedDims(false) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 122 | , m_IsModelBinary(true) |
| 123 | , m_VisualizePostOptimizationModel(false) |
| 124 | , m_EnableFp16TurboMode(false) |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 125 | , m_EnableBf16TurboMode(false) |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 126 | , m_PrintIntermediateLayers(false) |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 127 | , m_ParseUnsupported(false) |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 128 | , m_InferOutputShape(false) |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 129 | , m_EnableFastMath(false) |
Matthew Sloyan | 4243211 | 2021-01-08 10:30:51 +0000 | [diff] [blame] | 130 | , m_SaveCachedNetwork(false) |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 131 | , m_OutputDetailsToStdOut(false) |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 132 | , m_OutputDetailsOnlyToStdOut(false) |
Matthew Sloyan | 4243211 | 2021-01-08 10:30:51 +0000 | [diff] [blame] | 133 | , m_CachedNetworkFilePath("") |
Matthew Sloyan | 0a7dc6b | 2021-02-10 16:50:53 +0000 | [diff] [blame] | 134 | , m_NumberOfThreads(0) |
Finn Williams | 4064632 | 2021-02-11 16:16:42 +0000 | [diff] [blame] | 135 | , m_MLGOTuningFilePath("") |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 136 | , m_AsyncEnabled(false) |
Kevin May | 94dd4db | 2021-05-26 16:01:08 +0100 | [diff] [blame] | 137 | , m_ThreadPoolSize(0) |
Jim Flynn | 1542581 | 2022-02-15 16:53:13 +0000 | [diff] [blame] | 138 | , m_ImportInputsIfAligned(false) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 139 | {} |
| 140 | }; |
| 141 | |
| 142 | } // namespace InferenceModelInternal |
| 143 | |
| 144 | template <typename IParser> |
| 145 | struct CreateNetworkImpl |
| 146 | { |
| 147 | public: |
| 148 | using Params = InferenceModelInternal::Params; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 149 | |
| 150 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 151 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 152 | std::vector<armnn::BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 153 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 154 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 155 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 156 | // Create a network from a file on disk |
| 157 | auto parser(IParser::Create()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 158 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 159 | std::map<std::string, armnn::TensorShape> inputShapes; |
| 160 | if (!params.m_InputShapes.empty()) |
| 161 | { |
| 162 | const size_t numInputShapes = params.m_InputShapes.size(); |
| 163 | const size_t numInputBindings = params.m_InputBindings.size(); |
| 164 | if (numInputShapes < numInputBindings) |
| 165 | { |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 166 | throw armnn::Exception(fmt::format( |
| 167 | "Not every input has its tensor shape specified: expected={0}, got={1}", |
| 168 | numInputBindings, numInputShapes)); |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 169 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 170 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 171 | for (size_t i = 0; i < numInputShapes; i++) |
| 172 | { |
| 173 | inputShapes[params.m_InputBindings[i]] = params.m_InputShapes[i]; |
| 174 | } |
| 175 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 176 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 177 | std::vector<std::string> requestedOutputs = params.m_OutputBindings; |
| 178 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
| 179 | |
| 180 | { |
| 181 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 182 | // Handle text and binary input differently by calling the corresponding parser function |
| 183 | network = (params.m_IsModelBinary ? |
| 184 | parser->CreateNetworkFromBinaryFile(modelPath.c_str(), inputShapes, requestedOutputs) : |
| 185 | parser->CreateNetworkFromTextFile(modelPath.c_str(), inputShapes, requestedOutputs)); |
| 186 | } |
| 187 | |
| 188 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 189 | { |
| 190 | inputBindings.push_back(parser->GetNetworkInputBindingInfo(inputLayerName)); |
| 191 | } |
| 192 | |
| 193 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 194 | { |
| 195 | outputBindings.push_back(parser->GetNetworkOutputBindingInfo(outputLayerName)); |
| 196 | } |
| 197 | |
| 198 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 199 | } |
| 200 | }; |
| 201 | |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 202 | #if defined(ARMNN_SERIALIZER) |
| 203 | template <> |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 204 | struct CreateNetworkImpl<armnnDeserializer::IDeserializer> |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 205 | { |
| 206 | public: |
Derek Lamberti | 0028d1b | 2019-02-20 13:57:42 +0000 | [diff] [blame] | 207 | using IParser = armnnDeserializer::IDeserializer; |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 208 | using Params = InferenceModelInternal::Params; |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 209 | |
| 210 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 211 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 212 | std::vector<armnn::BindingPointInfo>& outputBindings) |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 213 | { |
| 214 | auto parser(IParser::Create()); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 215 | ARMNN_ASSERT(parser); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 216 | |
| 217 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
| 218 | |
| 219 | { |
| 220 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
Derek Lamberti | 2b183fb | 2019-02-18 16:36:57 +0000 | [diff] [blame] | 221 | |
Francis Murtagh | 532a29d | 2020-06-29 11:50:01 +0100 | [diff] [blame] | 222 | std::error_code errorCode; |
| 223 | fs::path pathToFile(params.m_ModelPath); |
| 224 | if (!fs::exists(pathToFile, errorCode)) |
Derek Lamberti | 2b183fb | 2019-02-18 16:36:57 +0000 | [diff] [blame] | 225 | { |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 226 | throw armnn::FileNotFoundException(fmt::format("Cannot find the file ({0}) errorCode: {1} {2}", |
| 227 | params.m_ModelPath, |
| 228 | errorCode.message(), |
Derek Lamberti | 2b183fb | 2019-02-18 16:36:57 +0000 | [diff] [blame] | 229 | CHECK_LOCATION().AsString())); |
| 230 | } |
| 231 | std::ifstream file(params.m_ModelPath, std::ios::binary); |
| 232 | |
| 233 | network = parser->CreateNetworkFromBinary(file); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 236 | unsigned int subgraphId = armnn::numeric_cast<unsigned int>(params.m_SubgraphId); |
Aron Virginas-Tar | 64e4ccb | 2019-02-12 11:27:53 +0000 | [diff] [blame] | 237 | |
| 238 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 239 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 240 | armnnDeserializer::BindingPointInfo inputBinding = |
Derek Lamberti | ff05cc5 | 2019-04-26 13:05:17 +0100 | [diff] [blame] | 241 | parser->GetNetworkInputBindingInfo(subgraphId, inputLayerName); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 242 | 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] | 243 | } |
| 244 | |
| 245 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 246 | { |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 247 | armnnDeserializer::BindingPointInfo outputBinding = |
Derek Lamberti | ff05cc5 | 2019-04-26 13:05:17 +0100 | [diff] [blame] | 248 | parser->GetNetworkOutputBindingInfo(subgraphId, outputLayerName); |
Derek Lamberti | 8ddae33 | 2019-02-21 16:29:43 +0000 | [diff] [blame] | 249 | 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] | 250 | } |
| 251 | |
| 252 | return network; |
| 253 | } |
| 254 | }; |
| 255 | #endif |
| 256 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 257 | #if defined(ARMNN_TF_LITE_PARSER) |
| 258 | template <> |
| 259 | struct CreateNetworkImpl<armnnTfLiteParser::ITfLiteParser> |
| 260 | { |
| 261 | public: |
| 262 | using IParser = armnnTfLiteParser::ITfLiteParser; |
| 263 | using Params = InferenceModelInternal::Params; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 264 | |
| 265 | static armnn::INetworkPtr Create(const Params& params, |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 266 | std::vector<armnn::BindingPointInfo>& inputBindings, |
| 267 | std::vector<armnn::BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 268 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 269 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 270 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 271 | // Create a network from a file on disk |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 272 | IParser::TfLiteParserOptions options; |
Mike Kelly | 80512b0 | 2022-05-16 23:10:42 +0100 | [diff] [blame] | 273 | options.m_AllowExpandedDims = params.m_AllowExpandedDims; |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 274 | options.m_StandInLayerForUnsupported = params.m_ParseUnsupported; |
Sadik Armagan | a9c2ce1 | 2020-07-14 10:02:22 +0100 | [diff] [blame] | 275 | options.m_InferAndValidate = params.m_InferOutputShape; |
Derek Lamberti | 132563c | 2019-12-02 16:06:40 +0000 | [diff] [blame] | 276 | auto parser(IParser::Create(options)); |
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 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
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 | { |
| 281 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 282 | network = parser->CreateNetworkFromBinaryFile(modelPath.c_str()); |
| 283 | } |
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 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 286 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 287 | armnn::BindingPointInfo inputBinding = |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 288 | parser->GetNetworkInputBindingInfo(params.m_SubgraphId, inputLayerName); |
| 289 | inputBindings.push_back(inputBinding); |
| 290 | } |
| 291 | |
| 292 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 293 | { |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 294 | armnn::BindingPointInfo outputBinding = |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 295 | parser->GetNetworkOutputBindingInfo(params.m_SubgraphId, outputLayerName); |
| 296 | outputBindings.push_back(outputBinding); |
| 297 | } |
| 298 | |
| 299 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 300 | } |
| 301 | }; |
| 302 | #endif |
| 303 | |
| 304 | #if defined(ARMNN_ONNX_PARSER) |
| 305 | template <> |
| 306 | struct CreateNetworkImpl<armnnOnnxParser::IOnnxParser> |
| 307 | { |
| 308 | public: |
| 309 | using IParser = armnnOnnxParser::IOnnxParser; |
| 310 | using Params = InferenceModelInternal::Params; |
| 311 | using BindingPointInfo = InferenceModelInternal::BindingPointInfo; |
| 312 | |
| 313 | static armnn::INetworkPtr Create(const Params& params, |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 314 | std::vector<BindingPointInfo>& inputBindings, |
| 315 | std::vector<BindingPointInfo>& outputBindings) |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 316 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 317 | const std::string& modelPath = params.m_ModelPath; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 318 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 319 | // Create a network from a file on disk |
| 320 | auto parser(IParser::Create()); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 321 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 322 | armnn::INetworkPtr network{nullptr, [](armnn::INetwork *){}}; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 323 | |
Narumol Prangnawarat | 1b11f32 | 2021-10-13 11:44:50 +0100 | [diff] [blame] | 324 | std::map<std::string, armnn::TensorShape> inputShapes; |
| 325 | if (!params.m_InputShapes.empty()) |
| 326 | { |
| 327 | const size_t numInputShapes = params.m_InputShapes.size(); |
| 328 | const size_t numInputBindings = params.m_InputBindings.size(); |
| 329 | if (numInputShapes < numInputBindings) |
| 330 | { |
| 331 | throw armnn::Exception(fmt::format( |
| 332 | "Not every input has its tensor shape specified: expected={0}, got={1}", |
| 333 | numInputBindings, numInputShapes)); |
| 334 | } |
| 335 | |
| 336 | for (size_t i = 0; i < numInputShapes; i++) |
| 337 | { |
| 338 | inputShapes[params.m_InputBindings[i]] = params.m_InputShapes[i]; |
| 339 | } |
| 340 | |
| 341 | { |
| 342 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 343 | network = (params.m_IsModelBinary ? |
| 344 | parser->CreateNetworkFromBinaryFile(modelPath.c_str(), inputShapes) : |
| 345 | parser->CreateNetworkFromTextFile(modelPath.c_str(), inputShapes)); |
| 346 | } |
| 347 | } |
| 348 | |
| 349 | else |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 350 | { |
| 351 | ARMNN_SCOPED_HEAP_PROFILING("Parsing"); |
| 352 | network = (params.m_IsModelBinary ? |
| 353 | parser->CreateNetworkFromBinaryFile(modelPath.c_str()) : |
| 354 | parser->CreateNetworkFromTextFile(modelPath.c_str())); |
| 355 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 356 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 357 | for (const std::string& inputLayerName : params.m_InputBindings) |
| 358 | { |
| 359 | BindingPointInfo inputBinding = parser->GetNetworkInputBindingInfo(inputLayerName); |
| 360 | inputBindings.push_back(inputBinding); |
| 361 | } |
| 362 | |
| 363 | for (const std::string& outputLayerName : params.m_OutputBindings) |
| 364 | { |
| 365 | BindingPointInfo outputBinding = parser->GetNetworkOutputBindingInfo(outputLayerName); |
| 366 | outputBindings.push_back(outputBinding); |
| 367 | } |
| 368 | |
| 369 | return network; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 370 | } |
| 371 | }; |
| 372 | #endif |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 373 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 374 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 375 | |
| 376 | template <typename IParser, typename TDataType> |
| 377 | class InferenceModel |
| 378 | { |
| 379 | public: |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 380 | using DataType = TDataType; |
| 381 | using Params = InferenceModelInternal::Params; |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 382 | using QuantizationParams = InferenceModelInternal::QuantizationParams; |
David Monahan | 6bb47a7 | 2021-10-22 12:57:28 +0100 | [diff] [blame] | 383 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 384 | |
| 385 | struct CommandLineOptions |
| 386 | { |
| 387 | std::string m_ModelDir; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 388 | std::vector<std::string> m_ComputeDevices; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 389 | std::string m_DynamicBackendsPath; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 390 | bool m_VisualizePostOptimizationModel; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 391 | bool m_EnableFp16TurboMode; |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 392 | bool m_EnableBf16TurboMode; |
Pablo Tello | 507f39d | 2019-04-15 15:44:39 +0100 | [diff] [blame] | 393 | std::string m_Labels; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 394 | |
| 395 | std::vector<armnn::BackendId> GetComputeDevicesAsBackendIds() |
| 396 | { |
| 397 | std::vector<armnn::BackendId> backendIds; |
| 398 | std::copy(m_ComputeDevices.begin(), m_ComputeDevices.end(), std::back_inserter(backendIds)); |
| 399 | return backendIds; |
| 400 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 401 | }; |
| 402 | |
James Ward | c89829f | 2020-10-12 14:17:36 +0100 | [diff] [blame] | 403 | static void AddCommandLineOptions(cxxopts::Options& options, |
| 404 | CommandLineOptions& cLineOptions, std::vector<std::string>& required) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 405 | { |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 406 | const std::vector<std::string> defaultComputes = { "CpuAcc", "CpuRef" }; |
David Beck | f0b4845 | 2018-10-19 15:20:56 +0100 | [diff] [blame] | 407 | |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 408 | const std::string backendsMessage = "Which device to run layers on by default. Possible choices: " |
| 409 | + armnn::BackendRegistryInstance().GetBackendIdsAsString(); |
| 410 | |
James Ward | c89829f | 2020-10-12 14:17:36 +0100 | [diff] [blame] | 411 | options |
| 412 | .allow_unrecognised_options() |
| 413 | .add_options() |
Nikhil Raj | 6dd178f | 2021-04-02 22:04:39 +0100 | [diff] [blame] | 414 | ("m,model-dir", "Path to directory containing model files (.prototxt/.tflite)", |
James Ward | c89829f | 2020-10-12 14:17:36 +0100 | [diff] [blame] | 415 | cxxopts::value<std::string>(cLineOptions.m_ModelDir)) |
| 416 | ("c,compute", backendsMessage.c_str(), |
| 417 | cxxopts::value<std::vector<std::string>>(cLineOptions.m_ComputeDevices)->default_value("CpuRef")) |
| 418 | ("b,dynamic-backends-path", |
| 419 | "Path where to load any available dynamic backend from. " |
| 420 | "If left empty (the default), dynamic backends will not be used.", |
| 421 | cxxopts::value(cLineOptions.m_DynamicBackendsPath)) |
| 422 | ("l,labels", |
| 423 | "Text file containing one image filename - correct label pair per line, " |
| 424 | "used to test the accuracy of the network.", cxxopts::value<std::string>(cLineOptions.m_Labels)) |
| 425 | ("v,visualize-optimized-model", |
| 426 | "Produce a dot file useful for visualizing the graph post optimization." |
| 427 | "The file will have the same name as the model with the .dot extention.", |
| 428 | cxxopts::value<bool>(cLineOptions.m_VisualizePostOptimizationModel)->default_value("false")) |
| 429 | ("fp16-turbo-mode", |
| 430 | "If this option is enabled FP32 layers, weights and biases will be converted " |
| 431 | "to FP16 where the backend supports it.", |
| 432 | cxxopts::value<bool>(cLineOptions.m_EnableFp16TurboMode)->default_value("false")) |
| 433 | ("bf16-turbo-mode", |
| 434 | "If this option is enabled FP32 layers, weights and biases will be converted " |
| 435 | "to BF16 where the backend supports it.", |
| 436 | cxxopts::value<bool>(cLineOptions.m_EnableBf16TurboMode)->default_value("false")); |
| 437 | |
| 438 | required.emplace_back("model-dir"); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Matthew Bentham | 3e68b97 | 2019-04-09 13:10:46 +0100 | [diff] [blame] | 441 | InferenceModel(const Params& params, |
| 442 | bool enableProfiling, |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 443 | const std::string& dynamicBackendsPath, |
Matthew Bentham | 3e68b97 | 2019-04-09 13:10:46 +0100 | [diff] [blame] | 444 | const std::shared_ptr<armnn::IRuntime>& runtime = nullptr) |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 445 | : m_EnableProfiling(enableProfiling), |
Jim Flynn | 1542581 | 2022-02-15 16:53:13 +0000 | [diff] [blame] | 446 | m_ProfilingDetailsMethod(armnn::ProfilingDetailsMethod::Undefined), |
| 447 | m_DynamicBackendsPath(dynamicBackendsPath), |
| 448 | m_ImportInputsIfAligned(params.m_ImportInputsIfAligned) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 449 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 450 | if (runtime) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 451 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 452 | m_Runtime = runtime; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 453 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 454 | else |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 455 | { |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 456 | armnn::IRuntime::CreationOptions options; |
Nina Drozd | 549ae37 | 2018-09-10 14:26:44 +0100 | [diff] [blame] | 457 | options.m_EnableGpuProfiling = m_EnableProfiling; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 458 | options.m_DynamicBackendsPath = m_DynamicBackendsPath; |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 459 | m_Runtime = armnn::IRuntime::Create(options); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 460 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 461 | |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 462 | // Configure the Profiler if the the profiling details are opted for |
| 463 | if (params.m_OutputDetailsOnlyToStdOut) |
| 464 | m_ProfilingDetailsMethod = armnn::ProfilingDetailsMethod::DetailsOnly; |
| 465 | else if (params.m_OutputDetailsToStdOut) |
| 466 | m_ProfilingDetailsMethod = armnn::ProfilingDetailsMethod::DetailsWithEvents; |
| 467 | |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 468 | std::string invalidBackends; |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 469 | if (!CheckRequestedBackendsAreValid(params.m_ComputeDevices, armnn::Optional<std::string&>(invalidBackends))) |
Aron Virginas-Tar | 5cc8e56 | 2018-10-23 15:14:46 +0100 | [diff] [blame] | 470 | { |
| 471 | throw armnn::Exception("Some backend IDs are invalid: " + invalidBackends); |
| 472 | } |
| 473 | |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 474 | armnn::IOptimizedNetworkPtr optNet{nullptr, [](armnn::IOptimizedNetwork*){}}; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 475 | { |
Finn Williams | 4422cec | 2021-03-22 17:51:06 +0000 | [diff] [blame] | 476 | const auto parsing_start_time = armnn::GetTimeNow(); |
| 477 | armnn::INetworkPtr network = CreateNetworkImpl<IParser>::Create(params, m_InputBindings, m_OutputBindings); |
| 478 | |
| 479 | ARMNN_LOG(info) << "Network parsing time: " << std::setprecision(2) |
Sadik Armagan | 4a0844d | 2022-01-26 09:57:05 +0000 | [diff] [blame] | 480 | << std::fixed << armnn::GetTimeDuration(parsing_start_time).count() << " ms."; |
Finn Williams | 4422cec | 2021-03-22 17:51:06 +0000 | [diff] [blame] | 481 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 482 | ARMNN_SCOPED_HEAP_PROFILING("Optimizing"); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 483 | |
| 484 | armnn::OptimizerOptions options; |
| 485 | options.m_ReduceFp32ToFp16 = params.m_EnableFp16TurboMode; |
Narumol Prangnawarat | d8cc811 | 2020-03-24 13:54:05 +0000 | [diff] [blame] | 486 | options.m_ReduceFp32ToBf16 = params.m_EnableBf16TurboMode; |
Matthew Jackson | 54658b9 | 2019-08-27 15:35:59 +0100 | [diff] [blame] | 487 | options.m_Debug = params.m_PrintIntermediateLayers; |
Finn Williams | d218d98 | 2021-08-09 13:00:08 +0100 | [diff] [blame] | 488 | options.m_shapeInferenceMethod = params.m_InferOutputShape ? |
| 489 | armnn::ShapeInferenceMethod::InferAndValidate : armnn::ShapeInferenceMethod::ValidateOnly; |
Derek Lamberti | 44c4c98 | 2021-10-14 00:28:37 +0100 | [diff] [blame] | 490 | options.m_ProfilingEnabled = m_EnableProfiling; |
Finn Williams | d218d98 | 2021-08-09 13:00:08 +0100 | [diff] [blame] | 491 | |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 492 | armnn::BackendOptions gpuAcc("GpuAcc", |
| 493 | { |
Matthew Sloyan | 4243211 | 2021-01-08 10:30:51 +0000 | [diff] [blame] | 494 | { "FastMathEnabled", params.m_EnableFastMath }, |
| 495 | { "SaveCachedNetwork", params.m_SaveCachedNetwork }, |
Finn Williams | 4064632 | 2021-02-11 16:16:42 +0000 | [diff] [blame] | 496 | { "CachedNetworkFilePath", params.m_CachedNetworkFilePath }, |
| 497 | { "MLGOTuningFilePath", params.m_MLGOTuningFilePath } |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 498 | }); |
Finn Williams | 4064632 | 2021-02-11 16:16:42 +0000 | [diff] [blame] | 499 | |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 500 | armnn::BackendOptions cpuAcc("CpuAcc", |
| 501 | { |
Matthew Sloyan | 0a7dc6b | 2021-02-10 16:50:53 +0000 | [diff] [blame] | 502 | { "FastMathEnabled", params.m_EnableFastMath }, |
| 503 | { "NumberOfThreads", params.m_NumberOfThreads } |
Sadik Armagan | a25886e | 2020-09-15 17:17:08 +0100 | [diff] [blame] | 504 | }); |
| 505 | options.m_ModelOptions.push_back(gpuAcc); |
| 506 | options.m_ModelOptions.push_back(cpuAcc); |
| 507 | |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 508 | const auto optimization_start_time = armnn::GetTimeNow(); |
Aron Virginas-Tar | 339bcae | 2019-01-31 16:44:26 +0000 | [diff] [blame] | 509 | optNet = armnn::Optimize(*network, params.m_ComputeDevices, m_Runtime->GetDeviceSpec(), options); |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 510 | |
| 511 | ARMNN_LOG(info) << "Optimization time: " << std::setprecision(2) |
Sadik Armagan | 4a0844d | 2022-01-26 09:57:05 +0000 | [diff] [blame] | 512 | << std::fixed << armnn::GetTimeDuration(optimization_start_time).count() << " ms."; |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 513 | |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 514 | if (!optNet) |
| 515 | { |
| 516 | throw armnn::Exception("Optimize returned nullptr"); |
| 517 | } |
Finn Williams | 4422cec | 2021-03-22 17:51:06 +0000 | [diff] [blame] | 518 | |
| 519 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 520 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 521 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 522 | if (params.m_VisualizePostOptimizationModel) |
| 523 | { |
Francis Murtagh | 532a29d | 2020-06-29 11:50:01 +0100 | [diff] [blame] | 524 | fs::path filename = params.m_ModelPath; |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 525 | filename.replace_extension("dot"); |
Rob Hughes | 9e10c2b | 2019-07-23 15:37:19 +0100 | [diff] [blame] | 526 | std::fstream file(filename.c_str(), std::ios_base::out); |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 527 | optNet->SerializeToDot(file); |
| 528 | } |
| 529 | |
| 530 | armnn::Status ret; |
| 531 | { |
| 532 | ARMNN_SCOPED_HEAP_PROFILING("LoadNetwork"); |
Matthew Sloyan | 4f29f15 | 2021-01-18 16:10:20 +0000 | [diff] [blame] | 533 | |
| 534 | const auto loading_start_time = armnn::GetTimeNow(); |
Francis Murtagh | 73d3e2e | 2021-04-29 14:23:04 +0100 | [diff] [blame] | 535 | armnn::INetworkProperties networkProperties(params.m_AsyncEnabled, |
| 536 | armnn::MemorySource::Undefined, |
Keith Davis | 554fa09 | 2021-07-20 11:25:22 +0100 | [diff] [blame] | 537 | armnn::MemorySource::Undefined, |
Keith Davis | f487486 | 2021-08-09 16:49:18 +0100 | [diff] [blame] | 538 | enableProfiling, |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 539 | m_ProfilingDetailsMethod); |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 540 | std::string errorMessage; |
| 541 | ret = m_Runtime->LoadNetwork(m_NetworkIdentifier, std::move(optNet), errorMessage, networkProperties); |
Matthew Sloyan | 4f29f15 | 2021-01-18 16:10:20 +0000 | [diff] [blame] | 542 | |
| 543 | ARMNN_LOG(info) << "Network loading time: " << std::setprecision(2) |
Sadik Armagan | 4a0844d | 2022-01-26 09:57:05 +0000 | [diff] [blame] | 544 | << std::fixed << armnn::GetTimeDuration(loading_start_time).count() << " ms."; |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 545 | |
| 546 | if (params.m_AsyncEnabled && params.m_ThreadPoolSize > 0) |
| 547 | { |
| 548 | std::vector<std::shared_ptr<armnn::IWorkingMemHandle>> memHandles; |
| 549 | for (size_t i = 0; i < params.m_ThreadPoolSize; ++i) |
| 550 | { |
| 551 | memHandles.emplace_back(m_Runtime->CreateWorkingMemHandle(m_NetworkIdentifier)); |
| 552 | } |
| 553 | |
| 554 | m_Threadpool = std::make_unique<armnn::Threadpool>(params.m_ThreadPoolSize, |
| 555 | m_Runtime.get(), |
| 556 | memHandles); |
| 557 | } |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 558 | } |
| 559 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 560 | if (ret == armnn::Status::Failure) |
| 561 | { |
| 562 | throw armnn::Exception("IRuntime::LoadNetwork failed"); |
| 563 | } |
| 564 | } |
| 565 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 566 | void CheckInputIndexIsValid(unsigned int inputIndex) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 567 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 568 | if (m_InputBindings.size() < inputIndex + 1) |
| 569 | { |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 570 | throw armnn::Exception(fmt::format("Input index out of range: {}", inputIndex)); |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 571 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 574 | void CheckOutputIndexIsValid(unsigned int outputIndex) const |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 575 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 576 | if (m_OutputBindings.size() < outputIndex + 1) |
| 577 | { |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 578 | throw armnn::Exception(fmt::format("Output index out of range: {}", outputIndex)); |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Aron Virginas-Tar | c82c873 | 2019-10-24 17:07:43 +0100 | [diff] [blame] | 582 | unsigned int GetInputSize(unsigned int inputIndex = 0u) const |
| 583 | { |
| 584 | CheckInputIndexIsValid(inputIndex); |
| 585 | return m_InputBindings[inputIndex].second.GetNumElements(); |
| 586 | } |
| 587 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 588 | unsigned int GetOutputSize(unsigned int outputIndex = 0u) const |
| 589 | { |
| 590 | CheckOutputIndexIsValid(outputIndex); |
| 591 | return m_OutputBindings[outputIndex].second.GetNumElements(); |
| 592 | } |
| 593 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 594 | std::chrono::duration<double, std::milli> Run( |
Francis Murtagh | 40d2741 | 2021-10-28 11:11:35 +0100 | [diff] [blame] | 595 | const std::vector<armnnUtils::TContainer>& inputContainers, |
| 596 | std::vector<armnnUtils::TContainer>& outputContainers) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 597 | { |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 598 | for (unsigned int i = 0; i < outputContainers.size(); ++i) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 599 | { |
| 600 | const unsigned int expectedOutputDataSize = GetOutputSize(i); |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 601 | |
James Ward | 6d9f5c5 | 2020-09-28 11:56:35 +0100 | [diff] [blame] | 602 | mapbox::util::apply_visitor([expectedOutputDataSize, i](auto&& value) |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 603 | { |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 604 | const unsigned int actualOutputDataSize = armnn::numeric_cast<unsigned int>(value.size()); |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 605 | if (actualOutputDataSize < expectedOutputDataSize) |
| 606 | { |
Matthew Sloyan | 80c6b14 | 2020-09-08 12:00:32 +0100 | [diff] [blame] | 607 | unsigned int outputIndex = i; |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 608 | throw armnn::Exception( |
James Ward | 08f4016 | 2020-09-07 16:45:07 +0100 | [diff] [blame] | 609 | fmt::format("Not enough data for output #{0}: expected " |
| 610 | "{1} elements, got {2}", outputIndex, expectedOutputDataSize, actualOutputDataSize)); |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 611 | } |
| 612 | }, |
| 613 | outputContainers[i]); |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 614 | } |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 615 | |
| 616 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkIdentifier); |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 617 | |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 618 | // Start timer to record inference time in EnqueueWorkload (in milliseconds) |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 619 | const auto start_time = armnn::GetTimeNow(); |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 620 | |
Jim Flynn | 1542581 | 2022-02-15 16:53:13 +0000 | [diff] [blame] | 621 | armnn::Status ret; |
| 622 | if (m_ImportInputsIfAligned) |
| 623 | { |
| 624 | std::vector<armnn::ImportedInputId> importedInputIds = m_Runtime->ImportInputs( |
| 625 | m_NetworkIdentifier, MakeInputTensors(inputContainers), armnn::MemorySource::Malloc); |
| 626 | |
| 627 | std::vector<armnn::ImportedOutputId> importedOutputIds = m_Runtime->ImportOutputs( |
| 628 | m_NetworkIdentifier, MakeOutputTensors(outputContainers), armnn::MemorySource::Malloc); |
| 629 | |
| 630 | ret = m_Runtime->EnqueueWorkload(m_NetworkIdentifier, |
| 631 | MakeInputTensors(inputContainers), |
| 632 | MakeOutputTensors(outputContainers), |
| 633 | importedInputIds, |
| 634 | importedOutputIds); |
| 635 | } |
| 636 | else |
| 637 | { |
| 638 | ret = m_Runtime->EnqueueWorkload(m_NetworkIdentifier, |
| 639 | MakeInputTensors(inputContainers), |
| 640 | MakeOutputTensors(outputContainers)); |
| 641 | } |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 642 | const auto duration = armnn::GetTimeDuration(start_time); |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 643 | |
Sadik Armagan | 2b7a158 | 2018-09-05 16:33:58 +0100 | [diff] [blame] | 644 | // if profiling is enabled print out the results |
| 645 | if (profiler && profiler->IsProfilingEnabled()) |
| 646 | { |
| 647 | profiler->Print(std::cout); |
| 648 | } |
| 649 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 650 | if (ret == armnn::Status::Failure) |
| 651 | { |
| 652 | throw armnn::Exception("IRuntime::EnqueueWorkload failed"); |
| 653 | } |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 654 | else |
| 655 | { |
alered01 | a7227ac | 2020-05-07 14:58:29 +0100 | [diff] [blame] | 656 | return duration; |
James Conroy | 7b4886f | 2019-04-11 10:23:58 +0100 | [diff] [blame] | 657 | } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 660 | std::tuple<unsigned int, std::chrono::duration<double, std::milli>> RunAsync( |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 661 | armnn::experimental::IWorkingMemHandle& workingMemHandleRef, |
Francis Murtagh | 40d2741 | 2021-10-28 11:11:35 +0100 | [diff] [blame] | 662 | const std::vector<armnnUtils::TContainer>& inputContainers, |
| 663 | std::vector<armnnUtils::TContainer>& outputContainers, |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 664 | unsigned int inferenceID) |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 665 | { |
| 666 | for (unsigned int i = 0; i < outputContainers.size(); ++i) |
| 667 | { |
| 668 | const unsigned int expectedOutputDataSize = GetOutputSize(i); |
| 669 | |
| 670 | mapbox::util::apply_visitor([expectedOutputDataSize, i](auto&& value) |
| 671 | { |
| 672 | const unsigned int actualOutputDataSize = armnn::numeric_cast<unsigned int>(value.size()); |
| 673 | if (actualOutputDataSize < expectedOutputDataSize) |
| 674 | { |
| 675 | unsigned int outputIndex = i; |
| 676 | throw armnn::Exception( |
| 677 | fmt::format("Not enough data for output #{0}: expected " |
| 678 | "{1} elements, got {2}", outputIndex, expectedOutputDataSize, actualOutputDataSize)); |
| 679 | } |
| 680 | }, |
| 681 | outputContainers[i]); |
| 682 | } |
| 683 | |
| 684 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkIdentifier); |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 685 | |
| 686 | // Start timer to record inference time in EnqueueWorkload (in milliseconds) |
| 687 | const auto start_time = armnn::GetTimeNow(); |
| 688 | |
| 689 | armnn::Status ret = m_Runtime->Execute(workingMemHandleRef, |
| 690 | MakeInputTensors(inputContainers), |
| 691 | MakeOutputTensors(outputContainers)); |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 692 | |
| 693 | const auto duration = armnn::GetTimeDuration(start_time); |
| 694 | |
| 695 | // if profiling is enabled print out the results |
| 696 | if (profiler && profiler->IsProfilingEnabled()) |
| 697 | { |
| 698 | profiler->Print(std::cout); |
| 699 | } |
| 700 | |
| 701 | if (ret == armnn::Status::Failure) |
| 702 | { |
| 703 | throw armnn::Exception( |
| 704 | fmt::format("IRuntime::Execute asynchronously failed for network #{0} on inference #{1}", |
| 705 | m_NetworkIdentifier, inferenceID)); |
| 706 | } |
| 707 | else |
| 708 | { |
| 709 | return std::make_tuple(inferenceID, duration); |
| 710 | } |
| 711 | } |
| 712 | |
Francis Murtagh | 40d2741 | 2021-10-28 11:11:35 +0100 | [diff] [blame] | 713 | void RunAsync(const std::vector<armnnUtils::TContainer>& inputContainers, |
| 714 | std::vector<armnnUtils::TContainer>& outputContainers, |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 715 | std::shared_ptr<armnn::IAsyncExecutionCallback> cb) |
Kevin May | b4b3ac9 | 2021-05-21 16:42:21 +0100 | [diff] [blame] | 716 | { |
| 717 | for (unsigned int i = 0; i < outputContainers.size(); ++i) |
| 718 | { |
| 719 | const unsigned int expectedOutputDataSize = GetOutputSize(i); |
| 720 | |
| 721 | mapbox::util::apply_visitor([expectedOutputDataSize, i](auto&& value) |
| 722 | { |
| 723 | const unsigned int actualOutputDataSize = armnn::numeric_cast<unsigned int>(value.size()); |
| 724 | if (actualOutputDataSize < expectedOutputDataSize) |
| 725 | { |
| 726 | unsigned int outputIndex = i; |
| 727 | throw armnn::Exception( |
| 728 | fmt::format("Not enough data for output #{0}: expected " |
| 729 | "{1} elements, got {2}", outputIndex, expectedOutputDataSize, actualOutputDataSize)); |
| 730 | } |
| 731 | }, |
| 732 | outputContainers[i]); |
| 733 | } |
| 734 | |
| 735 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkIdentifier); |
Kevin May | b4b3ac9 | 2021-05-21 16:42:21 +0100 | [diff] [blame] | 736 | |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 737 | m_Threadpool->Schedule(m_NetworkIdentifier, |
| 738 | MakeInputTensors(inputContainers), |
| 739 | MakeOutputTensors(outputContainers), |
| 740 | armnn::QosExecPriority::Medium, |
| 741 | cb); |
Kevin May | b4b3ac9 | 2021-05-21 16:42:21 +0100 | [diff] [blame] | 742 | |
| 743 | // if profiling is enabled print out the results |
| 744 | if (profiler && profiler->IsProfilingEnabled()) |
| 745 | { |
| 746 | profiler->Print(std::cout); |
| 747 | } |
| 748 | } |
| 749 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 750 | const armnn::BindingPointInfo& GetInputBindingInfo(unsigned int inputIndex = 0u) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 751 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 752 | CheckInputIndexIsValid(inputIndex); |
| 753 | return m_InputBindings[inputIndex]; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 756 | const std::vector<armnn::BindingPointInfo>& GetInputBindingInfos() const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 757 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 758 | return m_InputBindings; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 761 | const armnn::BindingPointInfo& GetOutputBindingInfo(unsigned int outputIndex = 0u) const |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 762 | { |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 763 | CheckOutputIndexIsValid(outputIndex); |
| 764 | return m_OutputBindings[outputIndex]; |
| 765 | } |
| 766 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 767 | const std::vector<armnn::BindingPointInfo>& GetOutputBindingInfos() const |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 768 | { |
| 769 | return m_OutputBindings; |
| 770 | } |
| 771 | |
| 772 | QuantizationParams GetQuantizationParams(unsigned int outputIndex = 0u) const |
| 773 | { |
| 774 | CheckOutputIndexIsValid(outputIndex); |
| 775 | return std::make_pair(m_OutputBindings[outputIndex].second.GetQuantizationScale(), |
| 776 | m_OutputBindings[outputIndex].second.GetQuantizationOffset()); |
| 777 | } |
| 778 | |
Narumol Prangnawarat | 4628d05 | 2019-02-25 17:26:05 +0000 | [diff] [blame] | 779 | QuantizationParams GetInputQuantizationParams(unsigned int inputIndex = 0u) const |
| 780 | { |
| 781 | CheckInputIndexIsValid(inputIndex); |
| 782 | return std::make_pair(m_InputBindings[inputIndex].second.GetQuantizationScale(), |
| 783 | m_InputBindings[inputIndex].second.GetQuantizationOffset()); |
| 784 | } |
| 785 | |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 786 | std::vector<QuantizationParams> GetAllQuantizationParams() const |
| 787 | { |
| 788 | std::vector<QuantizationParams> quantizationParams; |
| 789 | for (unsigned int i = 0u; i < m_OutputBindings.size(); i++) |
| 790 | { |
| 791 | quantizationParams.push_back(GetQuantizationParams(i)); |
| 792 | } |
| 793 | return quantizationParams; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 794 | } |
| 795 | |
Sadik Armagan | a04a9d7 | 2021-04-27 10:02:10 +0100 | [diff] [blame] | 796 | std::unique_ptr<armnn::experimental::IWorkingMemHandle> CreateWorkingMemHandle() |
| 797 | { |
| 798 | return m_Runtime->CreateWorkingMemHandle(m_NetworkIdentifier); |
| 799 | } |
| 800 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 801 | private: |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 802 | armnn::NetworkId m_NetworkIdentifier; |
| 803 | std::shared_ptr<armnn::IRuntime> m_Runtime; |
Finn Williams | f364d53 | 2021-06-09 17:07:33 +0100 | [diff] [blame] | 804 | std::unique_ptr<armnn::Threadpool> m_Threadpool; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 805 | |
Jim Flynn | b4d7eae | 2019-05-01 14:44:27 +0100 | [diff] [blame] | 806 | std::vector<armnn::BindingPointInfo> m_InputBindings; |
| 807 | std::vector<armnn::BindingPointInfo> m_OutputBindings; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 808 | bool m_EnableProfiling; |
Keith Davis | 4914d0c | 2021-08-18 17:14:05 +0100 | [diff] [blame] | 809 | armnn::ProfilingDetailsMethod m_ProfilingDetailsMethod; |
Matteo Martincigh | 00dda4a | 2019-08-14 11:42:30 +0100 | [diff] [blame] | 810 | std::string m_DynamicBackendsPath; |
Jim Flynn | 1542581 | 2022-02-15 16:53:13 +0000 | [diff] [blame] | 811 | bool m_ImportInputsIfAligned; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 812 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 813 | template<typename TContainer> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 814 | armnn::InputTensors MakeInputTensors(const std::vector<TContainer>& inputDataContainers) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 815 | { |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 816 | return armnnUtils::MakeInputTensors(m_InputBindings, inputDataContainers); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | template<typename TContainer> |
Aron Virginas-Tar | 7cf0eaa | 2019-01-24 17:05:36 +0000 | [diff] [blame] | 820 | armnn::OutputTensors MakeOutputTensors(std::vector<TContainer>& outputDataContainers) |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 821 | { |
Jim Flynn | 2fd6100 | 2019-05-03 12:54:26 +0100 | [diff] [blame] | 822 | return armnnUtils::MakeOutputTensors(m_OutputBindings, outputDataContainers); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 823 | } |
Ferran Balaguer | c602f29 | 2019-02-08 17:09:55 +0000 | [diff] [blame] | 824 | }; |