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