ONE - On-device Neural Engine
Loading...
Searching...
No Matches
kuma.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __KUMA_H__
18#define __KUMA_H__
19
20#include <cstdint>
21#include <set>
22
23namespace kuma
24{
25
26// Supported algorithms
28{
29 // No reuse
32};
33
37template <Algorithm Alg> class Context;
38
39using ItemID = uint32_t;
40using ItemSize = uint32_t;
41
42using MemoryOffset = uint32_t;
43using MemorySize = uint32_t;
44
45//
46// Greedy Algorithm
47//
48template <> class Context<Algorithm::Greedy>
49{
50public:
51 virtual ~Context() = default;
52
53public: // Inputs
54 // count() returns the number of items to be allocated
55 virtual uint32_t item_count(void) const = 0;
56
57 // size(N) returns the size of the N-th item
58 virtual ItemSize item_size(const ItemID &) const = 0;
59
60public: // Outputs
61 virtual void mem_offset(const ItemID &, const MemoryOffset &) = 0;
62 virtual void mem_total(const MemorySize &) = 0;
63};
64
66
67//
68// Linear Scan First-Fit Algorithm
69//
71{
72public:
73 virtual ~Context() = default;
74
75public: // Inputs
76 // count() returns the number of items to be allocated
77 virtual uint32_t item_count(void) const = 0;
78
79 // size(N) returns the size of the N-th item
80 virtual ItemSize item_size(const ItemID &) const = 0;
81
82 // conflict_with(N) returns all the items that are in conflict with item N
83 // - An item N is said to be in conflict with item M if item M and N cannot have overlap
84 //
85 // NOTE
86 // - conflict_with(N) SHOULD NOT include N itself
87 virtual std::set<ItemID> conflict_with(const ItemID &) const = 0;
88
89public: // Outputs
90 virtual void mem_offset(const ItemID &, const MemoryOffset &) = 0;
91 virtual void mem_total(const MemorySize &) = 0;
92};
93
95
96} // namespace kuma
97
98#endif // __KUMA_H__
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
virtual void mem_total(const MemorySize &)=0
virtual uint32_t item_count(void) const =0
virtual ItemSize item_size(const ItemID &) const =0
virtual std::set< ItemID > conflict_with(const ItemID &) const =0
virtual void mem_offset(const ItemID &, const MemoryOffset &)=0
Definition kuma.h:24
uint32_t MemoryOffset
Definition kuma.h:42
uint32_t ItemID
Definition kuma.h:39
uint32_t ItemSize
Definition kuma.h:40
uint32_t MemorySize
Definition kuma.h:43
void solve(Context< Greedy > *)
Algorithm
Definition kuma.h:28
@ Greedy
Definition kuma.h:30
@ LinearScanFirstFit
Definition kuma.h:31