PandA-2024.02
spider.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  */
33 
42 #include "SpiderParameter.hpp"
43 #include "design_flow_graph.hpp"
44 #include "design_flow_manager.hpp"
45 #include <filesystem>
46 #if HAVE_TECHNOLOGY_BUILT
47 #include "to_data_file_step.hpp"
49 #endif
50 #include "translator.hpp"
51 #if HAVE_TECHNOLOGY_BUILT
52 #include "technology_flow_step.hpp"
54 #endif
55 #include "custom_map.hpp"
56 #include "custom_set.hpp"
57 #include "data_xml_parser.hpp"
58 #include <fstream>
59 #include <iosfwd>
60 #include <string>
61 #if HAVE_TECHNOLOGY_BUILT
62 #include "generic_device.hpp"
63 #include "parse_technology.hpp"
64 #include "technology_manager.hpp"
65 #endif
66 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_
67 #include "exceptions.hpp"
68 #include "fileIO.hpp"
69 #include "string_manipulation.hpp"
70 
71 #define MAX_LENGTH 10000
72 
73 #define INIT(x, y) x.push_back(std::string(y))
74 
75 int main(int argc, char* argv[])
76 {
78  try
79  {
80  // ---------- Parameter parsing ------------ //
81  parameters = ParameterRef(new SpiderParameter(argv[0], argc, argv));
82  switch(parameters->Exec())
83  {
85  {
87  throw "Bad Parameters format";
88  }
89  case EXIT_SUCCESS:
90  {
91  if(not(parameters->getOption<bool>(OPT_no_clean)))
92  {
93  std::filesystem::remove_all(parameters->getOption<std::string>(OPT_output_temporary_directory));
94  }
95  return EXIT_SUCCESS;
96  }
97  case PARAMETER_PARSED:
98  {
99  exit_code = EXIT_FAILURE;
100  break;
101  }
102  default:
103  {
104  if(not(parameters->getOption<bool>(OPT_no_clean)))
105  {
106  std::filesystem::remove_all(parameters->getOption<std::string>(OPT_output_temporary_directory));
107  }
108  THROW_ERROR("Bad Parameters parsing");
109  }
110  }
111 #if !defined(NDEBUG)
112  auto debug_level = parameters->getOption<int>(OPT_debug_level);
113 #endif
114  Parameters_FileFormat input_format = parameters->getOption<Parameters_FileFormat>(OPT_input_format);
115  Parameters_FileFormat output_format = parameters->getOption<Parameters_FileFormat>(OPT_output_format);
116  switch(input_format)
117  {
119  {
120  switch(output_format)
121  {
123  {
124  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Input: XML - Output: TEX");
125  const auto input_files = parameters->getOption<CustomSet<std::string>>(OPT_input_file);
126  std::map<std::string, CustomMap<std::string, std::string>> results;
127  const DataXmlParserConstRef data_xml_parser(new DataXmlParser(parameters));
128  data_xml_parser->Parse(input_files, results);
129  TranslatorConstRef tr(new Translator(parameters));
130  tr->write_to_latex(results, Parameters_FileFormat::FF_XML,
131  parameters->getOption<std::string>(OPT_output_file));
132  break;
133  }
135 #if HAVE_FROM_AADL_ASN_BUILT
136  case(Parameters_FileFormat::FF_AADL):
137  case(Parameters_FileFormat::FF_ASN):
138 #endif
139 #if HAVE_FROM_C_BUILT
140  case(Parameters_FileFormat::FF_C):
141  case(Parameters_FileFormat::FF_OBJECTIVEC):
142  case(Parameters_FileFormat::FF_OBJECTIVECPP):
143  case(Parameters_FileFormat::FF_CPP):
144  case(Parameters_FileFormat::FF_FORTRAN):
145  case(Parameters_FileFormat::FF_LLVM):
146  case(Parameters_FileFormat::FF_LLVM_CPP):
147 #endif
149 #if HAVE_FROM_C_BUILT
150  case(Parameters_FileFormat::FF_RAW):
151 #endif
155  case(Parameters_FileFormat::FF_XML_BAMBU_RESULTS):
156 #if HAVE_HLS_BUILT
157  case(Parameters_FileFormat::FF_XML_CON):
158 #endif
162 #if HAVE_TECHNOLOGY_BUILT
163  case(Parameters_FileFormat::FF_XML_TARGET):
164  case(Parameters_FileFormat::FF_XML_TEC):
165 #endif
170  default:
171  THROW_ERROR("Not support combination input file - output file types");
172  }
173  break;
174  }
175  case(Parameters_FileFormat::FF_XML_BAMBU_RESULTS):
176  {
177  const auto input_files = parameters->getOption<CustomSet<std::string>>(OPT_input_file);
178  std::map<std::string, CustomMap<std::string, std::string>> results;
179  const DataXmlParserConstRef data_xml_parser(new DataXmlParser(parameters));
180  data_xml_parser->Parse(input_files, results);
181  TranslatorConstRef tr(new Translator(parameters));
182  switch(output_format)
183  {
185  {
186  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Input: xml - Output: tex");
187  tr->write_to_latex(results, input_format,
188  GetPath(parameters->getOption<std::string>(OPT_output_file)));
189  break;
190  }
192  {
193  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Input: XML - Output: CSV");
194  tr->write_to_csv(results, GetPath(parameters->getOption<std::string>(OPT_output_file)));
195  break;
196  }
197 #if HAVE_FROM_AADL_ASN_BUILT
198  case(Parameters_FileFormat::FF_AADL):
199  case(Parameters_FileFormat::FF_ASN):
200 #endif
201 #if HAVE_FROM_C_BUILT
202  case(Parameters_FileFormat::FF_C):
203  case(Parameters_FileFormat::FF_OBJECTIVEC):
204  case(Parameters_FileFormat::FF_OBJECTIVECPP):
205  case(Parameters_FileFormat::FF_CPP):
206  case(Parameters_FileFormat::FF_FORTRAN):
207  case(Parameters_FileFormat::FF_LLVM):
208  case(Parameters_FileFormat::FF_LLVM_CPP):
209 #endif
210 #if HAVE_FROM_C_BUILT
211  case(Parameters_FileFormat::FF_RAW):
212 #endif
217  case(Parameters_FileFormat::FF_XML_BAMBU_RESULTS):
218 #if HAVE_HLS_BUILT
219  case(Parameters_FileFormat::FF_XML_CON):
220 #endif
224 #if HAVE_TECHNOLOGY_BUILT
225  case(Parameters_FileFormat::FF_XML_TARGET):
226  case(Parameters_FileFormat::FF_XML_TEC):
227 #endif
232  default:
233  {
234  THROW_ERROR("Not supported combination input file - output file types");
235  }
236  }
237  break;
238  }
239 #if HAVE_TECHNOLOGY_BUILT
240  case(Parameters_FileFormat::FF_XML_TARGET):
241  {
242  auto output_level = parameters->getOption<int>(OPT_output_level);
243  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "-->Merging characterizations");
244  // Technology library manager
246 
248  generic_deviceRef device = generic_device::factory(parameters, TM);
249 
250  const DesignFlowManagerRef design_flow_manager(new DesignFlowManager(parameters));
251  const DesignFlowGraphConstRef design_flow_graph = design_flow_manager->CGetDesignFlowGraph();
252 
253  const DesignFlowStepFactoryConstRef technology_flow_step_factory(
254  new TechnologyFlowStepFactory(TM, device, design_flow_manager, parameters));
255  design_flow_manager->RegisterFactory(technology_flow_step_factory);
256 
257  const std::string load_technology_flow_signature =
259  const vertex load_technology_flow_step =
260  design_flow_manager->GetDesignFlowStep(load_technology_flow_signature);
261  const DesignFlowStepRef load_technology_design_flow_step =
262  load_technology_flow_step ?
263  design_flow_graph->CGetDesignFlowStepInfo(load_technology_flow_step)->design_flow_step :
264  GetPointer<const TechnologyFlowStepFactory>(technology_flow_step_factory)
265  ->CreateTechnologyFlowStep(TechnologyFlowStep_Type::LOAD_DEVICE_TECHNOLOGY);
266  design_flow_manager->AddStep(load_technology_design_flow_step);
267 
268  const std::string fix_technology_flow_signature =
270  const vertex fix_technology_flow_step =
271  design_flow_manager->GetDesignFlowStep(fix_technology_flow_signature);
272  const DesignFlowStepRef fix_technology_design_flow_step =
273  fix_technology_flow_step ?
274  design_flow_graph->CGetDesignFlowStepInfo(fix_technology_flow_step)->design_flow_step :
275  GetPointer<const TechnologyFlowStepFactory>(technology_flow_step_factory)
276  ->CreateTechnologyFlowStep(TechnologyFlowStep_Type::FIX_CHARACTERIZATION);
277  design_flow_manager->AddStep(fix_technology_design_flow_step);
278 
279  const std::string technology_flow_signature =
281  const vertex technology_flow_step = design_flow_manager->GetDesignFlowStep(technology_flow_signature);
282  const DesignFlowStepRef technology_design_flow_step =
283  technology_flow_step ?
284  design_flow_graph->CGetDesignFlowStepInfo(technology_flow_step)->design_flow_step :
285  GetPointer<const TechnologyFlowStepFactory>(technology_flow_step_factory)
286  ->CreateTechnologyFlowStep(TechnologyFlowStep_Type::WRITE_TECHNOLOGY);
287  design_flow_manager->AddStep(technology_design_flow_step);
288  design_flow_manager->Exec();
289  INDENT_OUT_MEX(OUTPUT_LEVEL_MINIMUM, output_level, "<--Merged characterizations");
290  break;
291  }
292  case(Parameters_FileFormat::FF_XML_TEC):
293  {
294 #if HAVE_CIRCUIT_BUILT
295  // Technology library manager
297 
299  generic_deviceRef device = generic_device::factory(parameters, TM);
300 
301  const DesignFlowManagerRef design_flow_manager(new DesignFlowManager(parameters));
302  const DesignFlowGraphConstRef design_flow_graph = design_flow_manager->CGetDesignFlowGraph();
303 
304  const DesignFlowStepFactoryConstRef technology_flow_step_factory(
305  new TechnologyFlowStepFactory(TM, device, design_flow_manager, parameters));
306  design_flow_manager->RegisterFactory(technology_flow_step_factory);
307 
308  const DesignFlowStepFactoryConstRef to_data_file_step_factory(
309  new ToDataFileStepFactory(device, design_flow_manager, parameters));
310  design_flow_manager->RegisterFactory(to_data_file_step_factory);
311 
312  const std::string to_data_file_step_signature =
313  ToDataFileStep::ComputeSignature(ToDataFileStep_Type::GENERATE_FU_LIST);
314  const vertex to_data_file_vertex = design_flow_manager->GetDesignFlowStep(to_data_file_step_signature);
315  const DesignFlowStepRef to_data_file_step =
316  to_data_file_vertex ? design_flow_graph->CGetDesignFlowStepInfo(to_data_file_vertex)->design_flow_step :
317  GetPointer<const ToDataFileStepFactory>(to_data_file_step_factory)
318  ->CreateStep(to_data_file_step_signature);
319  design_flow_manager->AddStep(to_data_file_step);
320  design_flow_manager->Exec();
321 #else
322  THROW_ERROR("Input technology file not supported.");
323 #endif
324 
325  break;
326  }
327 #endif
330 #if HAVE_FROM_AADL_ASN_BUILT
331  case(Parameters_FileFormat::FF_AADL):
332  case(Parameters_FileFormat::FF_ASN):
333 #endif
334 #if HAVE_FROM_C_BUILT
335  case(Parameters_FileFormat::FF_C):
336  case(Parameters_FileFormat::FF_OBJECTIVEC):
337  case(Parameters_FileFormat::FF_OBJECTIVECPP):
338  case(Parameters_FileFormat::FF_CPP):
339  case(Parameters_FileFormat::FF_FORTRAN):
340  case(Parameters_FileFormat::FF_LLVM):
341  case(Parameters_FileFormat::FF_LLVM_CPP):
342 #endif
343 #if HAVE_FROM_C_BUILT
344  case(Parameters_FileFormat::FF_RAW):
345 #endif
350 #if HAVE_HLS_BUILT
351  case(Parameters_FileFormat::FF_XML_CON):
352 #endif
359  default:
360  THROW_ERROR("Not supported input file type " + STR(static_cast<int>(input_format)));
361  }
362  }
363  catch(const char* str)
364  {
365  std::cerr << str << std::endl;
366  }
367  catch(const std::string& str)
368  {
369  std::cerr << str << std::endl;
370  }
371  catch(std::exception& inException)
372  {
373  PRINT_OUT_MEX(OUTPUT_LEVEL_NONE, 0, inException.what());
374  }
375  catch(...)
376  {
377  std::cerr << "Unknown error type" << std::endl;
378  }
379  if(!parameters->getOption<bool>(OPT_no_clean))
380  {
381  std::filesystem::remove_all(parameters->getOption<std::string>(OPT_output_temporary_directory));
382  }
383 
384  return exit_code;
385 }
Input function used to read the technology data structures.
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
int main(int argc, char *argv[])
Definition: spider.cpp:75
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
int exit_code
NOTE: this file must be included only by source code of the executable (i.e., the file with the main)...
Base class for data backend.
File containing functions and utilities to support the printing of debug messagges.
#define OUTPUT_LEVEL_NONE
no output print is performed.
(Input) XML benchhmarks to be execluded from training set
#define INDENT_OUT_MEX(outLevel, curOutLevel, mex)
(Output) XML weights of single operations computed
exceptions managed by PandA
Factory for to data file step.
Class specification of the manager of the technology library data structures.
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
static const std::string ComputeSignature(const ToDataFileStep_Type to_data_file_step_type)
Compute the signature of a to data file step.
redefinition of map to manage ordered/unordered structures
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
static generic_deviceRef factory(const ParameterConstRef &Param, const technology_managerRef &TM)
Factory method.
This class manages the technology library structures.
Classes to describe design flow graph.
#define PARAMETER_PARSED
An integer value to return if parameters have been right parsed.
Definition: Parameter.hpp:93
static const std::string ComputeSignature(const TechnologyFlowStep_Type technology_flow_step_type)
Compute the signature of a technology flow step.
redefinition of set to manage ordered/unordered structures
Factory for technology flow step.
refcount< Parameter > ParameterRef
Definition: Parameter.hpp:758
boost::graph_traits< graph >::vertex_descriptor vertex
vertex definition.
Definition: graph.hpp:1303
utility function used to read files.
(Input) XML storing symbolic symulation results
(Input) comma separated value
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
Wrapper of design_flow.
(Input) task graph for free
This class collects information about generic data.
Class to translate data from a format to another one.
Definition: translator.hpp:83
char tr[16206]
Definition: TR.h:1
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
Superclass include.
(Output) Latex table
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
char str[25]
Definition: fixedptc.c:8
Parameters_FileFormat
File formats.
Definition: Parameter.hpp:261
(Input/Output) XML symbolic weights
refcount< technology_manager > technology_managerRef
(Input) XML storing experimental setup
(Input) XML storing format of latex table to be produced
Dump information read already read from profiling file to other files.
Parse xml file containing generic data.
Generic device description.
#define PRINT_OUT_MEX(profLevel, curprofLevel, mex)
Base class for technology flow steps.
#define PARAMETER_NOTPARSED
Definition: Parameter.hpp:94

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