telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
David Beck | ecb56cd | 2018-09-05 12:52:57 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 4 | // |
| 5 | #pragma once |
| 6 | |
David Beck | b4540be | 2018-09-24 13:18:27 +0100 | [diff] [blame] | 7 | #include <armnn/Tensor.hpp> |
| 8 | #include <armnn/Types.hpp> |
| 9 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 10 | #include "Network.hpp" |
| 11 | #include "LayerFwd.hpp" |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 12 | #include "Profiling.hpp" |
David Beck | b4540be | 2018-09-24 13:18:27 +0100 | [diff] [blame] | 13 | |
Aron Virginas-Tar | c9cc804 | 2018-11-01 16:15:57 +0000 | [diff] [blame] | 14 | #include <backendsCommon/IBackendInternal.hpp> |
| 15 | #include <backendsCommon/Workload.hpp> |
| 16 | #include <backendsCommon/WorkloadFactory.hpp> |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 17 | |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 18 | #include <mutex> |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 19 | #include <unordered_map> |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 20 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 21 | namespace cl |
| 22 | { |
| 23 | class Context; |
| 24 | class CommandQueue; |
| 25 | class Device; |
| 26 | } |
| 27 | |
| 28 | namespace armnn |
| 29 | { |
| 30 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 31 | class LoadedNetwork |
| 32 | { |
| 33 | public: |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 34 | using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >; |
| 35 | ~LoadedNetwork(){ FreeWorkingMemory(); } |
| 36 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 37 | TensorInfo GetInputTensorInfo(LayerBindingId layerId) const; |
| 38 | TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const; |
| 39 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 40 | Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 41 | |
| 42 | static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net, |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 43 | std::string & errorMessage); |
| 44 | |
| 45 | // NOTE we return by reference as the purpose of this method is only to provide |
| 46 | // access to the private m_Profiler and in theory we should not need to increment |
| 47 | // the shared_ptr's reference counter |
| 48 | const std::shared_ptr<Profiler>& GetProfiler() const { return m_Profiler; } |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 49 | |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 50 | void AllocateWorkingMemory(); |
| 51 | void FreeWorkingMemory(); |
| 52 | |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 53 | private: |
David Beck | 9efb57d | 2018-11-05 13:40:33 +0000 | [diff] [blame] | 54 | LoadedNetwork(std::unique_ptr<OptimizedNetwork> net); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 55 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 56 | void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 57 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 58 | void EnqueueOutput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo); |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 59 | |
| 60 | bool Execute(); |
| 61 | |
surmeh01 | 3537c2c | 2018-05-18 16:31:43 +0100 | [diff] [blame] | 62 | const IWorkloadFactory& GetWorkloadFactory(const Layer& layer) const; |
| 63 | |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 64 | using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>; |
Aron Virginas-Tar | 5caf907 | 2018-11-14 18:35:18 +0000 | [diff] [blame] | 65 | |
| 66 | using WorkloadFactoryWithMemoryManager = |
| 67 | std::pair<IBackendInternal::IWorkloadFactoryPtr, IBackendInternal::IMemoryManagerSharedPtr>; |
| 68 | |
| 69 | using WorkloadFactoryMap = std::unordered_map<BackendId, WorkloadFactoryWithMemoryManager>; |
David Beck | 29c75de | 2018-10-23 13:35:58 +0100 | [diff] [blame] | 70 | |
| 71 | BackendPtrMap m_Backends; |
| 72 | WorkloadFactoryMap m_WorkloadFactories; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 73 | |
| 74 | std::unique_ptr<OptimizedNetwork> m_OptimizedNetwork; |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 75 | WorkloadQueue m_InputQueue; |
| 76 | WorkloadQueue m_WorkloadQueue; |
| 77 | WorkloadQueue m_OutputQueue; |
telsoa01 | c577f2c | 2018-08-31 09:22:23 +0100 | [diff] [blame] | 78 | std::shared_ptr<Profiler> m_Profiler; |
Derek Lamberti | 03614f6 | 2018-10-02 15:52:46 +0100 | [diff] [blame] | 79 | |
| 80 | using UniqueMutexLock = std::unique_lock<std::mutex>; |
| 81 | mutable std::mutex m_WorkingMemMutex; |
| 82 | UniqueMutexLock m_WorkingMemLock; |
| 83 | |
| 84 | bool m_IsWorkingMemAllocated=false; |
telsoa01 | 4fcda01 | 2018-03-09 14:13:49 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } |