PandA-2024.02
host_profiling.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  */
41 #include "host_profiling.hpp"
42 
43 #include "Parameter.hpp"
44 #include "application_manager.hpp"
45 #include "basic_block.hpp"
46 #include "behavioral_helper.hpp"
47 #include "custom_map.hpp"
48 #include "dbgPrintHelper.hpp"
49 #include "function_behavior.hpp"
50 #include "graph.hpp"
51 #include "hash_helper.hpp"
52 #include "loop.hpp"
53 #include "loops.hpp"
55 #include "string_manipulation.hpp"
56 
57 #include <cerrno>
58 #include <filesystem>
59 #include <unistd.h>
60 
62 {
63  return static_cast<HostProfiling_Method>(static_cast<int>(first) | static_cast<int>(second));
64 }
65 
66 HostProfiling::HostProfiling(const application_managerRef _AppM, const DesignFlowManagerConstRef _design_flow_manager,
67  const ParameterConstRef _parameters)
68  : ApplicationFrontendFlowStep(_AppM, HOST_PROFILING, _design_flow_manager, _parameters)
69 {
70  debug_level = parameters->get_class_debug_level(GET_CLASS(*this), DEBUG_LEVEL_NONE);
71 }
72 
74 
77 {
79  switch(relationship_type)
80  {
82  {
83  const HostProfiling_Method profiling_method =
84  parameters->getOption<HostProfiling_Method>(OPT_profiling_method);
85  THROW_ASSERT(profiling_method != HostProfiling_Method::PM_NONE,
86  "Host profiilng required but algorithm has not been selected");
87  if(static_cast<int>(profiling_method) & static_cast<int>(HostProfiling_Method::PM_BBP))
88  {
89  relationships.insert(std::make_pair(BASIC_BLOCKS_PROFILING, WHOLE_APPLICATION));
90  }
91  break;
92  }
95  {
96  break;
97  }
98  default:
99  {
100  THROW_UNREACHABLE("");
101  }
102  }
103  return relationships;
104 }
105 
107 {
109 }
110 
115 {
116 #ifndef NDEBUG
117  const int debug_level = parameters->get_class_debug_level("HostProfiling");
118 #endif
119  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Normalizing loop iteration");
120  // Iterating over all functions with body
121  for(const auto f : AppM->get_functions_with_body())
122  {
123  // Normalizing basic block execution time
124  // First computing number of execution of the function
125  // number of function execution
126  const FunctionBehaviorRef FB = AppM->GetFunctionBehavior(f);
128  "-->Function: " + FB->CGetBehavioralHelper()->get_function_name());
129 
130  // Normalizing loop number of iteration and frequency
131  const std::list<LoopConstRef>& loops = FB->CGetLoops()->GetList();
132  std::list<LoopConstRef>::const_iterator loop, loop_end = loops.end();
133  for(loop = loops.begin(); loop != loop_end; ++loop)
134  {
135  unsigned int loop_id = (*loop)->GetId();
137  if(loop_id == 0)
138  {
139  continue;
140  }
141  long double avg_number = 0.0L;
142  long double abs_execution = 0.0L;
143  PathProfilingInformation& path_profiling = FB->profiling_information->path_profiling;
144  if(path_profiling.find(loop_id) == path_profiling.end())
145  {
146  continue;
147  }
148  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Loop: " + std::to_string(loop_id));
149  const auto& elements = path_profiling.find(loop_id)->second;
150  for(const auto& element : elements)
151  {
152  abs_execution += element.second;
153  }
154  if(abs_execution != 0.0L)
155  {
156  if(loop_instances.find(f) == loop_instances.end())
157  {
159  "Function " + FB->CGetBehavioralHelper()->get_function_name() + " exited abnormally");
160  }
161  THROW_ASSERT(loop_instances.at(f).find(loop_id) != loop_instances.at(f).end(),
162  "Loop " + std::to_string(f) + " is no executed");
163  THROW_ASSERT(loop_instances.at(f).at(loop_id) != 0,
164  "Loop " + std::to_string(loop_id) + " of function " + std::to_string(f) +
165  " is executed but does not exist an external path with its header");
166  avg_number = abs_execution / loop_instances.at(f).at(loop_id);
167  }
169  "-->Avg. Number Executions: " + std::to_string(avg_number));
170  FB->profiling_information->avg_iterations[(*loop)->GetId()] = avg_number;
171  FB->profiling_information->abs_iterations[(*loop)->GetId()] =
172  static_cast<unsigned long long int>(llroundl(abs_execution));
173  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "Factor: " + std::to_string(abs_execution));
174  for(auto& k : path_profiling.at(loop_id))
175  {
176  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->New path");
177  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "---Absolute path: " + std::to_string(k.second));
178  k.second /= abs_execution;
179  INDENT_DBG_MEX(DEBUG_LEVEL_PEDANTIC, debug_level, "---Relative path: " + std::to_string(k.second));
180  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--");
181  }
182  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--");
183  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--");
184  }
185  if(parameters->getOption<bool>(OPT_print_dot))
186  {
187  FB->CGetLoops()->WriteDot("LF.dot", FB->CGetProfilingInformation());
188  }
189  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--");
190  }
191  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Normalized loop iteration");
192 }
error during profiling
Definition: exceptions.hpp:331
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
File containing functions and utilities to support the printing of debug messagges.
#define DEBUG_LEVEL_PEDANTIC
very verbose debugging print is performed.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
Definition of the class representing a generic C application.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
Class specification of the graph structures.
HostProfiling(const application_managerRef AppM, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
redefinition of map to manage ordered/unordered structures
Map storing path profiling information.
Auxiliary methods for manipulating string.
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Class specification for storing profiling information.
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
HostProfiling_Method
Different profiling method.
static const uint32_t k[]
Definition: sha-256.c:22
Abstract class for passes performing a dynamic profiling of loops, paths or both by means of predepen...
Basic blocks profiling.
HostProfiling_Method operator &(const HostProfiling_Method first, const HostProfiling_Method second)
const CustomUnorderedSet< std::pair< FrontendFlowStepType, FunctionRelationship > > ComputeFrontendRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
None profiling method selected.
static void normalize(const application_managerRef AppM, const CustomUnorderedMap< unsigned int, CustomUnorderedMapStable< unsigned int, long long unsigned int >> &loop_instances, const ParameterConstRef parameters)
Normalize path frequency according to execution times of whole function_id.
#define L
Definition: spmv.h:13
~HostProfiling() override
Destructor.
const application_managerRef AppM
The application manager.
Class specification of the basic_block structure.
This file collects some hash functors.
interface of a loop
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
#define THROW_ERROR_CODE(code, str_expr)
helper function used to throw an error with a code error
Definition: exceptions.hpp:266
interface of loops finding algorithm
this class is used to manage the command-line or XML options.
absl::node_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapStable
Definition: custom_map.hpp:152
int debug_level
The debug level.
DesignFlowStep_Status Exec() override
Do nothing.
A brief description of the C++ Header File.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

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