afc34ec21d4fe3975634444ae67bb739587a8719
[platform/core/ml/nnfw.git] / runtime / onert / core / include / backend / IKernelGenerator.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_IKERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_IKERNEL_GENERATOR_H__
19
20 #include <assert.h>
21 #include <memory>
22 #include <functional>
23
24 #include "ITensorBuilder.h"
25 #include "ir/OperationVisitor.h"
26 #include "ir/OpSequence.h"
27 #include <memory>
28 #include "exec/FunctionSequence.h"
29
30 namespace onert
31 {
32 namespace backend
33 {
34
35 class IKernelGenerator : public ir::OperationVisitor
36 {
37 public:
38   virtual ~IKernelGenerator() = default;
39
40   std::unique_ptr<exec::IFunction> releaseFunction()
41   {
42     assert(_return_fn);
43     return std::move(_return_fn);
44   }
45
46   std::unique_ptr<exec::FunctionSequence> generate(const ir::OpSequence &op_seq)
47   {
48     op_seq.accept(*this);
49     return std::move(_return_fn_seq);
50   }
51
52 protected:
53   using OperationVisitor::visit;
54
55   void visit(const ir::OpSequence &) override
56   {
57     throw std::runtime_error("KernelGenerator: NYI for operation 'OpSequence'");
58   }
59
60 #define OP(InternalName)                                                                \
61   void visit(const ir::operation::InternalName &) override                              \
62   {                                                                                     \
63     throw std::runtime_error("KernelGenerator: NYI for operation '" #InternalName "'"); \
64   }
65 #include "ir/Operations.lst"
66 #undef OP
67
68 protected:
69   std::unique_ptr<exec::IFunction> _return_fn;
70   std::unique_ptr<exec::FunctionSequence> _return_fn_seq; // TODO Extract this out
71 };
72
73 } // namespace backend
74 } // namespace onert
75
76 #endif // __ONERT_BACKEND_IKERNEL_GENERATOR_H__