ONE - On-device Neural Engine
Loading...
Searching...
No Matches
kuma Namespace Reference

Namespaces

namespace  details
 

Data Structures

class  Context
 
class  Context< Algorithm::Greedy >
 
class  Context< Algorithm::LinearScanFirstFit >
 

Typedefs

using ItemID = uint32_t
 
using ItemSize = uint32_t
 
using MemoryOffset = uint32_t
 
using MemorySize = uint32_t
 

Enumerations

enum  Algorithm { Greedy , LinearScanFirstFit }
 

Functions

void solve (Context< Greedy > *)
 
void solve (Context< Algorithm::LinearScanFirstFit > *)
 
void solve (Context< Algorithm::Greedy > *ctx)
 

Typedef Documentation

◆ ItemID

using kuma::ItemID = typedef uint32_t

Definition at line 39 of file kuma.h.

◆ ItemSize

using kuma::ItemSize = typedef uint32_t

Definition at line 40 of file kuma.h.

◆ MemoryOffset

using kuma::MemoryOffset = typedef uint32_t

Definition at line 42 of file kuma.h.

◆ MemorySize

using kuma::MemorySize = typedef uint32_t

Definition at line 43 of file kuma.h.

Enumeration Type Documentation

◆ Algorithm

Enumerator
Greedy 
LinearScanFirstFit 

Definition at line 27 of file kuma.h.

28{
29 // No reuse
30 Greedy,
32};
@ Greedy
Definition kuma.h:30
@ LinearScanFirstFit
Definition kuma.h:31

Function Documentation

◆ solve() [1/3]

void kuma::solve ( Context< Algorithm::Greedy > *  ctx)

Definition at line 25 of file kuma.cpp.

26{
27 uint32_t next = 0;
28
29 for (uint32_t n = 0; n < ctx->item_count(); ++n)
30 {
31 ctx->mem_offset(n, next);
32 next += ctx->item_size(n);
33 }
34
35 ctx->mem_total(next);
36};
virtual ItemSize item_size(const ItemID &) const =0
virtual void mem_total(const MemorySize &)=0
virtual uint32_t item_count(void) const =0
virtual void mem_offset(const ItemID &, const MemoryOffset &)=0

◆ solve() [2/3]

void kuma::solve ( Context< Algorithm::LinearScanFirstFit > *  ctx)

Definition at line 48 of file kuma.cpp.

49{
50 using namespace kuma::details;
51
52 uint32_t upper_bound = 0;
53 std::map<ItemID, std::pair<uint32_t /* BEGIN */, uint32_t /* END */>> committed_items;
54
55 // Allocate items in linear order (from item 0, item 1, ...)
56 //
57 // The implementor of Context is responsible for item ordering.
58 for (uint32_t n = 0; n < ctx->item_count(); ++n)
59 {
60 IntervalSet intervals;
61
62 for (auto item_in_conflict : ctx->conflict_with(n))
63 {
64 auto it = committed_items.find(item_in_conflict);
65
66 // Skip if item_in_conflict is not committed yet
67 if (it == committed_items.end())
68 {
69 continue;
70 }
71
72 auto const alloc_s = it->second.first;
73 auto const alloc_e = it->second.second;
74 intervals.insert(mask(alloc_s, alloc_e));
75 }
76
77 uint32_t const item_size = ctx->item_size(n);
78 uint32_t const item_alloc_s = intervals.firstfit(item_size);
79 uint32_t const item_alloc_e = item_alloc_s + item_size;
80
81 // Notify "mem_offset"
82 ctx->mem_offset(n, item_alloc_s);
83
84 // Update "upper bound" and commit allocation
85 upper_bound = std::max(upper_bound, item_alloc_e);
86 committed_items[n] = std::make_pair(item_alloc_s, item_alloc_e);
87 }
88
89 // Notify "mem_total"
90 ctx->mem_total(upper_bound);
91}
virtual void mem_total(const MemorySize &)=0
virtual uint32_t item_count(void) const =0
virtual ItemSize item_size(const ItemID &) const =0
virtual void mem_offset(const ItemID &, const MemoryOffset &)=0
void insert(const IntervalMask &)
uint32_t firstfit(uint32_t len) const
uint32_t ItemID
Definition kuma.h:39

References kuma::details::IntervalSet::firstfit(), and kuma::details::IntervalSet::insert().

◆ solve() [3/3]

void kuma::solve ( Context< Greedy > *  )