2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
7 #include <armnn/Tensor.hpp>
8 #include <armnn/Types.hpp>
10 #include "Network.hpp"
11 #include "LayerFwd.hpp"
12 #include "Profiling.hpp"
14 #include <backends/IBackendInternal.hpp>
15 #include <backends/Workload.hpp>
16 #include <backends/WorkloadFactory.hpp>
19 #include <unordered_map>
34 using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >;
35 ~LoadedNetwork(){ FreeWorkingMemory(); }
37 TensorInfo GetInputTensorInfo(LayerBindingId layerId) const;
38 TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const;
40 Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors);
42 static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
43 const IRuntime::CreationOptions& options,
44 std::string & errorMessage);
46 // NOTE we return by reference as the purpose of this method is only to provide
47 // access to the private m_Profiler and in theory we should not need to increment
48 // the shared_ptr's reference counter
49 const std::shared_ptr<Profiler>& GetProfiler() const { return m_Profiler; }
51 void AllocateWorkingMemory();
52 void FreeWorkingMemory();
55 LoadedNetwork(std::unique_ptr<OptimizedNetwork> net, const IRuntime::CreationOptions& options);
57 void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
59 void EnqueueOutput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
63 const IWorkloadFactory& GetWorkloadFactory(const Layer& layer) const;
65 using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>;
66 using WorkloadFactoryMap = std::unordered_map<BackendId, IBackendInternal::IWorkloadFactoryPtr>;
68 BackendPtrMap m_Backends;
69 WorkloadFactoryMap m_WorkloadFactories;
71 std::unique_ptr<OptimizedNetwork> m_OptimizedNetwork;
72 WorkloadQueue m_InputQueue;
73 WorkloadQueue m_WorkloadQueue;
74 WorkloadQueue m_OutputQueue;
75 std::shared_ptr<Profiler> m_Profiler;
77 using UniqueMutexLock = std::unique_lock<std::mutex>;
78 mutable std::mutex m_WorkingMemMutex;
79 UniqueMutexLock m_WorkingMemLock;
81 bool m_IsWorkingMemAllocated=false;