a8014e55d71bc79d22c34ba8bf53bc4a8e8cfe3b
[platform/core/ml/nnfw.git] / runtime / onert / core / include / backend / basic / TensorBuilder.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_BASIC_TENSOR_BUILDER_H__
18 #define __ONERT_BACKEND_BASIC_TENSOR_BUILDER_H__
19
20 #include <backend/basic/DynamicTensorManager.h>
21 #include <backend/basic/TensorRegistry.h>
22 #include <backend/basic/StaticTensorManager.h>
23
24 #include <ir/OperandIndexMap.h>
25
26 #include "Tensor.h"
27
28 #include <unordered_map>
29
30 namespace onert
31 {
32 namespace backend
33 {
34 namespace basic
35 {
36
37 class TensorBuilder
38 {
39 public:
40   TensorBuilder(const std::shared_ptr<TensorRegistry> &tensor_reg);
41
42   /**
43    * @brief     Register tensor information to allocate on CPU backend
44    * @param[in] ind    Operand index
45    * @param[in] info   Operand information
46    * @param[in] layout Operand data layout
47    */
48   void registerTensorInfo(const ir::OperandIndex &ind, const ir::OperandInfo &info,
49                           ir::Layout backend_layout);
50
51   void notifyFirstUse(const ir::OperandIndex &);
52   void notifyLastUse(const ir::OperandIndex &);
53
54   bool isRegistered(const ir::OperandIndex &) const;
55
56   void allocate(void);
57
58   DynamicTensorManager *dynamicTensorManager(void) { return _dynamic_tensor_mgr.get(); }
59
60 private:
61   const std::shared_ptr<TensorRegistry> _tensor_reg;
62   std::unique_ptr<DynamicTensorManager> _dynamic_tensor_mgr;
63   std::unique_ptr<StaticTensorManager> _static_tensor_mgr;
64   ir::OperandIndexMap<ir::OperandInfo> _tensor_info_map;
65 };
66
67 } // namespace basic
68 } // namespace backend
69 } // namespace onert
70
71 #endif // __ONERT_BACKEND_BASIC_TENSOR_BUILDER_H__