ONE - On-device Neural Engine
Loading...
Searching...
No Matches
MemoryPlanner.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 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
22#ifndef __ONERT_BACKEND_BASIC_MEMORY_PLANNER_H__
23#define __ONERT_BACKEND_BASIC_MEMORY_PLANNER_H__
24
25#include <map>
26#include <vector>
27#include <unordered_set>
28#include <memory>
29
32#include "ir/OperandIndexMap.h"
33
34namespace onert
35{
36namespace backend
37{
38namespace basic
39{
40
44class BumpPlanner : public IMemoryPlanner<ir::OperandIndex>
45{
46public:
52 void claim(const ir::OperandIndex &, size_t) override;
57 void release(const ir::OperandIndex &) override;
62 uint32_t capacity() override { return _capacity; }
67 MemoryPlans &memory_plans() override { return _mem_plans; }
68
69private:
70 uint32_t _capacity = 0;
71 MemoryPlans _mem_plans;
72};
73
77class FirstFitPlanner : public IMemoryPlanner<ir::OperandIndex>
78{
79public:
85 void claim(const ir::OperandIndex &, size_t) override;
90 void release(const ir::OperandIndex &) override;
95 uint32_t capacity() override { return _capacity; }
100 MemoryPlans &memory_plans() override { return _mem_plans; }
101
102private:
103 uint32_t _capacity = 0;
104 MemoryPlans _mem_plans;
105 // Use std::map because claim() assumes that _claim_table is sorted by uint32_t(base_offset)
106 std::map<uint32_t, ir::OperandIndex> _claim_table;
107};
108
112class WICPlanner : public IMemoryPlanner<ir::OperandIndex>
113{
114public:
115 WICPlanner();
116
122 void claim(const ir::OperandIndex &, size_t) override;
127 void release(const ir::OperandIndex &) override;
132 uint32_t capacity() override
133 {
134 if (!_initialized)
135 buildMemoryPlans();
136 return _capacity;
137 }
142 MemoryPlans &memory_plans() override;
143
144private:
145 void buildMemoryPlans();
146
147 bool _initialized;
148 uint32_t _capacity;
149 MemoryPlans _mem_plans;
150 std::unordered_set<ir::OperandIndex> _live_operands;
152 // Sort operands by descending order of size
153 std::multimap<uint32_t, ir::OperandIndex, std::greater<uint32_t>> _operands;
154};
155
156} // namespace basic
157} // namespace backend
158} // namespace onert
159
160#endif // __ONERT_BACKEND_BASIC_MEMORY_PLANNER_H__
Class to plan memory by bump way.
void release(const ir::OperandIndex &) override
Release memory for operand by bump way.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by bump way.
MemoryPlans & memory_plans() override
Get MemoryPlans.
uint32_t capacity() override
Get capacity for memory planning.
Class to plan memory by firstfit way.
uint32_t capacity() override
Get capacity for memory planning.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by firstfit way.
MemoryPlans & memory_plans() override
Get MemoryPlans.
void release(const ir::OperandIndex &) override
Release memory for operand by firstfit way.
Class to plan memory by Weighted Interval Color algorithm.
void claim(const ir::OperandIndex &, size_t) override
Claim memory for operand by WIC algorithm.
MemoryPlans & memory_plans() override
Get MemoryPlans.
uint32_t capacity() override
Get capacity for memory planning.
void release(const ir::OperandIndex &) override
Release memory for operand by WIC algorithm.
std::unordered_map< OperandIndex, T > OperandIndexMap
std::unordered_map< ir::OperandIndex, Block > MemoryPlans