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 | { |
| 20 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 21 | template <typename HalVersion> |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 22 | class ArmnnPreparedModel : public IPreparedModel |
| 23 | { |
| 24 | public: |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 25 | using HalModel = typename HalVersion::Model; |
| 26 | |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 27 | ArmnnPreparedModel(armnn::NetworkId networkId, |
| 28 | armnn::IRuntime* runtime, |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 29 | const HalModel& model, |
telsoa01 | ce3e84a | 2018-08-31 09:31:35 +0100 | [diff] [blame] | 30 | const std::string& requestInputsAndOutputsDumpDir, |
| 31 | const bool gpuProfilingEnabled); |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 32 | |
| 33 | virtual ~ArmnnPreparedModel(); |
| 34 | |
| 35 | virtual Return<ErrorStatus> execute(const Request& request, |
| 36 | const ::android::sp<IExecutionCallback>& callback) override; |
| 37 | |
| 38 | /// execute the graph prepared from the request |
| 39 | void ExecuteGraph(std::shared_ptr<std::vector<::android::nn::RunTimePoolInfo>>& pMemPools, |
| 40 | std::shared_ptr<armnn::InputTensors>& pInputTensors, |
| 41 | std::shared_ptr<armnn::OutputTensors>& pOutputTensors, |
| 42 | const ::android::sp<IExecutionCallback>& callback); |
| 43 | |
| 44 | /// Executes this model with dummy inputs (e.g. all zeroes). |
| 45 | void ExecuteWithDummyInputs(); |
| 46 | |
| 47 | private: |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 48 | template <typename TensorBindingCollection> |
| 49 | void DumpTensorsIfRequired(char const* tensorNamePrefix, const TensorBindingCollection& tensorBindings); |
| 50 | |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 51 | armnn::NetworkId m_NetworkId; |
| 52 | armnn::IRuntime* m_Runtime; |
| 53 | HalModel m_Model; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 54 | // There must be a single RequestThread for all ArmnnPreparedModel objects to ensure serial execution of workloads |
| 55 | // It is specific to this class, so it is declared as static here |
Matteo Martincigh | e48bdff | 2018-09-03 13:50:50 +0100 | [diff] [blame] | 56 | static RequestThread<HalVersion> m_RequestThread; |
| 57 | uint32_t m_RequestCount; |
| 58 | const std::string& m_RequestInputsAndOutputsDumpDir; |
| 59 | const bool m_GpuProfilingEnabled; |
telsoa01 | 5307bc1 | 2018-03-09 13:51:08 +0000 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | } |