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