dcf47aba69c01f3be914fac24f603681bded90f7
[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 } // namespace luci