Imported Upstream version 1.7.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 <backend/IKernelGenerator.h>
21 #include <backend/ITensorBuilder.h>
22 #include <exec/IExecutor.h>
23 #include <ir/Graph.h>
24 #include "TensorBuilder.h"
25 #include "compiler/TensorBuilders.h"
26
27 #include "compiler/TensorBuilders.h"
28
29 namespace onert
30 {
31 namespace backend
32 {
33 namespace controlflow
34 {
35
36 class KernelGenerator : public IKernelGenerator
37 {
38 public:
39   KernelGenerator(const ir::Graph &graph, const std::shared_ptr<TensorBuilder> &tensor_builder);
40
41   void setTensorBuilderSet(const compiler::TensorBuilders &tensor_builder_set)
42   {
43     _tensor_builder_set = tensor_builder_set;
44   }
45   void setExecutorMap(const std::shared_ptr<exec::ExecutorMap> &executor_map)
46   {
47     // FIXME Using shared_ptr's raw pointer!
48     _executor_map = executor_map.get();
49   }
50
51   using IKernelGenerator::visit;
52
53   void visit(const ir::OpSequence &) override;
54   void visit(const ir::operation::If &) override;
55   void visit(const ir::operation::Permute &) override;
56   void visit(const ir::operation::While &) override;
57
58 private:
59   std::shared_ptr<backend::ITensor> getTensor(const ir::OperandIndex &index);
60   std::shared_ptr<backend::ITensorBuilder> getTensorBuilder(const ir::OperandIndex &index);
61
62 private:
63   const ir::Graph &_graph;
64   std::shared_ptr<TensorBuilder> _tensor_builder;
65   compiler::TensorBuilders _tensor_builder_set;
66   exec::ExecutorMap *_executor_map;
67 };
68
69 } // namespace controlflow
70 } // namespace backend
71 } // namespace onert
72
73 #endif // __ONERT_BACKEND_CONTROLFLOW_KERNEL_GENERATOR_H__