23 #include <client/include/IProfilingService.hpp>
24 #include <client/include/TimelineUtilityMethods.hpp>
26 #include <common/include/LabelsAndEventClasses.hpp>
29 #include <condition_variable>
30 #include <unordered_map>
65 std::vector<ImportedInputId> preImportedInputIds = {},
66 std::vector<ImportedOutputId> preImportedOutputIds = {});
68 static std::unique_ptr<LoadedNetwork>
MakeLoadedNetwork(std::unique_ptr<IOptimizedNetwork> net,
69 std::string& errorMessage,
70 const INetworkProperties& networkProperties,
71 arm::pipe::IProfilingService* profilingService);
76 const std::shared_ptr<IProfiler>&
GetProfiler()
const {
return m_OptimizedNetwork->GetProfiler(); }
89 void AllocateWorkingMemory(
90 #
if !defined(ARMNN_DISABLE_THREADS)
91 std::lock_guard<std::mutex>& lock
94 void AllocateAndExecuteConstantWorkloads();
96 std::unordered_map<LayerGuid, std::unique_ptr<IWorkload>> m_ConstantWorkloads;
97 std::unordered_map<LayerGuid, ITensorHandle*> m_ConstantTensorHandles;
99 std::unique_ptr<IMemoryOptimizerStrategy> m_ConstantStrategy = std::make_unique<SingleAxisPriorityList>();
103 arm::pipe::IProfilingService* profilingService);
113 bool Execute(std::unique_ptr<arm::pipe::TimelineUtilityMethods>& timelineUtils,
114 arm::pipe::ProfilingGuid inferenceGuid);
121 void CreateMemoryProfile();
123 std::unique_ptr<MemoryManager> CreateExternalMemoryManger(
124 std::vector<std::pair<std::shared_ptr<TensorMemory>,
MemorySource>>& tensorMemory);
126 using BackendPtrMap = std::unordered_map<BackendId, IBackendInternalUniquePtr>;
128 BackendPtrMap m_Backends;
129 std::vector<IBackendInternal::IMemoryManagerSharedPtr> m_BackendMemoryMangers;
131 using WorkloadFactoryMap = std::unordered_map<BackendId, IBackendInternal::IWorkloadFactoryPtr>;
132 WorkloadFactoryMap m_WorkloadFactories;
134 std::unique_ptr<IOptimizedNetwork> m_OptimizedNetwork;
140 #if !defined(ARMNN_DISABLE_THREADS)
141 mutable std::mutex m_WorkingMemMutex;
144 bool m_IsWorkingMemAllocated =
false;
151 arm::pipe::IProfilingService* m_ProfilingService;
153 struct ImportedTensorHandlePin
155 ImportedTensorHandlePin()
159 std::unique_ptr<ITensorHandle> tensorHandle)
160 : m_LayerBindingId(layerBindingId)
161 , m_TensorHandle(
std::move(tensorHandle))
164 ImportedTensorHandlePin(ImportedTensorHandlePin&&) =
default;
166 ~ImportedTensorHandlePin()
170 m_TensorHandle->Unimport();
175 std::unique_ptr<ITensorHandle> m_TensorHandle;
178 std::vector<ImportedTensorHandlePin> m_PreImportedInputHandles;
179 std::vector<ImportedTensorHandlePin> m_PreImportedOutputHandles;
181 std::unordered_map<BackendId, std::vector<MemBlock>> m_MemBlockMap;
182 std::unordered_map<BackendId, std::vector<MemBin>> m_MemBinMap;
184 std::vector<ITensorHandle*> m_Tensorhandles;
186 std::vector<std::pair<std::shared_ptr<TensorMemory>,
MemorySource>> m_TensorMemory;
188 std::unique_ptr<MemoryManager> m_ExternalMemoryManager;
190 std::unordered_map<BackendId, bool> m_SupportsExternallyManagedMemory;
194 struct WorkloadIndices
196 unsigned int m_WorkloadIndex;
197 unsigned int m_SlotIndex;
200 struct OutputWorkloadIndices
202 WorkloadIndices m_OutputSlotIndices;
203 std::vector<WorkloadIndices> m_InputSlotIndices;
205 std::unordered_map<LayerBindingId, std::vector<WorkloadIndices>> m_InputWorkloadSlotPairs;
206 std::unordered_map<LayerBindingId, OutputWorkloadIndices> m_OutputWorkloadSlotPairs;
207 std::vector<bool> m_IsInputImported;
208 std::vector<bool> m_IsOutputImported;
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
void RegisterDebugCallback(const DebugCallbackFunction &func)
TensorInfo GetOutputTensorInfo(LayerBindingId layerId) const
std::vector< std::unique_ptr< IWorkload > > WorkloadQueue
std::vector< ImportedInputId > ImportInputs(const InputTensors &inputTensors, MemorySource forceImportMemorySource=MemorySource::Undefined)
Status EnqueueWorkload(const InputTensors &inputTensors, const OutputTensors &outputTensors, std::vector< ImportedInputId > preImportedInputIds={}, std::vector< ImportedOutputId > preImportedOutputIds={})
Single thread execution of the loaded network.
void ClearImportedInputs(const std::vector< ImportedInputId > inputIds)
std::vector< ImportedOutputId > ImportOutputs(const OutputTensors &outputTensors, MemorySource forceImportMemorySource=MemorySource::Undefined)
arm::pipe::ProfilingGuid GetNetworkGuid()
void SendNetworkStructure(arm::pipe::IProfilingService &profilingService)
const std::shared_ptr< IProfiler > & GetProfiler() const
void ClearImportedOutputs(const std::vector< ImportedOutputId > outputIds)
TensorInfo GetInputTensorInfo(LayerBindingId layerId) const
static std::unique_ptr< LoadedNetwork > MakeLoadedNetwork(std::unique_ptr< IOptimizedNetwork > net, std::string &errorMessage, const INetworkProperties &networkProperties, arm::pipe::IProfilingService *profilingService)
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
Copyright (c) 2021 ARM Limited and Contributors.
MemorySource
Define the Memory Source to reduce copies.
std::function< void(LayerGuid guid, unsigned int slotIndex, ITensorHandle *tensorHandle)> DebugCallbackFunction
Define the type of callback for the Debug layer to call.
std::vector< std::unique_ptr< IWorkload > > WorkloadQueue
unsigned int ImportedInputId
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
unsigned int ImportedOutputId