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