PandA-2024.02
BashBackendFlow.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) 2020-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  */
40 #include "BashBackendFlow.hpp"
41 
42 #include "DesignParameters.hpp"
43 #include "Parameter.hpp"
44 #include "SynthesisTool.hpp"
45 #include "area_info.hpp"
46 #include "dbgPrintHelper.hpp"
47 #include "fileIO.hpp"
48 #include "generic_device.hpp"
49 #include "string_manipulation.hpp"
50 #include "structural_objects.hpp"
51 #include "synthesis_constants.hpp"
52 #include "time_info.hpp"
53 #include "utility.hpp"
54 #include "xml_dom_parser.hpp"
55 #include "xml_script_command.hpp"
56 
57 #include "config_PANDA_DATA_INSTALLDIR.hpp"
58 
59 #define BASHBACKEND_AREA "BASHBACKEND_AREA"
60 #define BASHBACKEND_POWER "BASHBACKEND_POWER"
61 #define BASHBACKEND_DESIGN_DELAY "BASHBACKEND_DESIGN_DELAY"
62 
63 BashBackendFlow::BashBackendFlow(const ParameterConstRef _Param, const std::string& _flow_name,
64  const generic_deviceRef _device)
65  : BackendFlow(_Param, _flow_name, _device)
66 {
67  PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, " .:: Creating Generic Bash Backend Flow ::.");
68 
69  default_data["Generic-yosysOpenROAD"] = "Generic-yosysOpenROAD.data";
70 
72  if(Param->isOption(OPT_target_device_script))
73  {
74  auto xml_file_path = Param->getOption<std::string>(OPT_target_device_script);
75  if(!std::filesystem::exists(xml_file_path))
76  {
77  THROW_ERROR("File \"" + xml_file_path + "\" does not exist!");
78  }
79  PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, "Importing scripts from file: " + xml_file_path);
80  parser = XMLDomParserRef(new XMLDomParser(xml_file_path));
81  }
82  else
83  {
84  std::string device_string;
85  if(device->has_parameter("family"))
86  {
87  device_string = device->get_parameter<std::string>("family");
88  }
89  else
90  {
91  device_string = "yosysOpenROAD";
92  }
93  if(default_data.find(device_string) == default_data.end())
94  {
95  THROW_ERROR("Device family \"" + device_string + "\" not supported!");
96  }
98  "---Importing default scripts for target device family: " + device_string);
99  parser = XMLDomParserRef(
100  new XMLDomParser(relocate_compiler_path(PANDA_DATA_INSTALLDIR "/panda/wrapper/synthesis/", true) +
101  default_data[device_string]));
102  }
103  parse_flow(parser);
104 }
105 
107 
108 void BashBackendFlow::xparse_utilization(const std::string& fn)
109 {
110  try
111  {
112  XMLDomParser parser(fn);
113  parser.Exec();
114  if(parser)
115  {
116  // Walk the tree:
117  const xml_element* node = parser.get_document()->get_root_node(); // deleted by DomParser.
118  THROW_ASSERT(node->get_name() == "document", "Wrong root name: " + node->get_name());
119 
120  const xml_node::node_list list_int = node->get_children();
121  for(const auto& iter_int : list_int)
122  {
123  const auto* EnodeC = GetPointer<const xml_element>(iter_int);
124  if(!EnodeC)
125  {
126  continue;
127  }
128 
129  if(EnodeC->get_name() == "application")
130  {
131  const xml_node::node_list list_sec = EnodeC->get_children();
132  for(const auto& iter_sec : list_sec)
133  {
134  const auto* nodeS = GetPointer<const xml_element>(iter_sec);
135  if(!nodeS)
136  {
137  continue;
138  }
139 
140  if(nodeS->get_name() == "section")
141  {
142  std::string stringID;
143  if(CE_XVM(stringID, nodeS))
144  {
145  LOAD_XVM(stringID, nodeS);
146  }
147  if(stringID == "BASH_SYNTHESIS_SUMMARY")
148  {
149  const xml_node::node_list list_item = nodeS->get_children();
150  for(const auto& it_item : list_item)
151  {
152  const auto* nodeIt = GetPointer<const xml_element>(it_item);
153  if(!nodeIt or nodeIt->get_name() != "item")
154  {
155  continue;
156  }
157 
158  if(CE_XVM(stringID, nodeIt))
159  {
160  LOAD_XVM(stringID, nodeIt);
161  }
162 
163  std::string value;
164  if(CE_XVM(value, nodeIt))
165  {
166  LOAD_XVM(value, nodeIt);
167  boost::replace_all(value, ",", "");
168  design_values[stringID] = std::stod(value);
169  }
170  }
171  }
172  }
173  }
174  }
175  }
176  return;
177  }
178  }
179  catch(const char* msg)
180  {
181  std::cerr << msg << std::endl;
182  }
183  catch(const std::string& msg)
184  {
185  std::cerr << msg << std::endl;
186  }
187  catch(const std::exception& ex)
188  {
189  std::cout << "Exception caught: " << ex.what() << std::endl;
190  }
191  catch(...)
192  {
193  std::cerr << "unknown exception" << std::endl;
194  }
195  THROW_ERROR("Error during report parsing: " + fn);
196 }
197 
199 {
200  std::string sdc_filename = out_dir + "/" + dp->component_name + ".sdc";
201  std::ofstream SDC_file(sdc_filename.c_str());
202  if(dp->parameter_values.find(PARAM_clk_name) != dp->parameter_values.end() &&
203  !static_cast<bool>(std::stoi(dp->parameter_values[PARAM_is_combinational])))
204  {
205  SDC_file << "create_clock " << dp->parameter_values[PARAM_clk_name] << " -period "
206  << dp->parameter_values[PARAM_clk_period] << std::endl;
207  }
208  else
209  {
210  SDC_file << "set_max_delay " + dp->parameter_values[PARAM_clk_period] + " -from [all_inputs] -to [all_outputs]\n";
211  }
212 
213  if(Param->isOption(OPT_backend_sdc_extensions))
214  {
215  SDC_file << "source " + Param->getOption<std::string>(OPT_backend_sdc_extensions) + "\n";
216  }
217  SDC_file.close();
218  dp->parameter_values[PARAM_sdc_file] = sdc_filename;
219 }
220 
222 {
224  bool pwr_enabled = false;
225  if(Param->isOption("power_optimization") && Param->getOption<bool>("power_optimization"))
226  {
227  pwr_enabled = true;
228  }
230  auto device_name = device->get_parameter<std::string>("model");
232 
234  boost::replace_all_copy(actual_parameters->parameter_values[PARAM_HDL_files], ";", " ");
235 
237 
238  for(auto& step : steps)
239  {
240  step->tool->EvaluateVariables(actual_parameters);
241  }
242 }
243 
245 {
246  PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, "Analyzing synthesis results");
247  std::string report_filename = actual_parameters->parameter_values[PARAM_bash_backend_report];
248  xparse_utilization(report_filename);
249 
250  THROW_ASSERT(design_values.find(BASHBACKEND_AREA) != design_values.end(), "Missing logic elements");
252  area_m->set_area_value(design_values[BASHBACKEND_AREA]);
253  area_m->set_resource_value(area_info::LOGIC_AREA, design_values[BASHBACKEND_AREA]);
254  area_m->set_resource_value(area_info::POWER, design_values[BASHBACKEND_POWER]);
255 
258  {
259  auto is_time_unit_PS =
260  device->has_parameter("USE_TIME_UNIT_PS") && device->get_parameter<int>("USE_TIME_UNIT_PS") == 1;
261  time_m->set_execution_time(design_values[BASHBACKEND_DESIGN_DELAY] / (is_time_unit_PS ? 1000 : 1));
262  }
263  else
264  {
266  }
268  (Param->IsParameter("DumpingTimingReport") and Param->GetParameter<int>("DumpingTimingReport"))) and
271  std::filesystem::exists(actual_parameters->parameter_values.find(PARAM_bash_backend_timing_report)->second))))
272  {
274  }
275 }
276 
277 void BashBackendFlow::WriteFlowConfiguration(std::ostream& script)
278 {
279  script << "export PANDA_DATA_INSTALLDIR=" << relocate_compiler_path(std::string(PANDA_DATA_INSTALLDIR "/panda/"))
280  << "\n";
281  script << "export CURR_WORKDIR=" << GetCurrentPath() << "\n";
282 
283  for(const auto& pair : device->get_device_bash_vars())
284  {
285  script << ": ${" << pair.first << ":=" << pair.second << "}"
286  << "\n";
287  script << "export " << pair.first << "\n";
288  }
289 }
void CheckSynthesisResults() override
Checks the synthesis results and fills the corresponding data structures.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
Collect information about resource area.
#define PARAM_target_device
File containing functions and utilities to support the printing of debug messagges.
area_infoRef area_m
pointer to the data structure containing information about the resources
#define PARAM_bash_backend_timing_report
#define PARAM_sdc_file
DesignParametersRef actual_parameters
set of design parameters with the actual values
#define BASHBACKEND_AREA
constants used in synthesis wrappers
BashBackendFlow(const ParameterConstRef Param, const std::string &flow_name, const generic_deviceRef _device)
Constructor.
void set_execution_time(double execution_time, unsigned int cycles=time_info::cycles_time_DEFAULT)
Definition: time_info.cpp:64
Collect information about resource performance.
#define CE_XVM(variable, node)
Check existence XML Value Macro. Check if an XML attribute is present in the XML tree.
Definition: xml_helper.hpp:88
void InitDesignParameters() override
Evaluates design variables.
void WriteFlowConfiguration(std::ostream &script) override
Writes the proper flow configuration in the output script.
void parse_flow(const XMLDomParserRef parser)
Creates the synthesis flow based on the user&#39;s requirements.
time_infoRef time_m
pointer to the data structure containing timing information
const generic_deviceRef device
information about the target device
int debug_level
debugging level of the class
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
~BashBackendFlow() override
Destructor.
#define BASHBACKEND_POWER
map_t parameter_values
Map between the name of the parameter and the corresponding string-based value.
Backend based on a simple bash script.
#define PARAM_bash_backend_report
std::string get_name() const
Get the name of this node.
Definition: xml_node.hpp:132
std::vector< BackendStepRef > steps
ordered list of synthesis steps
This file contains the definition of the parameters for the synthesis tools.
refcount< XMLDomParser > XMLDomParserRef
XML DOM parser.
XML DOM parser.
utility function used to read files.
This file collects some utility functions and macros.
void Exec()
Parse an XML document from a file.
const ParameterConstRef Param
class containing all the parameters
std::list< xml_nodeRef > node_list
type for list of xml nodes
Definition: xml_node.hpp:90
std::map< std::string, std::string > default_data
map between the identifiers of the synthesis flows and the corresponding implementations ...
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
void xparse_utilization(const std::string &fn)
Parses device utilization.
std::string out_dir
name of the output directory
Classes for handling configuration files.
This class describes all classes used to represent a structural object.
static area_infoRef factory(const ParameterConstRef &Param)
Factory method.
Definition: area_info.cpp:52
std::string component_name
Name of the component.
#define PARAM_power_optimization
#define OUTPUT_LEVEL_VERY_PEDANTIC
verbose debugging print is performed.
unsigned int output_level
verbosity level of the class
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
xml_documentRef get_document()
Obtain the parsed document.
#define BASHBACKEND_DESIGN_DELAY
std::map< std::string, double > design_values
results from the synthesis
void create_sdc(const DesignParametersRef dp)
Creates the constraint file.
this class is used to manage the command-line or XML options.
#define LOAD_XVM(variable, node)
LOAD XML Value Macro. Set a variable starting from an XML value. Conversion is performed if needed...
Definition: xml_helper.hpp:65
#define PARAM_bash_sources_macro_list
superclass include
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
std::string GetCurrentPath()
Definition: fileIO.hpp:123
#define PARAM_clk_period
Generic device description.
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
void CopyStdout(const std::string &filename)
Copy a file to the standard output.
Definition: fileIO.hpp:106
#define OUTPUT_LEVEL_VERBOSE
verbose debugging print is performed.
#define DEBUG_LEVEL_VERBOSE
verbose debugging print is performed.
std::string relocate_compiler_path(const std::string &path, bool resolve_path=false)
Definition: fileIO.hpp:149
#define PARAM_clk_name
static time_infoRef factory(const ParameterConstRef Param)
Definition: time_info.cpp:110
#define PARAM_HDL_files
Abstract class for a generic synthesis tool.
#define PARAM_is_combinational
#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:56 for PandA-2024.02 by doxygen 1.8.13