Add --only-cubic-sizes option to analyze-blocking-sizes tool

This commit is contained in:
Benoit Jacob 2015-03-12 13:16:33 -07:00
parent fd78874888
commit f2c3e2b10f

View File

@ -25,6 +25,9 @@ using namespace std;
const int default_precision = 4;
// see --only-cubic-sizes
bool only_cubic_sizes = false;
uint8_t log2_pot(size_t x) {
size_t l = 0;
while (x >>= 1) l++;
@ -130,6 +133,9 @@ struct inputfile_t
cerr << "offending line:" << endl << line << endl;
exit(1);
}
if (only_cubic_sizes && !size_triple_t(product_size).is_cubic()) {
continue;
}
inputfile_entry_t entry;
entry.product_size = uint16_t(product_size);
entry.pot_block_size = uint16_t(block_size);
@ -155,6 +161,9 @@ struct inputfile_t
cerr << "offending line:" << endl << line << endl;
exit(1);
}
if (only_cubic_sizes && !size_triple_t(product_size).is_cubic()) {
continue;
}
inputfile_entry_t entry;
entry.product_size = uint16_t(product_size);
entry.pot_block_size = 0;
@ -505,28 +514,23 @@ void print_partition(
struct action_t
{
virtual const char* invokation_name() const { abort(); return nullptr; }
virtual void run(int, char*[]) const { abort(); }
virtual void run(const vector<string>&) const { abort(); }
virtual ~action_t() {}
};
struct partition_action_t : action_t
{
virtual const char* invokation_name() const { return "partition"; }
virtual void run(int argc, char *argv[]) const
virtual const char* invokation_name() const override { return "partition"; }
virtual void run(const vector<string>& input_filenames) const override
{
vector<preprocessed_inputfile_t> preprocessed_inputfiles;
if (!argc) {
if (input_filenames.empty()) {
cerr << "The " << invokation_name() << " action needs a list of input files." << endl;
exit(1);
}
vector<string> inputfilenames;
for (int i = 0; i < argc; i++) {
inputfilenames.emplace_back(argv[i]);
}
for (auto it = inputfilenames.begin(); it != inputfilenames.end(); ++it) {
for (auto it = input_filenames.begin(); it != input_filenames.end(); ++it) {
inputfile_t inputfile(*it);
switch (inputfile.type) {
case inputfile_t::type_t::all_pot_sizes:
@ -610,7 +614,7 @@ struct evaluate_defaults_action_t : action_t
static bool lower_efficiency(const results_entry_t& e1, const results_entry_t& e2) {
return e1.default_efficiency < e2.default_efficiency;
}
virtual const char* invokation_name() const { return "evaluate-defaults"; }
virtual const char* invokation_name() const override { return "evaluate-defaults"; }
void show_usage_and_exit() const
{
cerr << "usage: " << invokation_name() << " default-sizes-data all-pot-sizes-data" << endl;
@ -618,13 +622,13 @@ struct evaluate_defaults_action_t : action_t
<< "performance measured over all POT sizes." << endl;
exit(1);
}
virtual void run(int argc, char *argv[]) const
virtual void run(const vector<string>& input_filenames) const override
{
if (argc != 2) {
if (input_filenames.size() != 2) {
show_usage_and_exit();
}
inputfile_t inputfile_default_sizes(argv[0]);
inputfile_t inputfile_all_pot_sizes(argv[1]);
inputfile_t inputfile_default_sizes(input_filenames[0]);
inputfile_t inputfile_all_pot_sizes(input_filenames[1]);
if (inputfile_default_sizes.type != inputfile_t::type_t::default_sizes) {
cerr << inputfile_default_sizes.filename << " is not an input file with default sizes." << endl;
show_usage_and_exit();
@ -719,7 +723,7 @@ struct evaluate_defaults_action_t : action_t
void show_usage_and_exit(int argc, char* argv[],
const vector<unique_ptr<action_t>>& available_actions)
{
cerr << "usage: " << argv[0] << " <action> <input files...>" << endl;
cerr << "usage: " << argv[0] << " <action> [options...] <input files...>" << endl;
cerr << "available actions:" << endl;
for (auto it = available_actions.begin(); it != available_actions.end(); ++it) {
cerr << " " << (*it)->invokation_name() << endl;
@ -737,21 +741,52 @@ int main(int argc, char* argv[])
available_actions.emplace_back(new partition_action_t);
available_actions.emplace_back(new evaluate_defaults_action_t);
auto action = available_actions.end();
vector<string> input_filenames;
action_t* action = nullptr;
if (argc < 2) {
show_usage_and_exit(argc, argv, available_actions);
}
for (auto it = available_actions.begin(); it != available_actions.end(); ++it) {
if (!strcmp(argv[1], (*it)->invokation_name())) {
action = it;
break;
for (int i = 1; i < argc; i++) {
bool arg_handled = false;
// Step 1. Try to match action invokation names.
for (auto it = available_actions.begin(); it != available_actions.end(); ++it) {
if (!strcmp(argv[i], (*it)->invokation_name())) {
if (!action) {
action = it->get();
arg_handled = true;
break;
} else {
cerr << "can't specify more than one action!" << endl;
show_usage_and_exit(argc, argv, available_actions);
}
}
}
if (arg_handled) {
continue;
}
// Step 2. Try to match option names.
if (argv[i][0] == '-') {
if (!strcmp(argv[i], "--only-cubic-sizes")) {
only_cubic_sizes = true;
arg_handled = true;
}
if (!arg_handled) {
cerr << "Unrecognized option: " << argv[i] << endl;
show_usage_and_exit(argc, argv, available_actions);
}
}
if (arg_handled) {
continue;
}
// Step 3. Default to interpreting args as input filenames.
input_filenames.emplace_back(argv[i]);
}
if (action == available_actions.end()) {
if (!action) {
show_usage_and_exit(argc, argv, available_actions);
}
(*action)->run(argc - 2, argv + 2);
action->run(input_filenames);
}