telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | 93e4898 | 2018-09-05 13:05:09 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 4 | // |
| 5 | |
| 6 | #define LOG_TAG "ArmnnDriver" |
| 7 | |
| 8 | #include "ArmnnPreparedModel.hpp" |
| 9 | #include "Utils.hpp" |
| 10 | |
| 11 | #include <boost/format.hpp> |
| 12 | #include <log/log.h> |
| 13 | #include <OperationsUtils.h> |
surmeh01 | deb3bdb | 2018-07-05 12:06:04 +0100 | [diff] [blame] | 14 | #include <ValidateHal.h> |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 15 | |
surmeh01 | deb3bdb | 2018-07-05 12:06:04 +0100 | [diff] [blame] | 16 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 17 | #include <cassert> |
| 18 | #include <cinttypes> |
| 19 | |
| 20 | using namespace android; |
| 21 | |
| 22 | namespace |
| 23 | { |
| 24 | using namespace armnn_driver; |
| 25 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 26 | void NotifyCallbackAndCheck(const ::android::sp<V1_0::IExecutionCallback>& callback, V1_0::ErrorStatus errorStatus, |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 27 | std::string callingFunction) |
| 28 | { |
| 29 | Return<void> returned = callback->notify(errorStatus); |
| 30 | // This check is required, if the callback fails and it isn't checked it will bring down the service |
| 31 | if (!returned.isOk()) |
| 32 | { |
| 33 | ALOGE("ArmnnDriver::%s: hidl callback failed to return properly: %s", |
| 34 | callingFunction.c_str(), returned.description().c_str()); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | bool ValidateRequestArgument(const RequestArgument& requestArg, const armnn::TensorInfo& tensorInfo) |
| 39 | { |
| 40 | if (requestArg.dimensions.size() != 0) |
| 41 | { |
| 42 | if (requestArg.dimensions.size() != tensorInfo.GetNumDimensions()) |
| 43 | { |
| 44 | ALOGE("Mismatched dimensions (request argument: %zu, expected: %u)", |
| 45 | requestArg.dimensions.size(), tensorInfo.GetNumDimensions()); |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | for (unsigned int d = 0; d < tensorInfo.GetNumDimensions(); ++d) |
| 50 | { |
Finn Williams | a4983ce | 2020-07-23 12:55:12 +0100 | [diff] [blame] | 51 | if (requestArg.dimensions[d] != 0 && requestArg.dimensions[d] != tensorInfo.GetShape()[d]) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 52 | { |
| 53 | ALOGE("Mismatched size for dimension %d (request argument: %u, expected %u)", |
| 54 | d, requestArg.dimensions[d], tensorInfo.GetShape()[d]); |
| 55 | return false; |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | return true; |
| 61 | } |
| 62 | |
| 63 | armnn::Tensor GetTensorForRequestArgument(const RequestArgument& requestArg, |
| 64 | const armnn::TensorInfo& tensorInfo, |
| 65 | const std::vector<::android::nn::RunTimePoolInfo>& requestPools) |
| 66 | { |
| 67 | if (!ValidateRequestArgument(requestArg, tensorInfo)) |
| 68 | { |
| 69 | return armnn::Tensor(); |
| 70 | } |
| 71 | |
| 72 | return armnn::Tensor(tensorInfo, GetMemoryFromPool(requestArg.location, requestPools)); |
| 73 | } |
| 74 | |
| 75 | inline std::string BuildTensorName(const char* tensorNamePrefix, std::size_t index) |
| 76 | { |
| 77 | return tensorNamePrefix + std::to_string(index); |
| 78 | } |
| 79 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 80 | } // anonymous namespace |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 81 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 82 | using namespace android::hardware; |
| 83 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 84 | namespace armnn_driver |
| 85 | { |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 86 | template<typename HalVersion> |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 87 | RequestThread<ArmnnPreparedModel, HalVersion, CallbackContext_1_0> |
| 88 | ArmnnPreparedModel<HalVersion>::m_RequestThread; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 89 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 90 | template<typename HalVersion> |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 91 | template <typename TensorBindingCollection> |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 92 | void ArmnnPreparedModel<HalVersion>::DumpTensorsIfRequired(char const* tensorNamePrefix, |
| 93 | const TensorBindingCollection& tensorBindings) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 94 | { |
| 95 | if (!m_RequestInputsAndOutputsDumpDir.empty()) |
| 96 | { |
| 97 | const std::string requestName = boost::str(boost::format("%1%_%2%.dump") % m_NetworkId % m_RequestCount); |
| 98 | for (std::size_t i = 0u; i < tensorBindings.size(); ++i) |
| 99 | { |
| 100 | DumpTensor(m_RequestInputsAndOutputsDumpDir, |
| 101 | requestName, |
| 102 | BuildTensorName(tensorNamePrefix, i), |
| 103 | tensorBindings[i].second); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 108 | template<typename HalVersion> |
| 109 | ArmnnPreparedModel<HalVersion>::ArmnnPreparedModel(armnn::NetworkId networkId, |
| 110 | armnn::IRuntime* runtime, |
| 111 | const HalModel& model, |
| 112 | const std::string& requestInputsAndOutputsDumpDir, |
| 113 | const bool gpuProfilingEnabled) |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 114 | : m_NetworkId(networkId) |
| 115 | , m_Runtime(runtime) |
| 116 | , m_Model(model) |
| 117 | , m_RequestCount(0) |
| 118 | , m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir) |
| 119 | , m_GpuProfilingEnabled(gpuProfilingEnabled) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 120 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 121 | // Enable profiling if required. |
| 122 | m_Runtime->GetProfiler(m_NetworkId)->EnableProfiling(m_GpuProfilingEnabled); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 125 | template<typename HalVersion> |
| 126 | ArmnnPreparedModel<HalVersion>::~ArmnnPreparedModel() |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 127 | { |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 128 | // Get a hold of the profiler used by this model. |
| 129 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId); |
| 130 | |
| 131 | // Unload the network associated with this model. |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 132 | m_Runtime->UnloadNetwork(m_NetworkId); |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 133 | |
| 134 | // Dump the profiling info to a file if required. |
| 135 | DumpJsonProfilingIfRequired(m_GpuProfilingEnabled, m_RequestInputsAndOutputsDumpDir, m_NetworkId, profiler.get()); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 136 | } |
| 137 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 138 | template<typename HalVersion> |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 139 | Return<V1_0::ErrorStatus> ArmnnPreparedModel<HalVersion>::execute( |
| 140 | const V1_0::Request& request, |
| 141 | const ::android::sp<V1_0::IExecutionCallback>& callback) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 142 | { |
| 143 | ALOGV("ArmnnPreparedModel::execute(): %s", GetModelSummary(m_Model).c_str()); |
| 144 | m_RequestCount++; |
| 145 | |
| 146 | if (callback.get() == nullptr) { |
| 147 | ALOGE("ArmnnPreparedModel::execute invalid callback passed"); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 148 | return V1_0::ErrorStatus::INVALID_ARGUMENT; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | if (!android::nn::validateRequest(request, m_Model)) |
| 152 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 153 | NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::INVALID_ARGUMENT, "ArmnnPreparedModel::execute"); |
| 154 | return V1_0::ErrorStatus::INVALID_ARGUMENT; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | if (!m_RequestInputsAndOutputsDumpDir.empty()) |
| 158 | { |
| 159 | ALOGD("Dumping inputs and outputs for request %" PRIuPTR, reinterpret_cast<std::uintptr_t>(callback.get())); |
| 160 | } |
| 161 | |
| 162 | // allocate the tensors on the heap, as they are passed to the request thread |
| 163 | auto pInputTensors = std::make_shared<armnn::InputTensors>(); |
| 164 | auto pOutputTensors = std::make_shared<armnn::OutputTensors>(); |
| 165 | |
| 166 | // map the memory pool into shared pointers |
| 167 | // use a shared memory pools vector on the heap, as it is passed to the request thread |
| 168 | auto pMemPools = std::make_shared<std::vector<android::nn::RunTimePoolInfo>>(); |
| 169 | if (!setRunTimePoolInfosFromHidlMemories(pMemPools.get(), request.pools)) |
| 170 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 171 | NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute"); |
| 172 | return V1_0::ErrorStatus::GENERAL_FAILURE; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | // add the inputs and outputs with their data |
| 176 | try |
| 177 | { |
| 178 | pInputTensors->reserve(request.inputs.size()); |
| 179 | for (unsigned int i = 0; i < request.inputs.size(); i++) |
| 180 | { |
| 181 | const auto& inputArg = request.inputs[i]; |
| 182 | |
| 183 | const armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i); |
| 184 | const armnn::Tensor inputTensor = GetTensorForRequestArgument(inputArg, inputTensorInfo, *pMemPools); |
| 185 | if (inputTensor.GetMemoryArea() == nullptr) |
| 186 | { |
| 187 | ALOGE("Cannot execute request. Error converting request input %u to tensor", i); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 188 | return V1_0::ErrorStatus::GENERAL_FAILURE; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | pInputTensors->emplace_back(i, inputTensor); |
| 192 | } |
| 193 | |
| 194 | pOutputTensors->reserve(request.outputs.size()); |
| 195 | for (unsigned int i = 0; i < request.outputs.size(); i++) |
| 196 | { |
| 197 | const auto& outputArg = request.outputs[i]; |
| 198 | |
| 199 | const armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i); |
| 200 | const armnn::Tensor outputTensor = GetTensorForRequestArgument(outputArg, outputTensorInfo, *pMemPools); |
| 201 | if (outputTensor.GetMemoryArea() == nullptr) |
| 202 | { |
| 203 | ALOGE("Cannot execute request. Error converting request output %u to tensor", i); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 204 | return V1_0::ErrorStatus::GENERAL_FAILURE; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | pOutputTensors->emplace_back(i, outputTensor); |
| 208 | } |
| 209 | } |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 210 | catch (armnn::Exception& e) |
| 211 | { |
| 212 | ALOGW("armnn::Exception caught while preparing for EnqueueWorkload: %s", e.what()); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 213 | NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute"); |
| 214 | return V1_0::ErrorStatus::GENERAL_FAILURE; |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 215 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 216 | catch (std::exception& e) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 217 | { |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 218 | ALOGE("std::exception caught while preparing for EnqueueWorkload: %s", e.what()); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 219 | NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute"); |
| 220 | return V1_0::ErrorStatus::GENERAL_FAILURE; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | ALOGV("ArmnnPreparedModel::execute(...) before PostMsg"); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 224 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 225 | auto cb = [callback](V1_0::ErrorStatus errorStatus, std::string callingFunction) |
Mike Kelly | 65c42dc | 2019-07-22 14:06:00 +0100 | [diff] [blame] | 226 | { |
| 227 | NotifyCallbackAndCheck(callback, errorStatus, callingFunction); |
| 228 | }; |
| 229 | |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 230 | CallbackContext_1_0 armnnCb; |
Mike Kelly | 65c42dc | 2019-07-22 14:06:00 +0100 | [diff] [blame] | 231 | armnnCb.callback = cb; |
| 232 | // post the request for asynchronous execution |
| 233 | m_RequestThread.PostMsg(this, pMemPools, pInputTensors, pOutputTensors, armnnCb); |
| 234 | ALOGV("ArmnnPreparedModel::execute(...) after PostMsg"); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 235 | return V1_0::ErrorStatus::NONE; // successfully queued |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 236 | } |
| 237 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 238 | template<typename HalVersion> |
| 239 | void ArmnnPreparedModel<HalVersion>::ExecuteGraph( |
| 240 | std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools, |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 241 | armnn::InputTensors& inputTensors, |
| 242 | armnn::OutputTensors& outputTensors, |
| 243 | CallbackContext_1_0 cb) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 244 | { |
| 245 | ALOGV("ArmnnPreparedModel::ExecuteGraph(...)"); |
| 246 | |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 247 | DumpTensorsIfRequired("Input", inputTensors); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 248 | |
| 249 | // run it |
| 250 | try |
| 251 | { |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 252 | armnn::Status status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors); |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 253 | if (status != armnn::Status::Success) |
| 254 | { |
| 255 | ALOGW("EnqueueWorkload failed"); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 256 | cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph"); |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 257 | return; |
| 258 | } |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 259 | } |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 260 | catch (armnn::Exception& e) |
| 261 | { |
| 262 | ALOGW("armnn::Exception caught from EnqueueWorkload: %s", e.what()); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 263 | cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph"); |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 264 | return; |
| 265 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 266 | catch (std::exception& e) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 267 | { |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 268 | ALOGE("std::exception caught from EnqueueWorkload: %s", e.what()); |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 269 | cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph"); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 270 | return; |
| 271 | } |
| 272 | |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 273 | DumpTensorsIfRequired("Output", outputTensors); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 274 | |
| 275 | // Commit output buffers. |
| 276 | // Note that we update *all* pools, even if they aren't actually used as outputs - |
| 277 | // this is simpler and is what the CpuExecutor does. |
| 278 | for (android::nn::RunTimePoolInfo& pool : *pMemPools) |
| 279 | { |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 280 | // Type android::nn::RunTimePoolInfo has changed between Android P & Q and Android R, where |
| 281 | // update() has been removed and flush() added. |
| 282 | #if defined(ARMNN_ANDROID_R) // Use the new Android implementation. |
| 283 | pool.flush(); |
| 284 | #else |
| 285 | pool.update(); |
| 286 | #endif |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 287 | } |
| 288 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 289 | cb.callback(V1_0::ErrorStatus::NONE, "ExecuteGraph"); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 290 | } |
| 291 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 292 | template<typename HalVersion> |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 293 | bool ArmnnPreparedModel<HalVersion>::ExecuteWithDummyInputs() |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 294 | { |
| 295 | std::vector<std::vector<char>> storage; |
| 296 | armnn::InputTensors inputTensors; |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 297 | for (unsigned int i = 0; i < getMainModel(m_Model).inputIndexes.size(); i++) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 298 | { |
| 299 | const armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i); |
| 300 | storage.emplace_back(inputTensorInfo.GetNumBytes()); |
| 301 | const armnn::ConstTensor inputTensor(inputTensorInfo, storage.back().data()); |
| 302 | |
| 303 | inputTensors.emplace_back(i, inputTensor); |
| 304 | } |
| 305 | |
| 306 | armnn::OutputTensors outputTensors; |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 307 | for (unsigned int i = 0; i < getMainModel(m_Model).outputIndexes.size(); i++) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 308 | { |
| 309 | const armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i); |
| 310 | storage.emplace_back(outputTensorInfo.GetNumBytes()); |
| 311 | const armnn::Tensor outputTensor(outputTensorInfo, storage.back().data()); |
| 312 | |
| 313 | outputTensors.emplace_back(i, outputTensor); |
| 314 | } |
| 315 | |
| 316 | try |
| 317 | { |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 318 | armnn::Status status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors); |
| 319 | if (status != armnn::Status::Success) |
| 320 | { |
| 321 | ALOGW("ExecuteWithDummyInputs: EnqueueWorkload failed"); |
| 322 | return false; |
| 323 | } |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 324 | } |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 325 | catch (armnn::Exception& e) |
| 326 | { |
| 327 | ALOGW("ExecuteWithDummyInputs: armnn::Exception caught from EnqueueWorkload: %s", e.what()); |
| 328 | return false; |
| 329 | } |
Derek Lamberti | b9cb844 | 2019-11-28 13:34:48 +0000 | [diff] [blame] | 330 | catch (std::exception& e) |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 331 | { |
Kevin May | 7bdaac5 | 2020-02-10 12:10:07 +0000 | [diff] [blame] | 332 | ALOGE("ExecuteWithDummyInputs: std::exception caught from EnqueueWorkload: %s", e.what()); |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 333 | return false; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 334 | } |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 335 | return true; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 336 | } |
| 337 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 338 | /// |
| 339 | /// Class template specializations |
| 340 | /// |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 341 | |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 342 | template class ArmnnPreparedModel<hal_1_0::HalPolicy>; |
| 343 | |
Matteo Martincigh | 8b287c2 | 2018-09-07 09:25:10 +0100 | [diff] [blame] | 344 | #ifdef ARMNN_ANDROID_NN_V1_1 |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 345 | template class ArmnnPreparedModel<hal_1_1::HalPolicy>; |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 346 | #endif |
| 347 | |
Mike Kelly | b5fdf38 | 2019-06-11 16:35:25 +0100 | [diff] [blame] | 348 | #ifdef ARMNN_ANDROID_NN_V1_2 |
| 349 | template class ArmnnPreparedModel<hal_1_1::HalPolicy>; |
| 350 | template class ArmnnPreparedModel<hal_1_2::HalPolicy>; |
| 351 | #endif |
Kevin May | 42477c1 | 2020-03-26 13:34:14 +0000 | [diff] [blame] | 352 | |
| 353 | #ifdef ARMNN_ANDROID_NN_V1_3 |
| 354 | template class ArmnnPreparedModel<hal_1_1::HalPolicy>; |
| 355 | template class ArmnnPreparedModel<hal_1_2::HalPolicy>; |
| 356 | template class ArmnnPreparedModel<hal_1_3::HalPolicy>; |
| 357 | #endif |
Nikhil Raj | 7760582 | 2018-09-03 11:25:56 +0100 | [diff] [blame] | 358 | } // namespace armnn_driver |