2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
18 #define __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__
20 #include "ExternalContext.h"
21 #include "backend/basic/TensorRegistry.h"
22 #include "TensorBuilder.h"
25 #include <backend/train/KernelGeneratorBase.h>
26 #include <exec/train/IGradientApplier.h>
27 #include <exec/train/optimizer/Optimizer.h>
28 #include <ir/Operands.h>
29 #include <ir/Operations.h>
38 // TODO Unify TensorRegistry
39 class KernelGenerator : public backend::train::KernelGeneratorBase
42 KernelGenerator(const ir::train::TrainableGraph &tgraph,
43 const std::shared_ptr<TensorRegistry> &tensor_reg,
44 const std::shared_ptr<ExternalContext> &external_context,
45 std::shared_ptr<exec::train::optimizer::Optimizer> optimizer);
47 std::unique_ptr<exec::train::TrainableFnSequence> generate(ir::OperationIndex op_ind) override;
49 void visit(const ir::train::operation::Conv2D &) override;
50 void visit(const ir::train::operation::ElementwiseActivation &) override;
51 void visit(const ir::train::operation::FullyConnected &) override;
52 void visit(const ir::train::operation::Loss &) override;
53 void visit(const ir::train::operation::Reshape &node) override;
56 ir::Layout _current_layout;
57 std::shared_ptr<TensorRegistry> _tensor_reg;
58 const std::shared_ptr<ExternalContext> _external_context;
59 std::shared_ptr<exec::train::optimizer::Optimizer> _optimizer;
60 std::vector<std::unique_ptr<exec::train::IGradientApplier>> _update_funcs;
64 } // namespace backend
67 #endif // __ONERT_BACKEND_TRAIN_KERNEL_GENERATOR_H__