2 * Copyright (c) 2019 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__
18 #define __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__
20 #include "backend/IMemoryManager.h"
21 #include "MemoryPlanner.h"
22 #include "ir/OperandIndexMap.h"
31 class MemoryManager : public backend::IMemoryManager
35 MemoryManager(const std::string);
36 virtual ~MemoryManager() = default;
38 void allocate(void) override;
39 uint8_t *getBuffer(const ir::OperandIndex &ind) const;
40 void deallocate(void) override { _mem_alloc->release(); }
42 void claimPlan(const ir::OperandIndex &ind, uint32_t size);
43 void releasePlan(const ir::OperandIndex &ind);
46 cpu_common::IMemoryPlanner *createMemoryPlanner();
47 cpu_common::IMemoryPlanner *createMemoryPlanner(const std::string);
50 ir::OperandIndexMap<cpu_common::Block> _tensor_mem_map;
51 std::shared_ptr<cpu_common::IMemoryPlanner> _mem_planner;
52 std::shared_ptr<cpu_common::Allocator> _mem_alloc;
55 class DynamicMemoryManager
58 DynamicMemoryManager() = default;
59 virtual ~DynamicMemoryManager() = default;
61 std::shared_ptr<cpu_common::Allocator> allocate(const ir::OperandIndex &ind, uint32_t capacity);
62 void deallocate(void);
65 ir::OperandIndexMap<std::shared_ptr<cpu_common::Allocator>> _mem_alloc_map;
68 } // namespace cpu_common
69 } // namespace backend
72 #endif // __ONERT_BACKEND_CPU_MEMORY_MANAGER_H__