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_BACKEND_H__
18 #define __ONERT_BACKEND_TRAIN_BACKEND_H__
20 #include "BackendContext.h"
22 #include "KernelGenerator.h"
24 #include <backend/Backend.h>
25 #include <backend/train/ITrainableBackend.h>
36 // TODO Unify TensorBuilder
37 // TODO Unify TensorRegistry
38 class Backend : public ::onert::backend::Backend, public backend::train::ITrainableBackend
41 Backend() : _config{std::make_shared<Config>()} {}
43 std::shared_ptr<IConfig> config() const override { return _config; }
45 std::unique_ptr<onert::backend::BackendContext> newContext(ContextData &&data) const override
47 return std::make_unique<DummyBackendContext>(this, std::move(data));
50 std::unique_ptr<backend::train::TrainableBackendContext>
51 newContext(backend::train::TrainableContextData &&tdata) const override
53 const auto &tgraph = *tdata.tgraph;
54 auto tr = std::make_shared<TensorRegistry>();
55 auto tb = std::make_shared<TensorBuilder>(tr, "Bump");
56 auto tdata_ptr = std::make_unique<backend::train::TrainableContextData>(std::move(tdata));
57 auto context = std::make_unique<train::BackendContext>(this, std::move(tdata_ptr), tr, tb);
59 context->kernel_gen = std::make_shared<train::KernelGenerator>(
60 tgraph, tr, context->external_context(), context->data()->optimizer);
65 std::shared_ptr<IConfig> _config;
69 } // namespace backend
72 #endif // __ONERT_BACKEND_TRAIN_BACKEND_H__