blob: a401b30e21db0c871e42832ec9dba8907444bb22 [file] [log] [blame]
Mike Kellyb5fdf382019-06-11 16:35:25 +01001//
Mike Kellyde547162023-03-08 10:08:20 +00002// Copyright © 2017-2023 Arm Ltd and Contributors. All rights reserved.
Mike Kellyb5fdf382019-06-11 16:35:25 +01003// SPDX-License-Identifier: MIT
4//
5
6#define LOG_TAG "ArmnnDriver"
7
8#include "ArmnnPreparedModel_1_2.hpp"
Finn Williamsd8fb5402021-05-19 20:52:00 +01009
Mike Kellyb5fdf382019-06-11 16:35:25 +010010#include "Utils.hpp"
11
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +000012#include <armnn/Types.hpp>
13
Mike Kellyb5fdf382019-06-11 16:35:25 +010014#include <log/log.h>
15#include <OperationsUtils.h>
16#include <ExecutionBurstServer.h>
17#include <ValidateHal.h>
18
Colm Donelan0fc16c62022-03-16 11:54:13 +000019#include <chrono>
Mike Kellyb5fdf382019-06-11 16:35:25 +010020#include <cinttypes>
21
Sadik Armagan188675f2021-02-12 17:16:42 +000022#ifdef ARMNN_ANDROID_S
23#include <LegacyUtils.h>
24#endif
25
Mike Kellyb5fdf382019-06-11 16:35:25 +010026using namespace android;
27using namespace android::hardware;
28
Mike Kellyb5fdf382019-06-11 16:35:25 +010029namespace {
30
Sadik Armagan188675f2021-02-12 17:16:42 +000031static const V1_2::Timing g_NoTiming = {.timeOnDevice = UINT64_MAX, .timeInDriver = UINT64_MAX};
Mike Kellyb5fdf382019-06-11 16:35:25 +010032using namespace armnn_driver;
Mike Kelly44381512019-07-08 17:37:35 +010033using TimePoint = std::chrono::steady_clock::time_point;
34
35TimePoint Now()
36{
37 return std::chrono::steady_clock::now();
38}
39
40unsigned long MicrosecondsDuration(TimePoint endPoint, TimePoint startPoint)
41{
42 return static_cast<unsigned long>(std::chrono::duration_cast<std::chrono::microseconds>(
43 endPoint - startPoint).count());
44}
Mike Kellyb5fdf382019-06-11 16:35:25 +010045
Mike Kelly65c42dc2019-07-22 14:06:00 +010046void NotifyCallbackAndCheck(const ::android::sp<V1_0::IExecutionCallback>& callback,
Kevin Mayec1e5b82020-02-26 17:00:39 +000047 V1_0::ErrorStatus errorStatus,
Sadik Armagan188675f2021-02-12 17:16:42 +000048 std::vector<V1_2::OutputShape>,
49 const V1_2::Timing,
Mike Kellyb5fdf382019-06-11 16:35:25 +010050 std::string callingFunction)
51{
52 Return<void> returned = callback->notify(errorStatus);
53 // This check is required, if the callback fails and it isn't checked it will bring down the service
54 if (!returned.isOk())
55 {
56 ALOGE("ArmnnDriver::%s: hidl callback failed to return properly: %s",
57 callingFunction.c_str(), returned.description().c_str());
58 }
59}
60
Mike Kelly65c42dc2019-07-22 14:06:00 +010061void NotifyCallbackAndCheck(const ::android::sp<V1_2::IExecutionCallback>& callback,
Kevin Mayec1e5b82020-02-26 17:00:39 +000062 V1_0::ErrorStatus errorStatus,
Sadik Armagan188675f2021-02-12 17:16:42 +000063 std::vector<V1_2::OutputShape> outputShapes,
64 const V1_2::Timing timing,
Mike Kellyb5fdf382019-06-11 16:35:25 +010065 std::string callingFunction)
66{
Mike Kelly65c42dc2019-07-22 14:06:00 +010067 Return<void> returned = callback->notify_1_2(errorStatus, outputShapes, timing);
Mike Kellyb5fdf382019-06-11 16:35:25 +010068 // This check is required, if the callback fails and it isn't checked it will bring down the service
69 if (!returned.isOk())
70 {
71 ALOGE("ArmnnDriver::%s: hidl callback failed to return properly: %s",
72 callingFunction.c_str(), returned.description().c_str());
73 }
74}
75
Sadik Armagan188675f2021-02-12 17:16:42 +000076bool ValidateRequestArgument(const V1_0::RequestArgument& requestArg, const armnn::TensorInfo& tensorInfo)
Mike Kellyb5fdf382019-06-11 16:35:25 +010077{
78 if (requestArg.dimensions.size() != 0)
79 {
80 if (requestArg.dimensions.size() != tensorInfo.GetNumDimensions())
81 {
82 ALOGE("Mismatched dimensions (request argument: %zu, expected: %u)",
83 requestArg.dimensions.size(), tensorInfo.GetNumDimensions());
84 return false;
85 }
86
87 for (unsigned int d = 0; d < tensorInfo.GetNumDimensions(); ++d)
88 {
Finn Williamsa4983ce2020-07-23 12:55:12 +010089 if (requestArg.dimensions[d] != 0 && requestArg.dimensions[d] != tensorInfo.GetShape()[d])
Mike Kellyb5fdf382019-06-11 16:35:25 +010090 {
91 ALOGE("Mismatched size for dimension %d (request argument: %u, expected %u)",
92 d, requestArg.dimensions[d], tensorInfo.GetShape()[d]);
93 return false;
94 }
95 }
96 }
97
98 return true;
99}
100
Sadik Armagan188675f2021-02-12 17:16:42 +0000101armnn::Tensor GetTensorForRequestArgument(const V1_0::RequestArgument& requestArg,
Mike Kellyb5fdf382019-06-11 16:35:25 +0100102 const armnn::TensorInfo& tensorInfo,
103 const std::vector<::android::nn::RunTimePoolInfo>& requestPools)
104{
105 if (!ValidateRequestArgument(requestArg, tensorInfo))
106 {
107 return armnn::Tensor();
108 }
109
110 return armnn::Tensor(tensorInfo, GetMemoryFromPool(requestArg.location, requestPools));
111}
112
113inline std::string BuildTensorName(const char* tensorNamePrefix, std::size_t index)
114{
115 return tensorNamePrefix + std::to_string(index);
116}
117
118} // anonymous namespace
119
120using namespace android::hardware;
121
122namespace armnn_driver
123{
124
125template<typename HalVersion>
Derek Lamberti4de83c52020-03-17 13:40:18 +0000126RequestThread<ArmnnPreparedModel_1_2, HalVersion, CallbackContext_1_2>
Mike Kelly65c42dc2019-07-22 14:06:00 +0100127 ArmnnPreparedModel_1_2<HalVersion>::m_RequestThread;
Mike Kellyb5fdf382019-06-11 16:35:25 +0100128
129template<typename HalVersion>
Finn Williamsfdf2eae2021-07-08 13:07:19 +0100130std::unique_ptr<armnn::Threadpool> ArmnnPreparedModel_1_2<HalVersion>::m_Threadpool(nullptr);
131
132template<typename HalVersion>
Mike Kellyb5fdf382019-06-11 16:35:25 +0100133template<typename TensorBindingCollection>
134void ArmnnPreparedModel_1_2<HalVersion>::DumpTensorsIfRequired(char const* tensorNamePrefix,
135 const TensorBindingCollection& tensorBindings)
136{
137 if (!m_RequestInputsAndOutputsDumpDir.empty())
138 {
Colm Donelan08d9a1c2020-09-09 17:56:55 +0100139 const std::string requestName = std::to_string(m_NetworkId) + "_" + std::to_string(m_RequestCount) + ".dump";
Mike Kellyb5fdf382019-06-11 16:35:25 +0100140 for (std::size_t i = 0u; i < tensorBindings.size(); ++i)
141 {
142 DumpTensor(m_RequestInputsAndOutputsDumpDir,
143 requestName,
144 BuildTensorName(tensorNamePrefix, i),
145 tensorBindings[i].second);
146 }
147 }
148}
149
150template<typename HalVersion>
151ArmnnPreparedModel_1_2<HalVersion>::ArmnnPreparedModel_1_2(armnn::NetworkId networkId,
152 armnn::IRuntime* runtime,
153 const V1_2::Model& model,
154 const std::string& requestInputsAndOutputsDumpDir,
Finn Williamsd8fb5402021-05-19 20:52:00 +0100155 const bool gpuProfilingEnabled,
Finn Williamsca3a3e02021-06-11 15:04:02 +0100156 const bool asyncModelExecutionEnabled,
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +0000157 const unsigned int numberOfThreads,
158 const bool importEnabled,
159 const bool exportEnabled)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100160 : m_NetworkId(networkId)
161 , m_Runtime(runtime)
162 , m_Model(model)
163 , m_RequestCount(0)
164 , m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir)
165 , m_GpuProfilingEnabled(gpuProfilingEnabled)
Finn Williamsd8fb5402021-05-19 20:52:00 +0100166 , m_AsyncModelExecutionEnabled(asyncModelExecutionEnabled)
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +0000167 , m_EnableImport(importEnabled)
168 , m_EnableExport(exportEnabled)
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100169 , m_PreparedFromCache(false)
170{
171 // Enable profiling if required.
172 m_Runtime->GetProfiler(m_NetworkId)->EnableProfiling(m_GpuProfilingEnabled);
173
174 if (m_AsyncModelExecutionEnabled)
175 {
176 std::vector<std::shared_ptr<armnn::IWorkingMemHandle>> memHandles;
177 for (unsigned int i=0; i < numberOfThreads; ++i)
178 {
179 memHandles.emplace_back(m_Runtime->CreateWorkingMemHandle(networkId));
180 }
181
182 if (!m_Threadpool)
183 {
184 m_Threadpool = std::make_unique<armnn::Threadpool>(numberOfThreads, runtime, memHandles);
185 }
186 else
187 {
188 m_Threadpool->LoadMemHandles(memHandles);
189 }
190
191 m_WorkingMemHandle = memHandles.back();
192 }
193}
194
195template<typename HalVersion>
196ArmnnPreparedModel_1_2<HalVersion>::ArmnnPreparedModel_1_2(armnn::NetworkId networkId,
197 armnn::IRuntime* runtime,
198 const std::string& requestInputsAndOutputsDumpDir,
199 const bool gpuProfilingEnabled,
200 const bool asyncModelExecutionEnabled,
201 const unsigned int numberOfThreads,
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +0000202 const bool importEnabled,
203 const bool exportEnabled,
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100204 const bool preparedFromCache)
205 : m_NetworkId(networkId)
206 , m_Runtime(runtime)
207 , m_RequestCount(0)
208 , m_RequestInputsAndOutputsDumpDir(requestInputsAndOutputsDumpDir)
209 , m_GpuProfilingEnabled(gpuProfilingEnabled)
210 , m_AsyncModelExecutionEnabled(asyncModelExecutionEnabled)
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +0000211 , m_EnableImport(importEnabled)
212 , m_EnableExport(exportEnabled)
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100213 , m_PreparedFromCache(preparedFromCache)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100214{
215 // Enable profiling if required.
216 m_Runtime->GetProfiler(m_NetworkId)->EnableProfiling(m_GpuProfilingEnabled);
Finn Williamsd8fb5402021-05-19 20:52:00 +0100217
Finn Williamsfdf2eae2021-07-08 13:07:19 +0100218 if (m_AsyncModelExecutionEnabled)
Finn Williamsd8fb5402021-05-19 20:52:00 +0100219 {
Finn Williamsca3a3e02021-06-11 15:04:02 +0100220 std::vector<std::shared_ptr<armnn::IWorkingMemHandle>> memHandles;
Finn Williamsd27c13b2021-06-25 10:06:09 +0100221 for (unsigned int i=0; i < numberOfThreads; ++i)
Finn Williamsca3a3e02021-06-11 15:04:02 +0100222 {
223 memHandles.emplace_back(m_Runtime->CreateWorkingMemHandle(networkId));
224 }
225
Finn Williamsfdf2eae2021-07-08 13:07:19 +0100226 if (!m_Threadpool)
227 {
228 m_Threadpool = std::make_unique<armnn::Threadpool>(numberOfThreads, runtime, memHandles);
229 }
230 else
231 {
232 m_Threadpool->LoadMemHandles(memHandles);
233 }
234
Finn Williamsca3a3e02021-06-11 15:04:02 +0100235 m_WorkingMemHandle = memHandles.back();
Finn Williamsd8fb5402021-05-19 20:52:00 +0100236 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100237}
238
239template<typename HalVersion>
240ArmnnPreparedModel_1_2<HalVersion>::~ArmnnPreparedModel_1_2()
241{
242 // Get a hold of the profiler used by this model.
243 std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
Colm Donelan2048b682022-02-15 14:59:08 +0000244 if (profiler && m_GpuProfilingEnabled)
245 {
246 // Dump the profiling info to a file if required.
247 DumpJsonProfilingIfRequired(m_GpuProfilingEnabled, m_RequestInputsAndOutputsDumpDir, m_NetworkId,
248 profiler.get());
249 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100250
251 // Unload the network associated with this model.
252 m_Runtime->UnloadNetwork(m_NetworkId);
253
Finn Williamsfdf2eae2021-07-08 13:07:19 +0100254 // Unload the network memhandles from the threadpool
255 if (m_AsyncModelExecutionEnabled)
256 {
257 m_Threadpool->UnloadMemHandles(m_NetworkId);
258 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100259}
260
261template<typename HalVersion>
Kevin Mayec1e5b82020-02-26 17:00:39 +0000262Return <V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::execute(const V1_0::Request& request,
Mike Kellyb5fdf382019-06-11 16:35:25 +0100263 const ::android::sp<V1_0::IExecutionCallback>& callback)
264{
Mike Kelly65c42dc2019-07-22 14:06:00 +0100265 if (callback.get() == nullptr)
266 {
267 ALOGE("ArmnnPreparedModel_1_2::execute invalid callback passed");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000268 return V1_0::ErrorStatus::INVALID_ARGUMENT;
Mike Kelly65c42dc2019-07-22 14:06:00 +0100269 }
270
Kevin Mayec1e5b82020-02-26 17:00:39 +0000271 auto cb = [callback](V1_0::ErrorStatus errorStatus,
Sadik Armagan188675f2021-02-12 17:16:42 +0000272 std::vector<V1_2::OutputShape> outputShapes,
273 const V1_2::Timing& timing,
Mike Kelly65c42dc2019-07-22 14:06:00 +0100274 std::string callingFunction)
275 {
276 NotifyCallbackAndCheck(callback, errorStatus, outputShapes, timing, callingFunction);
277 };
278
Sadik Armagan188675f2021-02-12 17:16:42 +0000279 return Execute(request, V1_2::MeasureTiming::NO, cb);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100280}
281
282template<typename HalVersion>
Kevin Mayec1e5b82020-02-26 17:00:39 +0000283Return <V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::execute_1_2(
284 const V1_0::Request& request,
Sadik Armagan188675f2021-02-12 17:16:42 +0000285 V1_2::MeasureTiming measureTiming,
Kevin Mayec1e5b82020-02-26 17:00:39 +0000286 const sp<V1_2::IExecutionCallback>& callback)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100287{
Mike Kelly65c42dc2019-07-22 14:06:00 +0100288 if (callback.get() == nullptr)
289 {
290 ALOGE("ArmnnPreparedModel_1_2::execute_1_2 invalid callback passed");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000291 return V1_0::ErrorStatus::INVALID_ARGUMENT;
Mike Kelly65c42dc2019-07-22 14:06:00 +0100292 }
293
Kevin Mayec1e5b82020-02-26 17:00:39 +0000294 auto cb = [callback](V1_0::ErrorStatus errorStatus,
Sadik Armagan188675f2021-02-12 17:16:42 +0000295 std::vector<V1_2::OutputShape> outputShapes,
296 const V1_2::Timing& timing,
Mike Kelly65c42dc2019-07-22 14:06:00 +0100297 std::string callingFunction)
298 {
299 NotifyCallbackAndCheck(callback, errorStatus, outputShapes, timing, callingFunction);
300 };
301
302 return Execute(request, measureTiming, cb);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100303}
304
Derek Lamberti4de83c52020-03-17 13:40:18 +0000305template<typename HalVersion>
306Return<V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::PrepareMemoryForInputs(
307 armnn::InputTensors& inputs,
308 const V1_0::Request& request,
309 const std::vector<android::nn::RunTimePoolInfo>& memPools)
310{
311 inputs.reserve(request.inputs.size());
312 for (unsigned int i = 0; i < request.inputs.size(); i++)
313 {
314 const auto& inputArg = request.inputs[i];
Cathal Corbette27d4e82021-10-28 12:28:35 +0100315 armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i);
316 // inputs (of type InputTensors) is composed of a vector of ConstTensors.
317 // Therefore, set all TensorInfo isConstant parameters of input Tensors to true.
318 inputTensorInfo.SetConstant();
Mike Kellyde547162023-03-08 10:08:20 +0000319 auto result = ValidateRequestArgument<V1_0::ErrorStatus, V1_0::Request>(request,
320 inputTensorInfo,
321 inputArg,
322 "input");
323
324 if (result != V1_0::ErrorStatus::NONE)
325 {
326 return result;
327 }
328
Derek Lamberti4de83c52020-03-17 13:40:18 +0000329 const armnn::Tensor inputTensor = GetTensorForRequestArgument(inputArg, inputTensorInfo, memPools);
330
331 if (inputTensor.GetMemoryArea() == nullptr)
332 {
333 ALOGE("Cannot execute request. Error converting request input %u to tensor", i);
334 return V1_0::ErrorStatus::GENERAL_FAILURE;
335 }
336
337 inputs.emplace_back(i, inputTensor);
338 }
339
340 return V1_0::ErrorStatus::NONE;
341}
342
343template<typename HalVersion>
344Return<V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::PrepareMemoryForOutputs(
345 armnn::OutputTensors& outputs,
Sadik Armagan188675f2021-02-12 17:16:42 +0000346 std::vector<V1_2::OutputShape> &outputShapes,
Derek Lamberti4de83c52020-03-17 13:40:18 +0000347 const V1_0::Request& request,
348 const std::vector<android::nn::RunTimePoolInfo>& memPools)
349{
350 outputs.reserve(request.outputs.size());
351 for (unsigned int i = 0; i < request.outputs.size(); i++)
352 {
353 const auto& outputArg = request.outputs[i];
Mike Kellyde547162023-03-08 10:08:20 +0000354 armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i);
355 auto result = ValidateRequestArgument<V1_0::ErrorStatus, V1_0::Request>(request,
356 outputTensorInfo,
357 outputArg,
358 "output");
Derek Lamberti4de83c52020-03-17 13:40:18 +0000359
Mike Kellyde547162023-03-08 10:08:20 +0000360 if (result != V1_0::ErrorStatus::NONE)
361 {
362 return result;
363 }
364
Derek Lamberti4de83c52020-03-17 13:40:18 +0000365 const armnn::Tensor outputTensor = GetTensorForRequestArgument(outputArg, outputTensorInfo, memPools);
366 if (outputTensor.GetMemoryArea() == nullptr)
367 {
368 ALOGE("Cannot execute request. Error converting request output %u to tensor", i);
369 return V1_0::ErrorStatus::GENERAL_FAILURE;
370 }
371
372 const size_t outputSize = outputTensorInfo.GetNumBytes();
Finn Williamsa4983ce2020-07-23 12:55:12 +0100373
374 if (outputArg.location.length < outputSize)
375 {
376 ALOGW("ArmnnPreparedModel_1_2::Execute failed: outputArg.location.length < outputSize");
377 return V1_0::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE;
378 }
379
Sadik Armagan188675f2021-02-12 17:16:42 +0000380#if !defined(ARMNN_ANDROID_S)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000381 const size_t bufferSize = memPools.at(outputArg.location.poolIndex).getHidlMemory().size();
382 if (bufferSize < outputSize)
383 {
Finn Williamsa4983ce2020-07-23 12:55:12 +0100384 ALOGW("ArmnnPreparedModel_1_2::Execute failed: bufferSize < outputSize");
Derek Lamberti4de83c52020-03-17 13:40:18 +0000385 return V1_0::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE;
386 }
Sadik Armagan188675f2021-02-12 17:16:42 +0000387#else
Kevin Maydc873f62021-06-14 11:21:11 +0100388 const size_t bufferSize = memPools.at(outputArg.location.poolIndex).getSize();
Sadik Armagan188675f2021-02-12 17:16:42 +0000389 if (bufferSize < outputSize)
390 {
391 ALOGW("ArmnnPreparedModel_1_2::Execute failed bufferSize (%s) < outputSize (%s)",
392 std::to_string(bufferSize).c_str(), std::to_string(outputSize).c_str());
393 outputShapes[i].isSufficient = false;
394 return V1_0::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE;
395 }
396#endif
Derek Lamberti4de83c52020-03-17 13:40:18 +0000397 outputs.emplace_back(i, outputTensor);
398 outputShapes[i] = ComputeShape(outputTensorInfo);
399 }
400
401 return V1_0::ErrorStatus::NONE;
402}
403
404template<typename HalVersion>
405Return<V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::PrepareMemoryForIO(
406 armnn::InputTensors& inputs,
407 armnn::OutputTensors& outputs,
408 std::vector<android::nn::RunTimePoolInfo>& memPools,
409 const V1_0::Request& request,
410 CallbackAsync_1_2 callback)
411{
Sadik Armagan188675f2021-02-12 17:16:42 +0000412#if !defined(ARMNN_ANDROID_S)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000413 if (!setRunTimePoolInfosFromHidlMemories(&memPools, request.pools))
Sadik Armagan188675f2021-02-12 17:16:42 +0000414#else
415 if (!setRunTimePoolInfosFromCanonicalMemories(&memPools, uncheckedConvert(request.pools)))
416#endif
Derek Lamberti4de83c52020-03-17 13:40:18 +0000417 {
418 callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::execute");
419 return V1_0::ErrorStatus::GENERAL_FAILURE;
420 }
Derek Lamberti4de83c52020-03-17 13:40:18 +0000421 // add the inputs and outputs with their data
422 try
423 {
424 if (PrepareMemoryForInputs(inputs, request, memPools) != V1_0::ErrorStatus::NONE)
425 {
426 callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::execute");
427 return V1_0::ErrorStatus::GENERAL_FAILURE;
428 }
429
Sadik Armagan188675f2021-02-12 17:16:42 +0000430 std::vector<V1_2::OutputShape> outputShapes(request.outputs.size());
Derek Lamberti4de83c52020-03-17 13:40:18 +0000431
432 auto errorStatus = PrepareMemoryForOutputs(outputs, outputShapes, request, memPools);
433 if (errorStatus != V1_0::ErrorStatus::NONE)
434 {
435 callback(errorStatus,
436 outputShapes,
437 g_NoTiming,
438 "ArmnnPreparedModel_1_2::Execute");
439 return errorStatus;
440 }
441 }
442 catch (armnn::Exception& e)
443 {
444 ALOGW("armnn::Exception caught while preparing for EnqueueWorkload: %s", e.what());
445 callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::execute");
446 return V1_0::ErrorStatus::GENERAL_FAILURE;
447 }
448 catch (std::exception& e)
449 {
450 ALOGE("std::exception caught while preparing for EnqueueWorkload: %s", e.what());
451 callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::execute");
452 return V1_0::ErrorStatus::GENERAL_FAILURE;
453 }
454
455 return V1_0::ErrorStatus::NONE;
456}
457
Mike Kellyb5fdf382019-06-11 16:35:25 +0100458template<typename HalVersion>
Kevin Mayec1e5b82020-02-26 17:00:39 +0000459Return<void> ArmnnPreparedModel_1_2<HalVersion>::executeSynchronously(const V1_0::Request& request,
Sadik Armagan188675f2021-02-12 17:16:42 +0000460 V1_2::MeasureTiming measureTiming,
Mike Kelly44381512019-07-08 17:37:35 +0100461 executeSynchronously_cb cb)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100462{
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100463 if (!m_PreparedFromCache)
464 {
465 ALOGV("ArmnnPreparedModel_1_2::executeSynchronously(): %s", GetModelSummary(m_Model).c_str());
466 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100467 m_RequestCount++;
468
469 if (cb == nullptr)
470 {
471 ALOGE("ArmnnPreparedModel_1_2::executeSynchronously invalid callback passed");
472 return Void();
473 }
474
Derek Lamberti4de83c52020-03-17 13:40:18 +0000475 TimePoint driverStart;
Mike Kelly44381512019-07-08 17:37:35 +0100476
Sadik Armagan188675f2021-02-12 17:16:42 +0000477 if (measureTiming == V1_2::MeasureTiming::YES)
Mike Kelly44381512019-07-08 17:37:35 +0100478 {
479 driverStart = Now();
480 }
481
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100482 if (!m_PreparedFromCache && !android::nn::validateRequest(request, m_Model))
Mike Kellyb5fdf382019-06-11 16:35:25 +0100483 {
Mike Kelly44381512019-07-08 17:37:35 +0100484 ALOGE("ArmnnPreparedModel_1_2::executeSynchronously invalid request model");
Kevin Mayec1e5b82020-02-26 17:00:39 +0000485 cb(V1_0::ErrorStatus::INVALID_ARGUMENT, {}, g_NoTiming);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100486 return Void();
487 }
488
Derek Lamberti4de83c52020-03-17 13:40:18 +0000489 auto cbWrapper = [cb](V1_0::ErrorStatus errorStatus,
Sadik Armagan188675f2021-02-12 17:16:42 +0000490 std::vector<V1_2::OutputShape> outputShapes,
491 const V1_2::Timing& timing,
Derek Lamberti4de83c52020-03-17 13:40:18 +0000492 std::string)
493 {
494 cb(errorStatus, outputShapes, timing);
495 };
Mike Kellyb5fdf382019-06-11 16:35:25 +0100496
497 // map the memory pool into shared pointers
498 // use a shared memory pools vector on the heap, as it is passed to the request thread
Derek Lamberti4de83c52020-03-17 13:40:18 +0000499 auto memPools = std::make_shared<std::vector<android::nn::RunTimePoolInfo>>();
Mike Kellyb5fdf382019-06-11 16:35:25 +0100500
Derek Lamberti4de83c52020-03-17 13:40:18 +0000501 // allocate the tensors on the heap, as they are passed to the request thread
502 auto inputs = std::make_shared<armnn::InputTensors>();
503 auto outputs = std::make_shared<armnn::OutputTensors>();
504
505 auto prepareStatus = PrepareMemoryForIO(*inputs, *outputs, *memPools, request, cbWrapper);
506 if (prepareStatus != V1_0::ErrorStatus::NONE)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100507 {
Kevin May7bdaac52020-02-10 12:10:07 +0000508 return Void();
509 }
510
Mike Kellyb5fdf382019-06-11 16:35:25 +0100511 ALOGV("ArmnnPreparedModel_1_2::executeSynchronously() before Execution");
512
Derek Lamberti4de83c52020-03-17 13:40:18 +0000513 CallbackContext_1_2 cbCtx;
514 cbCtx.callback = cbWrapper;
515 cbCtx.ctx.measureTimings = measureTiming;
516 cbCtx.ctx.driverStart = driverStart;
517 ExecuteGraph(memPools, *inputs, *outputs, cbCtx);
518
519 return Void();
520}
521
522template<typename HalVersion>
523template<typename CallbackContext>
524bool ArmnnPreparedModel_1_2<HalVersion>::ExecuteGraph(
525 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
526 armnn::InputTensors& inputTensors,
527 armnn::OutputTensors& outputTensors,
528 CallbackContext cb)
529{
530 ALOGV("ArmnnPreparedModel_1_2::ExecuteGraph(...)");
531
532 TimePoint driverEnd, deviceStart, deviceEnd;
Colm Donelan0fc16c62022-03-16 11:54:13 +0000533 // Capture the graph execution start time.
534 std::chrono::time_point<std::chrono::system_clock> graphExecutionStart = std::chrono::system_clock::now();
Derek Lamberti4de83c52020-03-17 13:40:18 +0000535
536 DumpTensorsIfRequired("Input", inputTensors);
537
Sadik Armagan188675f2021-02-12 17:16:42 +0000538 std::vector<V1_2::OutputShape> outputShapes(outputTensors.size());
Derek Lamberti4de83c52020-03-17 13:40:18 +0000539 for (unsigned int i = 0; i < outputTensors.size(); i++)
540 {
541 std::pair<int, armnn::Tensor> outputTensorPair = outputTensors[i];
542 const armnn::Tensor outputTensor = outputTensorPair.second;
543 const armnn::TensorInfo outputTensorInfo = outputTensor.GetInfo();
544
545 outputShapes[i] = ComputeShape(outputTensorInfo);
546 }
547
Mike Kellyb5fdf382019-06-11 16:35:25 +0100548 // run it
549 try
550 {
Sadik Armagan188675f2021-02-12 17:16:42 +0000551 if (cb.ctx.measureTimings == V1_2::MeasureTiming::YES)
Mike Kelly44381512019-07-08 17:37:35 +0100552 {
553 deviceStart = Now();
554 }
555
Finn Williamsd8fb5402021-05-19 20:52:00 +0100556 armnn::Status status;
557 if (m_AsyncModelExecutionEnabled)
558 {
559 ALOGW("ArmnnPreparedModel_1_2::ExecuteGraph m_AsyncModelExecutionEnabled true");
560 status = m_Runtime->Execute(*m_WorkingMemHandle, inputTensors, outputTensors);
561 }
562 else
563 {
564 ALOGW("ArmnnPreparedModel_1_2::ExecuteGraph m_AsyncModelExecutionEnabled false");
Narumol Prangnawaratd1a947f2022-02-07 13:12:24 +0000565
566 // Create a vector of Input and Output Ids which can be imported. An empty vector means all will be copied.
567 std::vector<armnn::ImportedInputId> importedInputIds;
568 if (m_EnableImport)
569 {
570 importedInputIds = m_Runtime->ImportInputs(m_NetworkId, inputTensors, armnn::MemorySource::Malloc);
571 }
572 std::vector<armnn::ImportedOutputId> importedOutputIds;
573 if (m_EnableExport)
574 {
575 importedOutputIds = m_Runtime->ImportOutputs(m_NetworkId, outputTensors, armnn::MemorySource::Malloc);
576 }
577 status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors,
578 importedInputIds, importedOutputIds);
Finn Williamsd8fb5402021-05-19 20:52:00 +0100579 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100580
Sadik Armagan188675f2021-02-12 17:16:42 +0000581 if (cb.ctx.measureTimings == V1_2::MeasureTiming::YES)
Mike Kelly44381512019-07-08 17:37:35 +0100582 {
583 deviceEnd = Now();
584 }
Mike Kellyb5fdf382019-06-11 16:35:25 +0100585 if (status != armnn::Status::Success)
586 {
587 ALOGW("EnqueueWorkload failed");
Derek Lamberti4de83c52020-03-17 13:40:18 +0000588 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming,
589 "ArmnnPreparedModel_1_2::ExecuteGraph");
590 return false;
Mike Kellyb5fdf382019-06-11 16:35:25 +0100591 }
592 }
Kevin May7bdaac52020-02-10 12:10:07 +0000593 catch (armnn::Exception& e)
594 {
Derek Lamberti4de83c52020-03-17 13:40:18 +0000595 ALOGW("armnn:Exception caught from EnqueueWorkload: %s", e.what());
596 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::ExecuteGraph");
597 return false;
Kevin May7bdaac52020-02-10 12:10:07 +0000598 }
Derek Lambertib9cb8442019-11-28 13:34:48 +0000599 catch (std::exception& e)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100600 {
Kevin May7bdaac52020-02-10 12:10:07 +0000601 ALOGE("std::exception caught from EnqueueWorkload: %s", e.what());
Derek Lamberti4de83c52020-03-17 13:40:18 +0000602 cb.callback(V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel_1_2::ExecuteGraph");
603 return false;
Mike Kellyb5fdf382019-06-11 16:35:25 +0100604 }
605
Derek Lamberti4de83c52020-03-17 13:40:18 +0000606 CommitPools(*pMemPools);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100607
Derek Lamberti4de83c52020-03-17 13:40:18 +0000608 DumpTensorsIfRequired("Output", outputTensors);
Kevin Mayec1e5b82020-02-26 17:00:39 +0000609
Sadik Armagan188675f2021-02-12 17:16:42 +0000610 if (cb.ctx.measureTimings == V1_2::MeasureTiming::YES)
Mike Kelly44381512019-07-08 17:37:35 +0100611 {
612 driverEnd = Now();
Sadik Armagan188675f2021-02-12 17:16:42 +0000613 V1_2::Timing timing;
Mike Kelly44381512019-07-08 17:37:35 +0100614 timing.timeOnDevice = MicrosecondsDuration(deviceEnd, deviceStart);
Derek Lamberti4de83c52020-03-17 13:40:18 +0000615 timing.timeInDriver = MicrosecondsDuration(driverEnd, cb.ctx.driverStart);
Zingo Andersen7c561492022-01-25 11:09:41 +0100616 ALOGV("ArmnnPreparedModel_1_2::execute timing - Device = %lu Driver = %lu",
617 static_cast<unsigned long>(timing.timeOnDevice), static_cast<unsigned long>(timing.timeInDriver));
Derek Lamberti4de83c52020-03-17 13:40:18 +0000618 cb.callback(V1_0::ErrorStatus::NONE, outputShapes, timing, "ArmnnPreparedModel_1_2::ExecuteGraph");
619 } else {
620 cb.callback(V1_0::ErrorStatus::NONE, outputShapes, g_NoTiming, "ArmnnPreparedModel_1_2::ExecuteGraph");
Mike Kelly44381512019-07-08 17:37:35 +0100621 }
Derek Lamberti4de83c52020-03-17 13:40:18 +0000622
Colm Donelan0fc16c62022-03-16 11:54:13 +0000623 // Log the total time in this call. This is a good number to compare to that printed out by
624 // RuntimeImpl::EnqueueWorkload. The difference should be the execution overhead of the driver.
625 ALOGI("ArmnnPreparedModel_1_2::ExecuteGraph Execution time = %lld µs",
626 std::chrono::duration_cast<std::chrono::microseconds>
627 (std::chrono::system_clock::now() - graphExecutionStart).count());
Derek Lamberti4de83c52020-03-17 13:40:18 +0000628 return true;
Mike Kellyb5fdf382019-06-11 16:35:25 +0100629}
630
Derek Lamberti4de83c52020-03-17 13:40:18 +0000631template<typename HalVersion>
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100632bool ArmnnPreparedModel_1_2<HalVersion>::ExecuteWithDummyInputs(unsigned int numInputs, unsigned int numOutputs)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000633{
634 std::vector<std::vector<char>> storage;
635 armnn::InputTensors inputTensors;
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100636 for (unsigned int i = 0; i < numInputs; i++)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000637 {
Cathal Corbette27d4e82021-10-28 12:28:35 +0100638 armnn::TensorInfo inputTensorInfo = m_Runtime->GetInputTensorInfo(m_NetworkId, i);
639 // pInputTensors (of type InputTensors) is composed of a vector of ConstTensors.
640 // Therefore, set all TensorInfo isConstant parameters of input Tensors to true.
641 inputTensorInfo.SetConstant();
642
Derek Lamberti4de83c52020-03-17 13:40:18 +0000643 storage.emplace_back(inputTensorInfo.GetNumBytes());
644 const armnn::ConstTensor inputTensor(inputTensorInfo, storage.back().data());
645
646 inputTensors.emplace_back(i, inputTensor);
647 }
648
649 armnn::OutputTensors outputTensors;
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100650 for (unsigned int i = 0; i < numOutputs; i++)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000651 {
652 const armnn::TensorInfo outputTensorInfo = m_Runtime->GetOutputTensorInfo(m_NetworkId, i);
653 storage.emplace_back(outputTensorInfo.GetNumBytes());
654 const armnn::Tensor outputTensor(outputTensorInfo, storage.back().data());
655
656 outputTensors.emplace_back(i, outputTensor);
657 }
658
Sadik Armagan188675f2021-02-12 17:16:42 +0000659 auto nullCallback = [](V1_0::ErrorStatus, std::vector<V1_2::OutputShape>, const V1_2::Timing&, std::string) {};
Derek Lamberti4de83c52020-03-17 13:40:18 +0000660 CallbackContext_1_2 callbackContext;
661 callbackContext.callback = nullCallback;
Sadik Armagan188675f2021-02-12 17:16:42 +0000662 callbackContext.ctx.measureTimings = V1_2::MeasureTiming::NO;
Derek Lamberti4de83c52020-03-17 13:40:18 +0000663 auto memPools = std::make_shared<std::vector<::android::nn::RunTimePoolInfo>>();
664 return ExecuteGraph(memPools,
665 inputTensors,
666 outputTensors,
667 callbackContext);
668}
669
670template<typename HalVersion>
671Return <V1_0::ErrorStatus> ArmnnPreparedModel_1_2<HalVersion>::Execute(const V1_0::Request& request,
Sadik Armagan188675f2021-02-12 17:16:42 +0000672 V1_2::MeasureTiming measureTiming,
Derek Lamberti4de83c52020-03-17 13:40:18 +0000673 CallbackAsync_1_2 callback)
674{
675 ExecutionContext_1_2 ctx;
Sadik Armagan188675f2021-02-12 17:16:42 +0000676 if (measureTiming == V1_2::MeasureTiming::YES)
Derek Lamberti4de83c52020-03-17 13:40:18 +0000677 {
678 ctx.measureTimings = measureTiming;
679 ctx.driverStart = Now();
680 }
681
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100682 if (!m_PreparedFromCache)
683 {
684 ALOGV("ArmnnPreparedModel_1_2::execute(): %s", GetModelSummary(m_Model).c_str());
685 }
Derek Lamberti4de83c52020-03-17 13:40:18 +0000686 m_RequestCount++;
687
Sadik Armagan0a2dfab2021-10-06 16:41:44 +0100688 if (!m_PreparedFromCache && !android::nn::validateRequest(request, m_Model))
Derek Lamberti4de83c52020-03-17 13:40:18 +0000689 {
690 callback(V1_0::ErrorStatus::INVALID_ARGUMENT, {}, g_NoTiming, "ArmnnPreparedModel_1_2::execute");
691 return V1_0::ErrorStatus::INVALID_ARGUMENT;
692 }
693
694 if (!m_RequestInputsAndOutputsDumpDir.empty())
695 {
696 ALOGD("Dumping inputs and outputs for request %" PRIuPTR, reinterpret_cast<std::uintptr_t>(&callback));
697 }
698
699 // map the memory pool into shared pointers
700 // use a shared memory pools vector on the heap, as it is passed to the request thread
701 auto memPools = std::make_shared<std::vector<android::nn::RunTimePoolInfo>>();
702
703 // allocate the tensors on the heap, as they are passed to the request thread
704 auto inputTensors = std::make_shared<armnn::InputTensors>();
705 auto outputTensors = std::make_shared<armnn::OutputTensors>();
706
707 auto prepareStatus = PrepareMemoryForIO(*inputTensors, *outputTensors, *memPools, request, callback);
708 switch(prepareStatus)
709 {
710 case V1_0::ErrorStatus::OUTPUT_INSUFFICIENT_SIZE:
711 return V1_0::ErrorStatus::NONE;
712 case V1_0::ErrorStatus::GENERAL_FAILURE:
713 return V1_0::ErrorStatus::GENERAL_FAILURE;
714 default:
715 {}
716 }
717
Derek Lamberti4de83c52020-03-17 13:40:18 +0000718
719 // post the request for asynchronous execution
720 CallbackContext_1_2 cb;
721 cb.callback = callback;
722 cb.ctx = ctx;
Finn Williamsd8fb5402021-05-19 20:52:00 +0100723
724 if (m_AsyncModelExecutionEnabled)
725 {
726 ALOGV("ArmnnPreparedModel_1_2::execute(...) before ScheduleGraphForExecution");
727 ScheduleGraphForExecution(memPools, inputTensors, outputTensors, cb);
728 ALOGV("ArmnnPreparedModel_1_2::execute(...) after ScheduleGraphForExecution");
729 return V1_0::ErrorStatus::NONE;
730 }
731
732 ALOGV("ArmnnPreparedModel_1_2::execute(...) before PostMsg");
Derek Lamberti4de83c52020-03-17 13:40:18 +0000733 m_RequestThread.PostMsg(this, memPools, inputTensors, outputTensors, cb);
734 ALOGV("ArmnnPreparedModel_1_2::execute(...) after PostMsg");
735 return V1_0::ErrorStatus::NONE;
736}
737
Mike Kellyb5fdf382019-06-11 16:35:25 +0100738template<typename HalVersion>
739Return<void> ArmnnPreparedModel_1_2<HalVersion>::configureExecutionBurst(
Derek Lamberti4de83c52020-03-17 13:40:18 +0000740 const sp<V1_2::IBurstCallback>& callback,
741 const MQDescriptorSync<V1_2::FmqRequestDatum>& requestChannel,
742 const MQDescriptorSync<V1_2::FmqResultDatum>& resultChannel,
743 V1_2::IPreparedModel::configureExecutionBurst_cb cb)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100744{
745 ALOGV("ArmnnPreparedModel_1_2::configureExecutionBurst");
Mike Kelly65c42dc2019-07-22 14:06:00 +0100746 const sp<V1_2::IBurstContext> burst = ExecutionBurstServer::create(callback,
747 requestChannel,
748 resultChannel,
Kevin May42477c12020-03-26 13:34:14 +0000749 this);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100750
Mike Kelly44381512019-07-08 17:37:35 +0100751 if (burst == nullptr)
752 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000753 cb(V1_0::ErrorStatus::GENERAL_FAILURE, {});
Mike Kelly44381512019-07-08 17:37:35 +0100754 }
755 else
756 {
Kevin Mayec1e5b82020-02-26 17:00:39 +0000757 cb(V1_0::ErrorStatus::NONE, burst);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100758 }
759 return Void();
760}
761
Finn Williamsd8fb5402021-05-19 20:52:00 +0100762/// Schedule the graph prepared from the request for execution
763template<typename HalVersion>
764template<typename CallbackContext>
765void ArmnnPreparedModel_1_2<HalVersion>::ScheduleGraphForExecution(
766 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
767 std::shared_ptr<armnn::InputTensors>& inputTensors,
768 std::shared_ptr<armnn::OutputTensors>& outputTensors,
769 CallbackContext callbackContext)
770{
771 ALOGV("ArmnnPreparedModel_1_2::ScheduleGraphForExecution(...)");
772
773 DumpTensorsIfRequired("Input", *inputTensors);
774
775 unsigned int outputTensorSize = outputTensors.get()->size();
776 std::vector<V1_2::OutputShape> outputShapes(outputTensorSize);
777 for (unsigned int i = 0; i < outputTensorSize; i++)
778 {
779 std::pair<int, armnn::Tensor> outputTensorPair = outputTensors.get()->at(i);
780 const armnn::Tensor outputTensor = outputTensorPair.second;
781 const armnn::TensorInfo outputTensorInfo = outputTensor.GetInfo();
782
783 outputShapes[i] = ComputeShape(outputTensorInfo);
784 }
785
786 auto tpCb = std::make_shared<
787 ArmnnThreadPoolCallback_1_2<CallbackContext_1_2>>(this,
788 pMemPools,
789 outputShapes,
790 inputTensors,
791 outputTensors,
792 callbackContext);
793
Finn Williamsca3a3e02021-06-11 15:04:02 +0100794 m_Threadpool->Schedule(m_NetworkId,
795 *tpCb->m_InputTensors,
796 *tpCb->m_OutputTensors,
797 armnn::QosExecPriority::Medium,
798 tpCb);
Finn Williamsd8fb5402021-05-19 20:52:00 +0100799 ALOGV("ArmnnPreparedModel_1_2::ScheduleGraphForExecution end");
800}
801
802template<typename HalVersion>
803template <typename CallbackContext>
804void ArmnnPreparedModel_1_2<HalVersion>::ArmnnThreadPoolCallback_1_2<CallbackContext>::Notify(
805 armnn::Status status, armnn::InferenceTimingPair timeTaken)
806{
807 ALOGV("ArmnnPreparedModel_1_2::ArmnnThreadPoolCallback_1_2 Notify");
808
809 TimePoint driverEnd;
810
811 CommitPools(*m_MemPools);
812
813 m_Model->DumpTensorsIfRequired("Output", *m_OutputTensors);
814
815 if (status != armnn::Status::Success)
816 {
817 ALOGW("ArmnnThreadPoolCallback::Notify EnqueueWorkload failed");
818 m_CallbackContext.callback(
819 V1_0::ErrorStatus::GENERAL_FAILURE, {}, g_NoTiming, "ArmnnPreparedModel::ExecuteGraph");
820 return;
821 }
822
823 if (m_CallbackContext.ctx.measureTimings == V1_2::MeasureTiming::YES)
824 {
825 driverEnd = std::chrono::steady_clock::now();
826 V1_2::Timing timing;
827 timing.timeOnDevice = MicrosecondsDuration(timeTaken.second, timeTaken.first);
828 timing.timeInDriver = MicrosecondsDuration(driverEnd, m_CallbackContext.ctx.driverStart);
Zingo Andersen7c561492022-01-25 11:09:41 +0100829 ALOGV("ArmnnPreparedModel_1_2::execute timing - Device = %lu Driver = %lu",
830 static_cast<unsigned long>(timing.timeOnDevice), static_cast<unsigned long>(timing.timeInDriver));
Finn Williamsd8fb5402021-05-19 20:52:00 +0100831 m_CallbackContext.callback(
832 V1_0::ErrorStatus::NONE, m_OutputShapes, timing, "ArmnnPreparedModel_1_2::ExecuteGraph");
833 } else {
834 m_CallbackContext.callback(
835 V1_0::ErrorStatus::NONE, m_OutputShapes, g_NoTiming, "ArmnnPreparedModel_1_2::ExecuteGraph");
836 }
837 return;
838}
839
Kevin May42477c12020-03-26 13:34:14 +0000840#if defined(ARMNN_ANDROID_NN_V1_2) || defined(ARMNN_ANDROID_NN_V1_3)
Mike Kellyb5fdf382019-06-11 16:35:25 +0100841template class ArmnnPreparedModel_1_2<hal_1_2::HalPolicy>;
Derek Lamberti4de83c52020-03-17 13:40:18 +0000842template bool ArmnnPreparedModel_1_2<hal_1_2::HalPolicy>::ExecuteGraph<CallbackContext_1_2>(
843 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
844 armnn::InputTensors& pInputTensors,
845 armnn::OutputTensors& pOutputTensors,
846 CallbackContext_1_2 cb);
Finn Williamsd8fb5402021-05-19 20:52:00 +0100847
848template void ArmnnPreparedModel_1_2<hal_1_2::HalPolicy>::ScheduleGraphForExecution<CallbackContext_1_2>(
849 std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
850 std::shared_ptr<armnn::InputTensors>& inputTensors,
851 std::shared_ptr<armnn::OutputTensors>& outputTensors,
852 CallbackContext_1_2 callbackContext);
Mike Kellyb5fdf382019-06-11 16:35:25 +0100853#endif
854
855} // namespace armnn_driver