ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
23{
24
26{
27 // For now, there is no need to generate tensors for forwarding and backwarding.
28 // builtin train backend handles 3 operators: `Permute`, `IF`, `WHILE`.
29 // `Permute`: Tensor generation is not required.
30 // `IF`, `WHILE`: Not supported yet
31
33
34 for (auto &&op_ind : _tdata->op_order)
35 {
36 auto tn_seq = kernel_gen->generate(op_ind);
37 fn_map.emplace(op_ind, std::move(tn_seq));
38 }
39
41 [&](const ir::OperandIndex &ind, const ir::Operand &operand) {
42 if (!external_operands().contains(ind) && operand.isConstant())
43 {
44 throw std::runtime_error(
45 "BackendContext: builtin backend does not support updatable weights yet");
46 }
47 });
48
49 // TODO Enable prepare()
50 // for (auto &&it : fn_map)
51 // {
52 // auto &fn_seq = it.second;
53 // fn_seq->iterate([&](exec::IFunction &ifunc) { ifunc.prepare(); });
54 // }
55
56 return fn_map;
57}
58
59} // namespace onert::backend::builtin::train
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:77
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