From d73ccd717e000d0a91293db2b24c402e49c907ff Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Fri, 13 Mar 2015 10:36:01 -0700 Subject: Add support for dumping blocking sizes tables --- bench/analyze-blocking-sizes.cpp | 75 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'bench/analyze-blocking-sizes.cpp') diff --git a/bench/analyze-blocking-sizes.cpp b/bench/analyze-blocking-sizes.cpp index cf8236a82..c133df599 100644 --- a/bench/analyze-blocking-sizes.cpp +++ b/bench/analyze-blocking-sizes.cpp @@ -28,6 +28,9 @@ const int default_precision = 4; // see --only-cubic-sizes bool only_cubic_sizes = false; +// see --dump-tables +bool dump_tables = false; + uint8_t log2_pot(size_t x) { size_t l = 0; while (x >>= 1) l++; @@ -318,14 +321,74 @@ float efficiency_of_subset( efficiency_this_product_size = max(efficiency_this_product_size, efficiency_this_entry); } efficiency = min(efficiency, efficiency_this_product_size); - first_entry_index_with_this_product_size = entry_index; - product_size = first_file.entries[entry_index].product_size; + if (entry_index < num_entries) { + first_entry_index_with_this_product_size = entry_index; + product_size = first_file.entries[entry_index].product_size; + } } } return efficiency; } +void dump_table_for_subset( + const vector& preprocessed_inputfiles, + const vector& subset) +{ + const preprocessed_inputfile_t& first_file = preprocessed_inputfiles[subset[0]]; + const size_t num_entries = first_file.entries.size(); + size_t entry_index = 0; + size_t first_entry_index_with_this_product_size = 0; + uint16_t product_size = first_file.entries[0].product_size; + size_t i = 0; + size_triple_t min_product_size(first_file.entries.front().product_size); + size_triple_t max_product_size(first_file.entries.back().product_size); + if (!min_product_size.is_cubic() || !max_product_size.is_cubic()) { + abort(); + } + if (only_cubic_sizes) { + cout << "/* Warning: generated with --only-cubic-sizes ! */" << endl; + } + cout << "struct optimal_block_sizes_table {" << endl; + cout << " static const size_t min_size = " << min_product_size.k << ";" << endl; + cout << " static const size_t max_size = " << max_product_size.k << ";" << endl; + cout << " static const uint16_t* table() {" << endl; + cout << " static const uint16_t data[] = {"; + while (entry_index < num_entries) { + ++entry_index; + if (entry_index == num_entries || + first_file.entries[entry_index].product_size != product_size) + { + float best_efficiency_this_product_size = 0.0f; + uint16_t best_block_size_this_product_size = 0; + for (size_t e = first_entry_index_with_this_product_size; e < entry_index; e++) { + float efficiency_this_entry = 1.0f; + for (auto i = subset.begin(); i != subset.end(); ++i) { + efficiency_this_entry = min(efficiency_this_entry, preprocessed_inputfiles[*i].entries[e].efficiency); + } + if (efficiency_this_entry > best_efficiency_this_product_size) { + best_efficiency_this_product_size = efficiency_this_entry; + best_block_size_this_product_size = first_file.entries[e].block_size; + } + } + if ((i++) % 8) { + cout << ", "; + } else { + cout << endl << " "; + } + cout << "0x" << hex << best_block_size_this_product_size << dec; + if (entry_index < num_entries) { + first_entry_index_with_this_product_size = entry_index; + product_size = first_file.entries[entry_index].product_size; + } + } + } + cout << endl << " };" << endl; + cout << " return data;" << endl; + cout << " }" << endl; + cout << "};" << endl; +} + float efficiency_of_partition( const vector& preprocessed_inputfiles, const vector>& partition) @@ -507,6 +570,10 @@ void print_partition( for (auto file = subset->begin(); file != subset->end(); ++file) { cout << " " << preprocessed_inputfiles[*file].filename << endl; } + if (dump_tables) { + cout << " Table:" << endl; + dump_table_for_subset(preprocessed_inputfiles, *subset); + } } cout << endl; } @@ -772,6 +839,10 @@ int main(int argc, char* argv[]) only_cubic_sizes = true; arg_handled = true; } + if (!strcmp(argv[i], "--dump-tables")) { + dump_tables = true; + arg_handled = true; + } if (!arg_handled) { cerr << "Unrecognized option: " << argv[i] << endl; show_usage_and_exit(argc, argv, available_actions); -- cgit v1.2.3