PandA-2024.02
SpiderParameter.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 "SpiderParameter.hpp"
44 
45 #include "constant_strings.hpp"
46 #include "dbgPrintHelper.hpp"
47 #include "fileIO.hpp"
48 #include "string_manipulation.hpp"
49 #include "translator.hpp"
50 #include "utility.hpp"
51 
52 #include "config_HAVE_TECHNOLOGY_BUILT.hpp"
53 #include "config_RELEASE.hpp"
54 
55 #include <getopt.h>
56 #include <string>
57 #include <vector>
58 
60 #define INPUT_OPT_ACCURACY 256
61 #define INPUT_OPT_BENCHMARK_BOUNDS (1 + INPUT_OPT_ACCURACY)
62 #define INPUT_OPT_COMPONENTS (1 + INPUT_OPT_BENCHMARK_BOUNDS)
63 #define INPUT_OPT_CROSS_VALIDATION (1 + INPUT_OPT_COMPONENTS)
64 #define INPUT_OPT_MINIMUM_SIGNIFICANCE (1 + INPUT_OPT_CROSS_VALIDATION)
65 #define INPUT_OPT_NORMALIZATION_SEQUENCES (1 + INPUT_OPT_MINIMUM_SIGNIFICANCE)
66 #define INPUT_OPT_NORMALIZATION_WEIGHT_FILE (1 + INPUT_OPT_NORMALIZATION_SEQUENCES)
67 #define INPUT_OPT_PREDICTION_INTERVAL_VALUE (1 + INPUT_OPT_NORMALIZATION_WEIGHT_FILE)
68 #define INPUT_OPT_SEQUENCE_LENGTH (1 + INPUT_OPT_PREDICTION_INTERVAL_VALUE)
69 #define INPUT_OPT_SURVIVING_BENCHMARKS (1 + INPUT_OPT_SEQUENCE_LENGTH)
70 #define TOOL_OPT_BASE (1 + INPUT_OPT_SURVIVING_BENCHMARKS)
71 
72 void SpiderParameter::PrintHelp(std::ostream& os) const
73 {
74  os << "Usage: " << getOption<std::string>(OPT_program_name) << " [options] input_file [input_files] output_file"
75  << std::endl;
76  os << std::endl;
77  os << "Options: \n"
78  << "\n";
80  os << "\n"
81  << " Input options:\n"
82  << " --sequence_length Specify the length of the sequences\n"
83  << " --sequence-length Specify the length of the sequences\n"
84  << " --surviving-benchmarks=<number> Remove all but <number> benchmarks from the input (default=300)\n"
85  << " --analysis-level=<value> Set the analysis level for instructions sequences analysis (default=0): "
86  "\n"
87  << " 0: no analysis is performed;\n"
88  << " 1: analysis is performed at application level. Only aggregate "
89  "information of all benchmarks \n"
90  << " will be saved on XML file;\n"
91  << " 2: analysis is performed at application level. Aggregate information "
92  "of all benchmarks and\n"
93  << " data of each single benchmark will be saved on XML file;\n"
94  << " 3: analysis is performed at function level. XML file will be "
95  "completely generated(file contents:\n"
96  << " aggregate information of all benchmarks, data of each single "
97  "benchmark and data of each \n"
98  << " function analyzed); \n"
99  << "\n";
101  os << "\n"
102  << " Input options:\n"
103  << " --input-format, -I <extension> Format of the input file\n"
104  << " --normalize, -n <input_file> Input file storing the normalizing information\n"
105  << " --processing-element, -p <pe> Specify of which processing element model weights are\n"
106  << " --accuracy=<level> Accuracy level while evaluating similar benchmarks (default=0)\n"
107  << " --benchmark-bounds=<number,number>\n"
108  << " Set the bound of average execution cycles of benchmarks used for "
109  "training.\n"
110  << "\n"
111  << " Output options:\n"
112  << " --output-format, -O <extension> Format of the output file\n"
113  << "\n"
114  << " Possible formats are:\n"
115  << " csv comma separated values\n"
116  << " rtl.csv comma separated values of rtl sequences\n"
117  << " tex latex table\n"
118  << " tree.csv comma separated values of tree sequences\n"
119  << " xml xml files\n"
120  << "\n"
121  << " Other options:\n"
122  << " --normalization-sequences Sequences of transformations to be applied before building performance "
123  "model; sequences can be composed of:\n"
124  << " 'L' - remove pseudo-linear dependent benchmarks\n"
125  << " 'M' - remove smallest and largest benchmarks\n"
126  << " 'R' - remove smallest benchmarks\n"
127  << " 'S' - normalize benchmarks\n";
128 #if HAVE_TECHNOLOGY_BUILT
129  os << " --components=<value> The components to be inserted in the list of functional units to be "
130  "characterized (default=all).\n";
131 #endif
132 }
133 
134 void SpiderParameter::PrintProgramName(std::ostream& os) const
135 {
136  os << std::endl;
137  os << "********************************************************************************" << std::endl;
138  os << " ____ _ _" << std::endl;
139  os << " / ___| _ __ (_) __| | ___ _ __" << std::endl;
140  os << R"( \___ \| '_ \| |/ _` |/ _ \ '__|)" << std::endl;
141  os << " ___) | |_) | | (_| | __/ |" << std::endl;
142  os << " |____/| .__/|_|\\__,_|\\___|_|" << std::endl;
143  os << " |_|" << std::endl;
144  os << std::endl;
145  os << "********************************************************************************" << std::endl;
146 }
147 
148 SpiderParameter::SpiderParameter(const std::string& _program_name, int _argc, char** const _argv)
149  : Parameter(_program_name, _argc, _argv)
150 {
151  SetDefaults();
152 }
153 
155 {
157 
159  int option_index;
160 
161  const char* const short_options = COMMON_SHORT_OPTIONS_STRING "I:O:p:";
162 
163  const struct option long_options[] = {
165  {"accuracy", required_argument, nullptr, INPUT_OPT_ACCURACY},
166  {"benchmark-bounds", required_argument, nullptr, INPUT_OPT_BENCHMARK_BOUNDS},
167 #if HAVE_TECHNOLOGY_BUILT
168  {"components", required_argument, nullptr, INPUT_OPT_COMPONENTS},
169 #endif
170  {"input-format", required_argument, nullptr, 'I'},
171  {"normalization-sequences", required_argument, nullptr, INPUT_OPT_NORMALIZATION_SEQUENCES},
172  {"normalize", required_argument, nullptr, INPUT_OPT_NORMALIZATION_WEIGHT_FILE},
173  {"output-format", required_argument, nullptr, 'O'},
174  {"prediction-interval-value", required_argument, nullptr, INPUT_OPT_PREDICTION_INTERVAL_VALUE},
175  {"processing-element", required_argument, nullptr, 'p'},
176  {"sequence-length", required_argument, nullptr, INPUT_OPT_SEQUENCE_LENGTH},
177  {"surviving-benchmarks", required_argument, nullptr, INPUT_OPT_SURVIVING_BENCHMARKS},
178  {nullptr, 0, nullptr, 0}
179  };
180  if(argc == 1) // Panda called without arguments
181  {
182  PrintUsage(std::cerr);
183  return EXIT_SUCCESS;
184  }
185  while(true)
186  {
187  int next_option = getopt_long(argc, argv, short_options, long_options, &option_index);
188 
189  // no more options are available
190  if(next_option == -1)
191  {
192  break;
193  }
194 
195  switch(next_option)
196  {
197  case 'I':
198  {
199  setOption(OPT_input_format, optarg);
200  break;
201  }
202  case 'O':
203  {
204  setOption(OPT_output_format, optarg);
205  break;
206  }
207  case 'p':
208  {
209  setOption(OPT_processing_element_type, optarg);
210  break;
211  }
212  case INPUT_OPT_ACCURACY:
213  {
214  setOption(OPT_accuracy, optarg);
215  break;
216  }
218  {
219  std::string to_be_splitted(optarg);
220  std::vector<std::string> splitted = SplitString(to_be_splitted, ",");
221  if(splitted.size() != 2)
222  {
223  THROW_ERROR("Error in argument of --benchmark-bounds: " + std::string(optarg));
224  }
225  setOption(OPT_min_bound, splitted[0]);
226  setOption(OPT_max_bound, splitted[1]);
227  break;
228  }
230  {
231  setOption(OPT_component_name, optarg);
232  break;
233  }
235  {
236  setOption(OPT_cross_validation, optarg);
237  break;
238  }
240  {
241  setOption(OPT_normalization_sequences, optarg);
242  break;
243  }
245  {
246  setOption(OPT_normalization_file, optarg);
247  break;
248  }
250  {
251  setOption(OPT_sequence_length, optarg);
252  break;
253  }
255  {
256  setOption(OPT_surviving_benchmarks, optarg);
257  break;
258  }
259  default:
260  {
261  bool exit_success = false;
262  bool res = ManageDefaultOptions(next_option, optarg, exit_success);
263  if(exit_success)
264  {
265  return EXIT_SUCCESS;
266  }
267  else if(res)
268  {
269  std::cerr << optarg << std::endl;
270  return PARAMETER_NOTPARSED;
271  }
272  }
273  }
274  }
275 
276  THROW_ASSERT(argc >= optind + 2, "Wrong number of files");
277  while(optind + 1 < argc)
278  {
279  std::string input_file;
280  if(isOption(OPT_input_file))
281  {
282  input_file = getOption<std::string>(OPT_input_file) + STR_CST_string_separator;
283  }
284  setOption(OPT_input_file, input_file + GetPath(argv[optind]));
285  optind++;
286  }
287  setOption(OPT_output_file, GetPath(argv[optind]));
288 
289  CheckParameters();
290 
291  return PARAMETER_PARSED;
292 }
293 
295 {
296  setOption(OPT_accuracy, 0);
297 #if HAVE_TECHNOLOGY_BUILT
298  setOption(OPT_component_name, "all");
299 #endif
300  setOption(OPT_cross_validation, 1);
302 #if RELEASE
303  setOption(OPT_debug_level, DEBUG_LEVEL_NONE);
304 #else
305  setOption(OPT_debug_level, DEBUG_LEVEL_MINIMUM);
306 #endif
307  setOption(OPT_max_bound, INFINITE_LONG_DOUBLE);
308  setOption(OPT_min_bound, 0);
309  setOption(OPT_normalization_sequences, "S");
310  setOption(OPT_output_directory, GetPath("."));
312 #if RELEASE
313  setOption(OPT_output_level, OUTPUT_LEVEL_NONE);
314 #else
315  setOption(OPT_output_level, OUTPUT_LEVEL_MINIMUM);
316 #endif
317  setOption(OPT_precision, 3);
318  setOption(OPT_processing_element_type, "ARM");
319  setOption(OPT_sequence_length, 2);
320  setOption(OPT_surviving_benchmarks, NUM_CST_surviving_benchmarks);
321 }
322 
324 {
326  if(!isOption(OPT_input_format))
327  {
329  const auto input_files = getOption<CustomSet<std::string>>(OPT_input_file);
330  for(auto input_file : input_files)
331  {
332  input_file = GetPath(input_file);
333  temp = GetFileFormat(input_file, true);
334  switch(temp)
335  {
337  setOption(OPT_latex_format_file, input_file);
338  break;
340  setOption(OPT_skip_rows, input_file);
341  break;
342 #if HAVE_TECHNOLOGY_BUILT
343  case(Parameters_FileFormat::FF_XML_TARGET):
344  {
345  if(input_format != Parameters_FileFormat::FF_XML_TEC)
346  {
347  input_format = temp;
348  }
349  break;
350  }
351 #endif
353  {
354  setOption(OPT_experimental_setup_file, input_file);
355  break;
356  }
357 #if HAVE_FROM_AADL_ASN_BUILT
358  case(Parameters_FileFormat::FF_AADL):
359  case(Parameters_FileFormat::FF_ASN):
360 #endif
361 #if HAVE_FROM_C_BUILT
362  case(Parameters_FileFormat::FF_C):
363  case(Parameters_FileFormat::FF_OBJECTIVEC):
364  case(Parameters_FileFormat::FF_OBJECTIVECPP):
365  case(Parameters_FileFormat::FF_CPP):
366  case(Parameters_FileFormat::FF_FORTRAN):
367  case(Parameters_FileFormat::FF_LLVM):
368  case(Parameters_FileFormat::FF_LLVM_CPP):
369 #endif
371 #if HAVE_FROM_C_BUILT
372  case(Parameters_FileFormat::FF_RAW):
373 #endif
378  case(Parameters_FileFormat::FF_XML_BAMBU_RESULTS):
379 #if HAVE_HLS_BUILT
380  case(Parameters_FileFormat::FF_XML_CON):
381 #endif
383 #if HAVE_TECHNOLOGY_BUILT
384  case(Parameters_FileFormat::FF_XML_TEC):
385 #endif
390  default:
391  input_format = temp;
392  break;
393  }
394  }
395  setOption(OPT_input_format, static_cast<int>(input_format));
396  }
397  else
398  {
399  Parameters_FileFormat input_format = GetFileFormat(getOption<std::string>(OPT_input_format), true);
400  setOption(OPT_input_format, static_cast<int>(input_format));
401  }
402  if(!isOption(OPT_output_format))
403  {
404  Parameters_FileFormat output_format = GetFileFormat(getOption<std::string>(OPT_output_file), false);
405  setOption(OPT_output_format, static_cast<int>(output_format));
406  }
407  else
408  {
409  Parameters_FileFormat output_format = GetFileFormat(getOption<std::string>(OPT_output_format), false);
410  setOption(OPT_output_format, static_cast<int>(output_format));
411  }
412 #if HAVE_TECHNOLOGY_BUILT
413  for(const auto& input_file : getOption<CustomSet<std::string>>(OPT_input_file))
414  {
415  if(GetFileFormat(input_file, true) == Parameters_FileFormat::FF_XML_TEC)
416  {
417  setOption(OPT_technology_file, (isOption(OPT_technology_file) ?
418  (getOption<std::string>(OPT_technology_file) + STR_CST_string_separator) :
419  "") +
420  input_file);
421  }
422  else if(GetFileFormat(input_file, true) == Parameters_FileFormat::FF_XML_TARGET)
423  {
424  if(isOption(OPT_target_device_file) &&
425  getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_XML_TEC)
426  {
427  THROW_ERROR("Multiple target device file: " + input_file + " " +
428  getOption<std::string>(OPT_target_device_file));
429  }
430  setOption(OPT_target_device_file,
431  (isOption(OPT_target_device_file) ?
432  (getOption<std::string>(OPT_target_device_file) + STR_CST_string_separator) :
433  "") +
434  input_file);
435  }
436  }
437  if(getOption<Parameters_FileFormat>(OPT_input_format) == Parameters_FileFormat::FF_XML_TEC)
438  {
439  if(!isOption(OPT_target_device_file))
440  {
441  THROW_ERROR("Target device file not specified");
442  }
443  }
444 #endif
445 
446 #ifndef NDEBUG
447  Parameters_FileFormat input_format = getOption<Parameters_FileFormat>(OPT_input_format);
448  Parameters_FileFormat output_format = getOption<Parameters_FileFormat>(OPT_output_format);
449  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Input format is " + STR(static_cast<int>(input_format)));
450  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "Output format is " + STR(static_cast<int>(output_format)));
451 #endif
452 }
#define INPUT_OPT_NORMALIZATION_WEIGHT_FILE
#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;.
int exit_code
NOTE: this file must be included only by source code of the executable (i.e., the file with the main)...
void setOption(const std::string &name, const G value)
Sets the value of an option.
Definition: Parameter.hpp:516
SpiderParameter(const std::string &program_name, int argc, char **const argv)
Constructor.
File containing functions and utilities to support the printing of debug messagges.
#define OUTPUT_LEVEL_NONE
no output print is performed.
#define STR_CST_string_separator
The character used to separate concatenated string.
Definition: utility.hpp:61
char **const argv
The input parameters;.
Definition: Parameter.hpp:311
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
#define COMMON_SHORT_OPTIONS_STRING
define the default tool short option string
Definition: Parameter.hpp:201
(Input) XML benchhmarks to be execluded from training set
void PrintProgramName(std::ostream &os) const override
Print the name of the program to be included in the header.
(Output) XML weights of single operations computed
#define INPUT_OPT_CROSS_VALIDATION
int Exec() override
Execute parameter parsing.
#define OUTPUT_LEVEL_MINIMUM
minimum debugging print is performed.
#define INPUT_OPT_NORMALIZATION_SEQUENCES
void PrintUsage(std::ostream &os) const
Print the usage of this tool = PrintHeader() + PrintHelp()
Definition: Parameter.cpp:392
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
#define INPUT_OPT_COMPONENTS
Parameters_FileFormat GetFileFormat(const std::filesystem::path &file, bool check_cml_root_node=false) const
Return the file format given the file name or the extension.
Definition: Parameter.cpp:938
#define INPUT_OPT_ACCURACY
PARAMETERS STUFF ***********************///.
#define INPUT_OPT_SURVIVING_BENCHMARKS
#define PARAMETER_PARSED
An integer value to return if parameters have been right parsed.
Definition: Parameter.hpp:93
virtual void CheckParameters()=0
Checks the compatibility among the different parameters and determines the implications.
Definition: Parameter.cpp:139
utility function used to read files.
(Input) XML storing symbolic symulation results
This file collects some utility functions and macros.
#define DEBUG_LEVEL_NONE
no debugging print is performed.
(Input) comma separated value
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Definition: exceptions.hpp:263
(Input) task graph for free
#define INFINITE_LONG_DOUBLE
long double representing infinite
Definition: utility.hpp:79
#define COMMON_LONG_OPTIONS
define default TOOL long options
Definition: Parameter.hpp:204
#define NUM_CST_surviving_benchmarks
The number of surviving benchmarks.
int debug_level
debug level
Definition: Parameter.hpp:329
void CheckParameters() override
Check the compatibility among the different parameters and compute implicated parameters.
void PrintHelp(std::ostream &os) const override
Print the usage of this tool.
std::string GetPath(std::filesystem::path path)
Definition: fileIO.hpp:140
#define INPUT_OPT_BENCHMARK_BOUNDS
(Output) Latex table
Parameters_FileFormat
File formats.
Definition: Parameter.hpp:261
(Input/Output) XML symbolic weights
(Input) XML storing experimental setup
(Input) XML storing format of latex table to be produced
void SetDefaults() override
Sets the default values for the spider tool.
void getOption(const std::string &name, G &variable) const
Returns the value of an option.
Definition: Parameter.hpp:457
#define INPUT_OPT_SEQUENCE_LENGTH
constant strings
Dump information read already read from profiling file to other files.
void PrintGeneralOptionsUsage(std::ostream &os) const
Print the usage of the general common options.
Definition: Parameter.cpp:1105
bool isOption(const std::string &name) const
Tests if an option has been stored.
Definition: Parameter.hpp:548
#define INPUT_OPT_PREDICTION_INTERVAL_VALUE
void PrintOutputOptionsUsage(std::ostream &os) const
Print the usage of the output common options.
Definition: Parameter.cpp:1123
int argc
The number of input paramters.
Definition: Parameter.hpp:308
bool ManageDefaultOptions(int next_option, char *optarg_param, bool &exit_success)
Manage default options (common to all tools)
Definition: Parameter.cpp:398
#define DEBUG_LEVEL_MINIMUM
minimum debugging print is performed.
#define PARAMETER_NOTPARSED
Definition: Parameter.hpp:94
#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