PandA-2024.02
evaluation.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  */
43 #include "evaluation.hpp"
44 
45 #include "BackendFlow.hpp"
46 #include "Parameter.hpp"
48 #include "area_info.hpp"
49 #include "bambu_results_xml.hpp"
50 #include "behavioral_helper.hpp"
51 #include "call_graph_manager.hpp"
52 #include "dbgPrintHelper.hpp"
53 #include "fileIO.hpp"
54 #include "hls.hpp"
55 #include "hls_constraints.hpp"
57 #include "hls_manager.hpp"
58 #include "string_manipulation.hpp"
59 #include "tree_manager.hpp"
60 #include "tree_reindex.hpp"
61 #include "utility.hpp"
62 #include "xml_document.hpp"
63 #include "xml_helper.hpp"
64 
65 #include <filesystem>
66 
67 Evaluation::Evaluation(const ParameterConstRef _parameters, const HLS_managerRef _HLSMgr,
68  const DesignFlowManagerConstRef _design_flow_manager)
69  : HLS_step(_parameters, _HLSMgr, _design_flow_manager, HLSFlowStep_Type::EVALUATION)
70 {
71  debug_level = parameters->get_class_debug_level(GET_CLASS(*this));
72 }
73 
74 Evaluation::~Evaluation() = default;
75 
78 {
79  auto objective_string = parameters->getOption<std::string>(OPT_evaluation_objectives);
80  const auto objective_vector = string_to_container<std::vector<std::string>>(objective_string, ",");
82  switch(relationship_type)
83  {
85  {
86  switch(parameters->getOption<Evaluation_Mode>(OPT_evaluation_mode))
87  {
89  {
92  break;
93  }
95  {
96  for(const auto& objective : objective_vector)
97  {
98  if(false)
99  {
100  }
101 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT
102  else if(objective == "AREA")
103  {
104  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
107  }
108 #endif
109 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT && HAVE_SIMULATION_WRAPPER_BUILT
110  else if(objective == "AREAxTIME")
111  {
112  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
115  ret.insert(std::make_tuple(HLSFlowStep_Type::SIMULATION_EVALUATION,
118  }
119 #endif
120 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT
121  else if(objective == "BRAMS")
122  {
123  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
126  }
127  else if(objective == "DRAMS")
128  {
129  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
132  }
133  else if(objective == "CLOCK_SLACK")
134  {
135  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
138  }
139 #endif
140 #if HAVE_SIMULATION_WRAPPER_BUILT
141  else if(objective == "CYCLES" || objective == "TOTAL_CYCLES")
142  {
143  ret.insert(std::make_tuple(HLSFlowStep_Type::SIMULATION_EVALUATION,
146  }
147 #endif
148 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT
149  else if(objective == "DSPS")
150  {
151  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
154  }
155 #endif
156 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT
157  else if(objective == "FREQUENCY")
158  {
159  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
162  }
163  else if(objective == "PERIOD")
164  {
165  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
168  }
169  else if(objective == "REGISTERS")
170  {
171  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
174  }
175 #endif
176 #if HAVE_LIBRARY_CHARACTERIZATION_BUILT && HAVE_SIMULATION_WRAPPER_BUILT
177  else if(objective == "TIME" || objective == "TOTAL_TIME")
178  {
179  ret.insert(std::make_tuple(HLSFlowStep_Type::SIMULATION_EVALUATION,
182  ret.insert(std::make_tuple(HLSFlowStep_Type::SYNTHESIS_EVALUATION,
185  }
186 #endif
187  else
188  {
189  THROW_ERROR("Evaluation objective not yet supported " + objective);
190  }
191  }
192  break;
193  }
195  {
196  THROW_UNREACHABLE("");
197  break;
198  }
199  default:
200  THROW_UNREACHABLE("");
201  }
202  break;
203  }
205  {
206  break;
207  }
209  {
210 #if HAVE_VCD_BUILT
211  if(parameters->isOption(OPT_discrepancy) and parameters->getOption<bool>(OPT_discrepancy))
212  {
213  ret.insert(std::make_tuple(HLSFlowStep_Type::VCD_UTILITY, HLSFlowStepSpecializationConstRef(),
215  }
216 #endif
217  break;
218  }
219  default:
220  THROW_UNREACHABLE("");
221  }
222  return ret;
223 }
224 
226 {
227  bool printed_area = false;
228  bool printed_frequency = false;
229  auto objective_string = parameters->getOption<std::string>(OPT_evaluation_objectives);
230  const auto objective_vector = string_to_container<std::vector<std::string>>(objective_string, ",");
231  const auto& evaluations = HLSMgr->evaluations;
232  for(const auto& objective : objective_vector)
233  {
234  const auto evaluation = [&]() -> double {
235  if(objective == "AREAxTIME" or objective == "TIME" or objective == "TOTAL_TIME")
236  {
237  return 0.0;
238  }
239  THROW_ASSERT(HLSMgr->evaluations.find(objective) != HLSMgr->evaluations.end(), objective);
240  const auto local_evaluations = HLSMgr->evaluations.at(objective);
241  return local_evaluations;
242  }();
243  if(objective == "CYCLES")
244  {
245  THROW_ASSERT(evaluations.find("TOTAL_CYCLES") != evaluations.end(), "");
246  auto tot_cycles = static_cast<unsigned long long int>(evaluations.at("TOTAL_CYCLES"));
247  THROW_ASSERT(evaluations.find("NUM_EXECUTIONS") != evaluations.end(), "");
248  auto num_executions = static_cast<unsigned long long int>(evaluations.at("NUM_EXECUTIONS"));
249  auto avg_cycles = static_cast<unsigned long long int>(evaluation);
251  "---Total cycles : " + STR(tot_cycles) + " cycles");
252  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Number of executions : " + STR(num_executions));
254  "---Average execution : " + STR(avg_cycles) + " cycles");
255  }
256  else if((objective == "AREA" or objective == "AREAxTIME") and !printed_area)
257  {
258  printed_area = true;
259  // INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Area : " +
260  // STR(evaluations.at("AREA").at(0) ));
261  if(evaluations.find("SLICE") != evaluations.end())
262  {
264  "---Slices : " + STR(evaluations.at("SLICE")));
265  }
266  if(evaluations.find("SLICE_LUTS") != evaluations.end())
267  {
269  "---Luts : " + STR(evaluations.at("SLICE_LUTS")));
270  }
271  else if(evaluations.find("LUT_FF_PAIRS") != evaluations.end())
272  {
274  "---Luts : " + STR(evaluations.at("LUT_FF_PAIRS")));
275  }
276  if(evaluations.find("LOGIC_ELEMENTS") != evaluations.end())
277  {
279  "---Logic Elements : " + STR(evaluations.at("LOGIC_ELEMENTS")));
280  }
281  if(evaluations.find("FUNCTIONAL_ELEMENTS") != evaluations.end())
282  {
284  "---Functional Elements : " + STR(evaluations.at("FUNCTIONAL_ELEMENTS")));
285  }
286  if(evaluations.find("LOGIC_AREA") != evaluations.end())
287  {
289  "---Logic Area : " + STR(evaluations.at("LOGIC_AREA")));
290  }
291  if(evaluations.find("POWER") != evaluations.end())
292  {
294  "---Power : " + STR(evaluations.at("POWER")));
295  }
296  if(evaluations.find("ALMS") != evaluations.end())
297  {
299  "---ALMs : " + STR(evaluations.at("ALMS")));
300  }
301  if(evaluations.find("URAMS") != evaluations.end())
302  {
304  "---URAMs : " + STR(evaluations.at("URAMS")));
305  }
306  }
307  else if(objective == "BRAMS")
308  {
309  double brams = evaluation;
310  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---BRAMs : " + STR(brams));
311  }
312  else if(objective == "DRAMS")
313  {
314  double drams = evaluation;
315  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---DRAMs : " + STR(drams));
316  }
317  else if(objective == "CLOCK_SLACK")
318  {
320  const auto slack = evaluation;
321  if(parameters->getOption<bool>(OPT_timing_violation_abort) and slack < 0.0)
322  {
323  THROW_UNREACHABLE("Slack is " + STR(slack));
324  }
325  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Design slack : " + STR(slack));
326  }
327  else if(objective == "PERIOD")
328  {
330  double minimum_period = evaluation;
331  auto clock_period = parameters->getOption<double>(OPT_clock_period);
332  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Clock period : " + STR(clock_period));
333  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Design minimum period : " + STR(minimum_period));
334  }
335  else if(objective == "DSPS")
336  {
338  const auto dsps = evaluation;
339  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---DSPs : " + STR(dsps));
340  }
341  else if((objective == "FREQUENCY" or objective == "TIME" or objective == "TOTAL_TIME" or
342  objective == "AREAxTIME") and
343  not printed_frequency)
344  {
345  printed_frequency = true;
347  THROW_ASSERT(evaluations.find("PERIOD") != evaluations.end(), "");
348  double minimum_period = evaluations.at("PERIOD");
349  double maximum_frequency = 1000.0 / minimum_period;
350  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Frequency : " + STR(maximum_frequency));
351  }
352  else if(objective == "REGISTERS")
353  {
355  double reg = evaluation;
356  if(reg > 0.0)
357  {
358  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Registers : " + STR(reg));
359  }
360  }
361  }
362 
363  unsigned int progressive = 0U;
364  const auto out_file_name = [&]() {
365  std::string candidate_out_file_name;
366  do
367  {
368  candidate_out_file_name = GetPath("bambu_results_" + STR(progressive++) + ".xml");
369  } while(std::filesystem::exists(candidate_out_file_name));
370  return candidate_out_file_name;
371  }();
372 
373  xml_document document;
374  xml_element* nodeRoot = document.create_root_node("bambu_results");
375 
376  std::string bench_name;
377  if(parameters->isOption(OPT_benchmark_name))
378  {
379  bench_name += parameters->getOption<std::string>(OPT_benchmark_name) + ":";
380  }
381  if(parameters->isOption(OPT_configuration_name))
382  {
383  bench_name += parameters->getOption<std::string>(OPT_configuration_name);
384  }
385  if(bench_name == "" || !parameters->IsParameter("simple-benchmark-name") ||
386  parameters->GetParameter<int>("simple-benchmark-name") == 0)
387  {
388 #if HAVE_TASTE
389  if(parameters->getOption<bool>(OPT_generate_taste_architecture))
390  {
391  if(bench_name == "")
392  {
393  bench_name += "taste_architecture";
394  }
395  else
396  {
397  bench_name += ":taste_architecture";
398  }
399 
400  bench_name += "_" + STR(progressive - 1);
401  }
402  else
403 #endif
404  {
405 #ifndef NDEBUG
406  if(parameters->getOption<Evaluation_Mode>(OPT_evaluation_mode) == Evaluation_Mode::DRY_RUN)
407  {
408  if(bench_name == "")
409  {
410  bench_name = "dry_run";
411  }
412  }
413  else
414 #endif
415  if(parameters->isOption(OPT_top_functions_names))
416  {
417  if(bench_name == "")
418  {
419  bench_name += parameters->getOption<std::string>(OPT_top_functions_names);
420  }
421  else
422  {
423  bench_name += ":" + parameters->getOption<std::string>(OPT_top_functions_names);
424  }
425 
426  bench_name += "_" + STR(progressive - 1);
427  }
428  else
429  {
430  const auto top_symbols = parameters->getOption<std::vector<std::string>>(OPT_top_functions_names);
431  THROW_ASSERT(top_symbols.size() == 1, "Expected single top function name");
432  const auto top_fnode = HLSMgr->get_tree_manager()->GetFunction(top_symbols.front());
433  const FunctionBehaviorConstRef FB = HLSMgr->CGetFunctionBehavior(GET_INDEX_CONST_NODE(top_fnode));
434  if(bench_name == "")
435  {
436  bench_name += FB->CGetBehavioralHelper()->get_function_name();
437  }
438  else
439  {
440  bench_name += ":" + FB->CGetBehavioralHelper()->get_function_name();
441  }
442 
443  bench_name += "_" + STR(progressive - 1);
444  }
445  }
446  }
447 
448  const auto bambu_args = parameters->getOption<std::string>(OPT_cat_args);
449  const auto bambu_version = parameters->PrintVersion();
450  const auto current_time = TimeStamp::GetCurrentTimeStamp();
451  WRITE_XNVM2(STR_XML_bambu_results_bambu_args, bambu_args, nodeRoot);
452  WRITE_XNVM2(STR_XML_bambu_results_bambu_version, bambu_version, nodeRoot);
453  WRITE_XNVM2(STR_XML_bambu_results_timestamp, current_time, nodeRoot);
454  WRITE_XNVM2("benchmark_name", bench_name, nodeRoot);
455  xml_element* child_element;
456 
457  for(auto const& objective : objective_vector)
458  {
459  std::string value;
460  if(objective == "AREAxTIME")
461  {
462  THROW_ASSERT(HLSMgr->evaluations.find("AREA") != HLSMgr->evaluations.end(), "Area value not found");
463  THROW_ASSERT(HLSMgr->evaluations.find("CYCLES") != HLSMgr->evaluations.end(), "Cycles value not found");
464  THROW_ASSERT(HLSMgr->evaluations.find("FREQUENCY") != HLSMgr->evaluations.end(), "Frequency value not found");
465  value = STR(HLSMgr->evaluations.find("AREA")->second * HLSMgr->evaluations.find("CYCLES")->second /
466  HLSMgr->evaluations.find("FREQUENCY")->second);
467  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---AreaxTime : " + value);
468  }
469  else if(objective == "TIME")
470  {
471  THROW_ASSERT(HLSMgr->evaluations.find("CYCLES") != HLSMgr->evaluations.end(), "Cycles value not found");
472  THROW_ASSERT(HLSMgr->evaluations.find("FREQUENCY") != HLSMgr->evaluations.end(), "Frequency value not found");
473  value = STR(HLSMgr->evaluations.find("CYCLES")->second / HLSMgr->evaluations.find("FREQUENCY")->second);
474  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Time : " + value);
475  }
476  else if(objective == "TOTAL_TIME")
477  {
478  THROW_ASSERT(HLSMgr->evaluations.find("TOTAL_CYCLES") != HLSMgr->evaluations.end(), "Cycles value not found");
479  THROW_ASSERT(HLSMgr->evaluations.find("FREQUENCY") != HLSMgr->evaluations.end(), "Frequency value not found");
480  value = STR(HLSMgr->evaluations.find("TOTAL_CYCLES")->second / HLSMgr->evaluations.find("FREQUENCY")->second);
481  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "---Tot. Time : " + value);
482  }
483  else
484  {
485  THROW_ASSERT(HLSMgr->evaluations.find(objective) != HLSMgr->evaluations.end(),
486  "Value of " + objective + " not found");
487  double& local_evaluations = HLSMgr->evaluations.find(objective)->second;
488  value += STR(local_evaluations);
489  }
490  child_element = nodeRoot->add_child_element(objective);
491  WRITE_XNVM2("value", value, child_element);
492 
493  if(objective == "AREA" && HLSMgr->evaluations.find("SLICE") != HLSMgr->evaluations.end())
494  {
495  child_element = nodeRoot->add_child_element("SLICE");
496  value = STR(HLSMgr->evaluations.find("SLICE")->second);
497  WRITE_XNVM2("value", value, child_element);
498  }
499  if(objective == "AREA" && HLSMgr->evaluations.find("SLICE_LUTS") != HLSMgr->evaluations.end())
500  {
501  child_element = nodeRoot->add_child_element("SLICE_LUTS");
502  value = STR(HLSMgr->evaluations.find("SLICE_LUTS")->second);
503  WRITE_XNVM2("value", value, child_element);
504  }
505  if(objective == "AREA" && HLSMgr->evaluations.find("URAMS") != HLSMgr->evaluations.end())
506  {
507  child_element = nodeRoot->add_child_element("URAMS");
508  value = STR(HLSMgr->evaluations.find("URAMS")->second);
509  WRITE_XNVM2("value", value, child_element);
510  }
511  }
512  child_element = nodeRoot->add_child_element("HLS_execution_time");
513  long double exec_time = HLSMgr->HLS_execution_time;
514  WRITE_XNVM2("value", STR(exec_time / 1000), child_element);
515 
516  document.write_to_file_formatted(out_file_name);
518 }
519 
521 {
522  return true;
523 }
Class to compute evaluations about high-level synthesis.
const HLS_managerRef HLSMgr
information about all the HLS synthesis
Definition: hls_step.hpp:205
Data structure representing the entire HLS information.
Collect information about resource area.
File containing functions and utilities to support the printing of debug messagges.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
std::string get_function_name() const
Return the name of the function.
const int output_level
The output level.
RelationshipType
The relationship type.
Source must be executed to satisfy target.
#define INDENT_OUT_MEX(outLevel, curOutLevel, mex)
~Evaluation() override
Destructor.
#define STR_XML_bambu_results_bambu_version
The attribute containing bambu version.
constant strings used in bambu results
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
static std::string GetCurrentTimeStamp()
Return a timestamp of the current time.
Definition: utility.cpp:55
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
Definition: exceptions.hpp:292
Factory for hls flow step.
Evaluation_Mode
Definition: evaluation.hpp:52
HLSFlowStep_Type
Definition: hls_step.hpp:95
Class definition for high level synthesis result evaluationThis class is the abstract class for all k...
void write_to_file_formatted(const std::filesystem::path &filename)
Write the document to a file.
xml_element * create_root_node(const std::string &_name)
Creates the root node.
utility function used to read files.
const BehavioralHelperConstRef CGetBehavioralHelper() const
Returns the helper associated with the function.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
This file collects some utility functions and macros.
const CustomUnorderedSet< std::tuple< HLSFlowStep_Type, HLSFlowStepSpecializationConstRef, HLSFlowStep_Relationship > > ComputeHLSRelationships(const DesignFlowStep::RelationshipType relationship_type) const override
Return the set of analyses in relationship with this design step.
Definition: evaluation.cpp:77
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
Data structure definition for HLS constraints.
#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
This file contains the definition of the configurable flow for generating and executing synthesis scr...
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
Class specification of the tree_reindex support class.
#define STR_XML_bambu_results_bambu_args
The attribute containing bambu results.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
#define STR_XML_bambu_results_timestamp
The attribute containing the timestamp of the synthesis.
bool HasToBeExecuted() const override
Check if this step has actually to be executed.
Definition: evaluation.cpp:520
Some macro used to interface with the XML library.
Wrapper to call graph.
Evaluation(const ParameterConstRef _parameters, const HLS_managerRef HLSMgr, const DesignFlowManagerConstRef design_flow_manager)
Constructor.
Definition: evaluation.cpp:67
int debug_level
The debug level.
refcount< const HLSFlowStepSpecialization > HLSFlowStepSpecializationConstRef
const refcount definition of the class
Definition: hls_step.hpp:93
#define GET_INDEX_CONST_NODE(t)
Definition: tree_node.hpp:363
Data structure definition for high-level synthesis flow.
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
Definition: xml_node.cpp:54
Class specification of the manager of the tree structures extracted from the raw file.
DesignFlowStep_Status Exec() override
Execute the step.
Definition: evaluation.cpp:225
#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:53 for PandA-2024.02 by doxygen 1.8.13