ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
30{
31
33{
34public:
35 virtual ~KernelGeneratorBase() = default;
36 KernelGeneratorBase(const ir::Graph &graph) : _graph{graph} {}
37
38 virtual std::unique_ptr<exec::FunctionSequence> generate(ir::OperationIndex ind) = 0;
39
40protected:
41 using OperationVisitor::visit;
42
43#define OP(InternalName) \
44 void visit(const ir::operation::InternalName &) override \
45 { \
46 throw std::runtime_error("KernelGenerator: NYI for operation '" #InternalName "'"); \
47 }
48#include "ir/Operations.lst"
49#undef OP
50
51protected:
52 std::unique_ptr<exec::IFunction> releaseFunction()
53 {
54 assert(_return_fn);
55 return std::move(_return_fn);
56 }
57
58protected:
60 std::unique_ptr<exec::IFunction> _return_fn;
61};
62
63} // namespace onert::backend::basic
64
65#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