Imported Upstream version 1.9.0
[platform/core/ml/nnfw.git] / runtime / onert / core / include / backend / cpu_common / StaticTensorManager.h
1 /*
2  * Copyright (c) 2019 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_CPU_COMMON_STATICTENSOR_MANAGER_H__
18 #define __ONERT_BACKEND_CPU_COMMON_STATICTENSOR_MANAGER_H__
19
20 #include "MemoryManager.h"
21
22 #include "backend/IStaticTensorManager.h"
23 #include "backend/IDynamicTensorManager.h"
24 #include "ir/OperandIndexMap.h"
25 #include "ir/OperandInfo.h"
26 #include "TensorRegistry.h"
27
28 namespace onert
29 {
30 namespace backend
31 {
32 namespace cpu_common
33 {
34
35 class StaticTensorManager : public backend::IStaticTensorManager
36 {
37 public:
38   StaticTensorManager(const std::shared_ptr<TensorRegistry> &reg,
39                       IDynamicTensorManager *dynamic_tensor_manager);
40   virtual ~StaticTensorManager() = default;
41
42   void allocateConsts(void);
43   void allocateNonconsts(void);
44   void deallocateConsts(void);
45   void deallocateNonconsts(void);
46
47   void buildTensor(const ir::OperandIndex &ind, const ir::OperandInfo &tensor_info,
48                    ir::Layout backend_layout, bool as_const);
49
50   void claimPlan(const ir::OperandIndex &ind, uint32_t size);
51   void releasePlan(const ir::OperandIndex &ind);
52
53   void iterate(const std::function<void(const ir::OperandIndex &)> &fn);
54
55 private:
56   std::unique_ptr<DynamicMemoryManager> _const_mgr;
57   std::unique_ptr<MemoryManager> _nonconst_mgr;
58   const std::shared_ptr<TensorRegistry> _tensors;
59   ir::OperandIndexMap<bool> _as_constants;
60   IDynamicTensorManager *_dynamic_tensor_manager;
61 };
62
63 } // namespace cpu_common
64 } // namespace backend
65 } // namespace onert
66
67 #endif // __ONERT_BACKEND_CPU_COMMON_STATICTENSOR_MANAGER_H__