ONE - On-device Neural Engine
Loading...
Searching...
No Matches
luci_interpreter::RuntimeGraph::TensorAllocPlan Class Reference

Public Member Functions

 TensorAllocPlan (IMemoryManager *memory_manager)
 
void invalidate ()
 
bool isValid () const
 
void build (const RuntimeGraph &graph)
 
void allocate (size_t kernel_index) const
 
void deallocate (size_t kernel_index) const
 

Detailed Description

Definition at line 27 of file RuntimeGraph.cpp.

Constructor & Destructor Documentation

◆ TensorAllocPlan()

luci_interpreter::RuntimeGraph::TensorAllocPlan::TensorAllocPlan ( IMemoryManager memory_manager)
explicit

Definition at line 43 of file RuntimeGraph.cpp.

44 : _memory_manager(memory_manager)
45{
46}

Member Function Documentation

◆ allocate()

void luci_interpreter::RuntimeGraph::TensorAllocPlan::allocate ( size_t  kernel_index) const

Definition at line 85 of file RuntimeGraph.cpp.

86{
87 assert(_valid && kernel_index < _alloc_plan.size());
88 for (Tensor *tensor : _alloc_plan[kernel_index])
89 {
90 _memory_manager->allocate_memory(*tensor);
91 }
92}
virtual void allocate_memory(luci_interpreter::Tensor &tensor)=0

References luci_interpreter::IMemoryManager::allocate_memory().

◆ build()

void luci_interpreter::RuntimeGraph::TensorAllocPlan::build ( const RuntimeGraph graph)

Definition at line 48 of file RuntimeGraph.cpp.

49{
50 invalidate();
51 using Lifetime = std::pair<size_t, size_t>;
52 std::unordered_map<Tensor *, Lifetime> lifetimes;
53 const size_t num_kernels = graph._kernels.size();
54 for (size_t index = 0; index < num_kernels; ++index)
55 {
56 const auto &kernel = graph._kernels[index];
57 for (const Tensor *tensor : kernel->getInputTensors())
58 {
59 auto nc_tensor = const_cast<Tensor *>(tensor);
60 if (lifetimes.count(nc_tensor) > 0)
61 lifetimes.at(nc_tensor).second = index;
62 }
63 for (Tensor *tensor : kernel->getOutputTensors())
64 {
65 assert(lifetimes.count(tensor) == 0);
66 lifetimes[tensor] = Lifetime(index, index);
67 }
68 }
69 for (const Tensor *tensor : graph.getOutputTensors())
70 {
71 auto nc_tensor = const_cast<Tensor *>(tensor);
72 if (lifetimes.count(nc_tensor) > 0)
73 lifetimes.at(nc_tensor).second = num_kernels;
74 }
75 _alloc_plan.assign(num_kernels, std::vector<Tensor *>());
76 _dealloc_plan.assign(num_kernels + 1, std::vector<Tensor *>());
77 for (const auto &item : lifetimes)
78 {
79 _alloc_plan[item.second.first].push_back(item.first);
80 _dealloc_plan[item.second.second].push_back(item.first);
81 }
82 _valid = true;
83}
float & at(const vector< int > &coords)
const std::vector< Tensor * > & getOutputTensors() const
const std::vector< Tensor * > & getInputTensors() const
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References luci_interpreter::RuntimeGraph::invalidate().

◆ deallocate()

void luci_interpreter::RuntimeGraph::TensorAllocPlan::deallocate ( size_t  kernel_index) const

Definition at line 94 of file RuntimeGraph.cpp.

95{
96 assert(_valid && kernel_index < _dealloc_plan.size());
97 for (Tensor *tensor : _dealloc_plan[kernel_index])
98 {
99 _memory_manager->release_memory(*tensor);
100 }
101}
virtual void release_memory(luci_interpreter::Tensor &tensor)=0

References luci_interpreter::IMemoryManager::release_memory().

◆ invalidate()

void luci_interpreter::RuntimeGraph::TensorAllocPlan::invalidate ( )
inline

Definition at line 36 of file RuntimeGraph.cpp.

36{ _valid = false; }

◆ isValid()

bool luci_interpreter::RuntimeGraph::TensorAllocPlan::isValid ( ) const
inline

Definition at line 37 of file RuntimeGraph.cpp.

37{ return _valid; }

The documentation for this class was generated from the following file: