ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
35{
36
40class BumpPlanner : public IMemoryPlanner<ir::OperandIndex>
41{
42public:
48 void claim(const ir::OperandIndex &, size_t) override;
53 void release(const ir::OperandIndex &) override;
58 uint32_t capacity() override { return _capacity; }
63 MemoryPlans &memory_plans() override { return _mem_plans; }
64
65private:
66 uint32_t _capacity = 0;
67 MemoryPlans _mem_plans;
68};
69
73class FirstFitPlanner : public IMemoryPlanner<ir::OperandIndex>
74{
75public:
81 void claim(const ir::OperandIndex &, size_t) override;
86 void release(const ir::OperandIndex &) override;
91 uint32_t capacity() override { return _capacity; }
96 MemoryPlans &memory_plans() override { return _mem_plans; }
97
98private:
99 uint32_t _capacity = 0;
100 MemoryPlans _mem_plans;
101 // Use std::map because claim() assumes that _claim_table is sorted by uint32_t(base_offset)
102 std::map<uint32_t, ir::OperandIndex> _claim_table;
103};
104
108class WICPlanner : public IMemoryPlanner<ir::OperandIndex>
109{
110public:
111 WICPlanner();
112
118 void claim(const ir::OperandIndex &, size_t) override;
123 void release(const ir::OperandIndex &) override;
128 uint32_t capacity() override
129 {
130 if (!_initialized)
131 buildMemoryPlans();
132 return _capacity;
133 }
138 MemoryPlans &memory_plans() override;
139
140private:
141 void buildMemoryPlans();
142
143 bool _initialized;
144 uint32_t _capacity;
145 MemoryPlans _mem_plans;
146 std::unordered_set<ir::OperandIndex> _live_operands;
148 // Sort operands by descending order of size
149 std::multimap<uint32_t, ir::OperandIndex, std::greater<uint32_t>> _operands;
150};
151
152} // namespace onert::backend::basic
153
154#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