ArmNN
 21.08
WorkingMemHandle.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 #include "WorkingMemHandle.hpp"
8 #include "Network.hpp"
10 
11 namespace armnn
12 {
13 
14 namespace experimental
15 {
16 
18  NetworkId networkId,
19  std::vector<WorkingMemDescriptor> workingMemDescriptors,
20  std::unordered_map<LayerGuid, WorkingMemDescriptor> workingMemDescriptorMap,
21  std::vector<std::shared_ptr<IMemoryManager>> memoryManagers,
22  std::unordered_map<LayerGuid, std::vector<std::unique_ptr<ITensorHandle> > > ownedTensorHandles) :
23  m_NetworkId(networkId),
24  m_WorkingMemDescriptors(workingMemDescriptors),
25  m_WorkingMemDescriptorMap(workingMemDescriptorMap),
26  m_MemoryManagers(memoryManagers),
27  m_OwnedTensorHandles(std::move(ownedTensorHandles)),
28  m_IsAllocated(false),
29  m_Mutex()
30 {
31 }
32 
34 {
35  if (m_IsAllocated)
36  {
37  return;
38  }
39  m_IsAllocated = true;
40 
41  for (auto& mgr : m_MemoryManagers)
42  {
43  mgr->Acquire();
44  }
45 }
46 
48 {
49  if (!m_IsAllocated)
50  {
51  return;
52  }
53  m_IsAllocated = false;
54 
55  for (auto& mgr : m_MemoryManagers)
56  {
57  mgr->Release();
58  }
59 }
60 
61 } // end experimental namespace
62 
63 } // end armnn namespace
Copyright (c) 2021 ARM Limited and Contributors.
int NetworkId
Definition: IRuntime.hpp:24
void Allocate() override
Allocate the backing memory required for execution.
profiling::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition: Types.hpp:313
WorkingMemHandle(NetworkId networkId, std::vector< WorkingMemDescriptor > workingMemDescriptors, std::unordered_map< LayerGuid, WorkingMemDescriptor > workingMemDescriptorMap, std::vector< std::shared_ptr< IMemoryManager >> memoryManagers, std::unordered_map< LayerGuid, std::vector< std::unique_ptr< ITensorHandle > > > ownedTensorHandles)
void Free() override
Free the backing memory required for execution. The mutex must be locked.