bafa36d28ab87a0077f25906d23bbe3ab1fd1d57
[platform/core/ml/nnfw.git] / runtime / onert / core / src / backend / BackendContext.cc
1 /*
2  * Copyright (c) 2020 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 "backend/BackendContext.h"
18
19 #include "ir/Operation.h"
20 #include "backend/IConstantInitializer.h"
21
22 namespace onert
23 {
24 namespace backend
25 {
26
27 void BackendContext::initialize(const std::vector<OperationInfo> &operation_list,
28                                 const std::vector<ir::OperandIndex> &operand_list)
29 {
30   _operation_list = operation_list;
31   _operand_list = operand_list;
32 }
33
34 void BackendContext::initConsts()
35 {
36   for (auto &op : _operation_list)
37   {
38     constant_initializer->setLayout(op.layout);
39     _graph->operations().at(op.index).accept(*constant_initializer);
40   }
41
42   for (auto ind : _operand_list)
43   {
44     const auto &obj = _graph->operands().at(ind);
45     if (obj.isConstant() && !constant_initializer->exist(ind))
46     {
47       constant_initializer->registerDefaultInitializer(ind, obj);
48     }
49   }
50
51   constant_initializer->run();
52 }
53
54 } // namespace backend
55 } // namespace onert