ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 73 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 91 of file MemoryPlanner.h.

91{ 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 53 of file MemoryPlanner.cc.

54{
55 // Find the right position for claiming
56 uint32_t next_offset = 0;
57 for (const auto &[claimed_base_offset, claimed_operand_idx] : _claim_table)
58 {
59 auto claimed_size = _mem_plans[claimed_operand_idx].size;
60 if (next_offset + size <= claimed_base_offset)
61 {
62 break;
63 }
64 else
65 {
66 next_offset = claimed_base_offset + claimed_size;
67 }
68 }
69
70 // Now next_offset is set to the proper offset
71 _claim_table[next_offset] = ind;
72 _mem_plans[ind] = {next_offset, size};
73
74 VERBOSE(FF_PLANNER) << "claim(" << ind << "): [+" << next_offset << ", " << size << "sz]"
75 << std::endl;
76
77 if (_capacity < next_offset + size)
78 {
79 _capacity = next_offset + size;
80 }
81}
#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 96 of file MemoryPlanner.h.

96{ 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 83 of file MemoryPlanner.cc.

84{
85 for (auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
86 {
87 if (it->second == ind)
88 {
89 uint32_t offset = it->first;
90 uint32_t index = ind.value();
91 uint32_t size = _mem_plans[ind].size;
92
93 _claim_table.erase(it);
94
95 VERBOSE(FF_PLANNER) << "release(" << index << "): [+" << offset << ", " << size << "sz]"
96 << std::endl;
97 return;
98 }
99 }
100 assert(!"Cannot release for given index. It has been not claimed or released already.");
101}
__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: