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