ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::train::FirstFitPlanner< Index > Class Template Reference

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

#include <MemoryPlanner.h>

Collaboration diagram for onert::backend::train::FirstFitPlanner< Index >:

Public Member Functions

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

Additional Inherited Members

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

Detailed Description

template<typename Index>
class onert::backend::train::FirstFitPlanner< Index >

Class to plan memory by firstfit way.

Definition at line 80 of file MemoryPlanner.h.

Member Function Documentation

◆ capacity()

template<typename Index >
uint32_t onert::backend::train::FirstFitPlanner< Index >::capacity ( )
inlineoverridevirtual

Get capacity for memory planning.

Returns
The value of capacity

Implements onert::backend::basic::IMemoryPlanner< Index >.

Definition at line 101 of file MemoryPlanner.h.

101{ return _capacity; }

◆ claim()

template<typename Index >
void onert::backend::train::FirstFitPlanner< Index >::claim ( const Index &  ind,
size_t  size 
)
overridevirtual

Claim memory for tensor by firstfit way.

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

Implements onert::backend::basic::IMemoryPlanner< Index >.

Definition at line 62 of file MemoryPlanner.cc.

63{
64 // Find the right position for claiming
65 uint32_t next_offset = 0;
66 for (const auto &[claimed_base_offset, claimed_index] : _claim_table)
67 {
68 auto claimed_size = _mem_plans[claimed_index].size;
69 if (next_offset + size <= claimed_base_offset)
70 {
71 break;
72 }
73 else
74 {
75 next_offset = claimed_base_offset + claimed_size;
76 }
77 }
78
79 // Now next_offset is set to the proper offset
80 // std::map's operator[] requires default constructor of value
81 // _claim_table[next_offset] = ind;
82 _claim_table.emplace(std::make_pair(next_offset, ind));
83 _mem_plans[ind] = {next_offset, size};
84
85 VERBOSE(FF_PLANNER) << "claim(" << ind << "): [+" << next_offset << ", " << size << "sz]"
86 << std::endl;
87
88 if (_capacity < next_offset + size)
89 {
90 _capacity = next_offset + size;
91 }
92}
#define VERBOSE(name, lv)
Definition Log.h:71
int32_t size[5]
Definition Slice.cpp:35

References size, and VERBOSE.

◆ memory_plans()

template<typename Index >
MemoryPlans & onert::backend::train::FirstFitPlanner< Index >::memory_plans ( )
inlineoverridevirtual

Get MemoryPlans.

Returns
MemoryPlans

Implements onert::backend::basic::IMemoryPlanner< Index >.

Definition at line 106 of file MemoryPlanner.h.

106{ return _mem_plans; }

◆ release()

template<typename Index >
void onert::backend::train::FirstFitPlanner< Index >::release ( const Index &  ind)
overridevirtual

Release memory for tensor by firstfit way.

Parameters
[in]indexThe tensor index

Implements onert::backend::basic::IMemoryPlanner< Index >.

Definition at line 94 of file MemoryPlanner.cc.

95{
96 for (auto it = _claim_table.cbegin(); it != _claim_table.cend(); ++it)
97 {
98 if (it->second == ind)
99 {
100 uint32_t offset = it->first;
101 uint32_t size = _mem_plans[ind].size;
102
103 _claim_table.erase(it);
104
105 VERBOSE(FF_PLANNER) << "release(" << ind << "): [+" << offset << ", " << size << "sz]"
106 << std::endl;
107 return;
108 }
109 }
110 assert(!"Cannot release for given index. It has been not claimed or released already.");
111}
__global uchar * offset(const Image *img, int x, int y)
Definition helpers.h:540

References offset(), size, and VERBOSE.


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