Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / backend / cpu_common / IMemoryPlanner.h
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
17 #ifndef __ONERT_BACKEND_IMEMORY_PLANNER_H__
18 #define __ONERT_BACKEND_IMEMORY_PLANNER_H__
19
20 #include "ir/OperandIndexMap.h"
21
22 namespace onert
23 {
24 namespace backend
25 {
26 namespace cpu_common
27 {
28
29 /**
30  * @brief Structure to have memory offset and size
31  */
32 struct Block
33 {
34   uint32_t offset;
35   size_t size;
36 };
37
38 /**
39  * @brief Interface to plan memory
40  */
41 struct IMemoryPlanner
42 {
43   using MemoryPlans = ir::OperandIndexMap<Block>;
44
45   /**
46    * @brief Claim memory for operand
47    * @param[in] index The operand index
48    * @param[in] size The size of the memory
49    */
50   virtual void claim(const ir::OperandIndex &, size_t) = 0;
51   /**
52    * @brief Release memory for operand
53    * @param[in] index The operand index
54    */
55   virtual void release(const ir::OperandIndex &) = 0;
56   /**
57    * @brief Get capacity for memory planning
58    * @return The value of capacity
59    */
60   virtual uint32_t capacity() = 0;
61   /**
62    * @brief Get MemoryPlans
63    * @return MemoryPlans
64    */
65   virtual MemoryPlans &memory_plans() = 0;
66
67   virtual ~IMemoryPlanner() = default;
68 };
69
70 } // namespace cpu_common
71 } // namespace backend
72 } // namespace onert
73
74 #endif // __ONERT_BACKEND_IMEMORY_PLANNER_H__