PandA-2024.02
generic_device.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) 2023-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  */
39 #include "generic_device.hpp"
40 
41 #include "Parameter.hpp"
42 #include "config_PANDA_DATA_INSTALLDIR.hpp"
43 #include "constant_strings.hpp"
44 #include "dbgPrintHelper.hpp"
45 #include "exceptions.hpp"
46 #include "fileIO.hpp"
47 #include "polixml.hpp"
48 #include "string_manipulation.hpp" // for GET_CLASS
49 #include "technology_manager.hpp"
50 #include "xml_dom_parser.hpp"
51 #include "xml_helper.hpp"
52 #include <filesystem>
53 
55  : Param(_Param), TM(_TM), debug_level(_Param->get_class_debug_level(GET_CLASS(*this)))
56 {
57 }
58 
60 
62 {
63  return generic_deviceRef(new generic_device(param, TM));
64 }
65 
67 {
68  const xml_node::node_list& c_list = node->get_children();
69  for(const auto& n : c_list)
70  {
71  if(n->get_name() == "device")
72  {
73  const auto* dev_xml = GetPointer<const xml_element>(n);
74  xload_device_parameters(dev_xml);
75  }
76  }
77 
78  for(const auto& n : c_list)
79  {
80  // The second part of the condition is false when we are generating the list of functional units in spider
81  if(n->get_name() == "technology" and
82  (not Param->isOption(OPT_input_format) or
83  Param->getOption<Parameters_FileFormat>(OPT_input_format) != Parameters_FileFormat::FF_XML_TEC))
84  {
85  const auto* tech_xml = GetPointer<const xml_element>(n);
86  TM->xload(tech_xml);
87  }
88  }
89 }
90 
92 {
93  xml_element* tmRoot = nodeRoot->add_child_element("device");
94 
95  THROW_ASSERT(has_parameter("vendor"), "vendor value is missing");
96  xml_element* vendor_el = tmRoot->add_child_element("vendor");
97  auto vendor = get_parameter<std::string>("vendor");
98  WRITE_XNVM2("value", vendor, vendor_el);
99 
100  THROW_ASSERT(has_parameter("family"), "family value is missing");
101  xml_element* family_el = tmRoot->add_child_element("family");
102  auto family = get_parameter<std::string>("family");
103  WRITE_XNVM2("value", family, family_el);
104 
105  THROW_ASSERT(has_parameter("model"), "model value is missing");
106  xml_element* model_el = tmRoot->add_child_element("model");
107  auto model = get_parameter<std::string>("model");
108  WRITE_XNVM2("value", model, model_el);
109 
110  THROW_ASSERT(has_parameter("package"), "package value is missing");
111  xml_element* package_el = tmRoot->add_child_element("package");
112  auto package = get_parameter<std::string>("package");
113  WRITE_XNVM2("value", package, package_el);
114 
115  THROW_ASSERT(has_parameter("speed_grade"), "speed_grade value is missing");
116  xml_element* speed_grade_el = tmRoot->add_child_element("speed_grade");
117  auto speed_grade = get_parameter<std::string>("speed_grade");
118  WRITE_XNVM2("value", speed_grade, speed_grade_el);
119 
120  for(auto p = parameters.begin(); p != parameters.end(); ++p)
121  {
122  if(p->first == "vendor" || p->first == "family" || p->first == "model" || p->first == "package" ||
123  p->first == "speed_grade" || p->first == "clock_period")
124  {
125  continue;
126  }
127  xml_element* elRoot = tmRoot->add_child_element(p->first);
128  WRITE_XNVM2("value", p->second, elRoot);
129  }
130 }
131 
133 {
135  std::map<std::string, std::string> default_device_data;
137  default_device_data["xc4vlx100-10ff1513"] = "xc4vlx100-10ff1513.data";
138  default_device_data["xc5vlx50-3ff1153"] = "xc5vlx50-3ff1153.data";
139  default_device_data["xc5vlx110t-1ff1136"] = "xc5vlx110t-1ff1136.data";
140  default_device_data["xc5vlx330t-2ff1738"] = "xc5vlx330t-2ff1738.data";
141  default_device_data["xc6vlx240t-1ff1156"] = "xc6vlx240t-1ff1156.data";
142  default_device_data["xc7z020-1clg484"] = "xc7z020-1clg484.data";
143  default_device_data["xc7z020-1clg484-VVD"] = "xc7z020-1clg484-VVD.data";
144  default_device_data["xc7z045-2ffg900-VVD"] = "xc7z045-2ffg900-VVD.data";
145  default_device_data["xc7z020-1clg484-YOSYS-VVD"] = "xc7z020-1clg484-YOSYS-VVD.data";
146  default_device_data["xc7vx485t-2ffg1761-VVD"] = "xc7vx485t-2ffg1761-VVD.data";
147  default_device_data["xc7vx690t-3ffg1930-VVD"] = "xc7vx690t-3ffg1930-VVD.data";
148  default_device_data["xc7vx330t-1ffg1157"] = "xc7vx330t-1ffg1157.data";
149  default_device_data["xc7a100t-1csg324-VVD"] = "xc7a100t-1csg324-VVD.data";
150  default_device_data["xcku060-3ffva1156-VVD"] = "xcku060-3ffva1156-VVD.data";
151  default_device_data["xcu280-2Lfsvh2892-VVD"] = "xcu280-2Lfsvh2892-VVD.data";
152  default_device_data["xcu55c-2Lfsvh2892-VVD"] = "xcu55c-2Lfsvh2892-VVD.data";
153 
154  default_device_data["EP2C70F896C6"] = "EP2C70F896C6.data";
155  default_device_data["EP2C70F896C6-R"] = "EP2C70F896C6-R.data";
156  default_device_data["5CSEMA5F31C6"] = "5CSEMA5F31C6.data";
157  default_device_data["EP4SGX530KH40C2"] = "EP4SGX530KH40C2.data";
158  default_device_data["5SGXEA7N2F45C1"] = "5SGXEA7N2F45C1.data";
159  default_device_data["LFE335EA8FN484C"] = "LFE335EA8FN484C.data";
160  default_device_data["LFE5UM85F8BG756C"] = "LFE5UM85F8BG756C.data";
161  default_device_data["LFE5U85F8BG756C"] = "LFE5U85F8BG756C.data";
162  default_device_data["nx1h35S"] = "nx1h35S.data";
163  default_device_data["nx1h140tsp"] = "nx1h140tsp.data";
164  default_device_data["nx2h540tsc"] = "nx2h540tsc.data";
165 
166  default_device_data["nangate45"] = "nangate45.data";
167  default_device_data["asap7-BC"] = "asap7-BC.data";
168  default_device_data["asap7-TC"] = "asap7-TC.data";
169  default_device_data["asap7-WC"] = "asap7-WC.data";
170 
171  auto output_level = Param->getOption<unsigned int>(OPT_output_level);
172 
173  try
174  {
175  PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, "Available devices:");
176  for(auto d = default_device_data.begin(); d != default_device_data.end(); ++d)
177  {
178  PRINT_OUT_MEX(OUTPUT_LEVEL_VERBOSE, output_level, " - " + d->first);
179  }
180 
181  const CustomSet<XMLDomParserRef> parsers = [&]() -> CustomSet<XMLDomParserRef> {
183  if(Param->isOption(OPT_target_device_file))
184  {
185  const auto file_devices = Param->getOption<std::list<std::string>>(OPT_target_device_file);
186  for(const auto& file_device : file_devices)
187  {
188  PRINT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "Imported user data from file " + file_device);
189  ret.insert(XMLDomParserRef(new XMLDomParser(GetPath(file_device))));
190  }
191  }
192  else
193  {
194  auto device_string = Param->getOption<std::string>(OPT_device_string);
195 
196  if(default_device_data.find(device_string) != default_device_data.end())
197  {
198  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "---Loading " + device_string);
199  ret.insert(XMLDomParserRef(
200  new XMLDomParser(relocate_compiler_path(PANDA_DATA_INSTALLDIR "/panda/technology/", true) +
201  default_device_data[device_string])));
202  }
203  else
204  {
205  THROW_ERROR("Target device not supported: " + device_string);
206  }
207  }
208  return ret;
209  }();
210 
211  for(const auto& parser : parsers)
212  {
213  parser->Exec();
214  if(parser and *parser)
215  {
216  const xml_element* node = parser->get_document()->get_root_node(); // deleted by DomParser.
217  xload(node);
218  }
219  }
220 
221  return;
222  }
223  catch(const char* msg)
224  {
225  std::cerr << msg << std::endl;
226  }
227  catch(const std::string& msg)
228  {
229  std::cerr << msg << std::endl;
230  }
231  catch(const std::exception& ex)
232  {
233  std::cout << "Exception caught: " << ex.what() << std::endl;
234  }
235  catch(...)
236  {
237  std::cerr << "unknown exception" << std::endl;
238  }
239  THROW_ERROR("Error during XML parsing of device files");
240 }
241 
243 {
244  const xml_node::node_list& t_list = dev_xml->get_children();
245  for(const auto& t : t_list)
246  {
247  const auto* t_elem = GetPointer<const xml_element>(t);
248  if(!t_elem)
249  {
250  continue;
251  }
252 
253  std::string value;
254  LOAD_XVM(value, t_elem);
255 
256  bool is_bash_var = false;
257  if(CE_XVM(is_bash_var, t_elem))
258  {
259  LOAD_XVM(is_bash_var, t_elem);
260  }
261  if(is_bash_var)
262  {
263  vars[t_elem->get_name()] = value;
264  }
265  else
266  {
267  parameters[t_elem->get_name()] = value;
268  }
269  if(t_elem->get_name() == "model")
270  {
271  const_cast<Parameter*>(Param.get())->setOption("device_name", value);
272  }
273  if(t_elem->get_name() == "speed_grade")
274  {
275  const_cast<Parameter*>(Param.get())->setOption("device_speed", value);
276  }
277  if(t_elem->get_name() == "package")
278  {
279  const_cast<Parameter*>(Param.get())->setOption("device_package", value);
280  }
281  }
282  std::string device_string = Param->getOption<std::string>("device_name") +
283  Param->getOption<std::string>("device_speed") +
284  Param->getOption<std::string>("device_package");
285  const_cast<Parameter*>(Param.get())->setOption(OPT_device_string, device_string);
286 }
287 
289 {
290  return TM;
291 }
#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;.
TVMValue param[3]
File containing functions and utilities to support the printing of debug messagges.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
void xload(const xml_element *node)
XML load specialization.
int debug_level
The debug level.
exceptions managed by PandA
#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 load_devices()
Load device characteristics.
virtual ~generic_device()
Destructor of the class.
Class specification of the manager of the technology library data structures.
refcount< generic_device > generic_deviceRef
refcount definition for the class
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
Auxiliary methods for manipulating string.
std::map< std::string, std::string > vars
map between bash variables and values
static generic_deviceRef factory(const ParameterConstRef &Param, const technology_managerRef &TM)
Factory method.
const ParameterConstRef Param
class containing all the parameters
refcount< XMLDomParser > XMLDomParserRef
XML DOM parser.
XML DOM parser.
utility function used to read files.
void xwrite(xml_element *node)
XML write specialization.
std::list< xml_nodeRef > node_list
type for list of xml nodes
Definition: xml_node.hpp:90
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
const technology_managerRef TM
technology manager
std::map< std::string, std::string > parameters
Map of the technology parameter.
#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
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
bool has_parameter(const std::string &key) const
Check if parameter exist.
technology_managerRef get_technology_manager() const
Returns the technology manager.
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
T * get() const
Definition: refcount.hpp:169
Parameters_FileFormat
File formats.
Definition: Parameter.hpp:261
generic_device(const ParameterConstRef &Param, const technology_managerRef &TM)
Constructor of the class.
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
constant strings
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
Definition: xml_node.hpp:310
Generic device description.
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
#define OUTPUT_LEVEL_VERBOSE
verbose debugging print is performed.
std::string relocate_compiler_path(const std::string &path, bool resolve_path=false)
Definition: fileIO.hpp:149
xml_element * add_child_element(const std::string &name)
Add a child element to this node.
Definition: xml_node.cpp:54
void xload_device_parameters(const xml_element *dev_xml)
XML load of device parameters.
#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:55 for PandA-2024.02 by doxygen 1.8.13