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