ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
31{
32
33// TODO Unify TensorBuilder
34// TODO Unify TensorRegistry
36{
37public:
38 Backend() : _config{std::make_shared<Config>()} {}
39
40 std::shared_ptr<IConfig> config() const override { return _config; }
41
42 std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
43 {
44 return std::make_unique<DummyBackendContext>(this, std::move(data));
45 }
46
47 std::unique_ptr<backend::train::TrainableBackendContext>
49 {
50 const auto &tgraph = *tdata.tgraph;
51 auto optimizer = createOptimizer(tdata.optim_info);
52 auto tr = std::make_shared<TensorRegistry>();
53 auto tb = std::make_shared<TensorBuilder>(tr, optimizer.get());
54 auto tdata_ptr = std::make_unique<backend::train::TrainableContextData>(std::move(tdata));
55 auto context = std::make_unique<train::BackendContext>(this, std::move(tdata_ptr), tr, tb,
56 std::move(optimizer));
57
58 context->kernel_gen = std::make_shared<train::KernelGenerator>(
59 tgraph, tr, context->external_context(), context->optimizer());
60 return context;
61 }
62
63private:
64 std::shared_ptr<IConfig> _config;
65};
66
67} // namespace onert::backend::train
68
69#endif // __ONERT_BACKEND_TRAIN_BACKEND_H__
std::shared_ptr< IConfig > config() const override
Definition Backend.h:40
std::unique_ptr< onert::backend::BackendContext > newContext(ContextData &&data) const override
Definition Backend.h:42
std::unique_ptr< backend::train::TrainableBackendContext > newContext(backend::train::TrainableContextData &&tdata) const override
Definition Backend.h:48
std::unique_ptr< exec::train::optimizer::Optimizer > createOptimizer(const ir::train::OptimizerInfo &optim_info)
Definition Optimizers.h:29