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 <armnn/backends/IBackendInternal.hpp>
15 #include <backendsCommon/TensorHandleFactoryRegistry.hpp>
16 #include <backendsCommon/Workload.hpp>
17 #include <backendsCommon/WorkloadFactory.hpp>
18 #include <ProfilingService.hpp>
19 #include <TimelineUtilityMethods.hpp>
22 #include <unordered_map>
37 using WorkloadQueue = std::vector< std::unique_ptr<IWorkload> >;
38 ~LoadedNetwork(){ FreeWorkingMemory(); }
40 TensorInfo GetInputTensorInfo(LayerBindingId layerId) const;
41 TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const;
43 Status EnqueueWorkload(const InputTensors& inputTensors, const OutputTensors& outputTensors);
45 static std::unique_ptr<LoadedNetwork> MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
46 std::string & errorMessage,
47 const INetworkProperties& networkProperties,
48 profiling::ProfilingService& profilingService);
50 // NOTE we return by reference as the purpose of this method is only to provide
51 // access to the private m_Profiler and in theory we should not need to increment
52 // the shared_ptr's reference counter
53 const std::shared_ptr<Profiler>& GetProfiler() const { return m_Profiler; }
55 void FreeWorkingMemory();
57 void RegisterDebugCallback(const DebugCallbackFunction& func);
59 void SendNetworkStructure();
62 void AllocateWorkingMemory();
64 LoadedNetwork(std::unique_ptr<OptimizedNetwork> net,
65 const INetworkProperties& networkProperties,
66 profiling::ProfilingService& profilingService);
68 void EnqueueInput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
70 void EnqueueOutput(const BindableLayer& layer, ITensorHandle* tensorHandle, const TensorInfo& tensorInfo);
72 bool Execute(std::unique_ptr<profiling::TimelineUtilityMethods>& timelineUtils,
73 profiling::ProfilingGuid inferenceGuid);
76 const IWorkloadFactory& GetWorkloadFactory(const Layer& layer) const;
78 using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>;
80 using WorkloadFactoryWithMemoryManager =
81 std::pair<IBackendInternal::IWorkloadFactoryPtr, IBackendInternal::IMemoryManagerSharedPtr>;
83 using WorkloadFactoryMap = std::unordered_map<BackendId, WorkloadFactoryWithMemoryManager>;
85 BackendPtrMap m_Backends;
86 WorkloadFactoryMap m_WorkloadFactories;
88 std::unique_ptr<OptimizedNetwork> m_OptimizedNetwork;
89 WorkloadQueue m_InputQueue;
90 WorkloadQueue m_WorkloadQueue;
91 WorkloadQueue m_OutputQueue;
92 std::shared_ptr<Profiler> m_Profiler;
94 mutable std::mutex m_WorkingMemMutex;
96 bool m_IsWorkingMemAllocated=false;
97 bool m_IsImportEnabled=false;
98 bool m_IsExportEnabled=false;
100 TensorHandleFactoryRegistry m_TensorHandleFactoryRegistry;
102 profiling::ProfilingService& m_ProfilingService;