Imported Upstream version 1.12.0
[platform/core/ml/nnfw.git] / compiler / luci / pass / src / ProgressReporter.cpp
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 "ProgressReporter.h"
18
19 #include <luci/Log.h>
20 #include <luci/LogHelper.h>
21
22 #include <logo/Phase.h>
23 #include <logo/Pass.h>
24
25 #include <cassert>
26
27 namespace
28 {
29
30 char to_char(bool b) { return b ? 'Y' : 'N'; }
31
32 const char *to_str(logo::PhaseStrategy s)
33 {
34   switch (s)
35   {
36     case logo::PhaseStrategy::Saturate:
37       return "Saturate";
38     case logo::PhaseStrategy::Restart:
39       return "Restart";
40   }
41   assert(false);
42   return "";
43 }
44
45 } // namespace
46
47 namespace luci
48 {
49
50 void ProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PhaseBegin> *)
51 {
52   LOGGER(prime);
53
54   INFO(prime) << "==============================================================";
55   INFO(prime) << "PhaseRunner<" << to_str(strategy()) << ">";
56   INFO(prime) << "Initial graph";
57   INFO(prime) << luci::fmt(graph());
58 }
59
60 void ProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PhaseEnd> *)
61 {
62   LOGGER(prime);
63
64   INFO(prime) << "PhaseRunner<" << to_str(strategy()) << "> - done";
65 }
66
67 void ProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PassBegin> *info)
68 {
69   LOGGER(prime);
70
71   INFO(prime) << "--------------------------------------------------------------";
72   INFO(prime) << "Before " << logo::pass_name(info->pass());
73 }
74
75 void ProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PassEnd> *info)
76 {
77   LOGGER(prime);
78
79   INFO(prime) << "After " << logo::pass_name(info->pass())
80               << " (changed: " << to_char(info->changed()) << ")";
81   INFO(prime) << luci::fmt(graph());
82 }
83
84 void ModuleProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PhaseBegin> *)
85 {
86   LOGGER(prime);
87
88   INFO(prime) << "==============================================================";
89   INFO(prime) << "ModulePhaseRunner<" << to_str(strategy()) << ">";
90   INFO(prime) << "Initial graphs";
91   for (size_t g = 0; g < module()->size(); ++g)
92   {
93     INFO(prime) << "graphs #" << g;
94     INFO(prime) << luci::fmt(module()->graph(g));
95   }
96 }
97
98 void ModuleProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PhaseEnd> *)
99 {
100   LOGGER(prime);
101
102   INFO(prime) << "ModulePhaseRunner<" << to_str(strategy()) << "> - done";
103 }
104
105 void ModuleProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PassBegin> *info)
106 {
107   LOGGER(prime);
108
109   INFO(prime) << "--------------------------------------------------------------";
110   INFO(prime) << "Before " << logo::pass_name(info->pass());
111 }
112
113 void ModuleProgressReporter::notify(const logo::PhaseEventInfo<logo::PhaseEvent::PassEnd> *info)
114 {
115   LOGGER(prime);
116
117   INFO(prime) << "After " << logo::pass_name(info->pass())
118               << " (changed: " << to_char(info->changed()) << ")";
119   for (size_t g = 0; g < module()->size(); ++g)
120   {
121     INFO(prime) << "graphs #" << g;
122     INFO(prime) << luci::fmt(module()->graph(g));
123   }
124 }
125
126 } // namespace luci