Imported Upstream version 1.12.0
[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   auto profiling_subg_index = _tracing_ctx->getSubgraphIndex(&_graph);
43
44   _subject.notifySubgraphBegin(profiling_subg_index);
45   for (auto &&code : _code)
46   {
47     const auto op_seq = code.op_seq;
48     const auto backend = code.lower_info->backend();
49 // TODO : Move ruy profiler into ExecutionObserver
50 #ifdef RUY_PROFILER
51     ruy::profiler::ScopeLabel label(seq_to_label(op_seq, _graph.operations()));
52 #endif
53     _subject.notifyJobBegin(this, profiling_subg_index, op_seq, backend);
54
55     auto &fn_seq = code.fn_seq;
56
57     fn_seq->initRunning();
58
59     bool handle_dynamic_tensor = op_seq->has_dynamic_tensor() || hasDynamicInput();
60     fn_seq->enableDynamicShapeInferer(handle_dynamic_tensor);
61     fn_seq->run();
62
63     _subject.notifyJobEnd(this, profiling_subg_index, op_seq, backend);
64   }
65   _subject.notifySubgraphEnd(profiling_subg_index);
66 }
67
68 } // namespace exec
69 } // namespace onert