ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::basic::FirstFitPlanner Class Reference

Class to plan memory by firstfit way. More...

#include <MemoryPlanner.h>

Collaboration diagram for onert::backend::basic::FirstFitPlanner:

Public Member Functions

void claim (const ir::OperandIndex &, size_t) override
 Claim memory for operand by firstfit way.
 
void release (const ir::OperandIndex &) override
 Release memory for operand by firstfit way.
 
uint32_t capacity () override
 Get capacity for memory planning.
 
MemoryPlansmemory_plans () override
 Get MemoryPlans.
 
- Public Member Functions inherited from onert::backend::basic::IMemoryPlanner< ir::OperandIndex >
virtual ~IMemoryPlanner ()=default
 

Additional Inherited Members

- Public Types inherited from onert::backend::basic::IMemoryPlanner< ir::OperandIndex >
using MemoryPlans = std::unordered_map< ir::OperandIndex, Block >
 

Detailed Description

Class to plan memory by firstfit way.

Definition at line 77 of file MemoryPlanner.h.

Member Function Documentation

◆ capacity()

uint32_t onert::backend::basic::FirstFitPlanner::capacity ( )
inlineoverridevirtual

Get capacity for memory planning.

Returns
The value of capacity

Implements onert::backend::basic::IMemoryPlanner< ir::OperandIndex >.

Definition at line 95 of file MemoryPlanner.h.

95{ return _capacity; }

◆ claim()

void onert::backend::basic::FirstFitPlanner::claim ( const ir::OperandIndex ind,
size_t  size 
)
overridevirtual

Claim memory for operand by firstfit way.

Parameters
[in]indexThe operand index
[in]sizeThe size of the memory

Implements onert::backend::basic::IMemoryPlanner< ir::OperandIndex >.

Definition at line 57 of file MemoryPlanner.cc.

58{
59 // Find the right position for claiming
60 uint32_t next_offset = 0;
61 for (const auto &[claimed_base_offset, claimed_operand_idx] : _claim_table)
62 {
63 auto claimed_size = _mem_plans[claimed_operand_idx].size;
64 if (next_offset + size <= claimed_base_offset)
65 {
66 break;
67 }
68 else
69 {
70 next_offset = claimed_base_offset + claimed_size;
71 }
72 }
73
74 // Now next_offset is set to the proper offset
75 _claim_table[next_offset] = ind;
76 _mem_plans[ind] = {next_offset, size};
77
78 VERBOSE(FF_PLANNER) << "claim(" << ind << "): [+" << next_offset << ", " << size << "sz]"
79 << std::endl;
80
81 if (_capacity < next_offset + size)
82 {
83 _capacity = next_offset + size;
84 }
85}
#define VERBOSE(name, lv)
Definition Log.h:71
int32_t size[5]
Definition Slice.cpp:35

References size, and VERBOSE.

◆ memory_plans()

MemoryPlans & onert::backend::basic::FirstFitPlanner::memory_plans ( )
inlineoverridevirtual

Get MemoryPlans.

Returns
MemoryPlans

Implements onert::backend::basic::IMemoryPlanner< ir::OperandIndex >.

Definition at line 100 of file MemoryPlanner.h.

100{ return _mem_plans; }

◆ release()

void onert::backend::basic::FirstFitPlanner::release ( const ir::OperandIndex ind)
overridevirtual

Release memory for operand by firstfit way.

Parameters
[in]indexThe operand index

Implements onert::backend::basic::IMemoryPlanner< ir::OperandIndex >.

Definition at line 87 of file MemoryPlanner.cc.

88{
89 for (auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
90 {
91 if (it->second == ind)
92 {
93 uint32_t offset = it->first;
94 uint32_t index = ind.value();
95 uint32_t size = _mem_plans[ind].size;
96
97 _claim_table.erase(it);
98
99 VERBOSE(FF_PLANNER) << "release(" << index << "): [+" << offset << ", " << size << "sz]"
100 << std::endl;
101 return;
102 }
103 }
104 assert(!"Cannot release for given index. It has been not claimed or released already.");
105}
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540
loco::GraphInputIndex index(const TFPlaceholder *node)
Definition TFNode.cpp:54

References offset(), size, onert::util::Index< T, DummyTag >::value(), and VERBOSE.


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