Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / runtime / onert / core / src / backend / controlflow / KernelGenerator.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_CONTROLFLOW_KERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_CONTROLFLOW_KERNEL_GENERATOR_H__
19
20 #include <exec/IExecutor.h>
21 #include "ExternalContext.h"
22 #include <ir/Graph.h>
23 #include "TensorBuilder.h"
24 #include "compiler/TensorRegistries.h"
25 #include "backend/cpu_common/KernelGeneratorBase.h"
26 #include "TensorRegistry.h"
27
28 namespace onert
29 {
30 namespace backend
31 {
32 namespace controlflow
33 {
34
35 class KernelGenerator : public cpu_common::KernelGeneratorBase
36 {
37 public:
38   KernelGenerator(const ir::Graph &graph, DynamicTensorManager *dyn_tensor_manager,
39                   const std::shared_ptr<TensorRegistry> &tensor_reg,
40                   const std::shared_ptr<ExternalContext> &external_context);
41
42   void setTensorRegistries(const compiler::TensorRegistries &tensor_registries)
43   {
44     _tensor_registries = tensor_registries;
45   }
46   void setExecutorMap(const std::shared_ptr<exec::ExecutorMap> &executor_map)
47   {
48     // FIXME Using shared_ptr's raw pointer!
49     _executor_map = executor_map.get();
50   }
51
52   void visit(const ir::OpSequence &) override;
53   void visit(const ir::operation::If &) override;
54   void visit(const ir::operation::Permute &) override;
55   void visit(const ir::operation::While &) override;
56
57 private:
58   backend::ITensor *getTensor(const ir::OperandIndex &index);
59   backend::IPortableTensor *getPortableTensor(const ir::OperandIndex &index);
60
61 private:
62   const ir::Graph &_graph;
63   DynamicTensorManager *_dyn_tensor_manager;
64   std::shared_ptr<TensorRegistry> _tensor_reg;
65   compiler::TensorRegistries _tensor_registries;
66   exec::ExecutorMap *_executor_map;
67   const std::shared_ptr<ExternalContext> _external_context;
68 };
69
70 } // namespace controlflow
71 } // namespace backend
72 } // namespace onert
73
74 #endif // __ONERT_BACKEND_CONTROLFLOW_KERNEL_GENERATOR_H__