ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Backend.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_BACKEND_H__
18#define __ONERT_BACKEND_TRAIN_BACKEND_H__
19
20#include "BackendContext.h"
21#include "Config.h"
22#include "KernelGenerator.h"
24
25#include <backend/Backend.h>
27
28#include <memory>
29
30namespace onert
31{
32namespace backend
33{
34namespace train
35{
36
37// TODO Unify TensorBuilder
38// TODO Unify TensorRegistry
40{
41public:
42 Backend() : _config{std::make_shared<Config>()} {}
43
44 std::shared_ptr<IConfig> config() const override { return _config; }
45
46 std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
47 {
48 return std::make_unique<DummyBackendContext>(this, std::move(data));
49 }
50
51 std::unique_ptr<backend::train::TrainableBackendContext>
53 {
54 const auto &tgraph = *tdata.tgraph;
55 auto optimizer = createOptimizer(tdata.optim_info);
56 auto tr = std::make_shared<TensorRegistry>();
57 auto tb = std::make_shared<TensorBuilder>(tr, optimizer.get());
58 auto tdata_ptr = std::make_unique<backend::train::TrainableContextData>(std::move(tdata));
59 auto context = std::make_unique<train::BackendContext>(this, std::move(tdata_ptr), tr, tb,
60 std::move(optimizer));
61
62 context->kernel_gen = std::make_shared<train::KernelGenerator>(
63 tgraph, tr, context->external_context(), context->optimizer());
64 return context;
65 }
66
67private:
68 std::shared_ptr<IConfig> _config;
69};
70
71} // namespace train
72} // namespace backend
73} // namespace onert
74
75#endif // __ONERT_BACKEND_TRAIN_BACKEND_H__
std::shared_ptr< IConfig > config() const override
Definition Backend.h:44
std::unique_ptr< onert::backend::BackendContext > newContext(ContextData &&data) const override
Definition Backend.h:46
std::unique_ptr< backend::train::TrainableBackendContext > newContext(backend::train::TrainableContextData &&tdata) const override
Definition Backend.h:52
std::unique_ptr< exec::train::optimizer::Optimizer > createOptimizer(const ir::train::OptimizerInfo &optim_info)
Definition Optimizers.h:33