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