ONE - On-device Neural Engine
Loading...
Searching...
No Matches
BackendContext.cc
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#include "BackendContext.h"
18
21
22namespace onert
23{
24namespace backend
25{
26namespace builtin
27{
28namespace train
29{
30
32{
33 // For now, there is no need to generate tensors for forwarding and backwarding.
34 // builtin train backend handles 3 operators: `Permute`, `IF`, `WHILE`.
35 // `Permute`: Tensor generation is not required.
36 // `IF`, `WHILE`: Not supported yet
37
39
40 for (auto &&op_ind : _tdata->op_order)
41 {
42 auto tn_seq = kernel_gen->generate(op_ind);
43 fn_map.emplace(op_ind, std::move(tn_seq));
44 }
45
47 [&](const ir::OperandIndex &ind, const ir::Operand &operand) {
48 if (!external_operands().contains(ind) && operand.isConstant())
49 {
50 throw std::runtime_error(
51 "BackendContext: builtin backend does not support updatable weights yet");
52 }
53 });
54
55 // TODO Enable prepare()
56 // for (auto &&it : fn_map)
57 // {
58 // auto &fn_seq = it.second;
59 // fn_seq->iterate([&](exec::IFunction &ifunc) { ifunc.prepare(); });
60 // }
61
62 return fn_map;
63}
64
65} // namespace train
66} // namespace builtin
67} // namespace backend
68} // namespace onert
backend::train::FunctionMap gen() override
std::shared_ptr< KernelGenerator > kernel_gen
const ir::train::TrainableGraph * trainable_graph() const
const util::Set< ir::OperandIndex > & external_operands() const
std::unique_ptr< TrainableContextData > _tdata
bool isConstant(void) const
Get true if Operand is const, otherwise false a.
Definition Operand.h:79
const Operands & operands() const override
void iterate(const std::function< void(const Index &, const Object &)> &fn) const
Iterate over the container with given function.
std::unordered_map< ir::OperationIndex, std::unique_ptr< exec::train::TrainableFnSequence > > FunctionMap