PandA-2024.02
profiling_information.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
45 
46 #include "basic_block.hpp" // for BBEdgeSorter, BBVertexS...
47 #include "host_profiling_xml.hpp" // for STR_XML_host_profiling_id
48 #include "loop.hpp" // for LoopConstRef, Loop
49 #include "tree_basic_block.hpp" // for bloc
50 #include "xml_element.hpp" // for xml_element
51 #include "xml_helper.hpp" // for WRITE_XNVM2
52 #include <boost/graph/adjacency_list.hpp> // for adjacency_list, source
53 #include <boost/graph/filtered_graph.hpp> // for source, target
54 #include <string> // for string, operator+
55 #include <utility> // for pair
56 
57 #if HAVE_UNORDERED
58 BBExecutions::BBExecutions(const BBGraphConstRef) : CustomUnorderedMap<vertex, unsigned long long int>()
59 {
60 }
61 #else
63  : std::map<vertex, unsigned long long int, BBVertexSorter>(BBVertexSorter(_bb_graph))
64 {
65 }
66 #endif
67 
68 #if HAVE_UNORDERED
70 {
71 }
72 #else
74  : std::map<EdgeDescriptor, unsigned long long int, BBEdgeSorter>(BBEdgeSorter(_bb_graph))
75 {
76 }
77 #endif
78 
80  : bb_executions(_bb_graph), edge_executions(_bb_graph)
81 {
82 }
83 
85 
87 {
88  return path_profiling;
89 }
90 
91 unsigned long long int ProfilingInformation::GetBBExecutions(const vertex bb_vertex) const
92 {
93  if(bb_executions.find(bb_vertex) != bb_executions.end())
94  {
95  return bb_executions.find(bb_vertex)->second;
96  }
97  return 0.0;
98 }
99 
100 unsigned long long int ProfilingInformation::GetEdgeExecutions(const EdgeDescriptor edge) const
101 {
102  if(edge_executions.find(edge) != edge_executions.end())
103  {
104  return edge_executions.find(edge)->second;
105  }
106  return 0.0;
107 }
108 
109 unsigned long long int ProfilingInformation::GetLoopMaxIterations(const unsigned int loop_id) const
110 {
111  if(max_iterations.find(loop_id) != max_iterations.end())
112  {
113  return max_iterations.find(loop_id)->second;
114  }
115  return 0.0;
116 }
117 
118 long double ProfilingInformation::GetLoopAvgIterations(const unsigned int loop_id) const
119 {
120  if(avg_iterations.find(loop_id) != avg_iterations.end())
121  {
122  return avg_iterations.find(loop_id)->second;
123  }
124  return 0.0L;
125 }
126 
127 unsigned long long int ProfilingInformation::GetLoopAbsIterations(const unsigned int loop_id) const
128 {
129  if(abs_iterations.find(loop_id) != abs_iterations.end())
130  {
131  return abs_iterations.find(loop_id)->second;
132  }
133  return 0;
134 }
135 
136 long double ProfilingInformation::GetLoopAvgIterations(const LoopConstRef loop) const
137 {
138  return GetLoopAvgIterations(loop->GetId());
139 }
140 
141 unsigned long long int ProfilingInformation::GetLoopMaxIterations(const LoopConstRef loop) const
142 {
143  return GetLoopMaxIterations(loop->GetId());
144 }
145 
146 unsigned long long ProfilingInformation::GetLoopAbsIterations(const LoopConstRef loop) const
147 {
148  return GetLoopAbsIterations(loop->GetId());
149 }
150 
152 {
153  xml_element* path_profiling_xml = root->add_child_element(STR_XML_host_profiling_paths);
154  PathProfilingInformation::const_iterator loop, loop_end = path_profiling.end();
155  for(loop = path_profiling.begin(); loop != loop_end; ++loop)
156  {
157  xml_element* loop_xml = path_profiling_xml->add_child_element(STR_XML_host_profiling_paths_loop);
158  WRITE_XNVM2(STR_XML_host_profiling_id, std::to_string(loop->first), loop_xml);
159  const std::map<CustomOrderedSet<unsigned int>, long double>& loop_path_profiling = loop->second;
160  std::map<CustomOrderedSet<unsigned int>, long double>::const_iterator loop_path,
161  loop_path_end = loop_path_profiling.end();
162  for(loop_path = loop_path_profiling.begin(); loop_path != loop_path_end; ++loop_path)
163  {
165  std::string cer_path_string;
166  const CustomOrderedSet<unsigned int>& cer_path = loop_path->first;
167  CustomOrderedSet<unsigned int>::const_iterator cer, cer_end = cer_path.end();
168  for(cer = cer_path.begin(); cer != cer_end; ++cer)
169  {
170  cer_path_string += std::to_string(*cer) + "#";
171  }
172  WRITE_XNVM2(STR_XML_host_profiling_cers, cer_path_string, path);
173  WRITE_XNVM2(STR_XML_host_profiling_frequency, std::to_string(loop_path->second), path);
174  }
175  }
176 
178  std::map<unsigned int, long double> ordered_bb_executions;
179 
181  BBExecutions::const_iterator bb_execution, bb_execution_end = bb_executions.end();
182  for(bb_execution = bb_executions.begin(); bb_execution != bb_execution_end; ++bb_execution)
183  {
184  ordered_bb_executions[fcfg->CGetBBNodeInfo(bb_execution->first)->block->number] = bb_execution->second;
185  }
186 
187  std::map<unsigned int, long double>::const_iterator ordered_bb_execution,
188  ordered_bb_execution_end = ordered_bb_executions.end();
189  for(ordered_bb_execution = ordered_bb_executions.begin(); ordered_bb_execution != ordered_bb_execution_end;
190  ++ordered_bb_execution)
191  {
192  xml_element* bb_execution_xml = bb_executions_xml->add_child_element(STR_XML_host_profiling_bb_execution);
193  WRITE_XNVM2(STR_XML_host_profiling_id, std::to_string(ordered_bb_execution->first), bb_execution_xml);
194  WRITE_XNVM2(STR_XML_host_profiling_executions, std::to_string(ordered_bb_execution->second), bb_execution_xml);
195  }
196 
198  std::map<std::pair<unsigned int, unsigned int>, long double> ordered_edge_executions;
199 
201  BBEdgeExecutions::const_iterator edge_execution, edge_execution_end = edge_executions.end();
202  for(edge_execution = edge_executions.begin(); edge_execution != edge_execution_end; ++edge_execution)
203  {
204  ordered_edge_executions[std::pair<unsigned int, unsigned int>(
205  fcfg->CGetBBNodeInfo(boost::source(edge_execution->first, *fcfg))->block->number,
206  fcfg->CGetBBNodeInfo(boost::target(edge_execution->first, *fcfg))->block->number)] = edge_execution->second;
207  }
208 
209  std::map<std::pair<unsigned int, unsigned int>, long double>::const_iterator ordered_edge_execution,
210  ordered_edge_execution_end = ordered_edge_executions.end();
211  for(ordered_edge_execution = ordered_edge_executions.begin(); ordered_edge_execution != ordered_edge_execution_end;
212  ++ordered_edge_execution)
213  {
214  xml_element* edge_execution_xml = edge_executions_xml->add_child_element(STR_XML_host_profiling_edge_execution);
215  WRITE_XNVM2(STR_XML_host_profiling_source_id, std::to_string(ordered_edge_execution->first.first),
216  edge_execution_xml);
217  WRITE_XNVM2(STR_XML_host_profiling_target_id, std::to_string(ordered_edge_execution->first.second),
218  edge_execution_xml);
219  WRITE_XNVM2(STR_XML_host_profiling_executions, std::to_string(ordered_edge_execution->second),
220  edge_execution_xml);
221  }
222 
224  AvgIterations::const_iterator avg_iteration, avg_iteration_end = avg_iterations.end();
225  for(avg_iteration = avg_iterations.begin(); avg_iteration != avg_iteration_end; ++avg_iteration)
226  {
227  xml_element* avg_iteration_xml = avg_iterations_xml->add_child_element(STR_XML_host_profiling_avg_iteration);
228  WRITE_XNVM2(STR_XML_host_profiling_id, std::to_string(avg_iteration->first), avg_iteration_xml);
229  WRITE_XNVM2(STR_XML_host_profiling_iterations, std::to_string(avg_iteration->second), avg_iteration_xml);
230  }
231 
233  Iterations::const_iterator abs_iteration, abs_iteration_end = abs_iterations.end();
234  for(abs_iteration = abs_iterations.begin(); abs_iteration != abs_iteration_end; ++abs_iteration)
235  {
236  xml_element* abs_iteration_xml = abs_iterations_xml->add_child_element(STR_XML_host_profiling_abs_iteration);
237  WRITE_XNVM2(STR_XML_host_profiling_id, std::to_string(abs_iteration->first), abs_iteration_xml);
238  WRITE_XNVM2(STR_XML_host_profiling_iterations, std::to_string(abs_iteration->second), abs_iteration_xml);
239  }
240 
242  Iterations::const_iterator max_iteration, max_iteration_end = max_iterations.end();
243  for(max_iteration = max_iterations.begin(); max_iteration != max_iteration_end; ++max_iteration)
244  {
245  xml_element* max_iteration_xml = max_iterations_xml->add_child_element(STR_XML_host_profiling_max_iteration);
246  WRITE_XNVM2(STR_XML_host_profiling_id, std::to_string(max_iteration->first), max_iteration_xml);
247  WRITE_XNVM2(STR_XML_host_profiling_iterations, std::to_string(max_iteration->second), max_iteration_xml);
248  }
249 }
250 
252 {
253  path_profiling.clear();
254  bb_executions.clear();
255  edge_executions.clear();
256  avg_iterations.clear();
257  abs_iterations.clear();
258  max_iterations.clear();
259 }
#define STR_XML_host_profiling_max_iteration
The node containing information about max iterations of a loop.
#define STR_XML_host_profiling_paths_loop
The node containing information about path profiling in a loop.
string target
Definition: lenet_tvm.py:16
#define STR_XML_host_profiling_avg_iterations
The node containing information about average iterations of loops.
#define STR_XML_host_profiling_cers
The attribute containing the sequence of cers of the path.
#define STR_XML_host_profiling_edge_execution
The node containing information about executions of a basic block.
PathProfilingInformation path_profiling
map that represents, for each execution path of each loop (represented by the set of the executed con...
#define STR_XML_host_profiling_path
The node containing information about a single path.
Iterations abs_iterations
number of absolute execution (different from number of execution of the header); correspond to how ma...
Definition of hash function for EdgeDescriptor.
Definition: graph.hpp:1321
long double GetLoopAvgIterations(const unsigned int loop_id) const
Return number of average iterations of a loop.
const PathProfilingInformation & GetPathProfiling() const
Return the path profiling information.
Data structure describing a basic block at tree level.
Map storing path profiling information.
void WriteToXml(xml_element *root, const BBGraphConstRef fcfg) const
Write to xml.
BBEdgeExecutions(const BBGraphConstRef bb_graph)
Constructor.
#define STR_XML_host_profiling_source_id
The attribute containing id of the source vertex of the edge.
Class specification for storing profiling information.
Iterations max_iterations
Maximum number of iterations.
#define STR_XML_host_profiling_max_iterations
The node containing information about max iterations of loops.
unsigned map[NUM_VERTICES]
Definition: bfs.c:12
unsigned long long GetLoopAbsIterations(const unsigned int loop_id) const
Return the number of absolute iterations of a loop.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
#define STR_XML_host_profiling_paths
The node containing information path profiling.
#define STR_XML_host_profiling_abs_iteration
The node containing information about absolute iterations of loop.
#define STR_XML_host_profiling_executions
The attribute containing the number of executions of a basic block.
#define STR_XML_host_profiling_bb_executions
The node containing information about basic blocks executions.
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
unsigned long long int GetLoopMaxIterations(const unsigned int loop_id) const
Return the maximum number of iterations of a loop.
#define STR_XML_host_profiling_target_id
The attribute containing id of the target vertex of the edge.
#define STR_XML_host_profiling_bb_execution
The node containing information about executions of a basic block.
BBEdgeExecutions edge_executions
Absolute number of running of edges.
#define WRITE_XNVM2(name, value, node)
WRITE XML Name Value Macro second version. Insert a value in an XML tree given the name of the attrib...
Definition: xml_helper.hpp:58
#define STR_XML_host_profiling_abs_iterations
The node containing information about absolute iterations of a loop.
#define STR_XML_host_profiling_frequency
The attribute containing the frequency of a path.
~ProfilingInformation()
Destructor.
BBExecutions bb_executions
Absolute number of execution of each basic block.
Class specification of the basic_block structure.
interface of a loop
const BBNodeInfoConstRef CGetBBNodeInfo(const vertex node) const
Return the info associated with a basic block.
ProfilingInformation(const BBGraphConstRef bb_graph)
Constructor.
#define STR_XML_host_profiling_avg_iteration
The node containing information about average iterations of a loop.
unsigned long long int GetBBExecutions(const vertex bb_vertex) const
Return the absolute number of executions of a basic block.
Some macro used to interface with the XML library.
BBExecutions(const BBGraphConstRef bb_graph)
Constructor.
#define STR_XML_host_profiling_id
The attribute containing the id of a bb, function or loop.
xml nodes of host profiling data
#define STR_XML_host_profiling_iterations
The attribute containing the number of iterations.
AvgIterations avg_iterations
number of average iterations for one loop execution
#define STR_XML_host_profiling_edge_executions
The node containing information about basic blocks executions.
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
Definition: xml_node.cpp:54
unsigned long long int GetEdgeExecutions(const EdgeDescriptor edge) const
Return the absolute number of the executions of an edge.
boost::graph_traits< graph >::edge_descriptor EdgeDescriptor
edge definition.
Definition: graph.hpp:1316

Generated on Mon Feb 12 2024 13:02:50 for PandA-2024.02 by doxygen 1.8.13