61 #include <boost/algorithm/string/replace.hpp> 68 #define CSV_COL_SEPARATOR "," 70 #define SKIPPED_COLUMN \ 71 ("Loop_number")("bit_expr")("comp_expr")("const_readings")("div_expr")("mult_expr")("plusminus_expr")( \ 72 "memory_writings")("register_accesses")("memory_readings")("register_writing")("Backward_branches") 74 #define SKIPPING_MACRO(r, data, elem) skipping.insert(elem); 76 #define TF_NAME(r, data, elem) \ 78 name = name.substr(22); \ 79 name = name.substr(0, name.find(')')); \ 80 string_to_TF[name] = BOOST_PP_CAT(TF_, elem); 82 #define CO_NAME(r, data, elem) \ 84 name = name.substr(22); \ 85 name = name.substr(0, name.find(')')); \ 86 string_to_CO[name] = BOOST_PP_CAT(CO_, elem); 88 #define TOF_NAME(r, data, elem) \ 89 name = "TOF_" #elem; \ 90 name = name.substr(23); \ 91 name = name.substr(0, name.find(')')); \ 92 string_to_TOF[name] = BOOST_PP_CAT(TOF_, elem); 95 #include "latex_format_stat.data" 98 : column_alignment(
"c|"),
115 Translator::LatexColumnFormat::LatexColumnFormat::get_TF(
const std::string&
string)
128 Translator::LatexColumnFormat::LatexColumnFormat::get_CO(
const std::string&
string)
137 "String " +
string +
" is not a valid Comparison Operator");
142 Translator::LatexColumnFormat::LatexColumnFormat::GetTotalFormat(
const std::string&
string)
161 return fabsl(A) <= fabsl(B);
177 const std::string& file_name)
const 179 std::ofstream out(file_name.c_str());
180 THROW_ASSERT(out,
"Error in opening output file " + file_name);
182 for(
const auto&
row : results)
184 for(
const auto& column :
row.second)
186 column_labels.insert(column.first);
190 for(
const auto& column_label : column_labels)
195 for(
const auto&
row : results)
198 for(
const auto& column_label : column_labels)
200 const auto val_it =
row.second.find(column_label);
201 if(val_it !=
row.second.end())
219 const std::string& file_name)
const 221 std::ofstream out(file_name.c_str());
222 THROW_ASSERT(out,
"Error in opening output file " + file_name);
226 it_end = results.end();
227 for(it = results.begin(); it != it_end; ++it)
229 out <<
"#Benchmark " << it->first <<
"# ";
230 std::map<std::string, CustomOrderedSet<std::string>>::const_iterator it2, it2_end = tags.end();
231 for(it2 = tags.begin(); it2 != it2_end; ++it2)
233 out <<
"#" << it2->first <<
"# ";
234 const auto& bench_counters = it->second;
235 if(bench_counters.find(it2->first) != bench_counters.end())
237 const auto& cat_tags = it2->second;
238 const auto& cat_counters = bench_counters.find(it2->first)->second;
240 for(it4 = cat_tags.begin(); it4 != it4_end; ++it4)
242 out <<
"#" << *it4 <<
"# ";
243 if(cat_counters.find(*it4) != cat_counters.end())
245 out << cat_counters.find(*it4)->second;
266 for(
const auto&
row : results)
269 for(
auto const& column :
row.second)
283 std::map<std::string, CustomUnorderedMapStable<std::string, bool>> bold_cells;
286 std::string bambu_version;
289 std::string timestamp;
292 std::string bambu_arguments;
295 std::list<std::string> benchmarks;
297 if(
Param->isOption(OPT_experimental_setup_file))
308 const auto* child = GetPointer<const xml_element>(root_child);
327 for(
const auto& benchmark : child->get_children())
329 const auto* benchmark_xml = GetPointer<const xml_element>(benchmark);
330 if(not benchmark_xml)
339 catch(
const char* msg)
341 std::cerr << msg << std::endl;
342 THROW_ERROR(
"Error during parsing of experimental setup");
344 catch(
const std::string& msg)
346 std::cerr << msg << std::endl;
347 THROW_ERROR(
"Error during parsing of experimental setup");
349 catch(
const std::exception& ex)
351 std::cout <<
"Exception caught: " << ex.what() << std::endl;
352 THROW_ERROR(
"Error during parsing of experimental setup");
356 std::cerr <<
"unknown exception" << std::endl;
357 THROW_ERROR(
"Error during parsing of experimental setup");
364 if(
Param->isOption(OPT_latex_format_file))
373 std::list<LatexColumnFormat> latex_column_formats;
379 std::ofstream out(file_name.c_str());
384 for(
const auto& latex_column_format : latex_column_formats)
386 switch(latex_column_format.total_format)
388 case(LatexColumnFormat::TotalFormat::TOF_none):
390 case(LatexColumnFormat::TotalFormat::TOF_average):
393 long double total = 0;
394 for(
auto line : results)
396 if(
line.second.find(latex_column_format.source_name) !=
line.second.end())
398 total += std::stold(
line.second[latex_column_format.source_name]);
404 total /= results.size();
405 totals[latex_column_format.source_name] =
STR(total);
409 case(LatexColumnFormat::TotalFormat::TOF_overall):
412 long double total = 0;
413 for(
auto line : results)
415 if(
line.second.find(latex_column_format.source_name) !=
line.second.end())
417 total += std::stold(
line.second[latex_column_format.source_name]);
423 totals[latex_column_format.source_name] =
STR(total);
435 for(
const auto& column : latex_column_formats)
437 if(column.text_format == LatexColumnFormat::TF_number and column.precision != 0)
439 for(
auto&
line : results)
441 if(
line.second.find(column.source_name) !=
line.second.end())
443 std::stringstream modified_string_stream;
444 modified_string_stream.setf(std::ios::fixed, std::ios::floatfield);
445 modified_string_stream.precision(column.precision);
446 modified_string_stream << std::stold((
line.second)[column.source_name]);
447 (
line.second)[column.source_name] = modified_string_stream.str();
450 if(totals.find(column.source_name) != totals.end())
452 std::stringstream modified_string_stream;
453 modified_string_stream.setf(std::ios::fixed, std::ios::floatfield);
454 modified_string_stream.precision(column.precision);
455 modified_string_stream << std::stold(totals[column.source_name]);
456 totals[column.source_name] = modified_string_stream.str();
464 for(
auto const& column : latex_column_formats)
466 if(column.compared_columns.size())
469 for(
auto line : results)
475 column_to_be_compared_end = columns_to_be_compared.end();
476 for(column_to_be_compared = columns_to_be_compared.begin();
477 column_to_be_compared != column_to_be_compared_end; ++column_to_be_compared)
480 column.comparison_operator,
481 std::stold(
line.second[*column_to_be_compared])))
490 bold_cells[
line.first][column.source_name] =
true;
501 for(
const auto&
line : results)
504 std::string escaped_index =
line.first;
506 if(escaped_index.size() > data_width[(latex_column_formats.begin())->source_name])
508 data_width[(latex_column_formats.begin())->source_name] = escaped_index.size();
510 "---Set data width for column " + std::string((latex_column_formats.begin())->source_name) +
511 " to " +
STR(escaped_index.size()));
514 const auto& current_line =
line.second;
515 for(
const auto& current_tag : current_line)
518 if(current_tag.second.size() > data_width[current_tag.first])
520 data_width[current_tag.first] = current_tag.second.size();
522 "---New column width " +
STR(data_width[current_tag.first]));
528 for(
const auto& total : totals)
531 "-->Considering width total for column " + total.first +
": " +
STR(total.second.size()) +
" vs " +
532 STR(data_width[total.first]));
533 if(total.second.size() > data_width[total.first])
535 data_width[total.first] = total.second.size();
543 for(
auto& column : latex_column_formats)
545 if(column.text_format == LatexColumnFormat::TF_number)
548 "---" + column.column_name +
" " +
STR(data_width[column.source_name]) +
" vs " +
549 STR(max_column_width));
551 if(data_width[column.source_name] > max_column_width and column.text_format == LatexColumnFormat::TF_number)
553 column.text_format = LatexColumnFormat::TF_exponential;
560 for(
auto const& column : latex_column_formats)
562 if(column.text_format == LatexColumnFormat::TF_exponential)
564 for(
auto&
line : results)
566 auto& current_line =
line.second;
567 if(current_line.find(column.source_name) != current_line.end())
569 const auto value = current_line.find(column.source_name)->second;
573 if(totals.find(column.source_name) != totals.end())
575 const auto value = totals.find(column.source_name)->second;
582 for(
auto const& bold_line : bold_cells)
584 const auto& current_bold_line = bold_line.second;
586 for(bold_cell = current_bold_line.begin(); bold_cell != bold_cell_end; ++bold_cell)
588 std::string before_bold = results[bold_line.first][bold_cell->first];
589 results[bold_line.first][bold_cell->first] =
"\\textbf{" + before_bold +
"}";
595 for(
auto const& column : latex_column_formats)
597 if(column.text_format == LatexColumnFormat::TF_exponential or column.compared_columns.size())
599 data_width[column.source_name] = 0;
600 for(
auto const&
line : results)
602 if(
line.second.find(column.source_name) !=
line.second.end() and
603 line.second.find(column.source_name)->second.size() > data_width[column.source_name])
605 data_width[column.source_name] =
line.second.find(column.source_name)->second.size();
608 data_width[column.source_name] += 4;
610 else if(column.text_format == LatexColumnFormat::TF_number)
612 data_width[column.source_name] += 4;
614 "---New size of " + std::string(column.source_name) +
": " +
615 STR(data_width[column.source_name]));
618 for(
auto const& column : latex_column_formats)
620 if(column.column_name.size() > data_width[column.source_name])
622 data_width[column.source_name] = column.column_name.size();
630 if(bambu_version !=
"" or timestamp !=
"" or bambu_arguments !=
"")
635 out <<
" at " << timestamp;
637 if(bambu_version !=
"")
639 out <<
" with bambu " << bambu_version;
641 if(bambu_arguments !=
"")
643 out <<
" with arguments " << bambu_arguments;
647 out <<
"\\begin{tabular}{|";
648 for(
auto const& column : latex_column_formats)
650 out << column.column_alignment;
656 bool first_column =
true;
657 for(
const auto& column : latex_column_formats)
663 first_column =
false;
664 std::string column_name = column.column_name;
665 if(column_name.size() < data_width[column.source_name])
667 column_name.resize(data_width[column.source_name],
' ');
671 out <<
" \\\\" << std::endl;
672 out <<
"\\hline" << std::endl;
673 for(
auto const&
line : results)
677 for(
auto const& column : latex_column_formats)
680 "-->Printing column " + column.column_name +
" (" + column.source_name +
")");
685 if(column.text_format == LatexColumnFormat::TF_number or
686 column.text_format == LatexColumnFormat::TF_exponential)
695 else if(
line.second.find(column.source_name) !=
line.second.end())
697 value =
line.second.find(column.source_name)->second;
700 size_t numerical_delimiters_size = (column.text_format == LatexColumnFormat::TF_number or
701 column.text_format == LatexColumnFormat::TF_exponential) ?
704 if(value.size() + numerical_delimiters_size < data_width[column.source_name])
707 "---Resize to " +
STR(data_width[column.source_name]));
708 value.resize(data_width[column.source_name] - numerical_delimiters_size,
' ');
711 if(column.text_format == LatexColumnFormat::TF_number or
712 column.text_format == LatexColumnFormat::TF_exponential)
717 first_column =
false;
719 out <<
" \\\\" << std::endl;
726 for(
const auto& latex_column_format : latex_column_formats)
728 switch(latex_column_format.total_format)
730 case(LatexColumnFormat::TotalFormat::TOF_average):
731 case(LatexColumnFormat::TotalFormat::TOF_overall):
733 totals_to_be_written.insert(latex_column_format.total_format);
736 case(LatexColumnFormat::TotalFormat::TOF_none):
746 for(
const auto& line_to_be_written : totals_to_be_written)
748 out <<
"\\hline" << std::endl;
750 for(
const auto& column : latex_column_formats)
756 if(column.text_format == LatexColumnFormat::TF_number or
757 column.text_format == LatexColumnFormat::TF_exponential)
764 switch(line_to_be_written)
766 case(LatexColumnFormat::TotalFormat::TOF_average):
771 case(LatexColumnFormat::TotalFormat::TOF_overall):
776 case(LatexColumnFormat::TotalFormat::TOF_none):
787 else if(column.total_format == line_to_be_written and totals.find(column.source_name) != totals.end())
789 value = totals.find(column.source_name)->second;
792 size_t numerical_delimiters_size = (column.text_format == LatexColumnFormat::TF_number or
793 column.text_format == LatexColumnFormat::TF_exponential) ?
796 if(value.size() + numerical_delimiters_size < data_width[column.source_name])
799 "---Resize to " +
STR(data_width[column.source_name]));
800 value.resize(data_width[column.source_name] - numerical_delimiters_size,
' ');
803 if(column.text_format == LatexColumnFormat::TF_number or
804 column.text_format == LatexColumnFormat::TF_exponential)
808 first_column =
false;
810 out <<
" \\\\" << std::endl;
814 out <<
"\\hline" << std::endl;
815 out <<
"\\end{tabular}\n";
816 if(not benchmarks.empty())
818 out <<
"%Benchmarks:" << std::endl;
819 for(
const auto& benchmark : benchmarks)
821 out <<
"%" << benchmark << std::endl;
845 for(it =
input_data.begin(); it != it_end; ++it)
848 const auto& cat = it->second;
851 for(it2 = cat.begin(); it2 != it2_end; ++it2)
854 if(tags.find(it2->first) != tags.end())
857 for(it3 = tags.find(it2->first)->second.begin(); it3 != it3_end; ++it3)
860 if(keys.find(it2->first) != keys.end())
863 if(merge_data.find(it->first) != merge_data.end())
865 const auto& benchmark_merge_data = merge_data.find(it->first)->second;
866 if(benchmark_merge_data.find(it2->first) != benchmark_merge_data.end())
868 const auto& cat_merge_data = benchmark_merge_data.find(it2->first)->second;
869 if(cat_merge_data.find(*it3) != cat_merge_data.end())
871 output_data[it->first][it2->first][*it3] = cat_merge_data.find(*it3)->second;
873 "Replacing " + it->first +
"." + it2->first);
900 for(
const auto& iter : list)
902 const auto* feature = GetPointer<const xml_element>(iter);
907 if(feature->get_name() ==
"feature")
914 normalization[name] =
value;
916 "Read feature normalization" + name +
" " +
STR(value));
921 catch(
const char* msg)
923 std::cerr << msg << std::endl;
924 THROW_ERROR(
"Error during parsing of normalization file");
926 catch(
const std::string& msg)
928 std::cerr << msg << std::endl;
929 THROW_ERROR(
"Error during parsing of normalization file");
931 catch(
const std::exception& ex)
933 std::cout <<
"Exception caught: " << ex.what() << std::endl;
934 THROW_ERROR(
"Error during parsing of normalization file");
938 std::cerr <<
"unknown exception" << std::endl;
939 THROW_ERROR(
"Error during parsing of normalization file");
945 boost::algorithm::replace_all(ioString,
"_",
" ");
951 std::ostringstream
output;
952 output << std::setiosflags(std::ios::scientific);
953 output << std::setprecision(
Param->getOption<
int>(OPT_precision));
954 output << std::stold(input);
955 std::string
result = output.str();
956 std::string mantissa = result.substr(0, result.find(
'e'));
957 std::string exponent = result.substr(result.find(
'e') + 1);
958 std::string::size_type pos = 1;
959 while(exponent[pos] ==
'0')
963 if(pos != exponent.size())
965 if(exponent[0] ==
'-')
967 exponent = exponent[0] + exponent.substr(pos);
971 exponent = exponent.substr(pos);
978 return mantissa +
" \\cdot 10^{" + exponent +
"}";
982 size_t& max_column_size)
const 986 xml_element* root = parser->get_document()->get_root_node();
988 if(
CE_XVM(max_column_size, root))
993 xml_node::node_list::const_iterator child, child_end = list.end();
994 for(child = list.begin(); child != child_end; ++child)
996 const auto* child_element = GetPointer<const xml_element>(*child);
1003 "Child not known: " + child_element->get_name());
1008 xml_node::node_list::const_iterator field, field_end = fields.end();
1009 for(field = fields.begin(); field != field_end; ++field)
1011 const auto* field_element = GetPointer<const xml_element>(*field);
1020 latex_column_format.column_alignment = alignment;
1030 latex_column_format.source_name = source_name;
1035 latex_column_format.precision = boost::lexical_cast<std::streamsize>(precision);
1040 std::vector<std::string> splitted =
SplitString(values,
",");
1041 for(
const auto& column : splitted)
1043 latex_column_format.compared_columns.insert(column);
1047 const std::string comparison_operator =
1059 THROW_ERROR(
"Field " + field_element->get_name() +
" not supported");
1062 latex_column_formats.push_back(latex_column_format);
1066 "<--Read " +
STR(latex_column_formats.size()) +
" column format");
Class to compute evaluations about high-level synthesis.
#define STR_XML_latex_table_column
The node containing information about single column.
xml nodes used in file specifying latex table format
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define STR_XML_latex_table_text_format
The node containing type of text to be printed.
#define STR_XML_experimental_setup_timestamp
The node containing the timestamp of the data generation.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define NUM_CST_latex_table_max_column_width
The maximum width of a latex column.
File containing functions and utilities to support the printing of debug messagges.
#define PRINT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
#define GET_CLASS(obj)
Macro returning the actual type of an object.
void merge_pa(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomOrderedSet< std::string >> &keys, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &input_data, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &merge_data, CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &output_data) const
Merget profiling analysis.
const std::vector< std::string > SplitString(const std::string &input, const std::string &separators)
Function which splits a string into tokens.
static void replace_underscore(std::string &ioString)
Replace '_' with ' '.
#define STR_XML_latex_table_comparison
The node containing information about column comparison.
#define STR_XML_experimental_setup_bambu_arguments
The node containing the bambu argments.
#define STR_XML_latex_table_operator
The attribute containing information about type of comparison.
int debug_level
the debug level
void write_to_latex(std::map< std::string, CustomMap< std::string, std::string >> &results, const Parameters_FileFormat input_format, const std::string &file_name) const
Write data in latex table format.
CustomOrderedMap< T, U > CustomMap
#define COMPARISON_OPERATOR
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.
void read_column_formats(const XMLDomParserRef parser, std::list< LatexColumnFormat > &latex_column_formats, size_t &max_column_width) const
Read latex column format from xml.
#define STR_XML_experimental_setup_value
The attribute containing the actual value of a node.
redefinition of map to manage ordered/unordered structures
volatile int output[DIM_Y][DIM_X]
void add_escape(std::string &ioString, const std::string &to_be_escaped)
Header include.
#define STR_XML_latex_table_column_name
The node containing information about the name of the column.
void get_normalization(CustomUnorderedMap< std::string, long double > &normalization) const
Read normalization file.
#define STR(s)
Macro which performs a lexical_cast to a string.
void line(int x1, int y1, int x2, int y2, unsigned int color)
Auxiliary methods for manipulating string.
#define STR_XML_experimental_setup_bambu_version
The node containing the version of bambu.
std::string get_exponential_notation(const std::string &input) const
Return a number in latex exponential notation.
const ParameterConstRef Param
the set of parameters
#define THROW_UNREACHABLE(str_expr)
helper function used to specify that some points should never be reached
unsigned map[NUM_VERTICES]
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
std::string get_name() const
Get the name of this node.
#define NUM_CST_latex_table_number_precision
The default precision of the number.
#define STR_XML_latex_table_alignment
The node containing type of alignment.
refcount< XMLDomParser > XMLDomParserRef
redefinition of set to manage ordered/unordered structures
utility function used to read files.
void write_to_csv(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &results, const std::string &file_name) const
Write rtl data in csv format.
#define STR_XML_latex_table_source_name
The node containing the source name of this column.
This file collects some utility functions and macros.
void Exec()
Parse an XML document from a file.
std::list< xml_nodeRef > node_list
type for list of xml nodes
#define THROW_ERROR(str_expr)
helper function used to throw an error in a standard way
Translator(const ParameterConstRef Param)
Constructor.
#define TF_NAME(r, data, elem)
#define CSV_COL_SEPARATOR
coord_t input_data[TEST_COUNT][2]
void write_to_pa(const std::map< std::string, CustomOrderedSet< std::string >> &tags, const CustomUnorderedMap< std::string, CustomUnorderedMapStable< std::string, CustomUnorderedMapStable< std::string, long double >>> &results, const std::string &file_name) const
Write profiling analysis to pa.
#define STR_XML_latex_table_total
The node containing information about column total.
#define CO_NAME(r, data, elem)
#define STR_XML_experimental_setup_benchmarks
The node containing the list of benchmarks.
#define STR_XML_latex_table_root
The root node.
const char * default_latex_format_stat
xml nodes used in file specifying experimental setup
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
xml_documentRef get_document()
Obtain the parsed document.
Parameters_FileFormat
File formats.
#define STR_XML_latex_table_value
The attribute containing the value of the field.
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...
Dump information read already read from profiling file to other files.
Some macro used to interface with the XML library.
node_list const & get_children()
Obtain the list of child nodes.
absl::node_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMapStable
#define TOF_NAME(r, data, elem)
#define STR_XML_latex_table_precision
The node containg information about the precision of the number.
default value for latex tables
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...