6e6ca110fe52beacb67c094a55a28b37a0032720
[platform/core/ml/nnfw.git] / runtime / onert / core / src / exec / LinearExecutor.cc
1 /*
2  * Copyright (c) 2019 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 "LinearExecutor.h"
18 #ifdef RUY_PROFILER
19 #include "ruy/profiler/instrumentation.h"
20 #endif
21
22 namespace onert
23 {
24 namespace exec
25 {
26
27 #ifdef RUY_PROFILER
28 namespace
29 {
30 char *seq_to_label(const onert::ir::OpSequence *op_seq, const onert::ir::Operations &operations)
31 {
32   auto node_name = operations.at(*op_seq->begin()).name();
33   char *cstr = new char[node_name.length() + 1];
34   std::strcpy(cstr, node_name.c_str());
35   return cstr;
36 }
37 } // namespace
38 #endif
39
40 void LinearExecutor::executeImpl()
41 {
42   _subject.notifyModelBegin(this);
43   for (auto &&code : _code)
44   {
45     const auto op_seq = code.op_seq;
46     const auto backend = code.lower_info->backend();
47 // TODO : Move ruy profiler into ExecutionObserver
48 #ifdef RUY_PROFILER
49     ruy::profiler::ScopeLabel label(seq_to_label(op_seq, _graph.operations()));
50 #endif
51     _subject.notifyJobBegin(this, op_seq, backend);
52
53     auto &fn_seq = code.fn_seq;
54
55     fn_seq->initRunning();
56
57     bool handle_dynamic_tensor = op_seq->has_dynamic_tensor() || hasDynamicInput();
58     fn_seq->enableDynamicShapeInferer(handle_dynamic_tensor);
59     fn_seq->run();
60
61     _subject.notifyJobEnd(this, op_seq, backend);
62   }
63   _subject.notifyModelEnd(this);
64 }
65
66 } // namespace exec
67 } // namespace onert