ONE - On-device Neural Engine
Loading...
Searching...
No Matches
KernelGenerator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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_TRAIN_KERNEL_GENERATOR_H__
18#define __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
19
20#include "ExternalContext.h"
22#include "TensorBuilder.h"
23#include "Tensor.h"
24
28#include <ir/Operands.h>
29#include <ir/Operations.h>
30
31namespace onert
32{
33namespace backend
34{
35namespace train
36{
37
38// TODO Unify TensorRegistry
40{
41public:
43 const std::shared_ptr<TensorRegistry> &tensor_reg,
44 const std::shared_ptr<ExternalContext> &external_context,
45 const exec::train::optimizer::Optimizer *optimizer);
46
47 std::unique_ptr<exec::train::TrainableFnSequence> generate(ir::OperationIndex op_ind) override;
48
49 void visit(const ir::train::operation::BinaryArithmetic &) override;
50 void visit(const ir::train::operation::Conv2D &) override;
51 void visit(const ir::train::operation::DepthwiseConv2D &) override;
53 void visit(const ir::train::operation::FullyConnected &) override;
54 void visit(const ir::train::operation::Loss &) override;
55 void visit(const ir::train::operation::Pad &) override;
56 void visit(const ir::train::operation::Pool2D &) override;
57 void visit(const ir::train::operation::Reduce &node) override;
58 void visit(const ir::train::operation::Reshape &node) override;
59 void visit(const ir::train::operation::Softmax &node) override;
60
61private:
62 IPortableTensor *getBackPropIn(const ir::IOperation &node, const ir::OperandIndex &operand_index);
63 IPortableTensor *getBackPropOut(const ir::OperandIndex &index);
64
65private:
66 std::shared_ptr<TensorRegistry> _tensor_reg;
67 const std::shared_ptr<ExternalContext> _external_context;
68 const exec::train::optimizer::Optimizer *_optimizer;
69 std::vector<std::unique_ptr<exec::train::IGradientApplier>> _update_funcs;
70 std::unordered_map<const ir::IOperation *, ir::OperationIndex> _node_to_idx;
71};
72
73} // namespace train
74} // namespace backend
75} // namespace onert
76
77#endif // __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
A tensor class that is portable for other backends.
std::unique_ptr< exec::train::TrainableFnSequence > generate(ir::OperationIndex op_ind) override
void visit(const ir::train::operation::BinaryArithmetic &) override
Base class for all optimizers.
Definition Optimizer.h:43