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

97{ 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 58 of file MemoryPlanner.cc.

59{
60 // Find the right position for claiming
61 uint32_t next_offset = 0;
62 for (const auto &[claimed_base_offset, claimed_index] : _claim_table)
63 {
64 auto claimed_size = _mem_plans[claimed_index].size;
65 if (next_offset + size <= claimed_base_offset)
66 {
67 break;
68 }
69 else
70 {
71 next_offset = claimed_base_offset + claimed_size;
72 }
73 }
74
75 // Now next_offset is set to the proper offset
76 // std::map's operator[] requires default constructor of value
77 // _claim_table[next_offset] = ind;
78 _claim_table.emplace(std::make_pair(next_offset, ind));
79 _mem_plans[ind] = {next_offset, size};
80
81 VERBOSE(FF_PLANNER) << "claim(" << ind << "): [+" << next_offset << ", " << size << "sz]"
82 << std::endl;
83
84 if (_capacity < next_offset + size)
85 {
86 _capacity = next_offset + size;
87 }
88}
#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 102 of file MemoryPlanner.h.

102{ 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 90 of file MemoryPlanner.cc.

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