ONE - On-device Neural Engine
Loading...
Searching...
No Matches
KernelGeneratorBase.h
Go to the documentation of this file.
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_KERNEL_GENERATOR_BASE_H__
18#define __ONERT_BACKEND_BASIC_KERNEL_GENERATOR_BASE_H__
19
20#include <assert.h>
21#include <memory>
22#include <functional>
23
24#include "ir/Graph.h"
25#include "ir/OperationVisitor.h"
28
29namespace onert
30{
31namespace backend
32{
33namespace basic
34{
35
37{
38public:
39 virtual ~KernelGeneratorBase() = default;
40 KernelGeneratorBase(const ir::Graph &graph) : _graph{graph} {}
41
42 virtual std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) = 0;
43
44protected:
45 using OperationVisitor::visit;
46
47#define OP(InternalName) \
48 void visit(const ir::operation::InternalName &) override \
49 { \
50 throw std::runtime_error("KernelGenerator: NYI for operation '" #InternalName "'"); \
51 }
52#include "ir/Operations.lst"
53#undef OP
54
55protected:
56 std::unique_ptr<exec::IFunction> releaseFunction()
57 {
58 assert(_return_fn);
59 return std::move(_return_fn);
60 }
61
62protected:
64 std::unique_ptr<exec::IFunction> _return_fn;
65};
66
67} // namespace basic
68} // namespace backend
69} // namespace onert
70
71#endif // __ONERT_BACKEND_BASIC_KERNEL_GENERATOR_BASE_H__
std::unique_ptr< exec::IFunction > _return_fn
std::unique_ptr< exec::IFunction > releaseFunction()
virtual std::unique_ptr< exec::FunctionSequence > generate(ir::OperationIndex ind)=0