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 | #pragma once |
| 7 | |
surmeh01 | deb3bdb | 2018-07-05 12:06:04 +0100 | [diff] [blame] | 8 | #include "ArmnnDriver.hpp" |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 9 | #include "ArmnnDriverImpl.hpp" |
arovir01 | b0717b5 | 2018-09-05 17:03:25 +0100 | [diff] [blame] | 10 | #include "RequestThread.hpp" |
surmeh01 | deb3bdb | 2018-07-05 12:06:04 +0100 | [diff] [blame] | 11 | |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 12 | #include <NeuralNetworks.h> |
| 13 | #include <armnn/ArmNN.hpp> |
| 14 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | namespace armnn_driver |
| 19 | { |
Mike Kelly | 65c42dc | 2019-07-22 14:06:00 +0100 | [diff] [blame] | 20 | using armnnExecuteCallback_1_0 = std::function<void(V1_0::ErrorStatus status, std::string callingFunction)>; |
| 21 | |
| 22 | struct ArmnnCallback_1_0 |
| 23 | { |
| 24 | armnnExecuteCallback_1_0 callback; |
| 25 | }; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 26 | |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 27 | struct ExecutionContext_1_0 {}; |
| 28 | |
| 29 | using CallbackContext_1_0 = CallbackContext<armnnExecuteCallback_1_0, ExecutionContext_1_0>; |
| 30 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 31 | template <typename HalVersion> |
Matthew Bentham | 912b362 | 2019-05-03 15:49:14 +0100 | [diff] [blame] | 32 | class ArmnnPreparedModel : public V1_0::IPreparedModel |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 33 | { |
| 34 | public: |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 35 | using HalModel = typename HalVersion::Model; |
| 36 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 37 | ArmnnPreparedModel(armnn::NetworkId networkId, |
| 38 | armnn::IRuntime* runtime, |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 39 | const HalModel& model, |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 40 | const std::string& requestInputsAndOutputsDumpDir, |
| 41 | const bool gpuProfilingEnabled); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 42 | |
| 43 | virtual ~ArmnnPreparedModel(); |
| 44 | |
Kevin May | ec1e5b8 | 2020-02-26 17:00:39 +0000 | [diff] [blame] | 45 | virtual Return<V1_0::ErrorStatus> execute(const V1_0::Request& request, |
| 46 | const ::android::sp<V1_0::IExecutionCallback>& callback) override; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 47 | |
| 48 | /// execute the graph prepared from the request |
| 49 | void ExecuteGraph(std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools, |
Derek Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 50 | armnn::InputTensors& inputTensors, |
| 51 | armnn::OutputTensors& outputTensors, |
| 52 | CallbackContext_1_0 callback); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 53 | |
| 54 | /// Executes this model with dummy inputs (e.g. all zeroes). |
Matthew Bentham | 16196e2 | 2019-04-01 17:17:58 +0100 | [diff] [blame] | 55 | /// \return false on failure, otherwise true |
| 56 | bool ExecuteWithDummyInputs(); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 57 | |
| 58 | private: |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 59 | template <typename TensorBindingCollection> |
| 60 | void DumpTensorsIfRequired(char const* tensorNamePrefix, const TensorBindingCollection& tensorBindings); |
| 61 | |
Mike Kelly | 65c42dc | 2019-07-22 14:06:00 +0100 | [diff] [blame] | 62 | armnn::NetworkId m_NetworkId; |
| 63 | armnn::IRuntime* m_Runtime; |
| 64 | HalModel m_Model; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 65 | // 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 Lamberti | 4de83c5 | 2020-03-17 13:40:18 +0000 | [diff] [blame] | 67 | static RequestThread<ArmnnPreparedModel, HalVersion, CallbackContext_1_0> m_RequestThread; |
Mike Kelly | 65c42dc | 2019-07-22 14:06:00 +0100 | [diff] [blame] | 68 | uint32_t m_RequestCount; |
| 69 | const std::string& m_RequestInputsAndOutputsDumpDir; |
| 70 | const bool m_GpuProfilingEnabled; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | } |