PandA-2024.02
fix_characterization.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) 2016-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  */
42 #include "fix_characterization.hpp"
44 
45 #include "Parameter.hpp"
46 #include "area_info.hpp"
47 #include "custom_set.hpp"
48 #include "dbgPrintHelper.hpp"
49 #include "generic_device.hpp"
50 #include "library_manager.hpp"
51 #include "string_manipulation.hpp"
52 #include "technology_manager.hpp"
53 #include "technology_node.hpp"
54 #include "time_info.hpp"
55 #include "utility.hpp"
56 
57 #include <string>
58 #include <vector>
59 
61  const DesignFlowManagerConstRef _design_flow_manager,
62  const ParameterConstRef _parameters)
63  : TechnologyFlowStep(_TM, _target, _design_flow_manager, TechnologyFlowStep_Type::FIX_CHARACTERIZATION,
64  _parameters),
65  assignment_execution_time(0.0),
66  connection_time(0.0)
67 {
68  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
69 }
70 
72 
74 {
77 
78  const double connection_time_ratio = parameters->IsParameter("RelativeConnectionOffset") ?
79  parameters->GetParameter<double>("RelativeConnectionOffset") :
80  0.15;
81  connection_time = assignment_execution_time * connection_time_ratio;
82 }
83 
85 {
86  const auto libraries = TM->get_library_list();
87  for(const auto& library : libraries)
88  {
89  const auto LM = TM->get_library_manager(library);
90  const auto fus = LM->get_library_fu();
91  for(const auto& fu : fus)
92  {
93  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing " + fu.first);
94  auto single_fu = GetPointer<functional_unit>(fu.second);
95  if(!single_fu)
96  {
97  continue;
98  }
99  auto template_name = single_fu->fu_template_name;
100  auto fu_name = single_fu->functional_unit_name;
101  if(single_fu)
102  {
104  if(fu_name == "ASSIGN_REAL_FU" || fu_name == "ASSIGN_SIGNED_FU" || fu_name == "ASSIGN_UNSIGNED_FU" ||
105  fu_name == "ASSIGN_VECTOR_BOOL_FU" || fu_name == "addr_expr_FU" ||
106  fu_name == "fp_view_convert_expr_FU" || fu_name == "ui_view_convert_expr_FU" ||
107  fu_name == "view_convert_expr_FU" || fu_name == "assert_expr_FU")
108  {
109  single_fu->area_m->set_area_value(1);
110  for(const auto& op : single_fu->get_operations())
111  {
112  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
113  {
115  "---Fixing execution time of " + GetPointer<const operation>(op)->operation_name +
116  " on " + fu.first);
117  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
118  single_fu->characterization_timestamp = assignment_characterization_timestamp;
119  }
120  }
121  }
123  if(template_name == "rshift_expr_FU" || template_name == "ui_rshift_expr_FU" ||
124  template_name == "lshift_expr_FU" || template_name == "ui_lshift_expr_FU" ||
125  template_name == "ui_lrotate_expr_FU" || template_name == "ui_rrotate_expr_FU")
126  {
127  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
128  THROW_ASSERT(template_parameters.size() == 3, single_fu->fu_template_parameters);
129  if(template_parameters[1] == "0")
130  {
131  single_fu->area_m->set_area_value(1);
132  for(const auto& op : single_fu->get_operations())
133  {
134  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
135  {
137  "---Fixing execution time of " +
138  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
139  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
140  single_fu->characterization_timestamp = assignment_characterization_timestamp;
141  }
142  }
143  }
144  }
146  if(template_name == "vec_rshift_expr_FU" || template_name == "ui_vec_rshift_expr_FU" ||
147  template_name == "vec1_rshift_expr_FU" || template_name == "ui_vec1_rshift_expr_FU" ||
148  template_name == "vec_lshift_expr_FU" || template_name == "ui_vec_lshift_expr_FU" ||
149  template_name == "vec1_lshift_expr_FU" || template_name == "ui_vec1_lshift_expr_FU")
150  {
151  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
152  THROW_ASSERT(template_parameters.size() >= 4, single_fu->fu_template_parameters);
153  if(template_parameters[2] == "0")
154  {
155  single_fu->area_m->set_area_value(1);
156  for(const auto& op : single_fu->get_operations())
157  {
158  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
159  {
161  "---Fixing execution time of " +
162  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
163  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
164  single_fu->characterization_timestamp = assignment_characterization_timestamp;
165  }
166  }
167  }
168  }
170  if(fu_name == "IIdata_converter_FU" || fu_name == "UIdata_converter_FU" ||
171  fu_name == "IUdata_converter_FU" || fu_name == "UUdata_converter_FU" || fu_name == "IIconvert_expr_FU" ||
172  fu_name == "IUconvert_expr_FU" || fu_name == "UIconvert_expr_FU" || fu_name == "UUconvert_expr_FU")
173  {
174  single_fu->area_m->set_area_value(1);
175  for(const auto& op : single_fu->get_operations())
176  {
177  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
178  {
180  "---Fixing execution time of " + GetPointer<const operation>(op)->operation_name +
181  " on " + fu.first);
182  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
183  single_fu->characterization_timestamp = assignment_characterization_timestamp;
184  }
185  }
186  }
188  if(template_name == "bit_and_expr_FU" || template_name == "ui_bit_and_expr_FU" ||
189  template_name == "bit_ior_expr_FU" || template_name == "ui_bit_ior_expr_FU")
190  {
191  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
192  THROW_ASSERT(template_parameters.size() == 3, single_fu->fu_template_parameters);
193  if(template_parameters[0] == "0" || template_parameters[1] == "0")
194  {
195  single_fu->area_m->set_area_value(1);
196  for(const auto& op : single_fu->get_operations())
197  {
198  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
199  {
201  "---Fixing execution time of " +
202  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
203  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
204  single_fu->characterization_timestamp = assignment_characterization_timestamp;
205  }
206  }
207  }
208  }
210  if(template_name == "vec_bit_and_expr_FU" || template_name == "ui_vec_bit_and_expr_FU" ||
211  template_name == "vec_bit_ior_expr_FU" || template_name == "ui_vec_bit_ior_expr_FU")
212  {
213  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
214  THROW_ASSERT(template_parameters.size() >= 5, single_fu->fu_template_parameters);
215  if(template_parameters[0] == "0" || template_parameters[2] == "0")
216  {
217  single_fu->area_m->set_area_value(1);
218  for(const auto& op : single_fu->get_operations())
219  {
220  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
221  {
223  "---Fixing execution time of " +
224  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
225  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
226  single_fu->characterization_timestamp = assignment_characterization_timestamp;
227  }
228  }
229  }
230  }
232  if(template_name == "cond_expr_FU" || template_name == "ui_cond_expr_FU" ||
233  template_name == "fp_cond_expr_FU")
234  {
235  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
236  THROW_ASSERT(template_parameters.size() == 4, single_fu->fu_template_parameters);
237  if(template_parameters[0] == "0")
238  {
239  single_fu->area_m->set_area_value(1);
240  for(const auto& op : single_fu->get_operations())
241  {
242  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
243  {
245  "---Fixing execution time of " +
246  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
247  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
248  single_fu->characterization_timestamp = assignment_characterization_timestamp;
249  }
250  }
251  }
252  }
254  if(template_name == "vec_cond_expr_FU" || template_name == "ui_vec_cond_expr_FU")
255  {
256  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
257  THROW_ASSERT(template_parameters.size() >= 6, single_fu->fu_template_parameters);
258  if(template_parameters[0] == "0")
259  {
260  single_fu->area_m->set_area_value(1);
261  for(const auto& op : single_fu->get_operations())
262  {
263  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
264  {
266  "---Fixing execution time of " +
267  GetPointer<const operation>(op)->operation_name + " on " + fu.first);
268  (GetPointer<operation>(op))->time_m->set_execution_time(assignment_execution_time, 0);
269  single_fu->characterization_timestamp = assignment_characterization_timestamp;
270  }
271  }
272  }
273  }
274 #if 0
275  if(template_name == "plus_expr_FU" or template_name == "ui_plus_expr_FU" or template_name == "minus_expr_FU" or template_name == "ui_minus_expr_FU")
277  {
278  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
279  const auto output_size = std::stoul(template_parameters.back());
281  if(output_size > 32)
282  {
283  for(auto op : single_fu->get_operations())
284  {
285  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
286  {
287  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Fixing execution time of " + GetPointer<const operation>(op)->operation_name + " on " + fu.first);
288  (GetPointer<operation>(op))->time_m->set_execution_time(GetPointer<operation>(op)->time_m->get_execution_time() + connection_time, 0);
289  }
290  }
291  }
292  }
294  if(template_name == "ternary_alu_expr_FU" or template_name == "ui_ternary_alu_expr_FU" or template_name == "ternary_mm_expr_FU" or template_name == "ui_ternary_mm_expr_FU" or template_name == "ternary_mp_expr_FU" or template_name == "ui_ternary_mp_expr_FU" or template_name == "ternary_pm_expr_FU" or template_name == "ui_ternary_pm_expr_FU" or template_name == "ternary_plus_expr_FU" or template_name == "ui_ternary_plus_expr_FU")
295  {
296  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
297  const auto output_size = std::stoul(template_parameters.back());
299  if(output_size > 32)
300  {
301  for(auto op : single_fu->get_operations())
302  {
303  if(assignment_execution_time != (GetPointer<operation>(op))->time_m->get_execution_time())
304  {
305  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Fixing execution time of " + GetPointer<const operation>(op)->operation_name + " on " + fu.first);
306  (GetPointer<operation>(op))->time_m->set_execution_time(GetPointer<operation>(op)->time_m->get_execution_time() + connection_time, 0);
307  }
308  }
309  }
310  }
311 #endif
312  }
313 
314  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed " + fu.first);
315  }
316  }
318  for(const auto& library : libraries)
319  {
320  const auto LM = TM->get_library_manager(library);
321  const auto fus = LM->get_library_fu();
322  for(const auto& fu : fus)
323  {
324  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Analyzing " + fu.first);
325  auto single_fu = GetPointer<functional_unit>(fu.second);
326  if(!single_fu)
327  {
328  continue;
329  }
330  auto template_name = single_fu->fu_template_name;
331  if(single_fu)
332  {
334  if(template_name == "plus_expr_FU" or template_name == "ui_plus_expr_FU" or
335  template_name == "minus_expr_FU" or template_name == "ui_minus_expr_FU" or
336  template_name == "ternary_alu_expr_FU" or template_name == "ui_ternary_alu_expr_FU" or
337  template_name == "ternary_mm_expr_FU" or template_name == "ui_ternary_mm_expr_FU" or
338  template_name == "ternary_mp_expr_FU" or template_name == "ui_ternary_mp_expr_FU" or
339  template_name == "ternary_pm_expr_FU" or template_name == "ui_ternary_pm_expr_FU" or
340  template_name == "ternary_plus_expr_FU" or template_name == "ui_ternary_plus_expr_FU")
341  {
342  if(single_fu->fu_template_parameters.find(" 0") != std::string::npos or
343  (single_fu->fu_template_parameters.size() >= 2 and
344  single_fu->fu_template_parameters.substr(0, 2) == "0 "))
345  {
346  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Fixing " + single_fu->get_name());
347  std::vector<std::string> template_parameters = SplitString(single_fu->fu_template_parameters, " ");
348  const auto output_size = std::stoul(template_parameters.back());
349  std::string cell_name = template_name;
350  for(const auto& template_parameter : template_parameters)
351  {
352  cell_name += "_";
353  if(template_parameter == "0")
354  {
355  cell_name += STR(output_size);
356  }
357  else
358  {
359  cell_name += template_parameter;
360  }
361  }
362  const technology_nodeConstRef nc_f_unit = TM->get_fu(cell_name, TM->get_library(cell_name));
363  THROW_ASSERT(nc_f_unit, "Library miss component: " + std::string(cell_name));
364  CustomMap<std::string, double> non_constant_execution_times;
365  for(const auto& op : GetPointer<const functional_unit>(nc_f_unit)->get_operations())
366  {
367  non_constant_execution_times[op->get_name()] =
368  GetPointer<operation>(op)->time_m->get_execution_time();
369  }
370  for(const auto& op : single_fu->get_operations())
371  {
372  const std::string operation_name = op->get_name();
373  THROW_ASSERT(non_constant_execution_times.find(operation_name) !=
374  non_constant_execution_times.end(),
375  operation_name);
376  const auto non_constant_execution_time = non_constant_execution_times.find(operation_name)->second;
377  GetPointer<operation>(op)->time_m->set_execution_time(non_constant_execution_time, 0);
378  }
379  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Fixed " + single_fu->get_name());
380  }
381  }
382  }
383  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "<--Analyzed " + fu.first);
384  }
385  }
387 }
388 
391 {
393  switch(relationship_type)
394  {
396  {
397  break;
398  }
400  {
401  break;
402  }
404  {
407  relationships.insert(TechnologyFlowStep_Type::LOAD_FILE_TECHNOLOGY);
408  break;
409  }
410  default:
411  {
412  THROW_UNREACHABLE("");
413  }
414  }
415  return relationships;
416 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
double CGetSetupHoldTime() const
Return the setup hold time.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
double connection_time
The estimated execution time of connection.
Collect information about resource area.
const CustomUnorderedSet< TechnologyFlowStep_Type > ComputeTechnologyRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
const fu_map_type & get_library_fu() const
Return the list of the resources contained into the given library.
File containing functions and utilities to support the printing of debug messagges.
DesignFlowStep_Status Exec() override
Execute the step.
technology_nodeRef get_fu(const std::string &fu_name, const std::string &Library) const
Return the reference to a component given its name.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
const std::vector< std::string > & get_library_list() const
Return the list of the libraries.
double assignment_execution_time
The execution time of the assignment.
CustomOrderedMap< T, U > CustomMap
Definition: custom_map.hpp:167
Collect information about resource performance.
FixCharacterization(const technology_managerRef TM, const generic_deviceRef target, const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
Class specification of the manager of the technology library data structures.
Step to fix components characterization.
#define STR(s)
Macro which performs a lexical_cast to a string.
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 of the data structures used to manage technology information. ...
redefinition of set to manage ordered/unordered structures
const technology_managerRef TM
The technology manager.
~FixCharacterization() override
Destructor.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
TechnologyFlowStep_Type
TimeStamp CGetSetupHoldTimeStamp() const
Return the characterization timestamp of the setup hold time.
this class is used to manage the command-line or XML options.
void Initialize() override
Initialize the step (i.e., like a constructor, but executed just before exec.
Generic device description.
Class specification of the manager for each library.
int debug_level
The debug level.
library_managerRef get_library_manager(const std::string &Name) const
Return the library data structure corresponding to the given library id.
std::string get_library(const std::string &Name) const
Return the higher priority library where the given component is stored.
TimeStamp assignment_characterization_timestamp
The timestamp of the assignment.
#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