blob: 89f6226fc2e228ffa938227d5c2f5cefa3415c5d [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#pragma once
7
surmeh01deb3bdb2018-07-05 12:06:04 +01008#include "ArmnnDriver.hpp"
Matteo Martincighe48bdff2018-09-03 13:50:50 +01009#include "ArmnnDriverImpl.hpp"
arovir01b0717b52018-09-05 17:03:25 +010010#include "RequestThread.hpp"
surmeh01deb3bdb2018-07-05 12:06:04 +010011
telsoa01ce3e84a2018-08-31 09:31:35 +010012#include <NeuralNetworks.h>
13#include <armnn/ArmNN.hpp>
14
telsoa015307bc12018-03-09 13:51:08 +000015#include <string>
16#include <vector>
17
18namespace armnn_driver
19{
Mike Kelly65c42dc2019-07-22 14:06:00 +010020using armnnExecuteCallback_1_0 = std::function<void(V1_0::ErrorStatus status, std::string callingFunction)>;
21
22struct ArmnnCallback_1_0
23{
24 armnnExecuteCallback_1_0 callback;
25};
telsoa015307bc12018-03-09 13:51:08 +000026
Derek Lamberti4de83c52020-03-17 13:40:18 +000027struct ExecutionContext_1_0 {};
28
29using CallbackContext_1_0 = CallbackContext<armnnExecuteCallback_1_0, ExecutionContext_1_0>;
30
Matteo Martincighe48bdff2018-09-03 13:50:50 +010031template <typename HalVersion>
Matthew Bentham912b3622019-05-03 15:49:14 +010032class ArmnnPreparedModel : public V1_0::IPreparedModel
telsoa015307bc12018-03-09 13:51:08 +000033{
34public:
Matteo Martincighe48bdff2018-09-03 13:50:50 +010035 using HalModel = typename HalVersion::Model;
36
telsoa015307bc12018-03-09 13:51:08 +000037 ArmnnPreparedModel(armnn::NetworkId networkId,
38 armnn::IRuntime* runtime,
Matteo Martincighe48bdff2018-09-03 13:50:50 +010039 const HalModel& model,
telsoa01ce3e84a2018-08-31 09:31:35 +010040 const std::string& requestInputsAndOutputsDumpDir,
41 const bool gpuProfilingEnabled);
telsoa015307bc12018-03-09 13:51:08 +000042
43 virtual ~ArmnnPreparedModel();
44
Kevin Mayec1e5b82020-02-26 17:00:39 +000045 virtual Return<V1_0::ErrorStatus> execute(const V1_0::Request& request,
46 const ::android::sp<V1_0::IExecutionCallback>& callback) override;
telsoa015307bc12018-03-09 13:51:08 +000047
48 /// execute the graph prepared from the request
49 void ExecuteGraph(std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools,
Derek Lamberti4de83c52020-03-17 13:40:18 +000050 armnn::InputTensors& inputTensors,
51 armnn::OutputTensors& outputTensors,
52 CallbackContext_1_0 callback);
telsoa015307bc12018-03-09 13:51:08 +000053
54 /// Executes this model with dummy inputs (e.g. all zeroes).
Matthew Bentham16196e22019-04-01 17:17:58 +010055 /// \return false on failure, otherwise true
56 bool ExecuteWithDummyInputs();
telsoa015307bc12018-03-09 13:51:08 +000057
58private:
telsoa015307bc12018-03-09 13:51:08 +000059 template <typename TensorBindingCollection>
60 void DumpTensorsIfRequired(char const* tensorNamePrefix, const TensorBindingCollection& tensorBindings);
61
Mike Kelly65c42dc2019-07-22 14:06:00 +010062 armnn::NetworkId m_NetworkId;
63 armnn::IRuntime* m_Runtime;
64 HalModel m_Model;
telsoa015307bc12018-03-09 13:51:08 +000065 // There must be a single RequestThread for all ArmnnPreparedModel objects to ensure serial execution of workloads
66 // It is specific to this class, so it is declared as static here
Derek Lamberti4de83c52020-03-17 13:40:18 +000067 static RequestThread<ArmnnPreparedModel, HalVersion, CallbackContext_1_0> m_RequestThread;
Mike Kelly65c42dc2019-07-22 14:06:00 +010068 uint32_t m_RequestCount;
69 const std::string& m_RequestInputsAndOutputsDumpDir;
70 const bool m_GpuProfilingEnabled;
telsoa015307bc12018-03-09 13:51:08 +000071};
72
73}