blob: 259d1b8c47d7f6769ab1b94b65fce7addedbf75c [file] [log] [blame]
telsoa015307bc12018-03-09 13:51:08 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beck93e48982018-09-05 13:05:09 +01003// SPDX-License-Identifier: MIT
telsoa015307bc12018-03-09 13:51:08 +00004//
5
6#define LOG_TAG "ArmnnDriver"
7
8#include "ArmnnPreparedModel.hpp"
9#include "Utils.hpp"
10
telsoa015307bc12018-03-09 13:51:08 +000011#include <log/log.h>
12#include <OperationsUtils.h>
surmeh01deb3bdb2018-07-05 12:06:04 +010013#include <ValidateHal.h>
Kevin Mayec1e5b82020-02-26 17:00:39 +000014
telsoa015307bc12018-03-09 13:51:08 +000015#include <cassert>
16#include <cinttypes>
17
Sadik Armagan188675f2021-02-12 17:16:42 +000018#ifdef ARMNN_ANDROID_S
19#include <LegacyUtils.h>
20#endif
21
telsoa015307bc12018-03-09 13:51:08 +000022using namespace android;
23
24namespace
25{
26using namespace armnn_driver;
27
Kevin Mayec1e5b82020-02-26 17:00:39 +000028void NotifyCallbackAndCheck(const ::android::sp<V1_0::IExecutionCallback>& callback, V1_0::ErrorStatus errorStatus,
telsoa015307bc12018-03-09 13:51:08 +000029 std::string callingFunction)
30{
31 Return<void> returned = callback->notify(errorStatus);
32 // This check is required, if the callback fails and it isn't checked it will bring down the service
33 if (!returned.isOk())
34 {
35 ALOGE("ArmnnDriver::%s: hidl callback failed to return properly: %s",
36 callingFunction.c_str(), returned.description().c_str());
37 }
38}
39
Sadik Armagan188675f2021-02-12 17:16:42 +000040bool ValidateRequestArgument(const V1_0::RequestArgument& requestArg, const armnn::TensorInfo& tensorInfo)
telsoa015307bc12018-03-09 13:51:08 +000041{
42 if (requestArg.dimensions.size() != 0)
43 {
44 if (requestArg.dimensions.size() != tensorInfo.GetNumDimensions())
45 {
46 ALOGE("Mismatched dimensions (request argument: %zu, expected: %u)",
47 requestArg.dimensions.size(), tensorInfo.GetNumDimensions());
48 return false;
49 }
50
51 for (unsigned int d = 0; d < tensorInfo.GetNumDimensions(); ++d)
52 {
Finn Williamsa4983ce2020-07-23 12:55:12 +010053 if (requestArg.dimensions[d] != 0 && requestArg.dimensions[d] != tensorInfo.GetShape()[d])
telsoa015307bc12018-03-09 13:51:08 +000054 {
55 ALOGE("Mismatched size for dimension %d (request argument: %u, expected %u)",
56 d, requestArg.dimensions[d], tensorInfo.GetShape()[d]);
57 return false;
58 }
59 }
60 }
61
62 return true;
63}
64
Sadik Armagan188675f2021-02-12 17:16:42 +000065armnn::Tensor GetTensorForRequestArgument(const V1_0::RequestArgument& requestArg,
telsoa015307bc12018-03-09 13:51:08 +000066 const armnn::TensorInfo& tensorInfo,
67 const std::vector<::android::nn::RunTimePoolInfo>& requestPools)
68{
69 if (!ValidateRequestArgument(requestArg, tensorInfo))
70 {
71 return armnn::Tensor();
72 }
73
74 return armnn::Tensor(tensorInfo, GetMemoryFromPool(requestArg.location, requestPools));
75}
76
77inline std::string BuildTensorName(const char* tensorNamePrefix, std::size_t index)
78{
79 return tensorNamePrefix + std::to_string(index);
80}
81
Matteo Martincighe48bdff2018-09-03 13:50:50 +010082} // anonymous namespace
telsoa015307bc12018-03-09 13:51:08 +000083
telsoa01ce3e84a2018-08-31 09:31:35 +010084using namespace android::hardware;
85
telsoa015307bc12018-03-09 13:51:08 +000086namespace armnn_driver
87{
Matteo Martincighe48bdff2018-09-03 13:50:50 +010088template<typename HalVersion>
Derek Lamberti4de83c52020-03-17 13:40:18 +000089RequestThread<ArmnnPreparedModel, HalVersion, CallbackContext_1_0>
90 ArmnnPreparedModel<HalVersion>::m_RequestThread;
telsoa015307bc12018-03-09 13:51:08 +000091
Matteo Martincighe48bdff2018-09-03 13:50:50 +010092template<typename HalVersion>
telsoa015307bc12018-03-09 13:51:08 +000093template <typename TensorBindingCollection>
Matteo Martincighe48bdff2018-09-03 13:50:50 +010094void ArmnnPreparedModel<HalVersion>::DumpTensorsIfRequired(char const* tensorNamePrefix,
95 const TensorBindingCollection& tensorBindings)
telsoa015307bc12018-03-09 13:51:08 +000096{
97 if (!m_RequestInputsAndOutputsDumpDir.empty())
98 {
Colm Donelan08d9a1c2020-09-09 17:56:55 +010099 const std::string requestName = std::to_string(m_NetworkId) + "_" + std::to_string(m_RequestCount) + ".dump";
telsoa015307bc12018-03-09 13:51:08 +0000100 for (std::size_t i = 0u; i < tensorBindings.size(); ++i)
101 {
102 DumpTensor(m_RequestInputsAndOutputsDumpDir,
103 requestName,
104 BuildTensorName(tensorNamePrefix, i),
105 tensorBindings[i].second);
106 }
107 }
108}
109
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100110template<typename HalVersion>
111ArmnnPreparedModel<HalVersion>::ArmnnPreparedModel(armnn::NetworkId networkId,
112 armnn::IRuntime* runtime,
113 const HalModel& model,
114 const std::string& requestInputsAndOutputsDumpDir,
Finn Williamsd8fb5402021-05-19 20:52:00 +0100115 const bool gpuProfilingEnabled,
116 const bool asyncModelExecutionEnabled)
telsoa01ce3e84a2018-08-31 09:31:35 +0100117 : m_NetworkId(networkId)
118 , m_Runtime(runtime)
119 , m_Model(model)
120 , m_RequestCount(0)
121 , m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir)
122 , m_GpuProfilingEnabled(gpuProfilingEnabled)
Finn Williamsd8fb5402021-05-19 20:52:00 +0100123 , m_AsyncModelExecutionEnabled(asyncModelExecutionEnabled)
telsoa015307bc12018-03-09 13:51:08 +0000124{
telsoa01ce3e84a2018-08-31 09:31:35 +0100125 // Enable profiling if required.
126 m_Runtime->GetProfiler(m_NetworkId)->EnableProfiling(m_GpuProfilingEnabled);
Finn Williamsd8fb5402021-05-19 20:52:00 +0100127
128 if (asyncModelExecutionEnabled)
129 {
130 m_WorkingMemHandle = m_Runtime->CreateWorkingMemHandle(networkId);
131 }
telsoa015307bc12018-03-09 13:51:08 +0000132}
133
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100134template<typename HalVersion>
135ArmnnPreparedModel<HalVersion>::~ArmnnPreparedModel()
telsoa015307bc12018-03-09 13:51:08 +0000136{
telsoa01ce3e84a2018-08-31 09:31:35 +0100137 // Get a hold of the profiler used by this model.
138 std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
139
140 // Unload the network associated with this model.
telsoa015307bc12018-03-09 13:51:08 +0000141 m_Runtime->UnloadNetwork(m_NetworkId);
telsoa01ce3e84a2018-08-31 09:31:35 +0100142
143 // Dump the profiling info to a file if required.
144 DumpJsonProfilingIfRequired(m_GpuProfilingEnabled, m_RequestInputsAndOutputsDumpDir, m_NetworkId, profiler.get());
telsoa015307bc12018-03-09 13:51:08 +0000145}
146
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100147template<typename HalVersion>
Kevin Mayec1e5b82020-02-26 17:00:39 +0000148Return<V1_0::ErrorStatus> ArmnnPreparedModel<HalVersion>::execute(
149 const V1_0::Request& request,
150 const ::android::sp<V1_0::IExecutionCallback>& callback)
telsoa015307bc12018-03-09 13:51:08 +0000151{
152 ALOGV("ArmnnPreparedModel::execute(): %s", GetModelSummary(m_Model).c_str());
153 m_RequestCount++;
154
155 if (callback.get() == nullptr) {
156 ALOGE("ArmnnPreparedModel::execute invalid callback passed");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000157 return V1_0::ErrorStatus::INVALID_ARGUMENT;
telsoa015307bc12018-03-09 13:51:08 +0000158 }
159
160 if (!android::nn::validateRequest(request, m_Model))
161 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000162 NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::INVALID_ARGUMENT, "ArmnnPreparedModel::execute");
163 return V1_0::ErrorStatus::INVALID_ARGUMENT;
telsoa015307bc12018-03-09 13:51:08 +0000164 }
165
166 if (!m_RequestInputsAndOutputsDumpDir.empty())
167 {
168 ALOGD("Dumping inputs and outputs for request %" PRIuPTR, reinterpret_cast<std::uintptr_t>(callback.get()));
169 }
170
171 // allocate the tensors on the heap, as they are passed to the request thread
172 auto pInputTensors = std::make_shared<armnn::InputTensors>();
173 auto pOutputTensors = std::make_shared<armnn::OutputTensors>();
174
175 // map the memory pool into shared pointers
176 // use a shared memory pools vector on the heap, as it is passed to the request thread
177 auto pMemPools = std::make_shared<std::vector<android::nn::RunTimePoolInfo>>();
Sadik Armagan188675f2021-02-12 17:16:42 +0000178#if !defined(ARMNN_ANDROID_S)
telsoa015307bc12018-03-09 13:51:08 +0000179 if (!setRunTimePoolInfosFromHidlMemories(pMemPools.get(), request.pools))
Sadik Armagan188675f2021-02-12 17:16:42 +0000180#else
181 if (!setRunTimePoolInfosFromCanonicalMemories(pMemPools.get(), uncheckedConvert(request.pools)))
182#endif
telsoa015307bc12018-03-09 13:51:08 +0000183 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000184 NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute");
185 return V1_0::ErrorStatus::GENERAL_FAILURE;
telsoa015307bc12018-03-09 13:51:08 +0000186 }
telsoa015307bc12018-03-09 13:51:08 +0000187 // add the inputs and outputs with their data
188 try
189 {
190 pInputTensors->reserve(request.inputs.size());
191 for (unsigned int i = 0; i < request.inputs.size(); i++)
192 {
193 const auto& inputArg = request.inputs[i];
194
195 const armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i);
196 const armnn::Tensor inputTensor = GetTensorForRequestArgument(inputArg, inputTensorInfo, *pMemPools);
197 if (inputTensor.GetMemoryArea() == nullptr)
198 {
199 ALOGE("Cannot execute request. Error converting request input %u to tensor", i);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000200 return V1_0::ErrorStatus::GENERAL_FAILURE;
telsoa015307bc12018-03-09 13:51:08 +0000201 }
202
203 pInputTensors->emplace_back(i, inputTensor);
204 }
205
206 pOutputTensors->reserve(request.outputs.size());
207 for (unsigned int i = 0; i < request.outputs.size(); i++)
208 {
209 const auto& outputArg = request.outputs[i];
210
211 const armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i);
212 const armnn::Tensor outputTensor = GetTensorForRequestArgument(outputArg, outputTensorInfo, *pMemPools);
213 if (outputTensor.GetMemoryArea() == nullptr)
214 {
215 ALOGE("Cannot execute request. Error converting request output %u to tensor", i);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000216 return V1_0::ErrorStatus::GENERAL_FAILURE;
telsoa015307bc12018-03-09 13:51:08 +0000217 }
218
219 pOutputTensors->emplace_back(i, outputTensor);
220 }
221 }
Kevin May7bdaac52020-02-10 12:10:07 +0000222 catch (armnn::Exception& e)
223 {
224 ALOGW("armnn::Exception caught while preparing for EnqueueWorkload: %s", e.what());
Kevin Mayec1e5b82020-02-26 17:00:39 +0000225 NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute");
226 return V1_0::ErrorStatus::GENERAL_FAILURE;
Kevin May7bdaac52020-02-10 12:10:07 +0000227 }
Derek Lambertib9cb8442019-11-28 13:34:48 +0000228 catch (std::exception& e)
telsoa015307bc12018-03-09 13:51:08 +0000229 {
Kevin May7bdaac52020-02-10 12:10:07 +0000230 ALOGE("std::exception caught while preparing for EnqueueWorkload: %s", e.what());
Kevin Mayec1e5b82020-02-26 17:00:39 +0000231 NotifyCallbackAndCheck(callback, V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::execute");
232 return V1_0::ErrorStatus::GENERAL_FAILURE;
telsoa015307bc12018-03-09 13:51:08 +0000233 }
234
Kevin Mayec1e5b82020-02-26 17:00:39 +0000235 auto cb = [callback](V1_0::ErrorStatus errorStatus, std::string callingFunction)
Mike Kelly65c42dc2019-07-22 14:06:00 +0100236 {
237 NotifyCallbackAndCheck(callback, errorStatus, callingFunction);
238 };
239
Derek Lamberti4de83c52020-03-17 13:40:18 +0000240 CallbackContext_1_0 armnnCb;
Mike Kelly65c42dc2019-07-22 14:06:00 +0100241 armnnCb.callback = cb;
Finn Williamsd8fb5402021-05-19 20:52:00 +0100242
243 if (m_AsyncModelExecutionEnabled)
244 {
245 ALOGV("ArmnnPreparedModel::execute(...) before ScheduleGraphForExecution");
246 ScheduleGraphForExecution(pMemPools, pInputTensors, pOutputTensors, armnnCb);
247 ALOGV("ArmnnPreparedModel::execute(...) after ScheduleGraphForExecution");
248 return V1_0::ErrorStatus::NONE;
249 }
250
Mike Kelly65c42dc2019-07-22 14:06:00 +0100251 // post the request for asynchronous execution
Finn Williamsd8fb5402021-05-19 20:52:00 +0100252 ALOGV("ArmnnPreparedModel::execute(...) before PostMsg");
Mike Kelly65c42dc2019-07-22 14:06:00 +0100253 m_RequestThread.PostMsg(this, pMemPools, pInputTensors, pOutputTensors, armnnCb);
254 ALOGV("ArmnnPreparedModel::execute(...) after PostMsg");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000255 return V1_0::ErrorStatus::NONE; // successfully queued
telsoa015307bc12018-03-09 13:51:08 +0000256}
257
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100258template<typename HalVersion>
259void ArmnnPreparedModel<HalVersion>::ExecuteGraph(
260 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
Derek Lamberti4de83c52020-03-17 13:40:18 +0000261 armnn::InputTensors& inputTensors,
262 armnn::OutputTensors& outputTensors,
263 CallbackContext_1_0 cb)
telsoa015307bc12018-03-09 13:51:08 +0000264{
265 ALOGV("ArmnnPreparedModel::ExecuteGraph(...)");
266
Derek Lamberti4de83c52020-03-17 13:40:18 +0000267 DumpTensorsIfRequired("Input", inputTensors);
telsoa015307bc12018-03-09 13:51:08 +0000268
269 // run it
270 try
271 {
Finn Williamsd8fb5402021-05-19 20:52:00 +0100272 armnn::Status status;
273 if (m_AsyncModelExecutionEnabled)
274 {
275 ALOGW("ArmnnPreparedModel::ExecuteGraph m_AsyncModelExecutionEnabled true");
276 status = m_Runtime->Execute(*m_WorkingMemHandle, inputTensors, outputTensors);
277 }
278 else
279 {
280 ALOGW("ArmnnPreparedModel::ExecuteGraph m_AsyncModelExecutionEnabled false");
281 status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
282 }
283
Matthew Bentham16196e22019-04-01 17:17:58 +0100284 if (status != armnn::Status::Success)
285 {
286 ALOGW("EnqueueWorkload failed");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000287 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph");
Matthew Bentham16196e22019-04-01 17:17:58 +0100288 return;
289 }
telsoa015307bc12018-03-09 13:51:08 +0000290 }
Kevin May7bdaac52020-02-10 12:10:07 +0000291 catch (armnn::Exception& e)
292 {
293 ALOGW("armnn::Exception caught from EnqueueWorkload: %s", e.what());
Kevin Mayec1e5b82020-02-26 17:00:39 +0000294 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph");
Kevin May7bdaac52020-02-10 12:10:07 +0000295 return;
296 }
Derek Lambertib9cb8442019-11-28 13:34:48 +0000297 catch (std::exception& e)
telsoa015307bc12018-03-09 13:51:08 +0000298 {
Kevin May7bdaac52020-02-10 12:10:07 +0000299 ALOGE("std::exception caught from EnqueueWorkload: %s", e.what());
Kevin Mayec1e5b82020-02-26 17:00:39 +0000300 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, "ArmnnPreparedModel::ExecuteGraph");
telsoa015307bc12018-03-09 13:51:08 +0000301 return;
302 }
303
Derek Lamberti4de83c52020-03-17 13:40:18 +0000304 DumpTensorsIfRequired("Output", outputTensors);
telsoa015307bc12018-03-09 13:51:08 +0000305
306 // Commit output buffers.
307 // Note that we update *all* pools, even if they aren't actually used as outputs -
308 // this is simpler and is what the CpuExecutor does.
309 for (android::nn::RunTimePoolInfo& pool : *pMemPools)
310 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000311 // Type android::nn::RunTimePoolInfo has changed between Android P & Q and Android R, where
312 // update() has been removed and flush() added.
Sadik Armagan188675f2021-02-12 17:16:42 +0000313 #if defined(ARMNN_ANDROID_R) || defined(ARMNN_ANDROID_S) // Use the new Android implementation.
Kevin Mayec1e5b82020-02-26 17:00:39 +0000314 pool.flush();
315 #else
316 pool.update();
317 #endif
telsoa015307bc12018-03-09 13:51:08 +0000318 }
319
Kevin Mayec1e5b82020-02-26 17:00:39 +0000320 cb.callback(V1_0::ErrorStatus::NONE, "ExecuteGraph");
telsoa015307bc12018-03-09 13:51:08 +0000321}
322
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100323template<typename HalVersion>
Matthew Bentham16196e22019-04-01 17:17:58 +0100324bool ArmnnPreparedModel<HalVersion>::ExecuteWithDummyInputs()
telsoa015307bc12018-03-09 13:51:08 +0000325{
326 std::vector<std::vector<char>> storage;
327 armnn::InputTensors inputTensors;
Kevin May42477c12020-03-26 13:34:14 +0000328 for (unsigned int i = 0; i < getMainModel(m_Model).inputIndexes.size(); i++)
telsoa015307bc12018-03-09 13:51:08 +0000329 {
330 const armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i);
331 storage.emplace_back(inputTensorInfo.GetNumBytes());
332 const armnn::ConstTensor inputTensor(inputTensorInfo, storage.back().data());
333
334 inputTensors.emplace_back(i, inputTensor);
335 }
336
337 armnn::OutputTensors outputTensors;
Kevin May42477c12020-03-26 13:34:14 +0000338 for (unsigned int i = 0; i < getMainModel(m_Model).outputIndexes.size(); i++)
telsoa015307bc12018-03-09 13:51:08 +0000339 {
340 const armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i);
341 storage.emplace_back(outputTensorInfo.GetNumBytes());
342 const armnn::Tensor outputTensor(outputTensorInfo, storage.back().data());
343
344 outputTensors.emplace_back(i, outputTensor);
345 }
346
347 try
348 {
Finn Williams8fde84b2021-05-31 14:57:15 +0100349 armnn::Status status;
350 if (m_AsyncModelExecutionEnabled)
351 {
352 ALOGW("ArmnnPreparedModel::ExecuteGraph m_AsyncModelExecutionEnabled true");
353 status = m_Runtime->Execute(*m_WorkingMemHandle, inputTensors, outputTensors);
354 }
355 else
356 {
357 ALOGW("ArmnnPreparedModel::ExecuteGraph m_AsyncModelExecutionEnabled false");
358 status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
359 }
Matthew Bentham16196e22019-04-01 17:17:58 +0100360 if (status != armnn::Status::Success)
361 {
362 ALOGW("ExecuteWithDummyInputs: EnqueueWorkload failed");
363 return false;
364 }
telsoa015307bc12018-03-09 13:51:08 +0000365 }
Kevin May7bdaac52020-02-10 12:10:07 +0000366 catch (armnn::Exception& e)
367 {
368 ALOGW("ExecuteWithDummyInputs: armnn::Exception caught from EnqueueWorkload: %s", e.what());
369 return false;
370 }
Derek Lambertib9cb8442019-11-28 13:34:48 +0000371 catch (std::exception& e)
telsoa015307bc12018-03-09 13:51:08 +0000372 {
Kevin May7bdaac52020-02-10 12:10:07 +0000373 ALOGE("ExecuteWithDummyInputs: std::exception caught from EnqueueWorkload: %s", e.what());
Matthew Bentham16196e22019-04-01 17:17:58 +0100374 return false;
telsoa015307bc12018-03-09 13:51:08 +0000375 }
Matthew Bentham16196e22019-04-01 17:17:58 +0100376 return true;
telsoa015307bc12018-03-09 13:51:08 +0000377}
378
Finn Williamsd8fb5402021-05-19 20:52:00 +0100379/// Schedule the graph prepared from the request for execution
380template<typename HalVersion>
381template<typename CallbackContext>
382void ArmnnPreparedModel<HalVersion>::ScheduleGraphForExecution(
383 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
384 std::shared_ptr<armnn::InputTensors>& inputTensors,
385 std::shared_ptr<armnn::OutputTensors>& outputTensors,
386 CallbackContext callbackContext)
387{
388 ALOGV("ArmnnPreparedModel::ScheduleGraphForExecution(...)");
389
390 DumpTensorsIfRequired("Input", *inputTensors);
391
392
393 auto tpCb = std::make_shared<
394 ArmnnThreadPoolCallback<CallbackContext_1_0>>(this,
395 pMemPools,
396 inputTensors,
397 outputTensors,
398 callbackContext);
399
400 m_Runtime->Schedule(m_NetworkId,
401 *tpCb->m_InputTensors,
402 *tpCb->m_OutputTensors,
403 armnn::QosExecPriority::High,
404 tpCb);
405 ALOGV("ArmnnPreparedModel::ScheduleGraphForExecution end");
406}
407
408template<typename HalVersion>
409template <typename CallbackContext>
410void ArmnnPreparedModel<HalVersion>::ArmnnThreadPoolCallback<CallbackContext>::Notify(
411 armnn::Status status, armnn::InferenceTimingPair timeTaken)
412{
413 armnn::IgnoreUnused(status, timeTaken);
414 ALOGV("ArmnnPreparedModel::ArmnnThreadPoolCallback_1_2 Notify");
415
416 m_Model->DumpTensorsIfRequired("Output", *m_OutputTensors);
417
418 // Commit output buffers.
419 // Note that we update *all* pools, even if they aren't actually used as outputs -
420 // this is simpler and is what the CpuExecutor does.
421 for (android::nn::RunTimePoolInfo& pool : *m_MemPools)
422 {
423 // Type android::nn::RunTimePoolInfo has changed between Android P & Q and Android R, where
424 // update() has been removed and flush() added.
425 #if defined(ARMNN_ANDROID_R) || defined(ARMNN_ANDROID_S) // Use the new Android implementation.
426 pool.flush();
427 #else
428 pool.update();
429 #endif
430 }
431
432 m_CallbackContext.callback(V1_0::ErrorStatus::NONE, "ArmnnPreparedModel::ArmnnThreadPoolCallback_1_2 Notify");
433 return;
434}
435
arovir01b0717b52018-09-05 17:03:25 +0100436///
437/// Class template specializations
438///
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100439
arovir01b0717b52018-09-05 17:03:25 +0100440template class ArmnnPreparedModel<hal_1_0::HalPolicy>;
Finn Williamsd8fb5402021-05-19 20:52:00 +0100441template void ArmnnPreparedModel<hal_1_0::HalPolicy>::ScheduleGraphForExecution<CallbackContext_1_0>(
442 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
443 std::shared_ptr<armnn::InputTensors>& inputTensors,
444 std::shared_ptr<armnn::OutputTensors>& outputTensors,
445 CallbackContext_1_0 callbackContext);
arovir01b0717b52018-09-05 17:03:25 +0100446
Matteo Martincigh8b287c22018-09-07 09:25:10 +0100447#ifdef ARMNN_ANDROID_NN_V1_1
arovir01b0717b52018-09-05 17:03:25 +0100448template class ArmnnPreparedModel<hal_1_1::HalPolicy>;
Matteo Martincighe48bdff2018-09-03 13:50:50 +0100449#endif
450
Mike Kellyb5fdf382019-06-11 16:35:25 +0100451#ifdef ARMNN_ANDROID_NN_V1_2
452template class ArmnnPreparedModel<hal_1_1::HalPolicy>;
453template class ArmnnPreparedModel<hal_1_2::HalPolicy>;
454#endif
Kevin May42477c12020-03-26 13:34:14 +0000455
456#ifdef ARMNN_ANDROID_NN_V1_3
457template class ArmnnPreparedModel<hal_1_1::HalPolicy>;
458template class ArmnnPreparedModel<hal_1_2::HalPolicy>;
459template class ArmnnPreparedModel<hal_1_3::HalPolicy>;
460#endif
Nikhil Raj77605822018-09-03 11:25:56 +0100461} // namespace armnn_driver